some factorisation

This commit is contained in:
Vlyan
2020-12-16 19:05:18 +01:00
parent d9d9f43423
commit 182219337d
30 changed files with 269 additions and 393 deletions

View File

@@ -8,11 +8,6 @@ export class BaseSheetL5r5e extends ActorSheet {
getData() {
const sheetData = super.getData();
this._prepareItems(sheetData);
const techniques = sheetData.items.filter((item) => item.type === "technique");
sheetData.data.techniques.list = techniques;
sheetData.data.stances = CONFIG.L5r5e.stances;
return sheetData;
@@ -27,55 +22,6 @@ export class BaseSheetL5r5e extends ActorSheet {
return this.object.update(formData);
}
/**
* Prepare item data to be displayed in the actor sheet.
* @param sheetData Data of the actor been displayed in the sheet.
*/
_prepareItems(sheetData) {
for (let item of sheetData.items) {
switch (item.type) {
case "weapon":
item.isWeapon = true;
item.isEquipment = true;
break;
case "armor":
item.isArmor = true;
item.isEquipment = true;
break;
case "technique":
item.isTechnique = true;
break;
case "quality":
item.isQuality = true;
break;
case "advancement":
item.isAdvancement = true;
break;
case "advantage":
item.isAdvantage = true;
break;
case "disadvantage":
item.isDisadvantage = true;
break;
default:
item.isEquipment = true;
break;
}
}
}
/**
* TODO
*/
_prepareTechniques() {}
/**
* Subscribe to events from the sheet.
* @param html HTML content of the sheet.
@@ -83,107 +29,82 @@ export class BaseSheetL5r5e extends ActorSheet {
activateListeners(html) {
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) {
return;
}
// *** Items ***
// Update Inventory Item
html.find(".item-edit").on("click", (ev) => {
const li = $(ev.currentTarget).parents(".item");
const itemId = li.data("itemId");
const item = this.actor.getOwnedItem(itemId);
item.sheet.render(true);
});
// Delete Inventory Item
html.find(".item-delete").on("click", (ev) => {
const li = $(ev.currentTarget).parents(".item");
this.actor.deleteOwnedItem(li.data("itemId"));
});
// *** Techniques ***
html.find(".technique-add").on("click", (ev) => {
this._createTechnique();
});
html.find(".technique-delete").on("click", (ev) => {
const li = $(ev.currentTarget).parents(".technique");
const techniqueId = li.data("techniqueId");
console.log("Remove technique" + techniqueId + " clicked");
this.actor.deleteOwnedItem(techniqueId);
});
html.find(".technique-edit").on("click", (ev) => {
const li = $(ev.currentTarget).parents(".technique");
const techniqueId = li.data("techniqueId");
const technique = this.actor.getOwnedItem(techniqueId);
technique.sheet.render(true);
});
// *** Skills ***
html.find(".skill-name").on("click", (ev) => {
const li = $(ev.currentTarget).parents(".skill");
new game.l5r5e.DicePickerDialog({ skillId: li.data("skill"), actor: this.actor }).render(true);
});
// *** Everything below here is only needed if the sheet is editable ***
if (!this.options.editable) {
return;
}
// *** Items / Inventory ***
html.find(".item-edit").on("click", (ev) => {
this._editSubItem(ev, "item");
});
html.find(".item-delete").on("click", (ev) => {
this._deleteSubItem(ev, "item");
});
// *** Techniques ***
html.find(".technique-add").on("click", (ev) => {
this._addSubItem({
name: game.i18n.localize("l5r5e.techniques.title_new"),
type: "technique",
});
});
html.find(".technique-edit").on("click", (ev) => {
this._editSubItem(ev, "technique");
});
html.find(".technique-delete").on("click", (ev) => {
this._deleteSubItem(ev, "technique");
});
// *** Advancement ***
html.find(".advancement-add").on("click", (ev) => {
this._createAdvancement();
this._addSubItem({
name: game.i18n.localize("l5r5e.xp.advancements"),
type: "advancement",
});
});
html.find(".advancement-edit").on("click", (ev) => {
const li = $(ev.currentTarget).parents(".advancement");
const advancementId = li.data("advancementId");
const advancement = this.actor.getOwnedItem(advancementId);
advancement.sheet.render(true);
this._editSubItem(ev, "advancement");
});
html.find(".advancement-delete").on("click", (ev) => {
const li = $(ev.currentTarget).parents(".advancement");
this.actor.deleteOwnedItem(li.data("advancementId"));
this._deleteSubItem(ev, "advancement");
});
}
/**
* Creates a new feat for the character and shows a window to edit it.
* Add a generic item with sub type
* @private
*/
async _createTechnique() {
const data = {
name: game.i18n.localize("l5r5e.techniques.title_new"),
type: "technique",
};
async _addSubItem(data) {
const created = await this.actor.createEmbeddedEntity("OwnedItem", data);
const technique = this.actor.getOwnedItem(created._id);
// Default values
//technique.rank = 1;
//technique.xp_used = 0;
technique.sheet.render(true);
return technique;
const item = this.actor.getOwnedItem(created._id);
item.sheet.render(true);
return item;
}
/**
* Creates a new feat for the character and shows a window to edit it.
* Edit a generic item with sub type
* @private
*/
async _createAdvancement() {
const data = {
name: game.i18n.localize("l5r5e.xp.acquisitions"),
type: "advancement",
};
const created = await this.actor.createEmbeddedEntity("OwnedItem", data);
const acquisition = this.actor.getOwnedItem(created._id);
async _editSubItem(ev, type) {
const li = $(ev.currentTarget).parents("." + type);
const itemId = li.data(type + "Id");
const item = this.actor.getOwnedItem(itemId);
item.sheet.render(true);
}
acquisition.sheet.render(true);
// Default values
//acquisition.rank = 1;
//acquisition.xp_used = 0;
return acquisition;
/**
* Delete a generic item with sub type
* @private
*/
async _deleteSubItem(ev, type) {
const li = $(ev.currentTarget).parents("." + type);
return this.actor.deleteOwnedItem(li.data(type + "Id"));
}
}