fvtt-rolemaster-frp/module/sheets/actors/rmss_player_sheet_config.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-07-26 09:20:48 +02:00
export default class RMSSActorSheetConfig extends FormApplication {
constructor(selectOptions, character) {
super();
this.selectOptions = selectOptions;
this.character = character;
}
static get defaultOptions() {
2024-07-26 12:51:32 +02:00
return foundry.utils.mergeObject(super.defaultOptions, {
2024-07-26 09:20:48 +02:00
classes: ["form"],
popOut: true,
2024-07-26 12:51:32 +02:00
template: "systems/fvtt-rolemaster-frp/templates/sheets/actors/apps/actor-settings.html"
2024-07-26 09:20:48 +02:00
});
}
getData() {
// Send data to the template
return {
selectOptions: this.selectOptions
};
}
activateListeners(html) {
super.activateListeners(html);
}
async _updateObject(event, formData) {
console.log("Deleting Old Skill Categories.");
for (const item of this.character.items) {
if (item.type === "skill_category") {
item.delete();
}
}
const pack = game.packs.get(formData.selectOptions);
const skillCategoryData = await pack.getIndex();
console.log("Importing New Skill Categories.");
for (const sc of skillCategoryData) {
const newitem = await pack.getDocument(sc._id);
let newDocuments = [];
if (newitem.type === "skill_category") {
console.log(newitem);
newDocuments.push(newitem);
}
if (newDocuments.length > 0) {
await Item.createDocuments(newDocuments, {parent: this.character});
}
}
}
}