From 8a22706ad2500f1d992047db6c34a6d2e178b32c Mon Sep 17 00:00:00 2001 From: Vlyan Date: Tue, 9 Feb 2021 12:16:15 +0100 Subject: [PATCH] Split techniques in actor sheet for better readability --- CHANGELOG.md | 1 + system/scripts/actors/base-sheet.js | 48 ++++++++++++++++++- system/scripts/actors/character-sheet.js | 5 -- .../actors/character/techniques.html | 28 +++++------ system/templates/actors/npc/techniques.html | 30 +++++++++--- 5 files changed, 85 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5abebc..9150ca6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - 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 ## 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 a11b508..917311a 100644 --- a/system/scripts/actors/base-sheet.js +++ b/system/scripts/actors/base-sheet.js @@ -27,9 +27,46 @@ export class BaseSheetL5r5e extends ActorSheet { sheetData.data.stances = CONFIG.l5r5e.stances; sheetData.data.techniquesList = CONFIG.l5r5e.techniques; + // Sort Items by name + sheetData.items.sort((a, b) => { + return a.name.localeCompare(b.name); + }); + + // Split techniques by types + sheetData.data.splitTechniquesList = this._splitTechniques(sheetData); + return sheetData; } + /** + * Split techniques by types for better readability + * @private + */ + _splitTechniques(sheetData) { + const out = {}; + + // Build the list order + [...CONFIG.l5r5e.techniques, ...CONFIG.l5r5e.techniques_school].forEach((tech) => { + out[tech] = []; + }); + + // Add tech the character knows + sheetData.items.forEach((item) => { + if (item.type === "technique") { + out[item.data.technique_type].push(item); + } + }); + + // Remove unused techs + Object.keys(out).forEach((tech) => { + if (out[tech].length < 1 && !sheetData.data.techniques[tech]) { + delete out[tech]; + } + }); + + return out; + } + /** * Return a light sheet if in "limited" state * @override @@ -252,7 +289,7 @@ export class BaseSheetL5r5e extends ActorSheet { const created = await this.actor.createEmbeddedEntity("OwnedItem", { name: game.i18n.localize(titles[type]), type: type, - img: "icons/svg/mystery-man.svg", + img: `${CONFIG.l5r5e.paths.assets}icons/items/${type}.svg`, }); const item = this.actor.getOwnedItem(created._id); @@ -262,6 +299,15 @@ 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.includes(techType)) { + item.data.data.technique_type = techType; + item.data.img = `${CONFIG.l5r5e.paths.assets}/icons/techs/${techType}.svg`; + } + } + item.sheet.render(true); } diff --git a/system/scripts/actors/character-sheet.js b/system/scripts/actors/character-sheet.js index 1102833..a265074 100644 --- a/system/scripts/actors/character-sheet.js +++ b/system/scripts/actors/character-sheet.js @@ -49,11 +49,6 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e { // Split Money sheetData.data.money = this._zeniToMoney(this.actor.data.data.zeni); - // Sort Items by name - sheetData.items.sort((a, b) => { - return a.name.localeCompare(b.name); - }); - // split advancements list by rank, and calculate xp spent this._prepareAdvancement(sheetData); sheetData.data.xp_saved = Math.floor(parseInt(sheetData.data.xp_total) - parseInt(sheetData.data.xp_spent)); diff --git a/system/templates/actors/character/techniques.html b/system/templates/actors/character/techniques.html index e905379..b1e340a 100644 --- a/system/templates/actors/character/techniques.html +++ b/system/templates/actors/character/techniques.html @@ -8,19 +8,19 @@ {{/each}} -
- - {{ localize 'l5r5e.techniques.title' }} - {{#if editable}} - - {{/if}} - - -
+ + + + {{/each}} \ No newline at end of file diff --git a/system/templates/actors/npc/techniques.html b/system/templates/actors/npc/techniques.html index 7343848..d4f3aeb 100644 --- a/system/templates/actors/npc/techniques.html +++ b/system/templates/actors/npc/techniques.html @@ -1,13 +1,29 @@
{{ localize 'l5r5e.techniques.title' }} - - + + {{#each actor.data.splitTechniquesList as |list technique|}} +
+ + {{localize (localize 'l5r5e.techniques.{technique}' technique=technique) }} + {{#ifCond ../editable '&&' (lookup ../actor.data.techniques technique)}} + + {{/ifCond}} + +
    + {{#each list as |item id|}} + {{> 'systems/l5r5e/templates/items/technique/technique-entry.html' technique=item editable=../../editable }} + {{/each}} +
+
+ {{/each}}
\ No newline at end of file