Skip to content

Commit

Permalink
dnd5e 3.0 updates (#54)
Browse files Browse the repository at this point in the history
* Switch to appliedEffects

* Use appliedEffects when finding sources

* change manifest to require dnd5e 3.0

* Update CHANGELOG.md

* Use new stealthDisadvantage property

* Update CHANGELOG.md

* Use name instead of label on effect

* Update CHANGELOG.md

* Fix message tests

switch to appliedEffects and remove disabled/suspended tests since the code doesn't check that anymore

* Fix tests for stealth disadvantage from armor
  • Loading branch information
kaelad02 authored Feb 3, 2024
1 parent f7c946a commit 787f1ee
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 142 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 3.3.0

- bug fix: 3.0.0 compatibility for Messages and Souces from effects on items
- bug fix: 3.0.0 compatibility with new stealthDisadvantage property
- bug fix: use `name` instead of `label` on effect to remove deprecation warning
- feature: now requires dnd5e 3.0.0 and thus, Foundry 11

# 3.2.1

- bug fix: tweak how messages are added to the dialog to remove a conflict with another module that also changes that dialog
Expand Down
15 changes: 13 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@
"authors": [{ "name": "kaelad", "discord": "kaelad#1693" }],
"version": "0.1",
"compatibility": {
"minimum": "10",
"minimum": "11",
"verified": "11"
},
"relationships": {
"systems": [{ "id": "dnd5e" }, { "id": "sw5e" }]
"systems": [
{
"id": "dnd5e",
"compatibility": {
"minimum": "3.0.0",
"verified": "3.0.0"
}
},
{
"id": "sw5e"
}
]
},
"esmodules": ["src/module.js", "src/settings.js"],
"styles": ["css/adv-reminder.css"],
Expand Down
3 changes: 1 addition & 2 deletions src/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class BaseMessage {

_getActiveEffectKeys(actor) {
return actor
? actor.effects
.filter((effect) => !effect.isSuppressed && !effect.disabled)
? actor.appliedEffects
.flatMap((effect) => effect.changes)
.sort((a, b) => a.priority - b.priority)
: [];
Expand Down
2 changes: 1 addition & 1 deletion src/reminders.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class SkillReminder extends AbilityCheckReminder {
_armorStealthDisadvantage() {
if (this.skillId === "ste") {
const item = this.items.find(
(item) => item.type === "equipment" && item.system?.equipped && item.system?.stealth
(item) => item.type === "equipment" && item.system.equipped && item.system.properties.has("stealthDisadvantage")
);
debug("equiped item that imposes stealth disadvantage", item?.name);
return item?.name;
Expand Down
7 changes: 3 additions & 4 deletions src/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ const SourceMixin = (superclass) =>
_getFlags(actor) {
if (!actor) return {};

const asArray = actor.effects
.filter((effect) => !effect.isSuppressed && !effect.disabled)
const asArray = actor.appliedEffects
.flatMap((effect) =>
// make an object with the effect's label and change's key
effect.changes.map((change) => ({
label: effect.label,
name: effect.name,
key: change.key,
}))
)
.filter((change) => change.key.startsWith("flags.midi-qol."));
asArray.forEach((change) => (change.key = change.key.substring(15)));
return asArray.reduce((accum, curr) => {
if (!accum[curr.key]) accum[curr.key] = [];
accum[curr.key].push(curr.label);
accum[curr.key].push(curr.name);
return accum;
}, {});
}
Expand Down
132 changes: 3 additions & 129 deletions test/messages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ globalThis.setProperty = (object, key, value) => {
};

function createActorWithEffects(...keyValuePairs) {
const effects = keyValuePairs.map(createEffect);
const appliedEffects = keyValuePairs.map(createEffect);
return {
system: {
skills: {
Expand Down Expand Up @@ -83,23 +83,21 @@ function createActorWithEffects(...keyValuePairs) {
},
},
},
effects,
appliedEffects,
getRollData: () => ({}),
};
}

function createEffect([key, value]) {
return {
isSuppressed: false,
changes: [
{
key,
value,
mode: 0,
priority: "0",
},
],
disabled: false,
]
};
}

Expand All @@ -122,28 +120,6 @@ describe("AttackMessage no legit active effects", () => {

expect(options.dialogOptions).toBeUndefined();
});

test("attack with a suppressed active effect should not add a message", () => {
const actor = createActorWithEffects(["flags.adv-reminder.message.all", "some message"]);
actor.effects[0].isSuppressed = true;
const item = createItem("mwak", "str");
const options = {};

new AttackMessage(actor, undefined, item).addMessage(options);

expect(options.dialogOptions).toBeUndefined();
});

test("attack with a disabled active effect should not add a message", () => {
const actor = createActorWithEffects(["flags.adv-reminder.message.all", "some message"]);
actor.effects[0].disabled = true;
const item = createItem("mwak", "str");
const options = {};

new AttackMessage(actor, undefined, item).addMessage(options);

expect(options.dialogOptions).toBeUndefined();
});
});

describe("AttackMessage message flags", () => {
Expand Down Expand Up @@ -343,26 +319,6 @@ describe("AbilityCheckMessage no legit active effects", () => {

expect(options.dialogOptions).toBeUndefined();
});

test("ability check with a suppressed active effect should not add a message", () => {
const actor = createActorWithEffects(["flags.adv-reminder.message.all", "some message"]);
actor.effects[0].isSuppressed = true;
const options = {};

new AbilityCheckMessage(actor, "int").addMessage(options);

expect(options.dialogOptions).toBeUndefined();
});

test("ability check with a disabled active effect should not add a message", () => {
const actor = createActorWithEffects(["flags.adv-reminder.message.all", "some message"]);
actor.effects[0].disabled = true;
const options = {};

new AbilityCheckMessage(actor, "int").addMessage(options);

expect(options.dialogOptions).toBeUndefined();
});
});

describe("AbilityCheckMessage message flags", () => {
Expand Down Expand Up @@ -451,26 +407,6 @@ describe("AbilitySaveMessage no legit active effects", () => {

expect(options.dialogOptions).toBeUndefined();
});

test("saving throw with a suppressed active effect should not add a message", () => {
const actor = createActorWithEffects(["flags.adv-reminder.message.all", "some message"]);
actor.effects[0].isSuppressed = true;
const options = {};

new AbilitySaveMessage(actor, "int").addMessage(options);

expect(options.dialogOptions).toBeUndefined();
});

test("saving throw with a disabled active effect should not add a message", () => {
const actor = createActorWithEffects(["flags.adv-reminder.message.all", "some message"]);
actor.effects[0].disabled = true;
const options = {};

new AbilitySaveMessage(actor, "int").addMessage(options);

expect(options.dialogOptions).toBeUndefined();
});
});

describe("AbilitySaveMessage message flags", () => {
Expand Down Expand Up @@ -559,26 +495,6 @@ describe("SkillMessage no legit active effects", () => {

expect(options.dialogOptions).toBeUndefined();
});

test("skill check with a suppressed active effect should not add a message", () => {
const actor = createActorWithEffects(["flags.adv-reminder.message.all", "some message"]);
actor.effects[0].isSuppressed = true;
const options = {};

new SkillMessage(actor, "ath").addMessage(options);

expect(options.dialogOptions).toBeUndefined();
});

test("skill check with a disabled active effect should not add a message", () => {
const actor = createActorWithEffects(["flags.adv-reminder.message.all", "some message"]);
actor.effects[0].disabled = true;
const options = {};

new SkillMessage(actor, "ath").addMessage(options);

expect(options.dialogOptions).toBeUndefined();
});
});

describe("SkillMessage message flags", () => {
Expand Down Expand Up @@ -707,26 +623,6 @@ describe("DeathSaveMessage no legit active effects", () => {

expect(options.dialogOptions).toBeUndefined();
});

test("death save with a suppressed active effect should not add a message", () => {
const actor = createActorWithEffects(["flags.adv-reminder.message.all", "some message"]);
actor.effects[0].isSuppressed = true;
const options = {};

new DeathSaveMessage(actor).addMessage(options);

expect(options.dialogOptions).toBeUndefined();
});

test("death save with a disabled active effect should not add a message", () => {
const actor = createActorWithEffects(["flags.adv-reminder.message.all", "some message"]);
actor.effects[0].disabled = true;
const options = {};

new DeathSaveMessage(actor).addMessage(options);

expect(options.dialogOptions).toBeUndefined();
});
});

describe("DeathSaveMessage message flags", () => {
Expand Down Expand Up @@ -804,28 +700,6 @@ describe("DamageMessage no legit active effects", () => {

expect(options.dialogOptions).toBeUndefined();
});

test("damage with a suppressed active effect should not add a message", () => {
const actor = createActorWithEffects(["flags.adv-reminder.message.all", "some message"]);
actor.effects[0].isSuppressed = true;
const item = createItem("mwak", "str");
const options = {};

new DamageMessage(actor, undefined, item).addMessage(options);

expect(options.dialogOptions).toBeUndefined();
});

test("damage with a disabled active effect should not add a message", () => {
const actor = createActorWithEffects(["flags.adv-reminder.message.all", "some message"]);
actor.effects[0].disabled = true;
const item = createItem("mwak", "str");
const options = {};

new DamageMessage(actor, undefined, item).addMessage(options);

expect(options.dialogOptions).toBeUndefined();
});
});

describe("DamageMessage message flags", () => {
Expand Down
8 changes: 4 additions & 4 deletions test/reminders.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ describe("SkillReminder no legit active effects", () => {
type: "spell",
system: {
equipped: true,
stealth: true,
properties: new Set(["stealthDisadvantage"]),
},
},
];
Expand All @@ -690,7 +690,7 @@ describe("SkillReminder no legit active effects", () => {
type: "equipment",
system: {
equipped: false,
stealth: true,
properties: new Set(["stealthDisadvantage"]),
},
},
];
Expand Down Expand Up @@ -891,7 +891,7 @@ describe("SkillReminder disadvantage flags", () => {
type: "equipment",
system: {
equipped: true,
stealth: true,
properties: new Set(["stealthDisadvantage"]),
},
},
];
Expand All @@ -912,7 +912,7 @@ describe("SkillReminder disadvantage flags", () => {
type: "equipment",
system: {
equipped: true,
stealth: true,
properties: new Set(["stealthDisadvantage"]),
},
},
];
Expand Down

0 comments on commit 787f1ee

Please sign in to comment.