2022-07-19 23:16:03 +02:00
|
|
|
/**
|
|
|
|
* Extend the basic ActorSheet with some very simple modifications
|
|
|
|
* @extends {ActorSheet}
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { CrucibleUtility } from "./crucible-utility.js";
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
export class CrucibleActorSheet extends ActorSheet {
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
static get defaultOptions() {
|
|
|
|
|
|
|
|
return mergeObject(super.defaultOptions, {
|
|
|
|
classes: ["fvtt-crucible-rpg", "sheet", "actor"],
|
|
|
|
template: "systems/fvtt-crucible-rpg/templates/actor-sheet.html",
|
|
|
|
width: 960,
|
|
|
|
height: 720,
|
2022-07-25 21:33:00 +02:00
|
|
|
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "skills" }],
|
2022-07-19 23:16:03 +02:00
|
|
|
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
|
|
|
|
editScore: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async getData() {
|
|
|
|
const objectData = CrucibleUtility.data(this.object);
|
|
|
|
|
|
|
|
let actorData = duplicate(CrucibleUtility.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,
|
|
|
|
limited: this.object.limited,
|
|
|
|
skills: this.actor.getSkills( ),
|
|
|
|
weapons: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getWeapons()) ),
|
|
|
|
armors: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getArmors())),
|
2022-07-30 22:54:08 +02:00
|
|
|
shields: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getShields())),
|
|
|
|
spells: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getLore())),
|
2022-07-19 23:16:03 +02:00
|
|
|
equipments: this.actor.checkAndPrepareEquipments(duplicate(this.actor.getEquipmentsOnly()) ),
|
2022-07-30 22:54:08 +02:00
|
|
|
equippedWeapons: this.actor.checkAndPrepareEquipments(duplicate(this.actor.getEquippedWeapons()) ),
|
|
|
|
feats: duplicate(this.actor.getFeats()),
|
2022-07-19 23:16:03 +02:00
|
|
|
subActors: duplicate(this.actor.getSubActors()),
|
|
|
|
race: duplicate(this.actor.getRace()),
|
|
|
|
moneys: duplicate(this.actor.getMoneys()),
|
|
|
|
encCapacity: this.actor.getEncumbranceCapacity(),
|
2022-08-03 09:34:33 +02:00
|
|
|
saveRolls: this.actor.getSaveRoll(),
|
2022-07-19 23:16:03 +02:00
|
|
|
containersTree: this.actor.containersTree,
|
|
|
|
encCurrent: this.actor.encCurrent,
|
|
|
|
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")
|
|
|
|
CrucibleUtility.confirmDelete(this, li)
|
|
|
|
})
|
|
|
|
html.find('.item-add').click(ev => {
|
|
|
|
let dataType = $(ev.currentTarget).data("type")
|
|
|
|
this.actor.createEmbeddedDocuments('Item', [{ name: "NewItem", type: dataType }], { renderSheet: true })
|
|
|
|
})
|
|
|
|
|
|
|
|
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('.ammo-minus').click(event => {
|
|
|
|
const li = $(event.currentTarget).parents(".item")
|
|
|
|
this.actor.incDecAmmo( li.data("item-id"), -1 );
|
|
|
|
} );
|
|
|
|
html.find('.ammo-plus').click(event => {
|
|
|
|
const li = $(event.currentTarget).parents(".item")
|
|
|
|
this.actor.incDecAmmo( li.data("item-id"), +1 )
|
|
|
|
} );
|
|
|
|
|
2022-07-25 21:33:00 +02:00
|
|
|
html.find('.roll-ability').click((event) => {
|
|
|
|
const abilityKey = $(event.currentTarget).data("ability-key");
|
|
|
|
this.actor.rollAbility(abilityKey);
|
2022-07-19 23:16:03 +02:00
|
|
|
});
|
2022-07-25 21:33:00 +02:00
|
|
|
html.find('.roll-skill').click((event) => {
|
2022-07-19 23:16:03 +02:00
|
|
|
const li = $(event.currentTarget).parents(".item");
|
2022-07-25 21:33:00 +02:00
|
|
|
const skillId = li.data("item-id")
|
|
|
|
this.actor.rollSkill(skillId)
|
2022-07-19 23:16:03 +02:00
|
|
|
});
|
2022-08-01 21:39:17 +02:00
|
|
|
html.find('.roll-weapon').click((event) => {
|
|
|
|
const li = $(event.currentTarget).parents(".item");
|
|
|
|
const skillId = li.data("item-id")
|
|
|
|
this.actor.rollWeapon(skillId)
|
|
|
|
});
|
2022-08-03 09:34:33 +02:00
|
|
|
html.find('.roll-save').click((event) => {
|
|
|
|
const saveKey = $(event.currentTarget).data("save-key")
|
|
|
|
this.actor.rollSave(saveKey)
|
2022-07-19 23:16:03 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
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 _onDropItem(event, dragData) {
|
|
|
|
console.log(">>>>>> DROPPED!!!!")
|
|
|
|
let item = await CrucibleUtility.searchItem( dragData)
|
|
|
|
if (item == undefined) {
|
|
|
|
item = this.actor.items.get( dragData.data._id )
|
|
|
|
}
|
|
|
|
let ret = await this.actor.preprocessItem( event, item, true )
|
|
|
|
if ( ret ) {
|
|
|
|
super._onDropItem(event, dragData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
|
|
_updateObject(event, formData) {
|
|
|
|
// Update the Actor
|
|
|
|
return this.object.update(formData);
|
|
|
|
}
|
|
|
|
}
|