From dc5e06af2cccbf009f8e3e72c2d2d4e7c8c10546 Mon Sep 17 00:00:00 2001 From: Vlyan Date: Sat, 3 Jul 2021 12:29:11 +0200 Subject: [PATCH] Added cancelled properties in text for props and some fixes --- system/scripts/helpers.js | 36 +++-- system/templates/actors/npc-sheet.html | 2 +- system/templates/actors/npc/narrative.html | 134 ++++++++++++------ .../items/property/property-text.html | 4 + 4 files changed, 115 insertions(+), 61 deletions(-) diff --git a/system/scripts/helpers.js b/system/scripts/helpers.js index bcaff8d..8e2a074 100644 --- a/system/scripts/helpers.js +++ b/system/scripts/helpers.js @@ -75,18 +75,22 @@ export class HelpersL5r5e { return null; } const data = JSON.parse(json); + if (!data) { + return null; + } return await HelpersL5r5e.getObjectGameOrPack(data); } /** * Return the object from Game or Pack by his ID, or null if not found - * @param {number} id - * @param {string} type - * @param {string|null} data - * @param {string|null} pack + * @param {string} id + * @param {string} type Type (Item, JournalEntry...) + * @param {any[]|null} data Plain data + * @param {string|null} pack Pack name + * @param {string|null} parentId Used to avoid an infinite loop in properties if set * @return {Promise} */ - static async getObjectGameOrPack({ id, type, data = null, pack = null }) { + static async getObjectGameOrPack({ id, type, data = null, pack = null, parentId = null }) { let document = null; try { @@ -105,9 +109,9 @@ export class HelpersL5r5e { } if (pack) { - const data = await game.packs.get(pack).getDocument(id); - if (data) { - document = HelpersL5r5e.createDocumentFromCompendium({ type, data }); + const tmpData = await game.packs.get(pack).getDocument(id); + if (tmpData) { + document = HelpersL5r5e.createDocumentFromCompendium({ type, data: tmpData }); } } } @@ -126,9 +130,9 @@ export class HelpersL5r5e { continue; } - const data = await comp.getDocument(id); - if (data) { - document = HelpersL5r5e.createDocumentFromCompendium({ type, data }); + const tmpData = await comp.getDocument(id); + if (tmpData) { + document = HelpersL5r5e.createDocumentFromCompendium({ type, data: tmpData }); } } } @@ -141,13 +145,13 @@ export class HelpersL5r5e { } // Care to infinite loop in properties - if (document.type !== "property") { + if (!parentId) { await HelpersL5r5e.refreshItemProperties(document); } document.prepareData(); } } catch (err) { - console.warn(err); + console.warn("L5R5E | ", err); } return document; } @@ -195,7 +199,11 @@ export class HelpersL5r5e { if (document.data?.data?.properties && typeof Babele !== "undefined") { document.data.data.properties = await Promise.all( document.data.data.properties.map(async (property) => { - const gameProp = await HelpersL5r5e.getObjectGameOrPack({ id: property.id, type: "Item" }); + const gameProp = await HelpersL5r5e.getObjectGameOrPack({ + id: property.id, + type: "Item", + parentId: document.data?._id || 1, + }); if (gameProp) { return { id: gameProp.id, name: gameProp.name }; } else { diff --git a/system/templates/actors/npc-sheet.html b/system/templates/actors/npc-sheet.html index 476bf9b..f94e8fb 100644 --- a/system/templates/actors/npc-sheet.html +++ b/system/templates/actors/npc-sheet.html @@ -34,7 +34,7 @@ {{!-- Narrative Tab --}}
- {{> 'systems/l5r5e/templates/actors/character/narrative.html'}} + {{> 'systems/l5r5e/templates/actors/npc/narrative.html'}}
{{!-- Conflict Tab --}} diff --git a/system/templates/actors/npc/narrative.html b/system/templates/actors/npc/narrative.html index fa434e0..4c2c643 100644 --- a/system/templates/actors/npc/narrative.html +++ b/system/templates/actors/npc/narrative.html @@ -1,46 +1,88 @@ -
- - {{localize 'l5r5e.social.npc.advantages'}} - {{#if options.editable}} - - {{/if}} - -
    - {{#each actor.items as |item id|}} - {{#ifCond '["distinction","passion"]' 'includes' item.data.data.peculiarity_type}} - {{> 'systems/l5r5e/templates/items/peculiarity/peculiarity-entry.html' peculiarity=item id=id editable=../options.editable}} - {{/ifCond}} - {{/each}} -
-
-
- - {{localize 'l5r5e.social.npc.disadvantages'}} - {{#if options.editable}} - - {{/if}} - -
    - {{#each actor.items as |item id|}} - {{#ifCond '["adversity","anxiety"]' 'includes' item.data.data.peculiarity_type}} - {{> 'systems/l5r5e/templates/items/peculiarity/peculiarity-entry.html' peculiarity=item id=id editable=../options.editable}} - {{/ifCond}} - {{/each}} -
-
-{{!-- bonds --}} -
- - {{localize 'l5r5e.social.bonds'}} - {{#if options.editable}} - - {{/if}} - -
    - {{#each actor.items as |bond id|}} - {{#ifCond bond.data.type '==' 'bond'}} - {{> 'systems/l5r5e/templates/items/bond/bond-entry.html' bond=bond id=id editable=../options.editable}} - {{/ifCond}} - {{/each}} -
-
\ No newline at end of file +
+ {{!-- Ninjo/Giri --}} +
+ {{localize 'l5r5e.social.title'}} + + +
+ {{!-- Bushido Tenets --}} +
+ {{localize 'l5r5e.social.bushido_tenets.title'}} + + +
+
+
+ {{!-- Advantages --}} +
+ + {{localize 'l5r5e.social.advantages'}} + {{#if options.editable}} + + {{/if}} + +
    + {{#each actor.items as |item id|}} + {{#ifCond '["distinction","passion"]' 'includes' item.data.data.peculiarity_type}} + {{> 'systems/l5r5e/templates/items/peculiarity/peculiarity-entry.html' peculiarity=item id=id editable=../options.editable}} + {{/ifCond}} + {{/each}} +
+
+ {{!-- Disadvantages --}} +
+ + {{localize 'l5r5e.social.disadvantages'}} + {{#if options.editable}} + + {{/if}} + +
    + {{#each actor.items as |item id|}} + {{#ifCond '["adversity","anxiety"]' 'includes' item.data.data.peculiarity_type}} + {{> 'systems/l5r5e/templates/items/peculiarity/peculiarity-entry.html' peculiarity=item id=id editable=../options.editable}} + {{/ifCond}} + {{/each}} +
+
+ {{!-- Bonds --}} +
+ + {{localize 'l5r5e.social.bonds' }} + {{#if options.editable}} + + {{/if}} + +
    + {{#each actor.items as |bond id|}} + {{#ifCond bond.data.type '==' 'bond'}} + {{> 'systems/l5r5e/templates/items/bond/bond-entry.html' bond=bond id=id editable=../options.editable}} + {{/ifCond}} + {{/each}} +
+
+
+
+ {{!-- Description (public) --}} +
+ {{localize 'l5r5e.description' }} + {{editor content=data.data.description target="data.description" button=true editable=options.editable}} +
+ {{!-- Notes (private) --}} +
+ {{localize 'l5r5e.notes' }} + {{editor content=data.data.notes target="data.notes" button=true editable=options.editable}} +
+
\ No newline at end of file diff --git a/system/templates/items/property/property-text.html b/system/templates/items/property/property-text.html index 48447f1..c282d90 100644 --- a/system/templates/items/property/property-text.html +++ b/system/templates/items/property/property-text.html @@ -3,7 +3,11 @@

{{data.name}}

+ {{!--cancelled properties--}} + {{localize 'l5r5e.removed_properties'}} : {{#each data.data.properties as |property idx|}}{{#ifCond idx '>' 0}}, {{/ifCond}}{{property.name}}{{/each}} + {{!--item-infos--}} +
{{localize 'l5r5e.description'}} : {{{data.data.description}}}
{{localize 'l5r5e.book_reference'}} : {{data.data.book_reference}}