-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add roll dialog template * add message check to the reminders * move message checks into their own classes instead of including them in the advantage reminder classes * add unit test for AttackMessage * show multiple messages instead of just one * remove sorting Sorting the effects by priority was an attempt to repurpose that to just show one message. Probably not a good idea to change what priority was meant for, which was for how to apply multiple effects on the same thing. Also not as necessary since showing them all anyways. * await the addMessage method Fixes the unit tests and changed it into the module code as well to make sure we wait for setting up the dialog hook before proceeding. It worked fine without it but better to be safe * add test for two messages and check that the hook was setup * add test cases for AbilityCheckMessage * add unit tests for AbilitySaveMessage * add unit tests for SkillMessage * add unit tests for DeathSaveMessage * add DamageMessage implementation and tests * add sorting back * remove roll dialog replacement template Was going to use this to completely replace the core dialog but went with adding to the existing one instead. Don't need this anymore * flip priority around to match the order Foundry applies active effect changes * small CSS tweaks Some changes inspired by #9. Increases the padding by 2px to get close to what it had. I still think the smaller sides is better. Increased the margin to 8px. While not as large, it's the size of the padding of the dialog box (window-content class) * use dialogOptions.id to get the message on the right roll dialog * add nested options in for Damage message * update readme and changelog * fix readme type in MRE section * add links to issues in changelog just a convenience * add MRE compatibility with damage rolls MRE configures it's damage wrapper with libWrapper as MIXED. That means it always runs after WRAPPED methods like this module uses. If we are using MRE, always process it so we can pass critical and messages down to MRE and then it can decide what to do with them.
- Loading branch information
Showing
8 changed files
with
1,188 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
# 1.0 | ||
|
||
- feature: [#3](https://github.com/kaelad02/adv-reminder/issues/3) Messages that show up on the roll dialogs | ||
- feature: improve MRE compatibility to skip when it fast-forwards rolls | ||
|
||
# 0.4 | ||
|
||
* feature: support armor that imposes stealth disadvantage | ||
- feature: [#7](https://github.com/kaelad02/adv-reminder/issues/7) support armor that imposes stealth disadvantage | ||
|
||
# 0.3 | ||
|
||
* bug fix: Active effects from unequipped items weren't being ignored | ||
* documentation: Update readme with module compatibility info | ||
- bug fix: [#2](https://github.com/kaelad02/adv-reminder/issues/2) Active effects from unequipped items weren't being ignored | ||
- documentation: Update readme with module compatibility info | ||
|
||
# 0.2 | ||
|
||
* feature: add Tool checks support | ||
* mark compatible with v9 | ||
- feature: add Tool checks support | ||
- mark compatible with v9 | ||
|
||
# 0.1 | ||
|
||
* Initial release | ||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import { debug } from "./util.js"; | ||
|
||
class BaseMessage { | ||
constructor(actor) { | ||
/** @type {EffectChangeData[]} */ | ||
this.changes = actor.effects | ||
.filter((effect) => !effect.isSuppressed && !effect.data.disabled) | ||
.flatMap((effect) => effect.data.changes) | ||
.sort((a, b) => a.priority - b.priority); | ||
} | ||
|
||
get messageKeys() { | ||
return ["flags.adv-reminder.message.all"]; | ||
} | ||
|
||
async addMessage(options) { | ||
const keys = this.messageKeys; | ||
const messages = this.changes | ||
.filter((change) => keys.includes(change.key)) | ||
.map((change) => change.value); | ||
|
||
if (messages.length > 0) { | ||
// add id to dialogOptions to put the message on the correct roll dialog | ||
const messageId = randomID(); | ||
options.dialogOptions = options.dialogOptions || {}; | ||
options.dialogOptions.id = messageId; | ||
// build message | ||
const message = await renderTemplate( | ||
"modules/adv-reminder/templates/roll-dialog-messages.hbs", | ||
{ messages } | ||
); | ||
debug("adding hook to renderDialog w/ ", message); | ||
const hookId = Hooks.on("renderDialog", (dialog, html, data) => { | ||
debug("called on hook for renderDialog"); | ||
if (dialog.options.id !== messageId) return; | ||
// add message at the end | ||
const formGroups = html.find(".form-group:last"); | ||
formGroups.after(message); | ||
// reset dialog height | ||
const position = dialog.position; | ||
position.height = "auto"; | ||
dialog.setPosition(position); | ||
}); | ||
setTimeout(() => { | ||
Hooks.off("renderDialog", hookId); | ||
}, 10_000); | ||
} | ||
|
||
return messages; | ||
} | ||
} | ||
|
||
export class AttackMessage extends BaseMessage { | ||
constructor(actor, item) { | ||
super(actor); | ||
|
||
/** @type {string} */ | ||
this.actionType = item.data.data.actionType; | ||
/** @type {string} */ | ||
this.abilityId = item.abilityMod; | ||
} | ||
|
||
/** @override */ | ||
get messageKeys() { | ||
return super.messageKeys.concat( | ||
"flags.adv-reminder.message.attack.all", | ||
`flags.adv-reminder.message.attack.${this.actionType}`, | ||
`flags.adv-reminder.message.attack.${this.abilityId}` | ||
); | ||
} | ||
} | ||
|
||
class AbilityBaseMessage extends BaseMessage { | ||
constructor(actor, abilityId) { | ||
super(actor); | ||
|
||
/** @type {string} */ | ||
this.abilityId = abilityId; | ||
} | ||
|
||
/** @override */ | ||
get messageKeys() { | ||
return super.messageKeys.concat("flags.adv-reminder.message.ability.all"); | ||
} | ||
} | ||
|
||
export class AbilityCheckMessage extends AbilityBaseMessage { | ||
/** @override */ | ||
get messageKeys() { | ||
return super.messageKeys.concat( | ||
"flags.adv-reminder.message.ability.check.all", | ||
`flags.adv-reminder.message.ability.check.${this.abilityId}` | ||
); | ||
} | ||
} | ||
|
||
export class AbilitySaveMessage extends AbilityBaseMessage { | ||
/** @override */ | ||
get messageKeys() { | ||
return super.messageKeys.concat( | ||
"flags.adv-reminder.message.ability.save.all", | ||
`flags.adv-reminder.message.ability.save.${this.abilityId}` | ||
); | ||
} | ||
} | ||
|
||
export class SkillMessage extends AbilityCheckMessage { | ||
constructor(actor, skillId) { | ||
super(actor, actor.data.data.skills[skillId].ability); | ||
|
||
/** @type {string} */ | ||
this.skillId = skillId; | ||
} | ||
|
||
/** @override */ | ||
get messageKeys() { | ||
return super.messageKeys.concat( | ||
"flags.adv-reminder.message.skill.all", | ||
`flags.adv-reminder.message.skill.${this.skillId}` | ||
); | ||
} | ||
} | ||
|
||
export class DeathSaveMessage extends AbilityBaseMessage { | ||
constructor(actor) { | ||
super(actor, null); | ||
} | ||
|
||
/** @override */ | ||
get messageKeys() { | ||
return super.messageKeys.concat( | ||
"flags.adv-reminder.message.ability.save.all", | ||
"flags.adv-reminder.message.deathSave" | ||
); | ||
} | ||
} | ||
|
||
export class DamageMessage extends BaseMessage { | ||
constructor(actor, item) { | ||
super(actor); | ||
|
||
/** @type {string} */ | ||
this.actionType = item.data.data.actionType; | ||
} | ||
|
||
/** @override */ | ||
get messageKeys() { | ||
return super.messageKeys.concat( | ||
"flags.adv-reminder.message.damage.all", | ||
`flags.adv-reminder.message.damage.${this.actionType}` | ||
); | ||
} | ||
|
||
async addMessage(options) { | ||
// Damage options has a nested options variable, add that and pass it to super | ||
options.options = options.options || {}; | ||
return super.addMessage(options.options); | ||
} | ||
} |
Oops, something went wrong.