Split Items by category in actor sheet (pc & npc) for better readability

Fix actor fromData
This commit is contained in:
Vlyan
2021-02-13 14:31:12 +01:00
parent db5d5b62aa
commit cb0696f662
9 changed files with 87 additions and 38 deletions

View File

@@ -32,14 +32,17 @@ export class BaseSheetL5r5e extends ActorSheet {
return a.name.localeCompare(b.name);
});
// Split techniques by types
// Split Techniques by types
sheetData.data.splitTechniquesList = this._splitTechniques(sheetData);
// Split Items by types
sheetData.data.splitItemsList = this._splitItems(sheetData);
return sheetData;
}
/**
* Split techniques by types for better readability
* Split Techniques by types for better readability
* @private
*/
_splitTechniques(sheetData) {
@@ -73,12 +76,32 @@ export class BaseSheetL5r5e extends ActorSheet {
sheetData.data.techniques["mastery_ability"] = out["mastery_ability"].length === 0;
// Always display "school_ability", but display "mastery_ability" only if rank >= 5
if (sheetData.data.identity.school_rank < 5 && out["mastery_ability"].length === 0) {
if (sheetData.data.identity?.school_rank < 5 && out["mastery_ability"].length === 0) {
delete out["mastery_ability"];
}
return out;
}
/**
* Split Items by types for better readability
* @private
*/
_splitItems(sheetData) {
const out = {
weapon: [],
armor: [],
item: [],
};
sheetData.items.forEach((item) => {
if (["item", "armor", "weapon"].includes(item.type)) {
out[item.type].push(item);
}
});
return out;
}
/**
* Return a light sheet if in "limited" state
* @override
@@ -311,12 +334,22 @@ export class BaseSheetL5r5e extends ActorSheet {
item.data.data.bought_at_rank = this.actor.data.data.identity.school_rank;
}
// If technique, select the current type
if (item.data.type === "technique") {
const techType = $(event.currentTarget).data("tech-type");
if ([...CONFIG.l5r5e.techniques, ...CONFIG.l5r5e.techniques_school].includes(techType)) {
item.data.data.technique_type = techType;
item.data.img = `${CONFIG.l5r5e.paths.assets}/icons/techs/${techType}.svg`;
switch (item.data.type) {
case "armor": // no break
case "weapon":
if ($(event.currentTarget).data("item-eqquiped")) {
item.data.data.equipped = true;
}
break;
case "technique": {
// If technique, select the current type
const techType = $(event.currentTarget).data("tech-type");
if ([...CONFIG.l5r5e.techniques, ...CONFIG.l5r5e.techniques_school].includes(techType)) {
item.data.data.technique_type = techType;
item.data.img = `${CONFIG.l5r5e.paths.assets}/icons/techs/${techType}.svg`;
}
break;
}
}

View File

@@ -23,7 +23,7 @@ export class RollnKeepDialog extends FormApplication {
/**
* The current Roll
* @param {Roll} roll
* @param {RollL5r5e} roll
*/
roll = null;

View File

@@ -336,10 +336,16 @@ export class RollL5r5e extends Roll {
roll.l5r5e = duplicate(data.l5r5e);
// get real Actor object
if (data.l5r5e.actor && !(data.l5r5e.actor instanceof game.l5r5e.ActorL5r5e)) {
const actor = game.actors.get(data.l5r5e.actor.id);
if (actor) {
roll.l5r5e.actor = actor;
if (data.l5r5e.actor) {
if (data.l5r5e.actor instanceof game.l5r5e.ActorL5r5e) {
// duplicate break the object, relink it
roll.l5r5e.actor = data.l5r5e.actor;
} else {
// only id, get the object
const actor = game.actors.get(data.l5r5e.actor.id);
if (actor) {
roll.l5r5e.actor = actor;
}
}
}