334 lines
8.5 KiB
JavaScript
334 lines
8.5 KiB
JavaScript
import {onManageActiveEffect, prepareActiveEffectCategories} from "../system/effects.mjs";
|
|
|
|
/**
|
|
* Extend the basic ActorSheet with some very simple modifications
|
|
* @extends {ActorSheet}
|
|
*/
|
|
export class VermineActorSheet extends ActorSheet {
|
|
|
|
/** @override */
|
|
static get defaultOptions() {
|
|
return mergeObject(super.defaultOptions, {
|
|
classes: ["vermine2047", "sheet", "actor"],
|
|
template: "systems/vermine2047/templates/actor/actor-sheet.html",
|
|
height: 800,
|
|
width: 690,
|
|
resizable: false,
|
|
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "features" }]
|
|
});
|
|
}
|
|
|
|
/** @override */
|
|
get template() {
|
|
return `systems/vermine2047/templates/actor/actor-${this.actor.type}-sheet.html`;
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
getData() {
|
|
// Retrieve the data structure from the base sheet. You can inspect or log
|
|
// the context variable to see the structure, but some key properties for
|
|
// sheets are the actor object, the data object, whether or not it's
|
|
// editable, the items array, and the effects array.
|
|
const context = super.getData();
|
|
|
|
// Use a safe clone of the actor data for further operations.
|
|
const actorData = this.actor.toObject(false);
|
|
|
|
// Add the actor's data to context.data for easier access, as well as flags.
|
|
context.system = actorData.system;
|
|
context.flags = actorData.flags;
|
|
context.config = CONFIG.VERMINE;
|
|
|
|
// Prepare character data and items.
|
|
if (actorData.type == 'character') {
|
|
this._prepareCharacterItems(context);
|
|
}
|
|
|
|
// Prepare NPC data and items.
|
|
if (actorData.type == 'npc') {
|
|
this._prepareNpcItems(context);
|
|
}
|
|
|
|
// Prepare Group data and items.
|
|
if (actorData.type == 'group') {
|
|
this._prepareGroupItems(context);
|
|
}
|
|
|
|
// Prepare Creature data and items.
|
|
if (actorData.type == 'npc') {
|
|
this._prepareCreatureItems(context);
|
|
}
|
|
|
|
// Add roll data for TinyMCE editors.
|
|
context.rollData = context.actor.getRollData();
|
|
|
|
// Prepare active effects
|
|
context.effects = prepareActiveEffectCategories(this.actor.effects);
|
|
|
|
return context;
|
|
}
|
|
|
|
/** @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 Inventory Item
|
|
html.find('.item-create').click(this._onItemCreate.bind(this));
|
|
|
|
// Delete Inventory Item
|
|
html.find('.item-delete').click(ev => {
|
|
const li = $(ev.currentTarget).parents(".item");
|
|
const item = this.actor.items.get(li.data("itemId"));
|
|
item.delete();
|
|
li.slideUp(200, () => this.render(false));
|
|
});
|
|
|
|
// Active Effect management
|
|
html.find(".effect-control").click(ev => onManageActiveEffect(ev, this.actor));
|
|
|
|
|
|
// Drag events for macros.
|
|
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);
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Organize and classify Items for Character sheets.
|
|
*
|
|
* @param {Object} actorData The actor to prepare.
|
|
*
|
|
* @return {undefined}
|
|
*/
|
|
_prepareCharacterItems(context) {
|
|
// Initialize containers.
|
|
const gear = [];
|
|
const traits = [];
|
|
const defenses = [];
|
|
const specialties = [];
|
|
const abilities = [];
|
|
const weapons = [];
|
|
const evolutions = [];
|
|
const traumas = [];
|
|
const backgrounds = [];
|
|
const rumors = [];
|
|
|
|
// Iterate through items, allocating to containers
|
|
for (let i of context.items) {
|
|
i.img = i.img || DEFAULT_TOKEN;
|
|
// Append to gear.
|
|
if (i.type === 'item') {
|
|
gear.push(i);
|
|
}
|
|
else if (i.type === 'trait') {
|
|
traits.push(i);
|
|
}
|
|
else if (i.type === 'defense') {
|
|
defenses.push(i);
|
|
}
|
|
else if (i.type === 'weapon') {
|
|
weapons.push(i);
|
|
}
|
|
else if (i.type === 'specialty') {
|
|
specialties.push(i);
|
|
}
|
|
else if (i.type === 'ability') {
|
|
abilities.push(i);
|
|
}
|
|
else if (i.type === 'evolution') {
|
|
evolutions.push(i);
|
|
}
|
|
else if (i.type === 'trauma') {
|
|
traumas.push(i);
|
|
}
|
|
else if (i.type === 'background') {
|
|
backgrounds.push(i);
|
|
}
|
|
else if (i.type === 'rumor') {
|
|
rumors.push(i);
|
|
}
|
|
/* // Append to cephalie.
|
|
else if (i.type === 'spell') {
|
|
if (i.system.spellLevel != undefined) {
|
|
cephalie[i.system.spellLevel].push(i);
|
|
}
|
|
}*/
|
|
}
|
|
|
|
// Assign and return
|
|
context.gear = gear;
|
|
context.weapons = weapons;
|
|
context.defenses = defenses;
|
|
context.traits = traits;
|
|
context.specialties = specialties;
|
|
context.abilities = abilities;
|
|
context.evolutions = evolutions;
|
|
context.traumas = traumas;
|
|
context.backgrounds = backgrounds;
|
|
context.rumors = rumors;
|
|
// console.log("context", context);
|
|
}
|
|
|
|
|
|
/**
|
|
* Organize and classify Items for Npc sheets.
|
|
*
|
|
* @param {Object} actorData The actor to prepare.
|
|
*
|
|
* @return {undefined}
|
|
*/
|
|
_prepareNpcItems(context) {
|
|
// Initialize containers.
|
|
const gear = [];
|
|
const traits = [];
|
|
|
|
|
|
// Iterate through items, allocating to containers
|
|
for (let i of context.items) {
|
|
i.img = i.img || DEFAULT_TOKEN;
|
|
// Append to gear.
|
|
if (i.type === 'item') {
|
|
gear.push(i);
|
|
}
|
|
else if (i.type === 'trait') {
|
|
traits.push(i);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
// Assign and return
|
|
context.gear = gear;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Organize and classify Items for Group sheets.
|
|
*
|
|
* @param {Object} actorData The actor to prepare.
|
|
*
|
|
* @return {undefined}
|
|
*/
|
|
_prepareGroupItems(context) {
|
|
// Initialize containers.
|
|
const gear = [];
|
|
const defenses = [];
|
|
const abilities = [];
|
|
const totem_abilities = [];
|
|
const weapons = [];
|
|
const vehicles = [];
|
|
|
|
// Iterate through items, allocating to containers
|
|
for (let i of context.items) {
|
|
i.img = i.img || DEFAULT_TOKEN;
|
|
// Append to gear.
|
|
if (i.type === 'item') {
|
|
gear.push(i);
|
|
}
|
|
else if (i.type === 'defense') {
|
|
defenses.push(i);
|
|
}
|
|
else if (i.type === 'weapon') {
|
|
weapons.push(i);
|
|
}
|
|
else if (i.type === 'ability') {
|
|
if (i.system.type == 'totem'){
|
|
totem_abilities.push(i);
|
|
} else {
|
|
abilities.push(i);
|
|
}
|
|
|
|
}
|
|
else if (i.type === 'vehicle') {
|
|
vehicles.push(i);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
// Assign and return
|
|
context.gear = gear;
|
|
context.weapons = weapons;
|
|
context.defenses = defenses;
|
|
context.abilities = abilities;
|
|
context.totem_abilities = totem_abilities;
|
|
context.vehicles = vehicles;
|
|
}
|
|
|
|
/**
|
|
* Organize and classify Items for Creature sheets.
|
|
*
|
|
* @param {Object} actorData The actor to prepare.
|
|
*
|
|
* @return {undefined}
|
|
*/
|
|
_prepareCreatureItems(context) {
|
|
// Initialize containers.
|
|
const gear = [];
|
|
const traits = [];
|
|
|
|
|
|
// Iterate through items, allocating to containers
|
|
for (let i of context.items) {
|
|
i.img = i.img || DEFAULT_TOKEN;
|
|
// Append to gear.
|
|
if (i.type === 'item') {
|
|
gear.push(i);
|
|
}
|
|
else if (i.type === 'trait') {
|
|
traits.push(i);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
// Assign and return
|
|
context.gear = gear;
|
|
|
|
}
|
|
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()}`;
|
|
const name = game.i18n.localize('ITEMS.new_' + type);
|
|
|
|
// 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});
|
|
}
|
|
}
|