Skip to content

Commit

Permalink
[foundryvtt#1846] Convert DND5E.abilities to object, replace references
Browse files Browse the repository at this point in the history
  • Loading branch information
arbron committed Oct 13, 2022
1 parent e51cb4e commit be511f7
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 47 deletions.
10 changes: 2 additions & 8 deletions dnd5e.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,8 @@ Hooks.once("init", function() {
registerSystemSettings();

// Remove honor & sanity from configuration if they aren't enabled
if ( !game.settings.get("dnd5e", "honorScore") ) {
delete DND5E.abilities.hon;
delete DND5E.abilityAbbreviations.hon;
}
if ( !game.settings.get("dnd5e", "sanityScore") ) {
delete DND5E.abilities.san;
delete DND5E.abilityAbbreviations.san;
}
if ( !game.settings.get("dnd5e", "honorScore") ) delete DND5E.abilities.hon;
if ( !game.settings.get("dnd5e", "sanityScore") ) delete DND5E.abilities.san;

// Patch Core Functions
CONFIG.Combat.initiative.formula = "1d20 + @attributes.init.mod + @attributes.init.prof + @attributes.init.bonus + @abilities.dex.bonuses.check + @bonuses.abilities.check";
Expand Down
7 changes: 4 additions & 3 deletions module/applications/actor/ability-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ export default class ActorAbilityConfig extends DocumentSheet {

/** @override */
get title() {
return `${game.i18n.format("DND5E.AbilityConfigureTitle", {ability: CONFIG.DND5E.abilities[this._abilityId]})}: ${this.document.name}`;
return `${game.i18n.format("DND5E.AbilityConfigureTitle", {ability: CONFIG.DND5E.abilities[this._abilityId].label})}: ${this.document.name}`;
}

/* -------------------------------------------- */

/** @override */
getData(options) {
const src = this.object.toObject();
const ability = CONFIG.DND5E.abilities[this._abilityId].label;
return {
ability: src.system.abilities[this._abilityId] || {},
labelSaves: game.i18n.format("DND5E.AbilitySaveConfigure", {ability: CONFIG.DND5E.abilities[this._abilityId]}),
labelChecks: game.i18n.format("DND5E.AbilityCheckConfigure", {ability: CONFIG.DND5E.abilities[this._abilityId]}),
labelSaves: game.i18n.format("DND5E.AbilitySaveConfigure", {ability}),
labelChecks: game.i18n.format("DND5E.AbilityCheckConfigure", {ability}),
abilityId: this._abilityId,
proficiencyLevels: {
0: CONFIG.DND5E.proficiencyLevels[0],
Expand Down
4 changes: 2 additions & 2 deletions module/applications/actor/base-sheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ export default class ActorSheet5e extends ActorSheet {
for ( const [a, abl] of Object.entries(context.system.abilities) ) {
abl.icon = this._getProficiencyIcon(abl.proficient);
abl.hover = CONFIG.DND5E.proficiencyLevels[abl.proficient];
abl.label = CONFIG.DND5E.abilities[a];
abl.label = CONFIG.DND5E.abilities[a]?.label;
abl.baseProf = source.system.abilities[a]?.proficient ?? 0;
}

// Skills
for ( const [s, skl] of Object.entries(context.system.skills ?? {}) ) {
skl.ability = CONFIG.DND5E.abilityAbbreviations[skl.ability];
skl.ability = CONFIG.DND5E.abilities[skl.ability]?.abbreviation;
skl.icon = this._getProficiencyIcon(skl.value);
skl.hover = CONFIG.DND5E.proficiencyLevels[skl.value];
skl.label = CONFIG.DND5E.skills[s]?.label;
Expand Down
4 changes: 2 additions & 2 deletions module/applications/property-attribution.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export default class PropertyAttribution extends Application {
getPropertyLabel(property) {
const parts = property.split(".");
if ( parts[0] === "abilities" && parts[1] ) {
return CONFIG.DND5E.abilities[parts[1]] ?? property;
return CONFIG.DND5E.abilities[parts[1]]?.label ?? property;
} else if ( (property === "attributes.ac.dex") && CONFIG.DND5E.abilities.dex ) {
return CONFIG.DND5E.abilities.dex;
return CONFIG.DND5E.abilities.dex.label;
} else if ( (parts[0] === "prof") || (property === "attributes.prof") ) {
return game.i18n.localize("DND5E.Proficiency");
}
Expand Down
72 changes: 47 additions & 25 deletions module/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,57 @@ _______________________________`;

/**
* The set of Ability Scores used within the system.
* @enum {string}
* @enum {{
* label: string,
* abbreviation: string
* }}
*/
DND5E.abilities = {
str: "DND5E.AbilityStr",
dex: "DND5E.AbilityDex",
con: "DND5E.AbilityCon",
int: "DND5E.AbilityInt",
wis: "DND5E.AbilityWis",
cha: "DND5E.AbilityCha",
hon: "DND5E.AbilityHon",
san: "DND5E.AbilitySan"
str: {
label: "DND5E.AbilityStr",
abbreviation: "DND5E.AbilityStrAbbr"
},
dex: {
label: "DND5E.AbilityDex",
abbreviation: "DND5E.AbilityDexAbbr"
},
con: {
label: "DND5E.AbilityCon",
abbreviation: "DND5E.AbilityConAbbr"
},
int: {
label: "DND5E.AbilityInt",
abbreviation: "DND5E.AbilityIntAbbr"
},
wis: {
label: "DND5E.AbilityWis",
abbreviation: "DND5E.AbilityWisAbbr"
},
cha: {
label: "DND5E.AbilityCha",
abbreviation: "DND5E.AbilityChaAbbr"
},
hon: {
label: "DND5E.AbilityHon",
abbreviation: "DND5E.AbilityHonAbbr"
},
san: {
label: "DND5E.AbilitySan",
abbreviation: "DND5E.AbilitySanAbbr"
}
};
preLocalize("abilities");
preLocalize("abilities", { keys: ["label", "abbreviation"] });
patchConfig("abilities", "label", { since: 1.7, until: 1.9 });

/**
* Localized abbreviations for Ability Scores.
* @enum {string}
*/
DND5E.abilityAbbreviations = {
str: "DND5E.AbilityStrAbbr",
dex: "DND5E.AbilityDexAbbr",
con: "DND5E.AbilityConAbbr",
int: "DND5E.AbilityIntAbbr",
wis: "DND5E.AbilityWisAbbr",
cha: "DND5E.AbilityChaAbbr",
hon: "DND5E.AbilityHonAbbr",
san: "DND5E.AbilitySanAbbr"
};
preLocalize("abilityAbbreviations");
Object.defineProperty(DND5E, "abilityAbbreviations", {
get() {
foundry.utils.logCompatibilityWarning(
"The `abilityAbbreviations` configuration object has been merged with `abilities`.",
{ since: "DnD5e 2.0", until: "DnD5e 2.2" }
);
return Object.fromEntries(Object.entries(DND5E.abilities).map(([k, v]) => [k, v.abbreviation]));
}
});

/* -------------------------------------------- */

Expand Down
2 changes: 1 addition & 1 deletion module/dice/d20-roll.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export default class D20Roll extends Roll {
}
return t;
});
this.options.flavor += ` (${CONFIG.DND5E.abilities[form.ability.value]})`;
this.options.flavor += ` (${CONFIG.DND5E.abilities[form.ability.value]?.label ?? ""})`;
}

// Apply advantage or disadvantage
Expand Down
6 changes: 3 additions & 3 deletions module/documents/actor/actor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ export default class Actor5e extends Actor {
* @param {object} options Options which configure how ability tests or saving throws are rolled
*/
rollAbility(abilityId, options={}) {
const label = CONFIG.DND5E.abilities[abilityId] ?? "";
const label = CONFIG.DND5E.abilities[abilityId]?.label ?? "";
new Dialog({
title: `${game.i18n.format("DND5E.AbilityPromptTitle", {ability: label})}: ${this.name}`,
content: `<p>${game.i18n.format("DND5E.AbilityPromptText", {ability: label})}</p>`,
Expand All @@ -944,7 +944,7 @@ export default class Actor5e extends Actor {
* @returns {Promise<D20Roll>} A Promise which resolves to the created Roll instance
*/
async rollAbilityTest(abilityId, options={}) {
const label = CONFIG.DND5E.abilities[abilityId] ?? "";
const label = CONFIG.DND5E.abilities[abilityId]?.label ?? "";
const abl = this.system.abilities[abilityId];
const globalBonuses = this.system.bonuses?.abilities ?? {};
const parts = [];
Expand Down Expand Up @@ -1026,7 +1026,7 @@ export default class Actor5e extends Actor {
* @returns {Promise<D20Roll>} A Promise which resolves to the created Roll instance
*/
async rollAbilitySave(abilityId, options={}) {
const label = CONFIG.DND5E.abilities[abilityId] ?? "";
const label = CONFIG.DND5E.abilities[abilityId]?.label ?? "";
const abl = this.system.abilities[abilityId];
const globalBonuses = this.system.bonuses?.abilities ?? {};
const parts = [];
Expand Down
6 changes: 3 additions & 3 deletions module/documents/item.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export default class Item5e extends Item {
// Action usage
if ( "actionType" in this.system ) {
this.labels.abilityCheck = game.i18n.format("DND5E.AbilityPromptTitle", {
ability: CONFIG.DND5E.abilities[this.system.ability]
ability: CONFIG.DND5E.abilities[this.system.ability]?.label ?? ""
});

// Saving throws
Expand Down Expand Up @@ -534,7 +534,7 @@ export default class Item5e extends Item {
}

// Update labels
const abl = CONFIG.DND5E.abilities[save.ability] ?? "";
const abl = CONFIG.DND5E.abilities[save.ability]?.label ?? "";
this.labels.save = game.i18n.format("DND5E.SaveDC", {dc: save.dc || "", ability: abl});
return save.dc;
}
Expand Down Expand Up @@ -1261,7 +1261,7 @@ export default class Item5e extends Item {
*/
_toolChatData(data, labels, props) {
props.push(
CONFIG.DND5E.abilities[data.ability] || null,
CONFIG.DND5E.abilities[data.ability]?.label || null,
CONFIG.DND5E.proficiencyLevels[data.proficient || 0]
);
}
Expand Down

0 comments on commit be511f7

Please sign in to comment.