From 6241deca7f37fefacafd96229767f449d7c80241 Mon Sep 17 00:00:00 2001 From: TheGiddyLimit Date: Thu, 4 Jan 2024 23:09:59 +0000 Subject: [PATCH] fix(integration): map CPR Metamagic item names --- module/js/integrations/ChrisPremades.js | 41 +++++++++++++++++-------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/module/js/integrations/ChrisPremades.js b/module/js/integrations/ChrisPremades.js index 1717cb1..e5d185b 100644 --- a/module/js/integrations/ChrisPremades.js +++ b/module/js/integrations/ChrisPremades.js @@ -6,6 +6,33 @@ import {Util} from "../Util.js"; // Cheat and pretend we're not always overriding, as our patches are temporary/highly contextual const _LIBWRAPPER_TYPE_TEMP = "MIXED"; +class _ChrisPremadesNameMappings { + static _MAP_SPECIFIC = { + "classFeature": { + "Ki": "Ki Points", + // Note: for College of Creation bards it's "Bardic Inspiration, Magical Inspiration, & Mote of Potential" but we ignore this case + "Bardic Inspiration": "Bardic Inspiration & Magical Inspiration", + }, + }; + + static _MAP_GENERAL = { + "optionalfeature": ent => { + if (ent.featureType?.some(it => it === "MM")) return `Metamagic - ${ent.name}`; + + return null; + }, + }; + + static getMappedName ({propJson, ent}) { + if (this._MAP_SPECIFIC[propJson]?.[ent.name]) return this._MAP_SPECIFIC[propJson]?.[ent.name]; + if (this._MAP_GENERAL[propJson]) { + const mapped = this._MAP_GENERAL[propJson](ent); + if (mapped) return mapped; + } + return ent.name; + } +} + /** * Designed for use with `chris-premades` v0.9.17 * See: https://github.com/chrisk123999/chris-premades @@ -212,7 +239,7 @@ export class IntegrationChrisPremades extends StartupHookMixin(IntegrationBase) const type = this._pGetExpandedAddonData_getItemType({propJson}); // Create a stubbed `Item` subclass to bypass CPR's `instanceof Item` check - const fauxName = this._pGetExpandedAddonData_getMappedName({propJson, name: ent.name}); + const fauxName = _ChrisPremadesNameMappings.getMappedName({propJson, ent}); const fauxObject = this._pGetExpandedAddonData_getFauxObject({name: fauxName, propBase, base, fauxActor, type}); if (!fauxObject) return null; @@ -241,18 +268,6 @@ export class IntegrationChrisPremades extends StartupHookMixin(IntegrationBase) return "feat"; } - static _MAPPED_NAMES = { - "classFeature": { - "Ki": "Ki Points", - // Note: for College of Creation bards it's "Bardic Inspiration, Magical Inspiration, & Mote of Potential" but we ignore this case - "Bardic Inspiration": "Bardic Inspiration & Magical Inspiration", - }, - }; - - _pGetExpandedAddonData_getMappedName ({propJson, name}) { - return this.constructor._MAPPED_NAMES[propJson]?.[name] || name; - } - _pGetExpandedAddonData_getFauxObject ({name, propBase, base = undefined, fauxActor, type}) { try { const docData = {