fvtt-hero-system-6/modules/hero6-actor-sheet.js

267 lines
10 KiB
JavaScript
Raw Permalink Normal View History

2022-12-15 21:44:23 +01:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { Hero6Utility } from "./hero6-utility.js";
/* -------------------------------------------- */
export class Hero6ActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["fvtt-hero-system-6", "sheet", "actor"],
2023-02-01 12:16:04 +01:00
template: "systems/fvtt-hero-system-6/templates/actors/actor-sheet.hbs",
2023-03-21 20:43:41 +01:00
width: 1124,
height: 916,
2023-02-01 12:16:04 +01:00
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "main" }],
2022-12-15 21:44:23 +01:00
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
editScore: true
});
}
/* -------------------------------------------- */
async getData() {
2023-02-01 12:16:04 +01:00
const objectData = duplicate(this.object.system)
2022-12-15 21:44:23 +01:00
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",
2023-02-01 12:16:04 +01:00
system: objectData,
characteristics: this.actor.prepareCharac(),
2023-03-21 14:01:27 +01:00
defenses: duplicate(this.actor.system.defenses),
2023-03-21 20:43:41 +01:00
movements: duplicate(this.actor.system.movements),
2022-12-15 21:44:23 +01:00
limited: this.object.limited,
skills: this.actor.getSkills( ),
2023-02-14 15:34:37 +01:00
perks: this.actor.getPerks( ),
2023-02-21 20:22:08 +01:00
powers: await this.actor.getPowers( ),
2023-02-14 15:34:37 +01:00
talents: this.actor.getTalents( ),
complications: this.actor.getComplications( ),
2023-03-21 14:01:27 +01:00
maneuvers: this.actor.getManeuvers( ),
2023-03-24 10:17:20 +01:00
nonstockmaneuvers: this.actor.getNonStockManeuvers(),
2023-08-15 22:12:02 +02:00
allmaneuvers: this.actor.getAllManeuvers(),
2022-12-15 21:44:23 +01:00
weapons: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getWeapons()) ),
armors: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getArmors())),
shields: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getShields())),
2023-08-22 23:30:31 +02:00
moneys: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getMoneys())),
equipments: this.actor.checkAndPrepareEquipments(duplicate(this.actor.getEquipments()) ),
2022-12-15 21:44:23 +01:00
subActors: duplicate(this.actor.getSubActors()),
race: duplicate(this.actor.getRace()),
encCapacity: this.actor.getEncumbranceCapacity(),
2023-07-24 13:35:35 +02:00
isHold: this.actor.getHoldAction(),
isAbort: this.actor.getAbortAction(),
2022-12-15 21:44:23 +01:00
description: await TextEditor.enrichHTML(this.object.system.biodata.description, {async: true}),
2023-02-14 15:34:37 +01:00
motivation: await TextEditor.enrichHTML(this.object.system.biodata.motivation, {async: true}),
quote: await TextEditor.enrichHTML(this.object.system.biodata.quote, {async: true}),
tactics: await TextEditor.enrichHTML(this.object.system.biodata.tactics, {async: true}),
campaignuse: await TextEditor.enrichHTML(this.object.system.biodata.campaignuse, {async: true}),
appearance: await TextEditor.enrichHTML(this.object.system.biodata.appearance, {async: true}),
notes1: await TextEditor.enrichHTML(this.object.system.biodata.notes1, {async: true}),
notes2: await TextEditor.enrichHTML(this.object.system.biodata.notes2, {async: true}),
notes3: await TextEditor.enrichHTML(this.object.system.biodata.notes3, {async: true}),
notes4: await TextEditor.enrichHTML(this.object.system.biodata.notes4, {async: true}),
notes5: await TextEditor.enrichHTML(this.object.system.biodata.notes5, {async: true}),
2022-12-15 21:44:23 +01:00
containersTree: this.actor.containersTree,
encCurrent: this.actor.encCurrent,
2023-06-30 13:14:40 +02:00
totalValue: this.actor.totalValue,
2022-12-15 21:44:23 +01:00
options: this.options,
owner: this.document.isOwner,
editScore: this.options.editScore,
isGM: game.user.isGM
}
2023-08-15 22:12:02 +02:00
2022-12-15 21:44:23 +01:00
this.formData = formData;
2023-08-15 22:12:02 +02:00
this.stockManeuverDisplayed = false
2022-12-15 21:44:23 +01:00
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;
2023-08-09 18:05:16 +02:00
/*html.bind("keydown", function(e) { // Ignore Enter in actores sheet
2022-12-15 21:44:23 +01:00
if (e.keyCode === 13) return false;
2023-08-09 18:05:16 +02:00
});*/
2022-12-15 21:44:23 +01:00
// 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")
Hero6Utility.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 )
} );
2023-02-01 12:16:04 +01:00
html.find('.roll-charac').click((event) => {
const characKey = $(event.currentTarget).data("charac-key");
this.actor.rollCharac(characKey);
2022-12-15 21:44:23 +01:00
});
html.find('.roll-perception').click((event) => {
this.actor.rollPerception("int");
});
2023-08-25 23:00:21 +02:00
html.find('.roll-weapon').click((event) => {
const li = $(event.currentTarget).parents(".item")
this.actor.rollWeapon(li.data("item-id"));
});
html.find('.roll-power-attack').click((event) => {
const li = $(event.currentTarget).parents(".item")
this.actor.rollPowerAttack(li.data("item-id"));
2023-08-26 09:48:07 +02:00
});
2023-03-22 22:43:30 +01:00
html.find('.roll-direct').click((event) => {
2023-03-24 10:17:20 +01:00
const rollFormula = $(event.currentTarget).data("roll-formula")
const rollSource = $(event.currentTarget).data("roll-source")
Hero6Utility.processDirectRoll( { actorId: this.actor.id, rollFormula: rollFormula, rollSource: rollSource, mode:"directroll"} )
2023-08-26 09:48:07 +02:00
});
2023-02-14 15:34:37 +01:00
html.find('.roll-item').click((event) => {
const li = $(event.currentTarget).parents(".item");
let itemId = li.data("item-id")
this.actor.rollItem(itemId);
});
2023-05-07 14:03:14 +02:00
html.find('.roll-damage').click((event) => {
const li = $(event.currentTarget).parents(".item");
let itemId = li.data("item-id")
this.actor.rollDamage(itemId);
});
html.find('.roll-lift-dice').click((event) => {
const li = $(event.currentTarget).parents(".item");
let itemId = li.data("item-id")
this.actor.rollLiftDice(itemId);
2023-08-07 23:28:04 +02:00
});
2023-06-30 21:11:29 +02:00
html.find('.hold-action').click((event) => {
this.actor.holdAction()
});
html.find('.abort-action').click((event) => {
this.actor.abortAction()
});
2023-08-15 22:12:02 +02:00
html.find(".show-stock-maneuver").click((event) => {
if ( !this.stockManeuverDisplayed) {
$('div .maneuver-list').removeClass('maneuver-is-stock');
this.stockManeuverDisplayed = true
} else {
$('div .maneuver-list').addClass('maneuver-is-stock');
this.stockManeuverDisplayed = false
}
});
2022-12-15 21:44:23 +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) => {
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");
2023-03-21 20:43:41 +01:00
const fieldType = $(ev.currentTarget).data("dtype");
let value = ev.currentTarget.value
if (fieldType.toLowerCase() == "Number") {
value = Number(value)
}
2022-12-15 21:44:23 +01:00
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!!!!")
const item = fromUuidSync(dragData.uuid)
if (item == undefined) {
item = this.actor.items.get( item.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);
}
}