Skip to content

Commit

Permalink
Merge pull request dmdorman#1626 from aeauseth/main
Browse files Browse the repository at this point in the history
ActiveEffect changes. Better fades. Worse AP calculations. Improved AE UI.
  • Loading branch information
aeauseth authored Dec 15, 2024
2 parents 08a126f + 9d85a07 commit 43f30bb
Show file tree
Hide file tree
Showing 12 changed files with 337 additions and 15 deletions.
2 changes: 2 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export default [
ui: "readonly",
DetectionMode: "readonly",
OutlineOverlayFilter: "readonly",
DocumentSheetConfig: "readonly",
ActiveEffectConfig: "readonly",
},
},
},
Expand Down
36 changes: 36 additions & 0 deletions module/actor/active-effect-config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { HEROSYS } from "../herosystem6e.mjs";

export class HeroSystemActiveEffectConfig extends ActiveEffectConfig {
static get defaultOptions() {
const defaultOptions = super.defaultOptions;
return foundry.utils.mergeObject(defaultOptions, {
//classes: ["herosystem6e", "sheet", "item"],
// width: 520,
// height: 660,
// scrollY: [".sheet-body"],
classes: ["sheet", "herosystem-active-effect-config", "active-effect-sheet"],
template: `systems/${HEROSYS.module}/templates/actor/active-effect-config.hbs`,
});
}

async getData() {
const context = await super.getData();
for (let i = 0; i < context.data.changes.length; i++) {
context.data.changes[i] = { ...context.data.changes[i], ...context.data.flags.changes?.[i] };
}
const originItem = fromUuidSync(context.data.origin);
const token = fromUuidSync(context.data.origin.match(/(.*).Actor/)?.[1]);
context.originText = originItem
? `${token?.name || originItem.actor?.name}: ${originItem.name}`
: context.data.origin;
return context;
}

// async _updateObject(event, formData) {
// await super._updateObject(event, formData);

// // if (formData.changes) {
// // await this.object.update({ changes: formData.changes });
// // }
// }
}
19 changes: 19 additions & 0 deletions module/actor/actor-active-effects.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ import { HEROSYS } from "../herosystem6e.mjs";
import { RoundFavorPlayerUp } from "../utility/round.mjs";

export class HeroSystem6eActorActiveEffects extends ActiveEffect {
// static defineSchema() {
// const schema2 = this.schema; // foundry.deepClone(super.defineSchema());
// schema2.changes = new foundry.data.fields.ArrayField(
// new foundry.data.fields.SchemaField({
// key: new foundry.data.fields.StringField({ required: true, label: "EFFECT.ChangeKey" }),
// value: new foundry.data.fields.StringField({ required: true, label: "EFFECT.ChangeValue" }),
// mode: new foundry.data.fields.NumberField({
// integer: true,
// initial: CONST.ACTIVE_EFFECT_MODES.ADD,
// label: "EFFECT.ChangeMode",
// }),
// priority: new foundry.data.fields.NumberField(),
// seconds: new foundry.data.fields.NumberField({ integer: true, label: "EFFECT.Seconds" }),
// }),
// );
// return schema2;
// }
//ActiveEffect.schema.fields.changes.element.fields

// All status effects
static statusEffectsObj;

Expand Down
6 changes: 5 additions & 1 deletion module/actor/actor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ export class HeroSystem6eActor extends Actor {
newEffect.statuses = [activeEffect.id];

// Check if this ActiveEffect already exists
const existingEffect = this.effects.find((o) => o.statuses.has(activeEffect.id));
const existingEffect = this.effects.find(
(o) => o.statuses.has(activeEffect.id) && !activeEffect.id.includes("DRAIN"),
);
if (!existingEffect) {
await this.createEmbeddedDocuments("ActiveEffect", [newEffect]);
} else {
console.warn("There was a pre-existing ActiveEffect, so the new AE was not added.");
}
}

Expand Down
10 changes: 8 additions & 2 deletions module/effects-panel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@ export class EffectsPanel extends Application {
// Sometimes ae.parent?.system.active is false, but the power is active, unclear why.
// Consider making active a getter (looking for the AE) instead of using system.actor.
if (ae.parent instanceof HeroSystem6eItem && ae.duration.seconds) {
ae.flags.label = `${ae.duration.startTime + ae.duration.seconds - game.time.worldTime} seconds`;
const d = ae._prepareDuration();
ae.flags.label = d.label;
//ae.flags.label = `${ae.duration.startTime + ae.duration.seconds - game.time.worldTime} seconds`;
for (const target of ae.flags.target) {
const item = fromUuidSync(target);
ae.flags.targetDisplay = `${item?.name} [${item.system.XMLID}]`;
}
} else {
const d = ae._prepareDuration();
ae.flags.label = d.label;
ae.flags.targetDisplay = ae.flags.target;
}
ae.flags.targetDisplay = ae.flags.target;
}
}

