Skip to content

Commit

Permalink
update hooks for WFRP4e 8.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Forien committed Oct 3, 2024
1 parent 78ccce5 commit ee6b16f
Show file tree
Hide file tree
Showing 12 changed files with 347 additions and 163 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## v3.X.X

### v3.1.2 ?
### v3.2.0
* Fixed Grimoires not applying SourceId flag correctly, resulting in duplicating spells in very specific conditions
* Fixed spelling in Hooks registration after they have been renamed
* Added support for Character Sheet v2 introduced in WFRP4e 8.1.0 for Magical Endurance and Scrolls.

### v3.1.1
* Fixed multiple macros and features being broken due to renaming of Actor class from `ActorWfrp4e` to `ActorWFRP4e`
Expand Down
6 changes: 3 additions & 3 deletions dist/modules/apps/ScrollDialog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class ScrollDialog extends CastDialog {
data.scripts = data.scripts.concat(data.spell?.getScripts("dialog"), data.skill?.getScripts("dialog") || [])

return new Promise(resolve => {
new this(fields, data, resolve, options).render(true);
new this(data, fields, options, resolve).render(true);
});
}

Expand All @@ -48,8 +48,8 @@ export default class ScrollDialog extends CastDialog {
* @returns {{}}
* @protected
*/
_constructTestData() {
let data = super._constructTestData();
_getSubmissionData() {
let data = super._getSubmissionData();

data.item = this.data.spell;
data.scroll = this.data.scroll;
Expand Down
29 changes: 26 additions & 3 deletions dist/modules/features/CastingFatigue.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export default class CastingFatigue extends ForienBaseModule {
bindHooks() {
Hooks.on("wfrp4e:rollChannelTest", this.#processRollChannelTest.bind(this));
Hooks.on("wfrp4e:rollCastTest", this.#processRollCastTest.bind(this));
Hooks.on("renderActorSheetWfrp4eCharacter", this.#onRenderActorSheet.bind(this));
Hooks.on("renderActorSheetWfrp4eNPC", this.#onRenderActorSheet.bind(this));
Hooks.on("renderActorSheetWFRP4eCharacter", this.#onRenderActorSheet.bind(this));
Hooks.on("renderActorSheetWFRP4eNPC", this.#onRenderActorSheet.bind(this));
Hooks.on("renderActorSheetWFRP4eCharacterV2", this.#onRenderActorV2Sheet.bind(this));
// Hooks.on("renderActorSheetWFRP4eNPCV2", this.#onRenderActorV2Sheet.bind(this));
Hooks.on("ready", this.#registerAutoRegenListeners.bind(this));
}

Expand Down Expand Up @@ -55,7 +57,7 @@ export default class CastingFatigue extends ForienBaseModule {

/**
*
* @param {ActorSheetWfrp4e} sheet
* @param {ActorSheetWFRP4e} sheet
* @param {jQuery} html
* @param {{}} _options
*/
Expand All @@ -73,6 +75,27 @@ export default class CastingFatigue extends ForienBaseModule {
});
}

/**
*
* @param {ActorSheetWFRP4e} sheet
* @param {HTMLElement} html
* @param {{}} _options
*/
#onRenderActorV2Sheet(sheet, html, _options) {
if (!this.magicalEnduranceEnabled) return;

const tabMagic = html.querySelector('.tab[data-tab="magic"]');
const actor = sheet.actor;
const magicalEndurance = this.getMagicalEnduranceData(actor);

renderTemplate(Utility.getTemplate(this.templates.magicalEndurance), magicalEndurance).then(content => {
const child = Utility.stringToHTMLElement(content)
tabMagic.prepend(child);

html.querySelector('#magical-endurance-value').addEventListener("change", (ev) => this.#onMagicalEnduranceValueChange(ev, actor));
});
}

/**
* @param {Event} ev
* @param {ActorWFRP4e} actor
Expand Down
8 changes: 4 additions & 4 deletions dist/modules/features/Grimoires.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export default class Grimoires extends ForienBaseModule {
*/
bindHooks() {
Hooks.on("wfrp4e:constructInventory", this.#onWfrp4eConstructInventory.bind(this));
Hooks.on("renderActorSheetWfrp4eCharacter", this.#onRenderActorSheet.bind(this));
Hooks.on("renderActorSheetWfrp4eNPC", this.#onRenderActorSheet.bind(this));
Hooks.on("renderActorSheetWFRP4eCharacter", this.#onRenderActorSheet.bind(this));
Hooks.on("renderActorSheetWFRP4eNPC", this.#onRenderActorSheet.bind(this));
}

/**
* Add Scrolls to appropriate Inventory categories
*
* @param {ActorSheetWfrp4e} sheet
* @param {ActorSheetWFRP4e} sheet
* @param {{}} categories
* @param {{}} collapsed
*/
Expand All @@ -43,7 +43,7 @@ export default class Grimoires extends ForienBaseModule {
/**
* Registers Grimoire-specific Event Listeners
*
* @param {ActorSheetWfrp4e} sheet
* @param {ActorSheetWFRP4e} sheet
* @param {jQuery} html
* @param {{}} _options
*
Expand Down
61 changes: 54 additions & 7 deletions dist/modules/features/Scrolls.mjs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import ForienBaseModule from "../utility/ForienBaseModule.mjs";
import Utility from "../utility/Utility.mjs";
import ScrollDialog from "../apps/ScrollDialog.mjs";
import ScrollTest from "../tests/ScrollTest.mjs";
import {dataTypes, settings} from "../constants.mjs";

export default class Scrolls extends ForienBaseModule {
templates = {
magicScrolls: 'partials/actor-sheet-wfrp4e-magic-scrolls.hbs',
magicScrollsV2: 'partials/actor-sheet-wfrp4e-magic-scrolls-v2.hbs',
}

/**
* @inheritDoc
*/
bindHooks() {
Hooks.on("renderActorSheetWfrp4eCharacter", this.#onRenderActorSheet.bind(this));
Hooks.on("renderActorSheetWfrp4eNPC", this.#onRenderActorSheet.bind(this));
Hooks.on("renderActorSheetWFRP4eCharacter", this.#onRenderActorSheet.bind(this));
Hooks.on("renderActorSheetWFRP4eNPC", this.#onRenderActorSheet.bind(this));
Hooks.on("renderActorSheetWFRP4eCharacterV2", this.#onRenderActorSheetV2.bind(this));
Hooks.on("wfrp4e:constructInventory", this.#onWfrp4eConstructInventory.bind(this));
}

/**
* Add Scrolls to appropriate Inventory categories
*
* @param {ActorSheetWfrp4e} sheet
* @param {ActorSheetWFRP4e} sheet
* @param {{}} categories
* @param {{}} collapsed
*/
Expand All @@ -44,7 +45,7 @@ export default class Scrolls extends ForienBaseModule {
/**
* Adds scrolls to Magic tab and registers Scroll-specific Event Listeners
*
* @param {ActorSheetWfrp4e} sheet
* @param {ActorSheetWFRP4e} sheet
* @param {jQuery} html
* @param {{}} _options
*
Expand All @@ -70,10 +71,56 @@ export default class Scrolls extends ForienBaseModule {
}
}

/**
* Adds scrolls to Magic tab and registers Scroll-specific Event Listeners
*
* @param {ActorSheetWFRP4e} sheet
* @param {HTMLElement} html
* @param {{}} _options
*
* @returns {Promise<void>}
*/
async #onRenderActorSheetV2(sheet, html, _options) {
const actor = sheet.actor;
const scrolls = actor.itemTypes[dataTypes.scroll];

const content = await renderTemplate(Utility.getTemplate(this.templates.magicScrollsV2), {
scrolls,
isOwner: sheet.document.isOwner,
dataType: dataTypes.scroll
});

const tabMagic = html.querySelector('.tab[data-tab="magic"]');
tabMagic.append(Utility.stringToHTMLElement(content));

tabMagic.querySelectorAll(".scrolls .scroll-spell-link").forEach(element => {
element.addEventListener("click", (event) => this.#onScrollSpellLinkClick(event))
});
tabMagic.querySelectorAll(".scrolls .scroll-spell-cast").forEach(element => {
element.addEventListener("click", (event) => this.#onScrollSpellCastClick(sheet, event))
});

tabMagic.querySelectorAll(".scrolls .rollable").forEach(element => {
element.addEventListener("mouseenter", ev => {
let img = ev.target.matches("img") ? ev.target : ev.target.querySelector("img");
if (img) {
this._icon = img.src;
img.src = "systems/wfrp4e/ui/buttons/d10.webp";
}
})
element.addEventListener("mouseleave", ev => {
let img = ev.target.matches("img") ? ev.target : ev.target.querySelector("img");
if (img) {
img.src = this._icon;
}
})
});
}

/**
* When scroll is clicked to be used (for example by clicking on "Use Scroll" button), prepare the Test.
*
* @param {ActorSheetWfrp4e} sheet
* @param {ActorSheetWFRP4e} sheet
* @param {MouseEvent} event
*
* @returns {Promise<ScrollTest|false>}
Expand All @@ -90,7 +137,7 @@ export default class Scrolls extends ForienBaseModule {
/**
* When Scroll is clicked directly on Magic tab, unveil the Item Summary (on right click) or use the scroll
*
* @param {ActorSheetWfrp4e} sheet
* @param {ActorSheetWFRP4e} sheet
* @param {MouseEvent} event
*
* @returns {Promise<ScrollTest|void|false>}
Expand Down
1 change: 1 addition & 0 deletions dist/modules/tests/ScrollTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default class ScrollTest extends WomCastTest {
#mapEffects(e) {
let effect = foundry.utils.duplicate(e);
effect.uuid = `${this.scroll.system.spellUuid}.ActiveEffect.${effect._id}`;
effect.actor = this.data.actor;

return effect;
}
Expand Down
12 changes: 12 additions & 0 deletions dist/modules/utility/Utility.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,16 @@ export default class Utility {
static getSetting(setting) {
return game.settings.get(constants.moduleId, setting);
}

/**
* Converts a string representing a HTML containing a single top level node to ChildNode.
*
* @param {string} string
* @returns {ChildNode}
*/
static stringToHTMLElement(string) {
const element = document.createElement('template');
element.innerHTML = string.trim();
return element.content.firstChild;
}
}
Loading

0 comments on commit ee6b16f

Please sign in to comment.