From a1c6f0f373247b5419a8f9cb2c2ed5a9e7c77c11 Mon Sep 17 00:00:00 2001 From: Vlyan Date: Tue, 22 Mar 2022 20:35:11 +0100 Subject: [PATCH] Translate skills for technique list Fixed img following the technique_type --- CHANGELOG.md | 8 +-- system/assets/icons/techs/title_ability.svg | 33 ++++++++++++ system/scripts/actors/character-generator.js | 2 +- system/scripts/actors/npc-sheet.js | 2 +- system/scripts/config.js | 2 +- system/scripts/helpers.js | 28 ++++++++++ system/scripts/items/technique-sheet.js | 56 ++++++++++++++------ 7 files changed, 109 insertions(+), 22 deletions(-) create mode 100644 system/assets/icons/techs/title_ability.svg diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d2c613..dd0228a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ - Trying an autocomplete on some fields : clan, family, school, roles, demeanor. - Techniques Sheet & Compendiums : - Added difficulty and skill values (not to all techniques). - - Trying an autocomplete on skill(id) field. + - Trying an autocomplete on skill field. - DicePicker : - Added TN hidden difficulty visibility for GM (ex: ?2?). - Added a selection for techniques with skill list. @@ -26,6 +26,7 @@ - Fixed loading properties from custom compendiums. - Added a line strike on removed/unknown property and ability to remove them. - Added Inversion and Mantra icon and tag symbols (thanks to TesserWract). +- Fixed image following the technique_type on technique sheet. - Fixed linked actor image compatibility with Tokenizer. - Fixed svg height/width for firefox. @@ -44,10 +45,9 @@ Technique syntaxe "quick" explanation : - `@T:vigilance|min` : Difficulty will be the `vigilance` from the target with the minimum vigilance (implicit) value. it's the same to wrote `@T:vigilance|min(vigilance)`. - `@T:vigilance|max(statusRank)` : Difficulty will be the `vigilance` from the target with the maximum `statusRank` value. - Skill can be : - - SkillId : `melee`, `fitness`... - - SkillCategoryId : `scholar`, `martial`... + - Skill : `melee`, `fitness`... + - SkillCategory : `scholar`, `martial`... - Or both in list, coma separated. - - Ids are english names in lower case, see `config.js / L5R5E.skills` for the list. - Exemples : - `theology` - `melee,ranged,unarmed` diff --git a/system/assets/icons/techs/title_ability.svg b/system/assets/icons/techs/title_ability.svg new file mode 100644 index 0000000..72251ea --- /dev/null +++ b/system/assets/icons/techs/title_ability.svg @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/system/scripts/actors/character-generator.js b/system/scripts/actors/character-generator.js index ee5f42a..633dca7 100644 --- a/system/scripts/actors/character-generator.js +++ b/system/scripts/actors/character-generator.js @@ -430,7 +430,7 @@ export class CharacterGenerator { */ _generateDemeanor(actorDatas) { // demeanor { id: "adaptable", mod: { fire: 2, earth: -2 } }, - const demeanor = CharacterGenerator._getRandomArrayValue(CONFIG.l5r5e.demeanorList); + const demeanor = CharacterGenerator._getRandomArrayValue(CONFIG.l5r5e.demeanors); actorDatas.attitude = game.i18n.localize("l5r5e.demeanor." + demeanor.id); actorDatas.rings_affinities = foundry.utils.mergeObject( { diff --git a/system/scripts/actors/npc-sheet.js b/system/scripts/actors/npc-sheet.js index 3872578..cf35343 100644 --- a/system/scripts/actors/npc-sheet.js +++ b/system/scripts/actors/npc-sheet.js @@ -69,7 +69,7 @@ export class NpcSheetL5r5e extends BaseCharacterSheetL5r5e { game.l5r5e.HelpersL5r5e.autocomplete( html, "data.attitude", - CONFIG.l5r5e.demeanorList.map((e) => { + CONFIG.l5r5e.demeanors.map((e) => { let modifiers = []; Object.entries(e.mod).forEach(([k, v]) => { modifiers.push(`${game.i18n.localize(`l5r5e.rings.${k}`)} ${v}`); diff --git a/system/scripts/config.js b/system/scripts/config.js index 61354dc..da00d5d 100644 --- a/system/scripts/config.js +++ b/system/scripts/config.js @@ -152,7 +152,7 @@ L5R5E.families.set("qamarist", []); L5R5E.families.set("ujik", []); // *** demeanor *** -L5R5E.demeanorList = [ +L5R5E.demeanors = [ { id: "adaptable", mod: { fire: 2, earth: -2 } }, { id: "adaptable", mod: { water: 2, earth: -2 } }, { id: "aggressive", mod: { fire: 2, air: -2 } }, diff --git a/system/scripts/helpers.js b/system/scripts/helpers.js index c8e85f1..3cbde81 100644 --- a/system/scripts/helpers.js +++ b/system/scripts/helpers.js @@ -58,6 +58,34 @@ export class HelpersL5r5e { }, new Map()); } + /** + * Get a flat map for skill translation + * @param {boolean} bToSkillId if true flip props/values + * @return {Object} + */ + static getSkillsTranslationMap(bToSkillId) { + let map = Array.from(CONFIG.l5r5e.skills).reduce((acc, [id, cat]) => { + acc[id] = game.i18n.localize(`l5r5e.skills.${cat}.${id}`); + acc[cat] = game.i18n.localize(`l5r5e.skills.${cat}.title`); + return acc; + }, {}); + if (bToSkillId) { + map = Object.entries(map).reduce((obj, [key, value]) => ({ ...obj, [value]: key }), {}); + } + return map; + } + + /** + * Translate a list of skill and category + * @param {string[]} aIn + * @param {boolean} bToSkillId + * @return {string[]} + */ + static translateSkillsList(aIn, bToSkillId) { + const map = HelpersL5r5e.getSkillsTranslationMap(bToSkillId); + return aIn.map((skill) => map[skill.trim()]); + } + /** * Get Techniques for List / Select * @param types core|school|title|custom diff --git a/system/scripts/items/technique-sheet.js b/system/scripts/items/technique-sheet.js index d3b46c3..fc29bcc 100644 --- a/system/scripts/items/technique-sheet.js +++ b/system/scripts/items/technique-sheet.js @@ -27,8 +27,11 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e { sheetData.data.techniquesList = game.l5r5e.HelpersL5r5e.getTechniquesList({ types }); // Sanitize Difficulty and Skill list - sheetData.data.data.skill = TechniqueSheetL5r5e.formatSkillList(sheetData.data.data.skill); sheetData.data.data.difficulty = TechniqueSheetL5r5e.formatDifficulty(sheetData.data.data.difficulty); + sheetData.data.data.skill = game.l5r5e.HelpersL5r5e.translateSkillsList( + TechniqueSheetL5r5e.formatSkillList(sheetData.data.data.skill.split(",")), + false + ).join(", "); return sheetData; } @@ -41,9 +44,19 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e { * @override */ async _updateObject(event, formData) { + // Change the image according to the type if this is already the case + if ( + formData["data.technique_type"] && + formData.img === `${CONFIG.l5r5e.paths.assets}icons/techs/${this.object.data.data.technique_type}.svg` + ) { + formData.img = `${CONFIG.l5r5e.paths.assets}icons/techs/${formData["data.technique_type"]}.svg`; + } + // Sanitize Difficulty and Skill list - formData["data.skill"] = TechniqueSheetL5r5e.formatSkillList(formData["data.skill"]); formData["data.difficulty"] = TechniqueSheetL5r5e.formatDifficulty(formData["data.difficulty"]); + formData["data.skill"] = TechniqueSheetL5r5e.formatSkillList( + game.l5r5e.HelpersL5r5e.translateSkillsList(formData["data.skill"].split(","), true) + ).join(","); return super._updateObject(event, formData); } @@ -62,13 +75,26 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e { } // Autocomplete + game.l5r5e.HelpersL5r5e.autocomplete( + html, + "data.difficulty", + [ + "@T:intrigueRank", + "@T:focus", + "@T:martialRank", + "@T:statusRank|max", + "@T:strife.value|max", + "@T:vigilance", + "@T:vigilance|max", + "@T:vigilance|min", + "@T:vigilance|max(@T:statusRank)", + ], + "," + ); game.l5r5e.HelpersL5r5e.autocomplete( html, "data.skill", - Array.from(game.l5r5e.HelpersL5r5e.getCategoriesSkillsList()).reduce((acc, [cat, skills]) => { - acc.push(cat, ...skills); - return acc; - }, []), + Object.values(game.l5r5e.HelpersL5r5e.getSkillsTranslationMap(false)), "," ); } @@ -87,8 +113,8 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e { /** * Sanitize the technique skill list - * @param {string} skillList - * @return {string} + * @param {string[]} skillList + * @return {string[]} */ static formatSkillList(skillList) { if (!skillList) { @@ -98,18 +124,18 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e { // List categories const unqCatList = new Set(); - skillList.split(",").forEach((s) => { - s = s.trim(); - if (categories.has(s)) { + skillList.forEach((s) => { + s = s?.trim(); + if (!!s && categories.has(s)) { unqCatList.add(s); } }); // List skill (not include in cat) const unqSkillList = new Set(); - skillList.split(",").forEach((s) => { - s = s.trim(); - if (CONFIG.l5r5e.skills.has(s)) { + skillList.forEach((s) => { + s = s?.trim(); + if (!!s && CONFIG.l5r5e.skills.has(s)) { const cat = CONFIG.l5r5e.skills.get(s); if (!unqCatList.has(cat)) { unqSkillList.add(s); @@ -117,6 +143,6 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e { } }); - return [...unqCatList, ...unqSkillList].join(","); + return [...unqCatList, ...unqSkillList]; } }