Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve display of Token Config #194

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions draw-steel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,28 @@ Hooks.once("i18nInit", () => {
for (const model of Object.values(CONFIG.Actor.dataModels)) {
/** @type {InstanceType<foundry["data"]["fields"]["SchemaField"]>} */
const characteristicSchema = model.schema.getField("characteristics");
if (!characteristicSchema) continue;
for (const [characteristic, {label, hint}] of Object.entries(ds.CONFIG.characteristics)) {
const field = characteristicSchema.getField(`${characteristic}.value`);
if (!field) continue;
field.label = label;
field.hint = hint;
if (characteristicSchema) {
for (const [characteristic, {label, hint}] of Object.entries(ds.CONFIG.characteristics)) {
const field = characteristicSchema.getField(`${characteristic}.value`);
if (!field) continue;
field.label = label;
field.hint = hint;
}
}
// Allows CONFIG.damageTypes to only have to define the name of the damage type once
/** @type {InstanceType<foundry["data"]["fields"]["SchemaField"]>} */
const damageSchema = model.schema.getField("damage");
if (damageSchema) {
for (const field of Object.values(damageSchema.fields.immunities.fields)) {
if (field.label) {
field.label = game.i18n.format("DRAW_STEEL.Actor.base.FIELDS.damage.immunities.format", {type: game.i18n.localize(field.label)});
}
}
for (const field of Object.values(damageSchema.fields.weaknesses.fields)) {
if (field.label) {
field.label = game.i18n.format("DRAW_STEEL.Actor.base.FIELDS.damage.weaknesses.format", {type: game.i18n.localize(field.label)});
}
}
}
}
});
Expand All @@ -115,6 +131,7 @@ Hooks.on("renderChatMessage", applications.hooks.renderChatMessage);
Hooks.on("renderCombatantConfig", applications.hooks.renderCombatantConfig);
Hooks.on("renderCombatTracker", applications.hooks.renderCombatTracker);
Hooks.on("getCombatTrackerEntryContext", applications.hooks.getCombatTrackerEntryContext);
Hooks.on("renderTokenConfig", applications.hooks.renderTokenConfig);

/**
* Other hooks
Expand Down
49 changes: 47 additions & 2 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@
"combat": {
"label": "Combat",
"size": {
"label": "Size"
"label": "Size",
"value": {
"label": "Size Number"
}
},
"stability": {
"label": "Stability"
},
"turns": {
"label": "Turns Per Round"
}
},
"movement": {
Expand All @@ -125,6 +131,22 @@
"teleport": {
"label": "Teleport"
}
},
"damage": {
"immunities": {
"label": "Immunities",
"all": {
"label": "Damage"
},
"format": "{type} Immunity"
},
"weaknesses": {
"label": "Weaknesses",
"all": {
"label": "Damage"
},
"format": "{type} Weakness"
}
}
},
"sizes": {
Expand All @@ -138,7 +160,9 @@
"FIELDS": {
"hero": {
"primary": {
"label": "Heroic Resource"
"value": {
"label": "Heroic Resource"
}
},
"surges": {
"label": "Surges"
Expand All @@ -164,6 +188,27 @@
"skills": {
"label": "Skills"
}
},
"biography": {
"value": {
"label": "Biography"
},
"gm": {
"label": "GM Notes"
},
"languages": {
"label": "Languages"
},
"height": {
"value": {
"label": "Height"
}
},
"weight": {
"value": {
"label": "Weight"
}
}
}
},
"HeroicResourceGain": "Start of turn resource gain"
Expand Down
1 change: 1 addition & 0 deletions src/module/apps/hooks/_module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./activeEffectConfig.mjs";
export * from "./chatMessage.mjs";
export * from "./combatantConfig.mjs";
export * from "./combatTracker.mjs";
export * from "./tokenConfig.mjs";
46 changes: 46 additions & 0 deletions src/module/apps/hooks/tokenConfig.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/** @import {DrawSteelActor} from "../../documents/actor.mjs" */

/**
* A hook event that fires when the TokenConfig application is rendered
* @param {TokenConfig} app The Application instance being rendered
* @param {JQuery<HTMLElement>} jquery The inner HTML of the document that will be displayed and may be modified
* @param {Record<string, any>} context The object of data used when rendering the application
*/
export function renderTokenConfig(app, [html], context) {
/** @type {DrawSteelActor} */
const actor = app.document.actor;
// Replace option labels with schema-derived props
if (actor) {
const schema = actor.system.schema;
/** @type {HTMLSelectElement[]} */
const bars = html.querySelectorAll(".bar-attribute");
for (const bar of bars) {
const groups = {};
const options = [...bar.options];
for (const opt of options) {
const field = schema.getField(opt.value);
if (field?.label) opt.label = field.label;
if (!field || (opt.parentElement.label === game.i18n.localize("TOKEN.BarAttributes"))) continue;
// Build groups by going to the highest level ancestor with a label
let ancestor = field;
let p = field.parent;
while (p.name !== "system") {
if (p.label) ancestor = p;
p = p.parent;
}
if (field !== ancestor) {
if (ancestor.name in groups) {
groups[ancestor.name].appendChild(opt);
}
else {
const g = document.createElement("optgroup");
g.label = ancestor.label;
bar.appendChild(g);
groups[ancestor.name] = g;
g.appendChild(opt);
}
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/module/data/actor/character.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default class CharacterModel extends BaseActorModel {
/** @override */
prepareDerivedData() {
this.hero.recoveries.recoveryValue = Math.floor(this.stamina.max / 3) + this.hero.recoveries.bonus;
this.hero.primary.label = game.i18n.localize("DRAW_STEEL.Actor.Character.FIELDS.hero.primary.label");
this.hero.primary.label = game.i18n.localize("DRAW_STEEL.Actor.Character.FIELDS.hero.primary.value.label");
const heroClass = this.class;
if (heroClass && heroClass.system.primary) {
this.hero.primary.label = heroClass.system.primary;
Expand Down Expand Up @@ -210,7 +210,7 @@ export default class CharacterModel extends BaseActorModel {
/** @override */
get coreResource() {
return {
name: this.class?.system.primary ?? game.i18n.localize("DRAW_STEEL.Actor.Character.FIELDS.hero.primary.label"),
name: this.class?.system.primary ?? game.i18n.localize("DRAW_STEEL.Actor.Character.FIELDS.hero.primary.value.label"),
target: this.parent,
path: "system.hero.primary.value"
};
Expand Down
4 changes: 2 additions & 2 deletions src/module/data/item/ability.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export default class AbilityModel extends BaseItemModel {
system: this,
systemFields: this.schema.fields,
config: ds.CONFIG,
resourceName: this.actor?.system.coreResource.name ?? game.i18n.localize("DRAW_STEEL.Actor.Character.FIELDS.hero.primary.label")
resourceName: this.actor?.system.coreResource.name ?? game.i18n.localize("DRAW_STEEL.Actor.Character.FIELDS.hero.primary.value.label")
};
if (config.tier1) context.tier1 = true;
if (config.tier2) context.tier2 = true;
Expand Down Expand Up @@ -553,7 +553,7 @@ export default class AbilityModel extends BaseItemModel {
if (DrawSteelActiveEffect.isStatusSource(target, this.actor, "frightened")) modifiers.edges += 1; // Attacking the target the actor has frightened

// Grabbed condition check - targeting a non-source adds a bane
if (DrawSteelActiveEffect.isStatusSource(this.actor, target, "grabbed") === false) modifiers.banes += 1;
if (DrawSteelActiveEffect.isStatusSource(this.actor, target, "grabbed") === false) modifiers.banes += 1;

// Restrained condition check - targeting restrained gets an edge
if (target.statuses.has("restrained")) modifiers.edges += 1;
Expand Down