Skip to content

Commit

Permalink
Merge pull request #857 from Muttley/active-effects-improvements
Browse files Browse the repository at this point in the history
Active Effects improvements
  • Loading branch information
Muttley authored Aug 26, 2024
2 parents 31a8f60 + d03bf2a commit c8c0646
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 80 deletions.
4 changes: 2 additions & 2 deletions i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ SHADOWDARK.roll.spell_casting_check: Spellcasting Check
SHADOWDARK.roll.success: Success! ({value})
SHADOWDARK.settings.debugEnabled.hint: Enable or Disable additional debug logging
SHADOWDARK.settings.debugEnabled.name: Enable/Disable Debug
SHADOWDARK.settings.effect_panel.show_passive.hint: If checked the Effect Panel will show talents and other passive effects
SHADOWDARK.settings.effect_panel.show_passive.name: Show passive effects in panel
SHADOWDARK.settings.effect_panel.show_passive.hint: If checked, the Effect Panel will also show active effects from talents and items
SHADOWDARK.settings.effect_panel.show_passive.name: Show All Active Effects
SHADOWDARK.settings.migrateSystemCompendiums.hint: Perform data migration on the built in Shadowdark RPG system compendiums (don't modify this unless you know what you are doing)
SHADOWDARK.settings.migrateSystemCompendiums.name: Migrate System Compendiums
SHADOWDARK.settings.module_art.hint: Configure which module-provided art should be used
Expand Down
5 changes: 1 addition & 4 deletions system/shadowdark.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ Hooks.once("init", () => {
CONFIG.DiceSD = dice.DiceSD;
CONFIG.Combat.documentClass = documents.EncounterSD;

// TODO: V11 Compatability legacyTransferral
// Update to use the designed interface as specified here, once implemented into core
// https://github.com/foundryvtt/foundryvtt/issues/9185
if (game.version.split(".")[0] >= 11) CONFIG.ActiveEffect.legacyTransferral = true;
CONFIG.ActiveEffect.legacyTransferral = false;

registerHandlebarsHelpers();
registerSystemSettings();
Expand Down
107 changes: 36 additions & 71 deletions system/src/apps/EffectPanelSD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class EffectPanelSD extends Application {
});

expiredEffects.forEach(e => {
const i = this._controller._getSource(e);
const i = fromUuidSync(e.parent.uuid);
i.delete();
});
}
Expand Down Expand Up @@ -157,56 +157,47 @@ export class EffectPanelControllerSD {
get _actorEffects() {
const actor = this._actor;
if (!actor) return [];
const activeEffects = [];

// TODO: V11 Compatability legacyTransferral
// Update to use the designed interface as specified here, once implemented into core
// https://github.com/foundryvtt/foundryvtt/issues/9185
const sortedEffects = actor.effects
.map(effect => {
const src = this._getSource(effect);
if (!src) return false;
const effectData = effect.clone({}, { keepId: true});
actor.appliedEffects.forEach(effect => {
// only get effects that are applied to the actor
if (effect.transfer) {

// Set the effect and origin name
effectData.effectName = effect.name ?? effect.label;
effectData.originName = src.name;
const effectData = effect.clone({}, { keepId: true});

// Set the effect category
effectData.category = src.system.category;
// get the parent object of the effect
effectData.parentName = effect.parent.name;
if (effectData.parentName !== effect.name) {
effectData.effectName = effect.name;
}

// Duration
effectData.remainingDuration = src.remainingDuration;
effectData.rounds = (src.system.duration?.type === "rounds")
? src.system.duration.value
: 0;
effectData.isExpired = effectData.remainingDuration.expired;
// get properties if parent is effect type
if (effect.parent.type === "Effect") {
effectData.category = effect.parent.system.category;
effectData.hidden = !effect.parent.system.effectPanel.show ?? false;

effectData.infinite = effectData.remainingDuration.remaining === Infinity;
effectData.remainingDuration = effect.parent.remainingDuration;
effectData.rounds = (effect.parent.system.duration?.type === "rounds")
? effect.parent.system.duration.value
: 0;
effectData.isExpired = effectData.remainingDuration.expired;
effectData.infinite = effectData.remainingDuration.remaining === Infinity;
effectData.temporary = !effectData.infinite;

// Set the talent type if available
effectData.talentType = (src.system.talentClass)
? src.system.talentClass
: false;
// is item hidden
effectData.hidden = !effect.parent.system.effectPanel.show ?? false;

// Determine if the talent is temporary
if (effectData.talentType) {
effectData.temporary = false;
effectData.hidden = false;
}
else {
effectData.temporary = true;
effectData.hidden = !src.system.effectPanel?.show ?? false;

if (effect.parent.type === "Talent") {
effectData.talentType = effect.parent.system.talentClass;
}

return effectData;
})
.sort((a, b) => {
if (a.temporary) return -1;
if (b.temporary) return 1;
return 0;
});
activeEffects.push(effectData);
}
});

return sortedEffects;
return activeEffects;
}

/**
Expand All @@ -231,6 +222,7 @@ export class EffectPanelControllerSD {

effects.forEach(effect => {
if (effect.hidden) return;
// show non effect type item according to settings
if (!effect.category && game.settings.get("shadowdark", "showPassiveEffects")) {
passiveEffects.push(effect);
}
Expand All @@ -250,21 +242,6 @@ export class EffectPanelControllerSD {
};
}

/**
* Tries to get the item the effect originates from.
* @param {ActiveEffect} effect - Effect to get source from
* @returns {ItemSD|false}
*/
_getSource(effect) {
if (!effect.origin) return false;
try {
return fromUuidSync(effect.origin);
}
catch(Error) {
return false;
}
}

/**
* Gets the top level position as stored for the user
* @returns {string}
Expand Down Expand Up @@ -299,14 +276,8 @@ export class EffectPanelControllerSD {
async onIconRightClick(event) {
const $target = $(event.currentTarget);
const actor = this._actor;
// TODO: V11 Compatability legacyTransferral
// Update to use the designed interface as specified here, once implemented into core
// https://github.com/foundryvtt/foundryvtt/issues/9185
const effect = actor?.effects.get($target[0].dataset.effectId ?? "");

if (!effect) return;

const sourceItem = this._getSource(effect);
const sourceItem = actor.items.get($target[0].dataset.effectId);
if (!sourceItem || sourceItem.type !== "Effect") return;

// TODO: Consider allowing default behavior to just delete effect item in settings.
return Dialog.confirm({
Expand Down Expand Up @@ -334,14 +305,8 @@ export class EffectPanelControllerSD {
async onIconClick(event) {
const $target = $(event.currentTarget);
const actor = this._actor;
// TODO: V11 Compatability legacyTransferral
// Update to use the designed interface as specified here, once implemented into core
// https://github.com/foundryvtt/foundryvtt/issues/9185
const effect = actor?.effects.get($target[0].dataset.effectId ?? "");

if (!effect) return;

const sourceItem = this._getSource(effect);
const sourceItem = actor.items.get($target[0].dataset.effectId);
if (!sourceItem) return;

if (event.ctrlKey || event.metaKey) {
sourceItem?.sheet.render(true);
Expand Down
3 changes: 3 additions & 0 deletions system/src/sheets/ItemSheetSD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ export default class ItemSheetSD extends ItemSheet {
event.target?.parentElement.id === "effect-duration";

if (durationTarget && durationClassName) {
if (event.target.name === "system.duration.value") {
this.item.system.duration.value = event.target.value;
}
await this._onUpdateDurationEffect();
}

Expand Down
11 changes: 8 additions & 3 deletions system/templates/apps/effect-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
<div class="effect-item">
<div class="effect-info">
<h1>
{{effect.effectName}} ({{effect.originName}})
{{effect.parentName}}
{{#if effect.effectName}}
({{effect.effectName}})
{{/if}}
</h1>

<div class="tags">
Expand All @@ -47,15 +50,17 @@
</div>

<h2>
{{#if effect.category}}
<em>
{{localize "SHADOWDARK.apps.effect_panel.right_click_to_remove"}}
</em>
</h3>
{{/if}}
</h2>
</div>

<div
class="icon"
data-effect-id="{{effect.id}}"
data-effect-id="{{effect.parent.id}}"
style="background-image: url({{activeEffectIcon effect}});"
>
{{#if effect.temporary}}
Expand Down

0 comments on commit c8c0646

Please sign in to comment.