From 26789234dea17206e33badeeb8fd612140036e9a Mon Sep 17 00:00:00 2001 From: Kim Mantas Date: Mon, 16 Sep 2024 21:00:07 +0100 Subject: [PATCH] Re-shuffle languages based on 2024 rules. Add Common Sign Language. (#4269) --- dnd5e.mjs | 9 ++++++++ lang/en.json | 1 + module/config.mjs | 11 +++++----- module/data/advancement/trait.mjs | 35 +++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/dnd5e.mjs b/dnd5e.mjs index d0b73fbe01..aef1f6afd8 100644 --- a/dnd5e.mjs +++ b/dnd5e.mjs @@ -110,6 +110,15 @@ Hooks.once("init", function() { delete DND5E.transformationPresets.polymorph.options.addTemp; delete DND5E.transformationPresets.polymorph.options.keepHP; delete DND5E.transformationPresets.polymorph.options.keepType; + + // Adjust language categories. + delete DND5E.languages.standard.children.sign; + DND5E.languages.exotic.children.draconic = DND5E.languages.standard.children.draconic; + delete DND5E.languages.standard.children.draconic; + DND5E.languages.cant = DND5E.languages.exotic.children.cant; + delete DND5E.languages.exotic.children.cant; + DND5E.languages.druidic = DND5E.languages.exotic.children.druidic; + delete DND5E.languages.exotic.children.druidic; } // Register Roll Extensions diff --git a/lang/en.json b/lang/en.json index afe0c3f561..806a98bcff 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1865,6 +1865,7 @@ "DND5E.LanguagesAuran": "Auran", "DND5E.LanguagesCelestial": "Celestial", "DND5E.LanguagesCommon": "Common", +"DND5E.LanguagesCommonSign": "Common Sign Language", "DND5E.LanguagesDeepSpeech": "Deep Speech", "DND5E.LanguagesDraconic": "Draconic", "DND5E.LanguagesDruidic": "Druidic", diff --git a/module/config.mjs b/module/config.mjs index 09f8433d30..050a4c923c 100644 --- a/module/config.mjs +++ b/module/config.mjs @@ -3243,13 +3243,15 @@ DND5E.languages = { label: "DND5E.LanguagesStandard", children: { common: "DND5E.LanguagesCommon", + draconic: "DND5E.LanguagesDraconic", dwarvish: "DND5E.LanguagesDwarvish", elvish: "DND5E.LanguagesElvish", giant: "DND5E.LanguagesGiant", gnomish: "DND5E.LanguagesGnomish", goblin: "DND5E.LanguagesGoblin", halfling: "DND5E.LanguagesHalfling", - orc: "DND5E.LanguagesOrc" + orc: "DND5E.LanguagesOrc", + sign: "DND5E.LanguagesCommonSign" } }, exotic: { @@ -3257,9 +3259,10 @@ DND5E.languages = { children: { aarakocra: "DND5E.LanguagesAarakocra", abyssal: "DND5E.LanguagesAbyssal", + cant: "DND5E.LanguagesThievesCant", celestial: "DND5E.LanguagesCelestial", deep: "DND5E.LanguagesDeepSpeech", - draconic: "DND5E.LanguagesDraconic", + druidic: "DND5E.LanguagesDruidic", gith: "DND5E.LanguagesGith", gnoll: "DND5E.LanguagesGnoll", infernal: "DND5E.LanguagesInfernal", @@ -3275,9 +3278,7 @@ DND5E.languages = { sylvan: "DND5E.LanguagesSylvan", undercommon: "DND5E.LanguagesUndercommon" } - }, - druidic: "DND5E.LanguagesDruidic", - cant: "DND5E.LanguagesThievesCant" + } }; preLocalize("languages", { key: "label" }); preLocalize("languages.standard.children", { key: "label", sort: true }); diff --git a/module/data/advancement/trait.mjs b/module/data/advancement/trait.mjs index 62acb49109..d72413e22e 100644 --- a/module/data/advancement/trait.mjs +++ b/module/data/advancement/trait.mjs @@ -1,5 +1,17 @@ const { ArrayField, BooleanField, NumberField, SetField, SchemaField, StringField } = foundry.data.fields; +/** + * Map language category changes. + * @type {Record} + */ +const _MAP = { + "languages:exotic:draconic": "languages:standard:draconic", + "languages:cant": "languages:exotic:cant", + "languages:druidic": "languages:exotic:druidic" +}; + +const LANGUAGE_MAP = { modern: _MAP, legacy: foundry.utils.invertObject(_MAP) }; + /** * Configuration for a specific trait choice. * @@ -45,6 +57,18 @@ export class TraitConfigurationData extends foundry.abstract.DataModel { ); return this.parent.hint ?? ""; } + + /* -------------------------------------------- */ + + /** @inheritDoc */ + static migrateData(source) { + super.migrateData(source); + const version = game.settings.get("dnd5e", "rulesVersion"); + const languageMap = LANGUAGE_MAP[version] ?? {}; + if ( source.grants?.length ) source.grants = source.grants.map(t => languageMap[t] ?? t); + if ( source.choices?.length ) source.choices.forEach(c => c.pool = c.pool.map(t => languageMap[t] ?? t)); + return source; + } } /** @@ -58,4 +82,15 @@ export class TraitValueData extends foundry.abstract.DataModel { chosen: new SetField(new StringField(), { required: false }) }; } + + /* -------------------------------------------- */ + + /** @inheritDoc */ + static migrateData(source) { + super.migrateData(source); + const version = game.settings.get("dnd5e", "rulesVersion"); + const languageMap = LANGUAGE_MAP[version] ?? {}; + if ( source.chosen?.length ) source.chosen = source.chosen.map(t => languageMap[t] ?? t); + return source; + } }