Refactor some of the generic sheet for listener handling
This commit is contained in:
parent
52ea7959d4
commit
cfa2179817
2 changed files with 45 additions and 21 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
export class GenericSheet extends ActorSheet {
|
export class GenericActorSheet extends ActorSheet {
|
||||||
|
_expanded = new Set();
|
||||||
|
|
||||||
#propogatedSettings = [
|
#propogatedSettings = [
|
||||||
`devMode`,
|
`devMode`,
|
||||||
`showAvatarOnSheet`,
|
`showAvatarOnSheet`,
|
||||||
|
|
@ -17,6 +19,44 @@ export class GenericSheet extends ActorSheet {
|
||||||
|
|
||||||
ctx.isGM = game.users.current.hasRole(CONST.USER_ROLES.ASSISTANT);
|
ctx.isGM = game.users.current.hasRole(CONST.USER_ROLES.ASSISTANT);
|
||||||
|
|
||||||
|
ctx.meta = {
|
||||||
|
expanded: this._expanded,
|
||||||
|
};
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
|
};
|
||||||
|
|
||||||
|
activateListeners(html) {
|
||||||
|
if (this.document.isEmbedded) return;
|
||||||
|
if (!this.isEditable) return;
|
||||||
|
console.debug(`.dungeon | Generic sheet adding listeners`);
|
||||||
|
|
||||||
|
html.find(`.roll`).on(`click`, this._handleRoll);
|
||||||
|
html.find(`summary`).on(`click`, this._handleSummaryToggle);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
_handleSummaryToggle($e) {
|
||||||
|
let data = $e.target.dataset;
|
||||||
|
let open = $e.target.parentNode.open;
|
||||||
|
console.debug(`.dungeon | Collapse ID: ${data.collapseId} (open: ${open})`);
|
||||||
|
/*
|
||||||
|
This seeming inversion of logic is due to the fact that this handler
|
||||||
|
gets called before the element is updated to include/reflect the
|
||||||
|
change, so if the parentNode doesn't actually have it, then we're
|
||||||
|
opening it and vice-versa.
|
||||||
|
*/
|
||||||
|
if (!open) {
|
||||||
|
this._expanded.add(data.collapseId);
|
||||||
|
} else {
|
||||||
|
this._expanded.delete(data.collapseId);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_handleRoll($e) {
|
||||||
|
let data = $e.target.dataset;
|
||||||
|
if (!data.roll) return;
|
||||||
|
console.debug(`.dungeon | Attempting to roll ${data.roll}`);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { GenericSheet } from "./GenericSheet.mjs";
|
import { GenericActorSheet } from "./GenericSheet.mjs";
|
||||||
|
|
||||||
export class PlayerSheet extends GenericSheet {
|
export class PlayerSheet extends GenericActorSheet {
|
||||||
static get defaultOptions() {
|
static get defaultOptions() {
|
||||||
let opts = mergeObject(
|
let opts = mergeObject(
|
||||||
super.defaultOptions,
|
super.defaultOptions,
|
||||||
|
|
@ -23,23 +23,10 @@ export class PlayerSheet extends GenericSheet {
|
||||||
Toggles the expanded state for the detail elements in the sheet.
|
Toggles the expanded state for the detail elements in the sheet.
|
||||||
*/
|
*/
|
||||||
html.find(`summary`).on(`click`, ($e) => {
|
html.find(`summary`).on(`click`, ($e) => {
|
||||||
console.debug(`.dungeon | summary[data-collapse-id="${$e.target.dataset.collapseId}"] click event (open=${$e.target.parentNode.open})`);
|
|
||||||
/*
|
|
||||||
This seeming inversion of logic is due to the fact that this handler
|
|
||||||
gets called before the element is updated to include/reflect the
|
|
||||||
change, so if the parentNode doesn't actually have it, then we're
|
|
||||||
opening it and vice-versa.
|
|
||||||
*/
|
|
||||||
if (!$e.target.parentNode.open) {
|
|
||||||
this._expanded.add($e.target.dataset.collapseId);
|
|
||||||
} else {
|
|
||||||
this._expanded.delete($e.target.dataset.collapseId);
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
_expanded = new Set();
|
|
||||||
|
|
||||||
#syncValue() {
|
#syncValue() {
|
||||||
let delta = 0;
|
let delta = 0;
|
||||||
for (const actor of game.actors) {
|
for (const actor of game.actors) {
|
||||||
|
|
@ -60,10 +47,7 @@ export class PlayerSheet extends GenericSheet {
|
||||||
canChangeGroup: ctx.settings.playersCanChangeGroup || ctx.isGM,
|
canChangeGroup: ctx.settings.playersCanChangeGroup || ctx.isGM,
|
||||||
};
|
};
|
||||||
|
|
||||||
ctx.meta = {
|
ctx.meta.idp = this.actor.uuid;
|
||||||
idp: this.actor.uuid,
|
|
||||||
expanded: this._expanded,
|
|
||||||
};
|
|
||||||
|
|
||||||
console.groupCollapsed(`PlayerSheet.getData`);
|
console.groupCollapsed(`PlayerSheet.getData`);
|
||||||
console.log(`ctx`, ctx);
|
console.log(`ctx`, ctx);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue