Skip to content

Commit

Permalink
Merge pull request #30 from xeqi/v11-actorsheet-toggleable-status-eff…
Browse files Browse the repository at this point in the history
…ects

feat: v11 upgrade for checking status effects
  • Loading branch information
spyrella authored Jan 9, 2024
2 parents aace8aa + a25f1d4 commit 67ccc14
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 40 deletions.
10 changes: 5 additions & 5 deletions module/documents/actor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ export class FUActor extends Actor {
// Iterate through each temporary effect applied to the actor.
actorData.effects.forEach((effect) => {
// Get the status associated with the effect, if it exists.
if (effect.flags.core) {
const statusId = effect.flags.core.statusId;
const status = CONFIG.statusEffects.find((status) => status.id === statusId);
if (effect.statuses.size == 1) {
const status = CONFIG.statusEffects.find((status) => effect.statuses.has(status));

// If a valid status is found, apply its modifiers to the corresponding attributes.
if (status) {
Expand Down Expand Up @@ -322,8 +321,9 @@ export class FUActor extends Actor {
// Iterate through each temporary effect applied to the actor.
actorData.temporaryEffects.forEach((effect) => {
// Get the status associated with the effect, if it exists.
if (effect.flags.core) {
const status = CONFIG.statusEffects.find((status) => status.id === effect.flags.core.statusId);

if (effect.statuses.size == 1) {
const status = CONFIG.statusEffects.find((status) => effect.statuses.has(status.id));

// If a valid status is found, apply its modifiers to the corresponding attributes.
if (status) {
Expand Down
10 changes: 6 additions & 4 deletions module/helpers/effects.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export function prepareActiveEffectCategories(effects) {

// Iterate over active effects, classifying them into categories
for (let e of effects) {
e._getSourceName(); // Trigger a lookup for the source name
if (e.disabled) categories.inactive.effects.push(e);
else if (e.isTemporary) categories.temporary.effects.push(e);
else categories.passive.effects.push(e);
Expand All @@ -81,14 +80,17 @@ export async function toggleStatusEffect(actor, statusEffectId) {
const statusEffect = CONFIG.statusEffects.find((e) => e.id === statusEffectId)
const cls = getDocumentClass('ActiveEffect');
const createData = foundry.utils.deepClone(statusEffect);
createData.label = game.i18n.localize(statusEffect.label);
createData['flags.core.statusId'] = statusEffectId;
createData.statuses = [statusEffect.id];
delete createData.id;
cls.migrateDataSafe(createData);
cls.cleanData(createData);
createData.name = game.i18n.localize(statusEffect.name);
delete createData.id;
await cls.create(createData, { parent: actor });
return true;
}
}

export function isActiveEffectForStatusEffectId(effect, statusEffectId) {
return effect.flags.core && effect.flags.core.statusId === statusEffectId;
return effect.statuses.size == 1 && effect.statuses.has(statusEffectId);
}
50 changes: 25 additions & 25 deletions module/projectfu.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,155 +49,155 @@ Hooks.once('init', async () => {
CONFIG.statusEffects = [
{
id: 'accelerated',
label: 'Accelerated',
name: 'Accelerated',
icon: 'systems/projectfu/styles/static/statuses/Accelerated.webp',
},
{
id: 'aura',
label: 'Aura',
name: 'Aura',
icon: 'systems/projectfu/styles/static/statuses/Aura.webp',
},
{
id: 'barrier',
label: 'Barrier',
name: 'Barrier',
icon: 'systems/projectfu/styles/static/statuses/Barrier.webp',
},
{
id: 'beserk',
label: 'Beserk',
name: 'Beserk',
icon: 'systems/projectfu/styles/static/statuses/Beserk.webp',
},
{
id: 'blinded',
label: 'Blinded',
name: 'Blinded',
icon: 'systems/projectfu/styles/static/statuses/Blinded.webp',
},
{
id: 'death',
label: 'Death',
name: 'Death',
icon: 'systems/projectfu/styles/static/statuses/Death.webp',
},
{
id: 'dazed',
label: 'Dazed',
name: 'Dazed',
icon: 'systems/projectfu/styles/static/statuses/Dazed.webp',
stats: ['ins'],
mod: -2,
},
{
id: 'dex-down',
label: 'DEX Down',
name: 'DEX Down',
icon: 'systems/projectfu/styles/static/statuses/DexDown.webp',
stats: ['dex'],
mod: -2,
},
{
id: 'dex-up',
label: 'DEX Up',
name: 'DEX Up',
icon: 'systems/projectfu/styles/static/statuses/DexUp.webp',
stats: ['dex'],
mod: 2,
},
{
id: 'enraged',
label: 'Enraged',
name: 'Enraged',
icon: 'systems/projectfu/styles/static/statuses/Enraged.webp',
stats: ['dex', 'ins'],
mod: -2,
},
{
id: 'ins-down',
label: 'INS Down',
name: 'INS Down',
icon: 'systems/projectfu/styles/static/statuses/InsDown.webp',
stats: ['ins'],
mod: -2,
},
{
id: 'ins-up',
label: 'INS Up',
name: 'INS Up',
icon: 'systems/projectfu/styles/static/statuses/InsUp.webp',
stats: ['ins'],
mod: 2,
},
{
id: 'ko',
label: 'KO',
name: 'KO',
icon: 'systems/projectfu/styles/static/statuses/KO.webp',
},
{
id: 'mig-down',
label: 'MIG Down',
name: 'MIG Down',
icon: 'systems/projectfu/styles/static/statuses/MigDown.webp',
stats: ['mig'],
mod: -2,
},
{
id: 'mig-up',
label: 'MIG Up',
name: 'MIG Up',
icon: 'systems/projectfu/styles/static/statuses/MigUp.webp',
stats: ['mig'],
mod: 2,
},
{
id: 'reflect',
label: 'Reflect',
name: 'Reflect',
icon: 'systems/projectfu/styles/static/statuses/Reflect.webp',
},
{
id: 'regen',
label: 'Regen',
name: 'Regen',
icon: 'systems/projectfu/styles/static/statuses/Regen.webp',
},
{
id: 'shaken',
label: 'Shaken',
name: 'Shaken',
icon: 'systems/projectfu/styles/static/statuses/Shaken.webp',
stats: ['wlp'],
mod: -2,
},
{
id: 'sleep',
label: 'Sleep',
name: 'Sleep',
icon: 'systems/projectfu/styles/static/statuses/Sleep.webp',
},
{
id: 'slow',
label: 'Slow',
name: 'Slow',
icon: 'systems/projectfu/styles/static/statuses/Slow.webp',
stats: ['dex'],
mod: -2,
},
{
id: 'poisoned',
label: 'Poisoned',
name: 'Poisoned',
icon: 'systems/projectfu/styles/static/statuses/Poisoned.webp',
stats: ['mig', 'wlp'],
mod: -2,
},
{
id: 'weak',
label: 'Weak',
name: 'Weak',
icon: 'systems/projectfu/styles/static/statuses/Weak.webp',
stats: ['mig'],
mod: -2,
},
{
id: 'wlp-down',
label: 'WLP Down',
name: 'WLP Down',
icon: 'systems/projectfu/styles/static/statuses/WlpDown.webp',
stats: ['wlp'],
mod: -2,
},
{
id: 'wlp-up',
label: 'WLP Up',
name: 'WLP Up',
icon: 'systems/projectfu/styles/static/statuses/WlpUp.webp',
stats: ['wlp'],
mod: 2,
},
{
id: 'crisis',
label: 'Crisis',
name: 'Crisis',
icon: 'systems/projectfu/styles/static/statuses/Status_Bleeding.png',
},
];
Expand Down
2 changes: 1 addition & 1 deletion templates/actor/partials/actor-resources.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{{#each statusEffectToggles as |statusEffect|}}
<a class="status-effect-toggle {{#if statusEffect.active}}active{{/if}}"
data-status-id="{{statusEffect.id}}">
<img src="{{statusEffect.icon}}" data-tooltip="{{statusEffect.label}}">
<img src="{{statusEffect.icon}}" data-tooltip="{{statusEffect.name}}">
</a>
{{/each}}
</span>
Expand Down
6 changes: 3 additions & 3 deletions templates/actor/sections/actor-section-effects.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
<div class="item-name">
<div class="item-image">
<div class="rollable" data-roll-type="item">
<img src="{{ effect.icon }}" data-tooltip="{{ effect.label }}" />
<img src="{{ effect.icon }}" data-tooltip="{{ effect.name }}" />
</div>
</div>
<h4 class="click-item">
{{ effect.label }}
{{ effect.name }}
</h4>
</div>
<div class="item-lg">{{ effect.sourceName }}</div>
<div class="item-lg">{{ effect.duration.label }}</div>
<div class="item-lg">{{ effect.duration.name }}</div>
<div class="item-m end flexrow">
<a class="effect-control" data-action="toggle" title="{{localize 'FU.EffectToggle'}}">
<i class="fas {{#if effect.disabled}}fa-check{{else}}fa-times{{/if}}"></i>
Expand Down
4 changes: 2 additions & 2 deletions templates/item/partials/item-effects.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
<div class="item-image">
<a class="rollable" data-roll-type="item">
<div class="item-image-wrap">
<img src="{{ effect.icon }}" title="{{ effect.label }}" class="responsive-img" />
<img src="{{ effect.icon }}" title="{{ effect.name }}" class="responsive-img" />
</div>
</a>
</div>
<h4>{{ effect.label }}</h4>
<h4>{{ effect.name }}</h4>
</div>
<div class="effect-source">{{ effect.sourceName }}</div>
<div class="effect-duration">{{ effect.duration.label }}</div>
Expand Down

1 comment on commit 67ccc14

@spyrella
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.