169 lines
5.6 KiB
JavaScript
169 lines
5.6 KiB
JavaScript
/**
|
|
* Extend the basic ActorSheet with some very simple modifications
|
|
* @extends {ActorSheet}
|
|
*/
|
|
|
|
import { MournbladeUtility } from "./mournblade-utility.js";
|
|
import { MournbladeRollDialog } from "./mournblade-roll-dialog.js";
|
|
|
|
/* -------------------------------------------- */
|
|
export class MournbladeActorSheet extends ActorSheet {
|
|
|
|
/** @override */
|
|
static get defaultOptions() {
|
|
|
|
return mergeObject(super.defaultOptions, {
|
|
classes: ["fvtt-mournblade", "sheet", "actor"],
|
|
template: "systems/fvtt-mournblade/templates/actor-sheet.html",
|
|
width: 640,
|
|
height: 720,
|
|
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }],
|
|
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
|
|
editScore: false
|
|
});
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
async getData() {
|
|
const objectData = MournbladeUtility.data(this.object);
|
|
|
|
let actorData = duplicate(MournbladeUtility.templateData(this.object))
|
|
|
|
let formData = {
|
|
title: this.title,
|
|
id: objectData.id,
|
|
type: objectData.type,
|
|
img: objectData.img,
|
|
name: objectData.name,
|
|
editable: this.isEditable,
|
|
cssClass: this.isEditable ? "editable" : "locked",
|
|
data: actorData,
|
|
effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)),
|
|
limited: this.object.limited,
|
|
skills: duplicate(this.actor.getSkills()),
|
|
weapons: duplicate(this.actor.getWeapons()),
|
|
armors: duplicate(this.actor.getArmors()),
|
|
alignement: this.actor.getAlignement(),
|
|
//equipments: duplicate(this.actor.getEquipments()),
|
|
options: this.options,
|
|
owner: this.document.isOwner,
|
|
editScore: this.options.editScore,
|
|
isGM: game.user.isGM
|
|
}
|
|
this.formData = formData;
|
|
|
|
console.log("PC : ", formData, this.object);
|
|
return formData;
|
|
}
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
/** @override */
|
|
activateListeners(html) {
|
|
super.activateListeners(html);
|
|
|
|
// Everything below here is only needed if the sheet is editable
|
|
if (!this.options.editable) return;
|
|
|
|
// Update Inventory Item
|
|
html.find('.item-edit').click(ev => {
|
|
const li = $(ev.currentTarget).parents(".item")
|
|
let itemId = li.data("item-id")
|
|
const item = this.actor.items.get( itemId )
|
|
item.sheet.render(true)
|
|
})
|
|
// Delete Inventory Item
|
|
html.find('.item-delete').click(ev => {
|
|
const li = $(ev.currentTarget).parents(".item");
|
|
MournbladeUtility.confirmDelete(this, li);
|
|
})
|
|
html.find('.edit-item-data').change(ev => {
|
|
const li = $(ev.currentTarget).parents(".item")
|
|
let itemId = li.data("item-id")
|
|
let itemType = li.data("item-type")
|
|
let itemField = $(ev.currentTarget).data("item-field")
|
|
let dataType = $(ev.currentTarget).data("dtype")
|
|
let value = ev.currentTarget.value
|
|
this.actor.editItemField(itemId, itemType, itemField, dataType, value)
|
|
})
|
|
|
|
html.find('.quantity-minus').click(event => {
|
|
const li = $(event.currentTarget).parents(".item");
|
|
this.actor.incDecQuantity( li.data("item-id"), -1 );
|
|
} );
|
|
html.find('.quantity-plus').click(event => {
|
|
const li = $(event.currentTarget).parents(".item");
|
|
this.actor.incDecQuantity( li.data("item-id"), +1 );
|
|
} );
|
|
|
|
html.find('.roll-attribut').click((event) => {
|
|
const li = $(event.currentTarget).parents(".item")
|
|
let attrKey = li.data("attr-key")
|
|
this.actor.rollAttribut(attrKey)
|
|
})
|
|
html.find('.roll-competence').click((event) => {
|
|
const li = $(event.currentTarget).parents(".item")
|
|
let attrKey = $(event.currentTarget).data("attr-key")
|
|
let compId = li.data("item-id")
|
|
this.actor.rollCompetence(attrKey, compId)
|
|
})
|
|
|
|
html.find('.roll-spec').click((event) => {
|
|
const li = $(event.currentTarget).parents(".item");
|
|
const specId = li.data("item-id");
|
|
this.actor.rollSpec(specId);
|
|
});
|
|
html.find('.weapon-roll').click((event) => {
|
|
const li = $(event.currentTarget).parents(".item");
|
|
const weaponId = li.data("item-id");
|
|
this.actor.rollWeapon(weaponId);
|
|
});
|
|
html.find('.armor-roll').click((event) => {
|
|
const li = $(event.currentTarget).parents(".item");
|
|
const armorId = li.data("item-id");
|
|
this.actor.rollArmor(armorId);
|
|
});
|
|
|
|
html.find('.weapon-damage-roll').click((event) => {
|
|
const li = $(event.currentTarget).parents(".item");
|
|
const weaponId = li.data("item-id");
|
|
this.actor.rollWeapon(weaponId, true);
|
|
});
|
|
|
|
html.find('.lock-unlock-sheet').click((event) => {
|
|
this.options.editScore = !this.options.editScore;
|
|
this.render(true);
|
|
});
|
|
html.find('.item-equip').click(ev => {
|
|
const li = $(ev.currentTarget).parents(".item");
|
|
this.actor.equipItem( li.data("item-id") );
|
|
this.render(true);
|
|
});
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
/** @override */
|
|
setPosition(options = {}) {
|
|
const position = super.setPosition(options);
|
|
const sheetBody = this.element.find(".sheet-body");
|
|
const bodyHeight = position.height - 192;
|
|
sheetBody.css("height", bodyHeight);
|
|
return position;
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
async _onDropItem(event, dragData) {
|
|
let item = await MournbladeUtility.searchItem( dragData)
|
|
this.actor.preprocessItem( event, item, true )
|
|
super._onDropItem(event, dragData)
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
/** @override */
|
|
_updateObject(event, formData) {
|
|
// Update the Actor
|
|
return this.object.update(formData);
|
|
}
|
|
}
|