Skip to content

Commit

Permalink
Cpr (#156)
Browse files Browse the repository at this point in the history
Allow sourcing from CPR effect interface
  • Loading branch information
Eligarf authored Aug 17, 2024
1 parent fb67689 commit 84b0589
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 32 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v4.7.0
* dnd5e: CPR is now an option to be a source for Stealthy's active effects if your version of CPR has the `getSidebarEffectsData` function, which is only available in 12.21 beta and beyond AFAIK. Stealthy will ignore CPR if the function isn't there.

# v4.6.2
* Fix the fix in 4.6.1

Expand Down
5 changes: 5 additions & 0 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
"beforeLabel": "Couldn't find effect",
"afterLabel": "in CLT, using Stealthy's default instead"
},
"cpr": {
"name": "Chris's Premades",
"beforeLabel": "Couldn't find effect",
"afterLabel": "in CPR, using Stealthy's default instead"
},
"ae": "Stealthy",
"min": "Stealthy (no token effect)"
},
Expand Down
5 changes: 5 additions & 0 deletions languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
"beforeLabel": "Impossible de trouver l'effet",
"afterLabel": "dans CLT, en utilisant la valeur par défaut de Stealthy à la place"
},
"cpr": {
"name": "Chris's Premades",
"beforeLabel": "Impossible de trouver l'effet",
"afterLabel": "dans CPR, en utilisant la valeur par défaut de Stealthy à la place"
},
"ae": "Stealthy",
"min": "Stealthy (no token effect)"
},
Expand Down
5 changes: 5 additions & 0 deletions languages/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
"beforeLabel": "Não foi possível encontrar o efeito",
"afterLabel": "no CLT, usando o padrão do Stealthy"
},
"cpr": {
"name": "Chris's Premades",
"beforeLabel": "Não foi possível encontrar o efeito",
"afterLabel": "no CPR, usando o padrão do Stealthy"
},
"ae": "Stealthy",
"min": "Stealthy (sem efeito no token)"
},
Expand Down
5 changes: 5 additions & 0 deletions languages/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
"beforeLabel": "Эффект не найдет",
"afterLabel": "Использовать Невидимость по умолчанию для СLT"
},
"cpr": {
"name": "Chris's Premades",
"beforeLabel": "Эффект не найдет",
"afterLabel": "Использовать Невидимость по умолчанию для СPR"
},
"ae": "Невидимость",
"min": "Невидимость (без эффекта на токене)"
},
Expand Down
70 changes: 39 additions & 31 deletions scripts/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,42 +603,50 @@ export default class Engine {
};
}

