Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) feat: ✨ use active effects to sync conditions [fix #378] #385

Merged
merged 5 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ten-papayas-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"foundry-types": minor
---

Move conditions to ActiveEffects
37 changes: 22 additions & 15 deletions src/actor/actor-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,29 @@ export class ForbiddenLandsActor extends Actor {
}

toggleCondition(conditionName) {
const conditionValue = this.conditions[conditionName].value;
const conditionLabel = this.conditions[conditionName].label;
const effect = this.effects.find(
(condition) => condition.getFlag("core", "statusId") === conditionName,
const statusEffect = CONFIG.statusEffects.find(
(it) => it.id === conditionName,
);
if (CONFIG.fbl.conditions.includes(conditionName)) {
this.update({
[`system.condition.${conditionName}.value`]: !conditionValue,
});
if (conditionValue && effect)
this.deleteEmbeddedDocuments("ActiveEffect", [effect.id]);
else if (!conditionValue && !effect)
this.createEmbeddedDocuments("ActiveEffect", {
...CONFIG.fbl.activeEffects[conditionName],
label: localize(conditionLabel),
});
const currentEffect = Array.from(this.effects?.values()).find(
(it) => it.icon === statusEffect.icon,
);
if (currentEffect) {
this.deleteEmbeddedDocuments("ActiveEffect", [currentEffect.id]);
} else {
this.createEmbeddedDocuments("ActiveEffect", [
{
label: game.i18n.localize(statusEffect.label),
icon: statusEffect.icon,
changes: statusEffect.changes,
id: this.uuid,
statuses: statusEffect.statuses,
flags: {
core: {
statusId: statusEffect.id,
},
},
},
]);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/actor/actor-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class ForbiddenLandsActorSheet extends ActorSheet {
data.carriedStates = this.#getCarriedStates();
data.gear = this.#filterGear(data.items);
data.system.useHealthAndResolve = this.useHealthAndResolve;
data.system.condition = this.actor.system.condition;
data.statuses = this.actor.statuses;

return data;
}
Expand Down
7 changes: 7 additions & 0 deletions src/forbidden-lands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import registerSettings from "@system/core/settings.js";
import { registerSheets } from "@system/core/sheets.js";
import localizeString from "@utils/localize-string.js";
import { YearZeroRollManager } from "foundry-year-zero-roller";
import { ForbiddenLandsTokenHUD } from "@system/core/hud.js";

/**
* We use this label to remove the debug option in production builds.
Expand All @@ -48,6 +49,7 @@ Hooks.once("init", () => {
config: FBL,
roll: FBLRollHandler.createRoll,
};

CONFIG.Actor.documentClass = ForbiddenLandsActor;
CONFIG.Combat.documentClass = FBLCombat;
// @ts-expect-error - PF2 types Internal Type Error
Expand All @@ -57,6 +59,7 @@ Hooks.once("init", () => {
CONFIG.JournalEntry.documentClass = ForbiddenLandsJournalEntry;
// @ts-expect-error - PF2 types Internal Type Error
CONFIG.ui.combat = FBLCombatTracker;
CONFIG.statusEffects = FBL.statusEffects;
CONFIG.fbl = FBL;
CONFIG.fbl.adventureSites.utilities = utilities;
CONFIG.fbl.adventureSites.generate = (path: string, adventureSite: unknown) =>
Expand Down Expand Up @@ -107,3 +110,7 @@ Hooks.once("ready", () => {
});
});
});

Hooks.on("canvasReady", (canvas) => {
canvas.hud.token = new ForbiddenLandsTokenHUD();
});
294 changes: 0 additions & 294 deletions src/system/core/config.js

This file was deleted.

Loading