Skip to content

Commit

Permalink
fix(integration): map CPR Metamagic item names
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGiddyLimit committed Jan 4, 2024
1 parent dfb2ca9 commit 6241dec
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions module/js/integrations/ChrisPremades.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 6241dec

Please sign in to comment.