Skip to content

Commit

Permalink
Merge pull request #12 from foundryvtt/effects-element
Browse files Browse the repository at this point in the history
Move active effects lists into custom element
  • Loading branch information
arbron authored Nov 29, 2023
2 parents cffbbd2 + c53b8f2 commit f7c3381
Show file tree
Hide file tree
Showing 15 changed files with 270 additions and 149 deletions.
36 changes: 21 additions & 15 deletions less/apps.less
Original file line number Diff line number Diff line change
Expand Up @@ -528,23 +528,29 @@ h5 {
}
}
}
}

/* ----------------------------------------- */
/* Active Effects */
/* ----------------------------------------- */
/* ----------------------------------------- */
/* Active Effects */
/* ----------------------------------------- */

.effects .item {
.effect-source,
.effect-duration,
.effect-controls {
text-align: center;
border-left: 1px solid var(--dnd5e-color-faint);
border-right: 1px solid var(--dnd5e-color-faint);
font-size: var(--font-size-12);
}
.effect-controls {
border: none;
}
dnd5e-effects {
display: flex;
flex-direction: column;
overflow-y: hidden;

.effects-list {
flex-grow: 1;
}
.effect-source,
.effect-duration,
.effect-controls {
text-align: center;
border-inline: 1px solid var(--dnd5e-color-faint);
font-size: var(--font-size-12);
}
.effect-controls {
border: none;
}
}

Expand Down
38 changes: 8 additions & 30 deletions module/applications/actor/base-sheet.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ActiveEffect5e from "../../documents/active-effect.mjs";
import * as Trait from "../../documents/actor/trait.mjs";
import Item5e from "../../documents/item.mjs";
import EffectsElement from "../components/effects.mjs";

import ActorAbilityConfig from "./ability-config.mjs";
import ActorArmorConfig from "./armor-config.mjs";
Expand Down Expand Up @@ -65,7 +65,7 @@ export default class ActorSheet5e extends ActorSheetMixin(ActorSheet) {
return foundry.utils.mergeObject(super.defaultOptions, {
scrollY: [
"dnd5e-inventory .inventory-list",
".effects .inventory-list",
"dnd5e-effects .effects-list",
".center-pane"
],
tabs: [{navSelector: ".tabs", contentSelector: ".sheet-body", initial: "description"}],
Expand All @@ -74,7 +74,10 @@ export default class ActorSheet5e extends ActorSheetMixin(ActorSheet) {
237 + (Object.keys(CONFIG.DND5E.abilities).length * 70),
240 + (Object.keys(CONFIG.DND5E.skills).length * 24)
)),
inventoryElement: "dnd5e-inventory"
elements: {
effects: "dnd5e-effects",
inventory: "dnd5e-inventory"
}
});
}

Expand Down Expand Up @@ -117,7 +120,7 @@ export default class ActorSheet5e extends ActorSheetMixin(ActorSheet) {
labels: this._getLabels(),
movement: this._getMovementSpeed(this.actor.system),
senses: this._getSenses(this.actor.system),
effects: ActiveEffect5e.prepareActiveEffectCategories(this.actor.effects),
effects: EffectsElement.prepareCategories(this.actor.effects),
warnings: foundry.utils.deepClone(this.actor._preparationWarnings),
filters: this._filters,
owner: this.actor.isOwner,
Expand All @@ -134,7 +137,7 @@ export default class ActorSheet5e extends ActorSheetMixin(ActorSheet) {
overrides: {
attunement: foundry.utils.hasProperty(this.actor.overrides, "system.attributes.attunement.max")
},
inventoryElement: this.options.inventoryElement
elements: this.options.elements
};

// Remove items in containers & sort remaining
Expand Down Expand Up @@ -647,14 +650,11 @@ export default class ActorSheet5e extends ActorSheetMixin(ActorSheet) {
html.find(".slot-max-override").click(this._onSpellSlotOverride.bind(this));
html.find(".attunement-max-override").click(this._onAttunementOverride.bind(this));

// Active Effect management
html.find(".effect-control").click(ev => ActiveEffect5e.onManageActiveEffect(ev, this.actor));
this._disableOverriddenFields(html);
}

// Owner Only Listeners, for non-compendium actors.
if ( this.actor.isOwner && !this.actor.compendium ) {

// Ability Checks
html.find(".ability-name").click(this._onRollAbilityTest.bind(this));

Expand All @@ -663,12 +663,8 @@ export default class ActorSheet5e extends ActorSheetMixin(ActorSheet) {

// Roll Tool Checks.
html.find(".tool-name").on("click", this._onRollToolCheck.bind(this));

}

// Item Context Menu
new ContextMenu(html, ".item-list .item", [], {onOpen: this._onItemContext.bind(this)});

// Handle default listeners last so system listeners are triggered first
super.activateListeners(html);
}
Expand Down Expand Up @@ -709,24 +705,6 @@ export default class ActorSheet5e extends ActorSheetMixin(ActorSheet) {
}
}

