fvtt-imperium5/modules/imperium5-actor-sheet.js

175 lines
5.7 KiB
JavaScript
Raw Normal View History

2022-03-13 16:17:04 +01:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { Imperium5Utility } from "./imperium5-utility.js";
import { Imperium5RollDialog } from "./imperium5-roll-dialog.js";
/* -------------------------------------------- */
2022-03-19 09:30:00 +01:00
export class Imperium5ActorSheet extends ActorSheet {
2022-03-13 16:17:04 +01:00
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
2022-03-19 09:30:00 +01:00
classes: ["fvtt-imperium5", "sheet", "actor"],
template: "systems/fvtt-imperium5/templates/actor-sheet.html",
2022-10-19 17:30:47 +02:00
width: 720,
height: 760,
2022-03-13 16:17:04 +01:00
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "combat" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
editScore: true
});
}
/* -------------------------------------------- */
2022-10-19 17:30:47 +02:00
async getData() {
let actorData = duplicate(this.object.system)
2022-03-13 16:17:04 +01:00
let formData = {
title: this.title,
2022-10-19 17:30:47 +02:00
id: this.actor.id,
type: this.actor.type,
img: this.actor.img,
name: this.actor.name,
2022-03-13 16:17:04 +01:00
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
2022-10-19 17:30:47 +02:00
system: actorData,
2022-03-19 09:30:00 +01:00
archetype: this.actor.getArchetype(),
specialites: this.actor.getSpecialites(),
familiarites: this.actor.getFamiliarites(),
2022-03-22 09:01:20 +01:00
nature: this.actor.getNatureProfonde(),
traits: this.actor.getTraits(),
symbioses: this.actor.getSymbioses(),
equipements: this.actor.getEquipements(),
capacites: this.actor.getCapacites(),
singularites: this.actor.getSingularites(),
contacts: this.actor.getContacts(),
2022-03-13 16:17:04 +01:00
effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)),
limited: this.object.limited,
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;
html.bind("keydown", function(e) { // Ignore Enter in actores sheet
if (e.keyCode === 13) return false;
});
// 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");
2022-03-19 09:30:00 +01:00
Imperium5Utility.confirmDelete(this, li);
2022-03-13 16:17:04 +01:00
});
html.find('.equip-activate').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
this.actor.equipActivate( itemId)
});
html.find('.equip-deactivate').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
this.actor.equipDeactivate( itemId)
});
html.find('.subactor-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let actorId = li.data("actor-id");
let actor = game.actors.get( actorId );
actor.sheet.render(true);
});
html.find('.subactor-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let actorId = li.data("actor-id");
this.actor.delSubActor(actorId);
});
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 );
} );
2022-10-20 23:59:31 +02:00
html.find('.roll-ame-button').click((event) => {
2022-10-19 17:30:47 +02:00
const ameKey = $(event.currentTarget).data("ame-key")
this.actor.rollAme(ameKey)
2022-03-13 16:17:04 +01:00
});
html.find('.lock-unlock-sheet').click((event) => {
this.options.editScore = !this.options.editScore;
this.render(true);
});
html.find('.item-link a').click((event) => {
2022-10-21 09:38:43 +02:00
const itemId = $(event.currentTarget).data("item-id")
2022-03-13 16:17:04 +01:00
const item = this.actor.getOwnedItem(itemId);
item.sheet.render(true);
});
html.find('.item-equip').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.equipItem( li.data("item-id") );
this.render(true);
});
html.find('.update-field').change(ev => {
const fieldName = $(ev.currentTarget).data("field-name");
let value = Number(ev.currentTarget.value);
this.actor.update( { [`${fieldName}`]: value } );
});
}
/* -------------------------------------------- */
/** @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;
}
/* -------------------------------------------- */
2022-10-19 17:30:47 +02:00
async _onDropItemUNUSED(event, dragData) {
2022-03-19 09:30:00 +01:00
let item = await Imperium5Utility.searchItem( dragData)
2022-03-13 16:17:04 +01:00
if (item == undefined) {
item = this.actor.items.get( dragData.data._id )
}
2022-03-19 09:30:00 +01:00
//this.actor.preprocessItem( event, item, true )
2022-03-13 16:17:04 +01:00
super._onDropItem(event, dragData)
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Update the Actor
return this.object.update(formData);
}
}