213 lines
7.1 KiB
JavaScript
213 lines
7.1 KiB
JavaScript
/**
|
|
* Extend the basic ActorSheet with some very simple modifications
|
|
* @extends {ActorSheet}
|
|
*/
|
|
|
|
import { Imperium5Utility } from "./imperium5-utility.js";
|
|
import { Imperium5RollDialog } from "./imperium5-roll-dialog.js";
|
|
|
|
/* -------------------------------------------- */
|
|
export class Imperium5ActorSheet extends ActorSheet {
|
|
|
|
/** @override */
|
|
static get defaultOptions() {
|
|
|
|
return mergeObject(super.defaultOptions, {
|
|
classes: ["fvtt-imperium5", "sheet", "actor"],
|
|
template: "systems/fvtt-imperium5/templates/actor-sheet.html",
|
|
width: 720,
|
|
height: 760,
|
|
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "combat" }],
|
|
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
|
|
editScore: true
|
|
});
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
async getData() {
|
|
let actorData = duplicate(this.object.system)
|
|
|
|
let formData = {
|
|
title: this.title,
|
|
id: this.actor.id,
|
|
type: this.actor.type,
|
|
img: this.actor.img,
|
|
name: this.actor.name,
|
|
editable: this.isEditable,
|
|
cssClass: this.isEditable ? "editable" : "locked",
|
|
system: actorData,
|
|
archetype: this.actor.getArchetype(),
|
|
specialites: this.actor.getSpecialites(),
|
|
familiarites: this.actor.getFamiliarites(),
|
|
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(),
|
|
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;
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
async openGenericRoll() {
|
|
let rollData = Imperium5Utility.getBasicRollData()
|
|
rollData.alias = "Dice Pool Roll",
|
|
rollData.mode = "generic"
|
|
rollData.title = `Dice Pool Roll`
|
|
rollData.img = "icons/dice/d12black.svg"
|
|
|
|
let rollDialog = await Imperium5RollDialog.create( this.actor, rollData);
|
|
rollDialog.render( true );
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
async rollIDR( itemId, diceValue) {
|
|
let item = this.actor.items.get( itemId) ?? {name: "Unknown"}
|
|
let myRoll = new Roll(diceValue+"x").roll({ async: false })
|
|
await Imperium5Utility.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
|
|
let chatData = {
|
|
user: game.user.id,
|
|
rollMode: game.settings.get("core", "rollMode"),
|
|
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM')),
|
|
content: `${this.actor.name} has roll IDR for ${item.name} : ${myRoll.total}`
|
|
}
|
|
ChatMessage.create(chatData)
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
/** @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");
|
|
Imperium5Utility.confirmDelete(this, li);
|
|
});
|
|
|
|
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 );
|
|
} );
|
|
|
|
html.find('.roll-ame').click((event) => {
|
|
const ameKey = $(event.currentTarget).data("ame-key")
|
|
this.actor.rollAme(ameKey)
|
|
});
|
|
|
|
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-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-link a').click((event) => {
|
|
const itemId = $(event.currentTarget).data("item-id");
|
|
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;
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
async _onDropItemUNUSED(event, dragData) {
|
|
console.log(">>>>>> DROPPED!!!!")
|
|
let item = await Imperium5Utility.searchItem( dragData)
|
|
if (item == undefined) {
|
|
item = this.actor.items.get( dragData.data._id )
|
|
}
|
|
//this.actor.preprocessItem( event, item, true )
|
|
super._onDropItem(event, dragData)
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
/** @override */
|
|
_updateObject(event, formData) {
|
|
// Update the Actor
|
|
return this.object.update(formData);
|
|
}
|
|
}
|