Expand Down
39 changes: 35 additions & 4 deletions module/herosystem6e.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import HeroSystem6eMeasuredTemplate from "./measuretemplate.mjs";
import { HeroSystem6eCombat } from "./combat.mjs";
import { HeroSystem6eCombatTracker } from "./combatTracker.mjs";
import SettingsHelpers from "./settings/settings-helpers.mjs";
import { HeroSystem6eTokenHud } from "./bar3/tokenHud.mjs";
import { extendTokenConfig } from "./bar3/extendTokenConfig.mjs";
//import { HeroSystem6eTokenHud } from "./bar3/tokenHud.mjs";
//import { extendTokenConfig } from "./bar3/extendTokenConfig.mjs";
import { HeroRuler } from "./ruler.mjs";
import { initializeHandlebarsHelpers } from "./handlebars-helpers.mjs";
import { expireEffects, getCharacteristicInfoArrayForActor } from "./utility/util.mjs";
Expand All @@ -33,6 +33,7 @@ import "./utility/chat-dice.mjs";

import "./testing/testing-main.mjs";
import { EffectsPanel } from "./effects-panel.mjs";
import { HeroSystemActiveEffectConfig } from "./actor/active-effect-config.mjs";

Hooks.once("init", async function () {
// Custom HeroSystem VisionMode
Expand Down Expand Up @@ -83,6 +84,7 @@ Hooks.once("init", async function () {
CONFIG.Token.objectClass = HeroSystem6eToken;
CONFIG.MeasuredTemplate.objectClass = HeroSystem6eMeasuredTemplate;
CONFIG.ActiveEffect.documentClass = HeroSystem6eActorActiveEffects;
// CONFIG.ActiveEffect.dataModels.base = HeroSystem6eActorActiveEffects.defineSchema();
CONFIG.Canvas.rulerClass = HeroRuler;
CONFIG.Canvas.visionSourceClass = HeroPointVisionSource;

Expand All @@ -106,6 +108,12 @@ Hooks.once("init", async function () {
makeDefault: true,
});

//Not sure why ActiveEffect.registerSheet is missing.
DocumentSheetConfig.registerSheet(ActiveEffect, "herosystem6e", HeroSystemActiveEffectConfig, {
makeDefault: true,
label: "HeroSystemActiveEffectConfig",
});

const templatePaths = [
`systems/${HEROSYS.module}/templates/item/item-common-partial.hbs`,
`systems/${HEROSYS.module}/templates/item/item-effects-partial.hbs`,
Expand All @@ -120,6 +128,7 @@ Hooks.once("init", async function () {
`systems/${HEROSYS.module}/templates/actor/actor-sheet-partial-powers-item.hbs`,
`systems/${HEROSYS.module}/templates/actor/actor-sheet-partial-equipment.hbs`,
`systems/${HEROSYS.module}/templates/actor/actor-sheet-partial-equipment-item.hbs`,
`systems/${HEROSYS.module}/templates/actor/active-effect-config.hbs`,
// `systems/${HEROSYS.module}/templates/sidebar/partials/document-partial.hbs`,
`systems/${HEROSYS.module}/templates/system/effects-panel.hbs`,
`systems/${HEROSYS.module}/templates/system/heroRoll-panel.hbs`,
Expand Down Expand Up @@ -527,8 +536,8 @@ Hooks.on("getActorDirectoryEntryContext", (_dialog, html) => {
});

//Modify TokenHUD (need 3 bars: end, stun, body)
Hooks.on("renderTokenHUD", HeroSystem6eTokenHud);
Hooks.on("renderTokenConfig", extendTokenConfig);
// Hooks.on("renderTokenHUD", HeroSystem6eTokenHud);
// Hooks.on("renderTokenConfig", extendTokenConfig);

// Expire ActiveEffects
let secondsSinceRecovery = 0;
Expand Down Expand Up @@ -942,3 +951,25 @@ Hooks.on("renderSidebarTab", async (app, html) => {
}
});
});

// Hooks.on("renderActiveEffectConfig", (activeEffectConfig, html, data) => {
// console.log(activeEffectConfig, html, data);

// const effectsTab = html.find("section[data-tab='effects']");
// const header = effectsTab.find("header");
// const headerValue = header.find("div.value");
// headerValue.after("<div>Seconds</div>");

// const changesList = effectsTab.find("ol.changes-list");
// changesList.find("li").each(function (idx) {
// const liValue = $(this).find("div.value");
// //const idx = liValue.name.match(/changes\.(\d+)/)[1];
// liValue.after(`<input type="text" class="seconds" name="changes.${idx}.seconds" value="">`);
// });

// const submitButton = html.find("button[type='submit']");
// submitButton.one("submit", function () {
// debugger;
// console.log(this);
// });
// });
12 changes: 6 additions & 6 deletions module/item/item.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5070,12 +5070,12 @@ export class HeroSystem6eItem extends Item {

async addActiveEffect(activeEffect) {
const newEffect = foundry.utils.deepClone(activeEffect);
// newEffect.duration.duration ??= newEffect.duration.seconds;
// newEffect.duration.startTime ??= game.time.worldTime;
// newEffect.duration.startRound ??= game.combat.current.round;
// newEffect.duration.startTurn ??= game.combat.current.turn;
// newEffect.duration.type ??= "seconds";
newEffect.transfer = false;
newEffect.duration.duration ??= newEffect.duration.seconds;
newEffect.duration.startTime ??= game.time.worldTime;
newEffect.duration.startRound ??= game.combat.current.round;
newEffect.duration.startTurn ??= game.combat.current.turn;
newEffect.duration.type ??= "seconds";
//newEffect.transfer = false;

//const ae = await this.createEmbeddedDocuments("ActiveEffect", [newEffect]);
//ae.duration = ae.updateDuration();
Expand Down
7 changes: 5 additions & 2 deletions module/utility/adjustment.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,14 @@ export function determineCostPerActivePoint(targetCharacteristic, targetPower, t
}

function _findExistingMatchingEffect(item, potentialCharacteristic, powerTargetName, targetSystem) {
// Kluge: Ignore any negative changes as we want each DRAIN to be separate so we can properly track the fades.
// This introduces issues where the AP of multiple DRAINs don't add up partial drains.
// Caution: The item may no longer exist.
return targetSystem.effects.find(
(effect) =>
effect.origin === item.uuid &&
effect.flags.target[0] === (powerTargetName?.uuid || potentialCharacteristic),
effect.flags.target[0] === (powerTargetName?.uuid || potentialCharacteristic) &&
parseInt(effect.changes?.[0].value || 0) >= 0,
);
}

Expand Down Expand Up @@ -301,7 +304,7 @@ function _createNewAdjustmentEffect(
attackerTokenId: action?.current?.attackerTokenId,
},
origin: item.uuid,
//description: item.system.description, // Issues with core FoundryVTT where description doesn't show, nor is editable.
description: item.system.description, // Issues with core FoundryVTT where description doesn't show, nor is editable.
transfer: true,
disabled: false,
};
Expand Down
15 changes: 15 additions & 0 deletions scss/components/_active-effects.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// div.herosystem-active-effect-config {
// background: red;
// }

// div.herosystem-active-effect-config > .window-content {
// background: red;
// }

div.herosystem-active-effect-config div.description {
background-color: rgba(0 0 0 / 10%);
border: 1px dashed rgb(0 0 0 / 50%);
padding: 5px;
max-width: 100%;
user-select: text;
}
2 changes: 2 additions & 0 deletions scss/components/_actor-sheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,12 @@ form.item-sheet h1.charname input {

.herosystem6e.sheet.item div.description,
form div.attack-card div.description {
background-color: rgba(0 0 0 / 10%);
border: 1px dashed rgb(0 0 0 / 50%);
margin: 15px 0;
padding: 5px;
max-width: 100%;
user-select: text;
}

.herosystem6e.sheet.item tr.modifier-adder td:first-child {
Expand Down
3 changes: 3 additions & 0 deletions scss/herosystem6e.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@

/* Styles for Notes */
@include meta.load-css("components/notes");

/* Styles for Notes */
@include meta.load-css("components/active-effects");
Loading

0 comments on commit 43f30bb

Please sign in to comment.