actor class cleaning

This commit is contained in:
François-Xavier Guillois
2023-09-06 09:17:11 +02:00
parent 25b4179cd3
commit 980ab943c4
5 changed files with 28 additions and 484 deletions
+10 -81
View File
@@ -134,6 +134,14 @@ export class VermineGroupSheet extends VermineActorSheet {
context.encounters.push(game.actors.get(encounterId));
}
context.gear = this.actor.itemTypes['item'];
context.weapons = this.actor.itemTypes['weapon'];
context.defenses = this.actor.itemTypes['defense'];
context.vehicles = this.actor.itemTypes['vehicle'];
context.totem_abilities = this.actor.itemTypes['ability'].filter(i=>i.type !== 'totem');
context.abilities = this.actor.itemTypes['ability'].filter(i=>i.type === 'totem');
}
/* -------------------------------------------- */
@@ -141,20 +149,7 @@ export class VermineGroupSheet extends VermineActorSheet {
/** @override */
activateListeners(html) {
super.activateListeners(html);
// Render the item sheet for viewing/editing prior to the editable check.
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.items.get(li.data("itemId"));
item.sheet.render(true);
});
// -------------------------------------------------------------
// Everything below here is only needed if the sheet is editable
if (!this.isEditable) return;
// Add and delete Inventory Item
// already configured in parents listeners
// Choose Totem
html.find('.chooseTotem').click(this._onTotemButton.bind(this));
@@ -181,75 +176,9 @@ export class VermineGroupSheet extends VermineActorSheet {
this.actor.update({ "system.encounters": this.actor.system.encounters });
this.render(true);
});
if (this.actor.isOwner) {
let handler = ev => this._onDragStart(ev);
html.find('li.item').each((i, li) => {
if (li.classList.contains("inventory-header")) return;
li.setAttribute("draggable", true);
li.addEventListener("dragstart", handler, false);
});
}
}
/**
* Handle creating a new Owned Item for the actor using initial data defined in the HTML dataset
* @param {Event} event The originating click event
* @private
*/
async _onItemCreate(event) {
event.preventDefault();
const header = event.currentTarget;
// Get the type of item to create.
const type = header.dataset.type;
// Grab any data associated with this control.
const data = duplicate(header.dataset);
// Initialize a default name.
const name = `New ${type.capitalize()}`;
// Prepare the item object.
const itemData = {
name: name,
type: type,
system: data
};
// Remove the type from the dataset since it's in the itemData.type prop.
delete itemData.system["type"];
// Finally, create the item!
return await Item.create(itemData, {parent: this.actor});
}
/**
* Handle clickable rolls.
* @param {Event} event The originating click event
* @private
*/
_onRoll(event) {
event.preventDefault();
const element = event.currentTarget;
const dataset = element.dataset;
// Handle item rolls.
if (dataset.rollType) {
if (dataset.rollType == 'item') {
const itemId = element.closest('.item').dataset.itemId;
const item = this.actor.items.get(itemId);
if (item) return item.roll();
}
}
// Handle rolls that supply the formula directly.
if (dataset.roll) {
let label = dataset.label ? `[ability] ${dataset.label}` : '';
let roll = new Roll(dataset.roll, this.actor.getRollData());
roll.toMessage({
speaker: ChatMessage.getSpeaker({ actor: this.actor }),
flavor: label,
rollMode: game.settings.get('core', 'rollMode'),
});
return roll;
}
}
/**
* Handle totem pick