/* -------------------------------------------- */

/**
* Handle activation of a context menu for an embedded Item or ActiveEffect document.
* Dynamically populate the array of context menu options.
* @param {HTMLElement} element The HTML element for which the context menu is activated
* @protected
*/
_onItemContext(element) {
// Active Effects
if ( element.classList.contains("effect") ) {
const effect = this.actor.effects.get(element.dataset.effectId);
if ( !effect ) return;
ui.context.menuItems = this._getActiveEffectContextOptions(effect);
Hooks.call("dnd5e.getActiveEffectContextOptions", effect, ui.context.menuItems);
}
}

/* -------------------------------------------- */
/* Event Listeners and Handlers */
/* -------------------------------------------- */
Expand Down
6 changes: 4 additions & 2 deletions module/applications/actor/group-sheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export default class GroupActorSheet extends ActorSheetMixin(ActorSheet) {
scrollY: ["dnd5e-inventory .inventory-list"],
width: 620,
height: 620,
inventoryElement: "dnd5e-inventory"
elements: {
inventory: "dnd5e-inventory"
}
});
}

Expand Down Expand Up @@ -61,7 +63,7 @@ export default class GroupActorSheet extends ActorSheetMixin(ActorSheet) {
// Inventory
context.itemContext = {};
context.inventory = this.#prepareInventory(context);
context.inventoryElement = this.options.inventoryElement;
context.elements = this.options.elements;
context.expandedData = {};
for ( const id of this._expanded ) {
const item = this.actor.items.get(id);
Expand Down
37 changes: 0 additions & 37 deletions module/applications/actor/sheet-mixin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,6 @@ export const ActorSheetMixin = Base => class extends Base {

/* -------------------------------------------- */

/**
* Prepare an array of context menu options which are available for owned ActiveEffect documents.
* @param {ActiveEffect5e} effect The ActiveEffect for which the context menu is activated
* @returns {ContextMenuEntry[]} An array of context menu options offered for the ActiveEffect
* @protected
*/
_getActiveEffectContextOptions(effect) {
return [
{
name: "DND5E.ContextMenuActionEdit",
icon: "<i class='fas fa-edit fa-fw'></i>",
condition: () => effect.isOwner,
callback: () => effect.sheet.render(true)
},
{
name: "DND5E.ContextMenuActionDuplicate",
icon: "<i class='fas fa-copy fa-fw'></i>",
condition: () => effect.isOwner,
callback: () => effect.clone({label: game.i18n.format("DOCUMENT.CopyOf", {name: effect.label})}, {save: true})
},
{
name: "DND5E.ContextMenuActionDelete",
icon: "<i class='fas fa-trash fa-fw'></i>",
condition: () => effect.isOwner,
callback: () => effect.deleteDialog()
},
{
name: effect.disabled ? "DND5E.ContextMenuActionEnable" : "DND5E.ContextMenuActionDisable",
icon: effect.disabled ? "<i class='fas fa-check fa-fw'></i>" : "<i class='fas fa-times fa-fw'></i>",
condition: () => effect.isOwner,
callback: () => effect.update({disabled: !effect.disabled})
}
];
}

/* -------------------------------------------- */

/**
* Stack identical consumables when a new one is dropped rather than creating a duplicate item.
* @param {object} itemData The item data requested for creation.
Expand Down
4 changes: 3 additions & 1 deletion module/applications/components/_module.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import EffectsElement from "./effects.mjs";
import InventoryElement from "./inventory.mjs";

window.customElements.define("dnd5e-effects", EffectsElement);
window.customElements.define("dnd5e-inventory", InventoryElement);

export { InventoryElement };
export { EffectsElement, InventoryElement };
Loading

0 comments on commit f7c3381

Please sign in to comment.