async updateOrCreateEffect({ name, actor, flag, source, makeEffect, tweakEffect }) {
async createSourcedEffect({ name, actor, source, makeEffect }) {
const beforeV11 = Math.floor(game.version) < 11;
let effect = actor.effects.find((e) => name === (beforeV11 ? e.label : e.name));

if (!effect) {
switch (source) {
case 'ce': {
if (game.dfreds?.effectInterface?.findEffectByName(name)) {
await game.dfreds.effectInterface.addEffect({ effectName: name, uuid: actor.uuid });
effect = actor.effects.find((e) => name === (beforeV11 ? e.label : e.name));
}
if (!effect && !this.warnedMissingCE) {
this.warnedMissingCE = true;
if (game.user.isGM)
ui.notifications.warn(
`${game.i18n.localize('stealthy.source.ce.beforeLabel')} '${name}' ${game.i18n.localize('stealthy.source.ce.afterLabel')}`);
console.error(`stealthy | Convenient Effects couldn't find the '${name}' effect so Stealthy will use the default one. Add your customized effect to CE or select a different effect source in Game Settings`);
}
break;
let effect = null;
switch (source) {
case 'ce': {
if (game.dfreds?.effectInterface?.findEffectByName(name)) {
await game.dfreds.effectInterface.addEffect({ effectName: name, uuid: actor.uuid });
effect = actor.effects.find((e) => name === (beforeV11 ? e.label : e.name));
}
if (!effect && !this.warnedMissingCE) {
this.warnedMissingCE = true;
if (game.user.isGM)
ui.notifications.warn(
`${game.i18n.localize('stealthy.source.ce.beforeLabel')} '${name}' ${game.i18n.localize('stealthy.source.ce.afterLabel')}`);
console.error(`stealthy | Convenient Effects couldn't find the '${name}' effect so Stealthy will use the default one. Add your customized effect to CE or select a different effect source in Game Settings`);
}
break;
}

case 'clt': {
if (game.clt?.getCondition(name)) {
await game.clt.applyCondition(name, actor);
effect = actor.effects.find(e => name === (beforeV11 ? e.label : e.name));
}
if (!effect && !this.warnedMissingCLT) {
this.warnedMissingCLT = true;
if (game.user.isGM)
ui.notifications.warn(
`${game.i18n.localize('stealthy.source.clt.beforeLabel')} '${name}' ${game.i18n.localize('stealthy.source.clt.afterLabel')}`);
console.error(`stealthy | Condition Lab & Triggler couldn't find the '${name}' effect so Stealthy will use the default one. Add your customized effect to CLT or select a different effect source in Game Settings`);
}
break;
case 'clt': {
if (game.clt?.getCondition(name)) {
await game.clt.applyCondition(name, actor);
effect = actor.effects.find(e => name === (beforeV11 ? e.label : e.name));
}
if (!effect && !this.warnedMissingCLT) {
this.warnedMissingCLT = true;
if (game.user.isGM)
ui.notifications.warn(
`${game.i18n.localize('stealthy.source.clt.beforeLabel')} '${name}' ${game.i18n.localize('stealthy.source.clt.afterLabel')}`);
console.error(`stealthy | Condition Lab & Triggler couldn't find the '${name}' effect so Stealthy will use the default one. Add your customized effect to CLT or select a different effect source in Game Settings`);
}
break;

}
}
return effect;
}

async updateOrCreateEffect({ name, actor, flag, source, makeEffect, tweakEffect }) {
const beforeV11 = Math.floor(game.version) < 11;
let effect = actor.effects.find((e) => name === (beforeV11 ? e.label : e.name));

if (!effect) {
effect = await this.createSourcedEffect({ name, actor,source, makeEffect });

// If we haven't found an ouside source, create the default one
if (!effect) {
Expand Down
28 changes: 27 additions & 1 deletion scripts/systems/dnd5e.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Engine5e extends Engine {

constructor() {
super();

this.warnedMissingCPR = false;
}

init() {
Expand Down Expand Up @@ -122,6 +124,11 @@ class Engine5e extends Engine {

getSettingsParameters(version) {
let settings = super.getSettingsParameters(version);
let cpr = chrisPremades?.utils?.effectUtils?.getSidebarEffectData;
if (cpr) {
settings.hiddenSource.choices.cpr = "stealthy.source.cpr.name";
settings.spotSource.choices.cpr = "stealthy.source.cpr.name";
}

const hidingAvailable = CONFIG?.DND5E.statusEffects?.hiding.name;
if (hidingAvailable) {
Expand All @@ -130,7 +137,7 @@ class Engine5e extends Engine {
settings.hiddenIcon.hint = 'stealthy.dnd5e.hiding.iconhint';
const beforeV12 = Math.floor(game.version) < 12;
if (!beforeV12) {
settings.hiddenSource.choices['hiding'] = 'stealthy.dnd5e.hiding.choice';
settings.hiddenSource.choices.hiding = 'stealthy.dnd5e.hiding.choice';
settings.hiddenSource.default = 'hiding';
settings.hiddenSource.requiresReload = true;
}
Expand Down Expand Up @@ -275,6 +282,25 @@ class Engine5e extends Engine {
return super.findStealthEffect(actor);
}

async createSourcedEffect({ name, actor, source, makeEffect }) {
if (source !== 'cpr')
return super.createSourcedEffect({ name, actor, source, makeEffect });
const beforeV11 = Math.floor(game.version) < 11;
let effect = chrisPremades?.utils?.effectUtils?.getSidebarEffectData(name);
if (effect) {
await actor.createEmbeddedDocuments('ActiveEffect', [effect]);
effect = actor.effects.find((e) => name === (beforeV11 ? e.label : e.name));
}
else if (!this.warnedMissingCPR) {
this.warnedMissingCPR = true;
if (game.user.isGM)
ui.notifications.warn(
`${game.i18n.localize('stealthy.source.cpr.beforeLabel')} '${name}' ${game.i18n.localize('stealthy.source.cpr.afterLabel')}`);
console.error(`stealthy | Chris's Premades couldn't find the '${name}' effect so Stealthy will use the default one. Add your customized effect to CPR or select a different effect source in Game Settings`);
}
return effect;
}

async updateOrCreateStealthEffect(actor, flag) {
if (!this.hiding) {
return await super.updateOrCreateStealthEffect(actor, flag);
Expand Down

0 comments on commit 84b0589

Please sign in to comment.