Better import and various stuff

This commit is contained in:
2024-08-10 09:48:43 +02:00
parent 2b1da44f3a
commit aad90144fe
22 changed files with 97 additions and 75 deletions

View File

@ -11,6 +11,7 @@ export default class RMSSToolsSCImporter extends FormApplication {
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["form"],
width: 520,
popOut: true,
title: "Import Skill Categories",
template: "systems/fvtt-rolemaster-frp/templates/sheets/apps/app_skill_category_importer.html"
@ -29,34 +30,38 @@ export default class RMSSToolsSCImporter extends FormApplication {
}
async _updateObject(event, formData) {
//console.log("Update ", event, formData);
await this.character.setFlag("world", "importing", true);
let itemType = event.submitter.value;
let toDelete = [];
for (const item of this.character.items) {
if (item.type === itemType) {
toDelete.push(item.id);
}
if (itemType == "skill_category" && item.type === "skill") {
toDelete.push(item.id); // Delete also skill when re-importing skill categories.
}
}
this.character.deleteEmbeddedDocuments("Item", toDelete);
await this.character.deleteEmbeddedDocuments("Item", toDelete);
let comp = (itemType == "skill") ? formData.selectOptionsSkills : formData.selectOptionsCategories;
const pack = game.packs.get(comp);
const skillCategoryData = await pack.getIndex();
console.log("Importing New Skills/Skill Categories.");
let newDocuments = [];
let gameSystem = RFRPUtility.getGameSystem();
for (const sc of skillCategoryData) {
const newitem = await pack.getDocument(sc._id);
let newDocuments = [];
const newitem = await pack.getDocument(sc._id);
if (newitem.type === itemType && (newitem.system.game_system === "common" || newitem.system.game_system === gameSystem)) {
//console.log(newitem);
newDocuments.push(newitem);
}
if (newDocuments.length > 0) {
await Item.createDocuments(newDocuments, {parent: this.character});
}
}
if (newDocuments.length > 0) {
await Item.createDocuments(newDocuments, {parent: this.character});
}
await this.character.setFlag("world", "importing", false);
}
}