From 31894a844f52b1924415aaf4be1314e9fd99aa08 Mon Sep 17 00:00:00 2001 From: jalensailin Date: Tue, 5 Dec 2023 20:39:53 -0500 Subject: [PATCH] improve display of Special Training attributes --- lang/en.json | 3 ++ module/actor/actor-sheet.js | 63 ++++++++++++++++++---- module/config.js | 55 +++++++++++++++++++ templates/actor/custom-skills-partial.html | 2 +- templates/dialog/special-training.html | 28 +++++++--- 5 files changed, 132 insertions(+), 19 deletions(-) create mode 100644 module/config.js diff --git a/lang/en.json b/lang/en.json index a69df3e..0813eab 100644 --- a/lang/en.json +++ b/lang/en.json @@ -66,6 +66,9 @@ "DG.TypeSkills.Other": "Other", "DG.SpecialTraining.Dialog.CreateSpecialTraining": "Add Special Training", + "DG.SpecialTraining.Dialog.DropDown.CustomSkills": "Custom/Typed Skills", + "DG.SpecialTraining.Dialog.DropDown.Skills": "Skills", + "DG.SpecialTraining.Dialog.DropDown.Statistics": "Statistics", "DG.SpecialTraining.Dialog.EditSpecialTraining": "Edit Special Training", "DG.SpecialTraining.Dialog.NameLabel": "Name", "DG.SpecialTraining.Dialog.SkillLabel": "Skill or Stat", diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index 29541ce..00a41e4 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -1,5 +1,6 @@ /* globals $ game Roll ChatMessage AudioHelper ActorSheet mergeObject Dialog TextEditor ActiveEffect ui duplicate fromUuidSync renderTemplate randomID */ +import DG from "../config.js"; import { DGPercentileRoll, DGLethalityRoll, @@ -66,6 +67,32 @@ export default class DeltaGreenActorSheet extends ActorSheet { this._prepareCharacterItems(data); } + // Prepare a simplified version of the special training for display on sheet. + const specialTraining = this.actor.system.specialTraining.map( + (training) => { + const simplifiedTraining = { + name: training.name, + id: training.id, + }; + // Convert the machine-readable name to a human-readable one. + switch (true) { + case DG.statistics.includes(training.skill): + simplifiedTraining.skill = training.skill.toUpperCase(); + break; + case DG.skills.includes(training.skill): + simplifiedTraining.skill = + this.actor.system.skills[training.skill].label; + break; + default: + simplifiedTraining.skill = + this.actor.system.typedSkills[training.skill].label; + break; + } + return simplifiedTraining; + }, + ); + data.specialTraining = specialTraining; + switch (this.actor.type) { case "agent": data.enrichedDescription = await TextEditor.enrichHTML( @@ -712,28 +739,43 @@ export default class DeltaGreenActorSheet extends ActorSheet { (training) => training.id === targetID, ); - const skillList = Object.entries(this.actor.system.skills).map( - ([k, v]) => ({ - key: k, - label: v.label, - targetNumber: v.proficiency, + // Prepare simplified stat list + const statList = Object.entries(this.actor.system.statistics).map( + ([key, stat]) => ({ + key, + label: game.i18n.localize(`DG.Attributes.${key}`), + targetNumber: stat.value * 5, }), ); - const typedSkillList = Object.values(this.actor.system.typedSkills).map( - (skill) => ({ - key: skill.label, + + // Prepare simplified skill list + const skillList = Object.entries(this.actor.system.skills).map( + ([key, skill]) => ({ + key, + label: skill.label, + targetNumber: skill.proficiency, + }), + ); + + // Prepare simplified typed/custom skill list + const typedSkillList = Object.entries(this.actor.system.typedSkills).map( + ([key, skill]) => ({ + key, group: skill.group, label: skill.label, targetNumber: skill.proficiency, }), ); - const combinedSkillList = [...skillList, ...typedSkillList]; + + // Prepare the template to feed to Dialog. const content = await renderTemplate( "systems/deltagreen/templates/dialog/special-training.html", { name: specialTraining?.name || "", currentSkill: specialTraining?.skill || "", - skillList: combinedSkillList, + statList, + skillList, + typedSkillList, }, ); @@ -741,6 +783,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { `DG.SpecialTraining.Dialog.${action}SpecialTraining`, ); + // Prepare and render dialog with above template. new Dialog({ content, title: game.i18n.localize("DG.SpecialTraining.Dialog.Title"), diff --git a/module/config.js b/module/config.js new file mode 100644 index 0000000..b55443c --- /dev/null +++ b/module/config.js @@ -0,0 +1,55 @@ +/** + * In config.js we can create constants that may be used all around the code base. + * I tried to get some of these values from `game.system` but it seems they + * aren't loaded yet when this is called. Oh well, this shouldn't really ever + * change. + */ + +const DG = { + // All the base skills + skills: [ + "accounting", + "alertness", + "anthropology", + "archeology", + "artillery", + "athletics", + "bureaucracy", + "computer_science", + "criminology", + "demolitions", + "disguise", + "dodge", + "drive", + "firearms", + "first_aid", + "forensics", + "heavy_machiner", + "heavy_weapons", + "history", + "humint", + "law", + "medicine", + "melee_weapons", + "navigate", + "occult", + "persuade", + "pharmacy", + "psychotherapy", + "ride", + "search", + "sigint", + "stealth", + "surgery", + "survival", + "swim", + "unarmed_combat", + "unnatural", + "ritual", + ], + + // All the base rollable stats. + statistics: ["str", "con", "dex", "int", "pow", "cha"], +}; + +export default DG; diff --git a/templates/actor/custom-skills-partial.html b/templates/actor/custom-skills-partial.html index 8b3263a..774fe08 100644 --- a/templates/actor/custom-skills-partial.html +++ b/templates/actor/custom-skills-partial.html @@ -22,7 +22,7 @@ {{/each}} - {{#each actor.system.specialTraining as |training|}} + {{#each specialTraining as |training|}}
{{#select currentSkill}} {{/select}}