From cb0696f6626befbef722215e5c186139266b5b75 Mon Sep 17 00:00:00 2001 From: Vlyan Date: Sat, 13 Feb 2021 14:31:12 +0100 Subject: [PATCH] Split Items by category in actor sheet (pc & npc) for better readability Fix actor fromData --- CHANGELOG.md | 3 +- system/scripts/actors/base-sheet.js | 51 ++++++++++++++++---- system/scripts/dice/roll-n-keep-dialog.js | 2 +- system/scripts/dice/roll.js | 14 ++++-- system/templates/actors/character-sheet.html | 5 +- system/templates/actors/npc-sheet.html | 12 +++-- system/templates/items/armor/armors.html | 4 +- system/templates/items/item/items.html | 30 ++++++------ system/templates/items/weapon/weapons.html | 4 +- 9 files changed, 87 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bfea2a..6647ed2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,8 @@ - Added confirm dialog on item's deletion (Hold "ctrl" on the click, if you want to bypass it) - Added "Sleep" & "Scene End" buttons in "GM ToolBox" (old "difficulty" box) - Added an option to reverse the token's bar on fatigue (thanks to Jzrzmy), and colorize in red the strife bar if compromise -- Split techniques in actor sheet for better readability +- Split Techniques & Items by category in actor sheet (pc & npc) for better readability +- Armor & Weapon added in the conflict tab now set the "eqquiped" props by default ## 1.1.2 - One Compendium to bring them all - Added compendiums (Thanks to Stéfano Fara for the English version !) Partial for French as PoW and CR are not translated yet diff --git a/system/scripts/actors/base-sheet.js b/system/scripts/actors/base-sheet.js index 6dc1830..1d6a2c8 100644 --- a/system/scripts/actors/base-sheet.js +++ b/system/scripts/actors/base-sheet.js @@ -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; } } diff --git a/system/scripts/dice/roll-n-keep-dialog.js b/system/scripts/dice/roll-n-keep-dialog.js index d22fc42..fad6b9e 100644 --- a/system/scripts/dice/roll-n-keep-dialog.js +++ b/system/scripts/dice/roll-n-keep-dialog.js @@ -23,7 +23,7 @@ export class RollnKeepDialog extends FormApplication { /** * The current Roll - * @param {Roll} roll + * @param {RollL5r5e} roll */ roll = null; diff --git a/system/scripts/dice/roll.js b/system/scripts/dice/roll.js index a2d6b47..d3eefe8 100644 --- a/system/scripts/dice/roll.js +++ b/system/scripts/dice/roll.js @@ -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; + } } } diff --git a/system/templates/actors/character-sheet.html b/system/templates/actors/character-sheet.html index 9b1a521..ab3d658 100644 --- a/system/templates/actors/character-sheet.html +++ b/system/templates/actors/character-sheet.html @@ -62,7 +62,10 @@ - {{> 'systems/l5r5e/templates/items/item/items.html' }} +
+ {{localize 'l5r5e.equipment' }} + {{> 'systems/l5r5e/templates/items/item/items.html' }} +
{{!-- Experience Tab --}} diff --git a/system/templates/actors/npc-sheet.html b/system/templates/actors/npc-sheet.html index 23b81fe..1475828 100644 --- a/system/templates/actors/npc-sheet.html +++ b/system/templates/actors/npc-sheet.html @@ -28,9 +28,15 @@ {{> 'systems/l5r5e/templates/actors/npc/narrative.html' }}
- {{> 'systems/l5r5e/templates/items/weapon/weapons.html' }} - {{> 'systems/l5r5e/templates/items/armor/armors.html' }} - {{> 'systems/l5r5e/templates/items/item/items.html' }} +
+ {{localize 'l5r5e.armors.equipped' }} + {{> 'systems/l5r5e/templates/items/weapon/weapons.html' }} + {{> 'systems/l5r5e/templates/items/armor/armors.html' }} +
+
+ {{localize 'l5r5e.equipment' }} + {{> 'systems/l5r5e/templates/items/item/items.html' }} +
{{> 'systems/l5r5e/templates/actors/npc/techniques.html' }} diff --git a/system/templates/items/armor/armors.html b/system/templates/items/armor/armors.html index ceaba3b..b70f821 100644 --- a/system/templates/items/armor/armors.html +++ b/system/templates/items/armor/armors.html @@ -1,8 +1,8 @@
- {{ localize 'l5r5e.armors.title' }} + {{localize 'l5r5e.armors.title'}} {{#if editable}} - + {{/if}}
    diff --git a/system/templates/items/item/items.html b/system/templates/items/item/items.html index 395bbb2..041fe50 100644 --- a/system/templates/items/item/items.html +++ b/system/templates/items/item/items.html @@ -1,15 +1,15 @@ -
    - - {{ localize 'l5r5e.equipment' }} - {{#if editable}} - - {{/if}} - -
      - {{#each actor.items as |item id|}} - {{#ifCond '["item", "armor", "weapon"]' 'includes' item.type}} - {{> 'systems/l5r5e/templates/items/item/item-entry.html' item=item id=id editable=../editable }} - {{/ifCond}} - {{/each}} -
    -
    \ No newline at end of file +{{#each data.splitItemsList as |cat type|}} +
    + + {{localize (localize 'l5r5e.{type}s.title' type=type) }} + {{#if ../editable}} + + {{/if}} + +
      + {{#each cat as |item id|}} + {{> 'systems/l5r5e/templates/items/item/item-entry.html' item=item id=id editable=../../editable }} + {{/each}} +
    +
    +{{/each}} \ No newline at end of file diff --git a/system/templates/items/weapon/weapons.html b/system/templates/items/weapon/weapons.html index 08b80c5..287664d 100644 --- a/system/templates/items/weapon/weapons.html +++ b/system/templates/items/weapon/weapons.html @@ -1,8 +1,8 @@
    - {{ localize 'l5r5e.weapons.title' }} + {{localize 'l5r5e.weapons.title'}} {{#if editable}} - + {{/if}}