fvtt-ecryme/modules/actors/ecryme-actor-sheet.js

201 lines
7.2 KiB
JavaScript
Raw Normal View History

2023-04-19 18:44:41 +02:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
2023-04-28 15:25:57 +02:00
import { EcrymeUtility } from "../common/ecryme-utility.js";
2023-04-19 18:44:41 +02:00
/* -------------------------------------------- */
export class EcrymeActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
2023-04-19 18:44:41 +02:00
classes: ["fvtt-ecryme", "sheet", "actor"],
template: "systems/fvtt-ecryme/templates/actors/actor-sheet.hbs",
2023-05-03 20:05:31 +02:00
width: 860,
2023-04-19 18:44:41 +02:00
height:680,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "skills" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
editScore: true
});
}
/* -------------------------------------------- */
async getData() {
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: foundry.utils.duplicate(this.object.system),
2023-04-19 18:44:41 +02:00
limited: this.object.limited,
2023-05-03 20:05:31 +02:00
skills: this.actor.prepareSkills(),
2023-05-26 07:46:06 +02:00
traits: this.actor.getRollTraits(),
2023-05-31 09:16:30 +02:00
confrontations: this.actor.getConfrontations(),
2023-05-26 07:46:06 +02:00
ideal: this.actor.getIdeal(),
spleen: this.actor.getSpleen(),
2023-05-30 22:22:52 +02:00
impacts: this.object.getImpacts(),
config: foundry.utils.duplicate(game.system.ecryme.config),
2023-05-30 22:22:52 +02:00
weapons: this.actor.getWeapons(),
2023-07-29 09:44:29 +02:00
maneuvers: this.actor.getManeuvers(),
2023-05-31 09:16:30 +02:00
impactsMalus: this.actor.getImpactsMalus(),
archetype: foundry.utils.duplicate(this.actor.getArchetype()),
2023-08-25 09:09:21 +02:00
equipments: this.actor.getEquipments(),
2023-07-21 18:57:41 +02:00
hasCephaly: EcrymeUtility.hasCephaly(),
2023-08-08 09:08:11 +02:00
hasBoheme: EcrymeUtility.hasBoheme(),
hasAmertume: EcrymeUtility.hasAmertume(),
2023-07-21 18:57:41 +02:00
cephalySkills: this.actor.getCephalySkills(),
subActors: foundry.utils.duplicate(this.actor.getSubActors()),
2023-08-08 14:54:39 +02:00
annency: this.actor.getAnnency(),
2024-03-15 12:10:44 +01:00
description: await TextEditor.enrichHTML(this.object.system.biodata.description, { async: true }),
notes: await TextEditor.enrichHTML(this.object.system.biodata.notes, { async: true }),
equipementlibre: await TextEditor.enrichHTML(this.object.system.equipmentfree, { async: true }),
2023-04-19 18:44:41 +02:00
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;
});
2023-08-08 14:54:39 +02:00
html.find('.open-annency').click(ev => {
let actorId = $(ev.currentTarget).data("annency-id")
const actor = game.actors.get(actorId)
actor.sheet.render(true)
})
2023-04-19 18:44:41 +02:00
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
if (!itemId) {
itemId = $(ev.currentTarget).data("item-id")
}
2023-04-19 18:44:41 +02:00
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")
2023-05-31 09:26:55 +02:00
EcrymeUtility.confirmDelete(this, li).catch("Error : No deletion confirmed")
2023-04-19 18:44:41 +02:00
})
html.find('.item-add').click(ev => {
let dataType = $(ev.currentTarget).data("type")
this.actor.createEmbeddedDocuments('Item', [{ name: "NewItem", type: dataType }], { renderSheet: true })
})
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 );
} );
2023-04-28 09:39:18 +02:00
html.find('.roll-skill').click((event) => {
2023-05-03 20:05:31 +02:00
let categKey = $(event.currentTarget).data("category-key")
let skillKey = $(event.currentTarget).data("skill-key")
this.actor.rollSkill(categKey, skillKey)
2023-04-19 18:44:41 +02:00
});
2023-10-10 20:02:13 +02:00
html.find('.roll-spec').click((event) => {
let categKey = $(event.currentTarget).data("category-key")
let skillKey = $(event.currentTarget).data("skill-key")
let specId = $(event.currentTarget).data("spec-id")
this.actor.rollSpec(categKey, skillKey, specId)
});
2023-05-30 19:25:26 +02:00
html.find('.roll-skill-confront').click((event) => {
let categKey = $(event.currentTarget).data("category-key")
let skillKey = $(event.currentTarget).data("skill-key")
this.actor.rollSkillConfront(categKey, skillKey)
2023-07-21 18:57:41 +02:00
});
html.find('.roll-cephaly').click((event) => {
let skillKey = $(event.currentTarget).data("skill-key")
this.actor.rollCephalySkillConfront(skillKey)
});
2023-06-28 11:12:51 +02:00
html.find('.roll-weapon-confront').click((event) => {
const li = $(event.currentTarget).parents(".item")
let weaponId = li.data("item-id");
this.actor.rollWeaponConfront(weaponId)
});
2023-05-30 19:25:26 +02:00
2023-05-30 22:22:52 +02:00
html.find('.impact-modify').click((event) => {
let impactType = $(event.currentTarget).data("impact-type")
let impactLevel = $(event.currentTarget).data("impact-level")
let modifier = Number($(event.currentTarget).data("impact-modifier"))
this.actor.modifyImpact(impactType, impactLevel, modifier)
});
2023-04-28 09:39:18 +02:00
html.find('.roll-weapon').click((event) => {
2023-04-19 18:44:41 +02:00
const armeId = $(event.currentTarget).data("arme-id")
this.actor.rollArme(armeId)
});
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);
});
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;
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Update the Actor
return this.object.update(formData);
}
}