foundryvtt-shadows-over-sol/module/actor-sheet.js

224 lines
8.5 KiB
JavaScript
Raw Normal View History

2021-01-18 16:11:27 +01:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { SoSUtility } from "./sos-utility.js";
/* -------------------------------------------- */
export class SoSActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["sos", "sheet", "actor"],
template: "systems/foundryvtt-shadows-over-sol/templates/actor-sheet.html",
width: 640,
2021-02-16 21:14:13 +01:00
height: 720,
2021-01-18 16:11:27 +01:00
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }],
2021-01-18 22:05:02 +01:00
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
editStatSkill: false
2021-01-18 16:11:27 +01:00
});
}
/* -------------------------------------------- */
2022-09-28 15:53:50 +02:00
async getData() {
2022-07-13 08:11:00 +02:00
const objectData = this.object
2021-05-22 23:20:23 +02:00
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",
2022-07-13 08:11:00 +02:00
data: foundry.utils.deepClone(this.object.system),
2021-05-22 23:20:23 +02:00
effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)),
2022-09-28 15:53:50 +02:00
history: await TextEditor.enrichHTML(this.object.system.history, {async: true}),
notes: await TextEditor.enrichHTML(this.object.system.notes, {async: true}),
gmnotes: await TextEditor.enrichHTML(this.object.system.gmnotes, {async: true}),
2021-05-22 23:20:23 +02:00
limited: this.object.limited,
options: this.options,
owner: this.document.isOwner
};
this.actor.checkDeck();
2021-03-12 17:41:13 +01:00
2021-05-22 23:20:23 +02:00
formData.edgecard = this.actor.getEdgesCard();
formData.deckSize = this.actor.getDeckSize();
2021-02-16 22:04:59 +01:00
2022-07-13 08:11:00 +02:00
formData.skills = this.actor.items.filter( item => item.type == 'skill').sort( (a, b) => {
2021-03-22 21:02:56 +01:00
if ( a.name > b.name ) return 1;
return -1;
});
2021-05-22 23:20:23 +02:00
formData.skill1 = formData.skills.slice(0, Math.ceil(formData.skills.length/2) )
formData.skill2 = formData.skills.slice(Math.ceil(formData.skills.length/2), formData.skills.length )
2022-07-13 08:11:00 +02:00
formData.consequences = this.actor.items.filter( item => item.type == 'consequence').sort( (a, b) => {
2021-01-31 17:23:14 +01:00
if ( a.name > b.name ) return 1;
return -1;
});
2022-07-13 08:11:00 +02:00
formData.gears = this.actor.items.filter( item => item.type == 'gear').concat( this.actor.items.filter( item => item.type == 'container') );
2021-03-22 21:02:56 +01:00
// Build the gear tree
2022-07-13 08:11:00 +02:00
formData.gearsRoot = formData.gears.filter(item => item.system.containerid == "");
2021-05-22 23:20:23 +02:00
for ( let container of formData.gearsRoot) {
2021-03-22 21:02:56 +01:00
if ( container.type == 'container') {
2023-05-25 16:22:02 +02:00
container.system.contains = []
container.system.containerEnc = 0;
2022-03-05 23:39:35 +01:00
for (let gear of formData.gears) {
console.log("GEAR", gear, container)
2022-07-13 08:11:00 +02:00
if ( gear.system.containerid == container.id) {
2023-05-25 16:22:02 +02:00
container.system.contains.push( gear )
2022-07-13 08:11:00 +02:00
if ( !gear.system.neg && !gear.system.software ) {
container.system.containerEnc += (gear.system.big > 0) ? gear.system.big : 1;
2021-03-22 21:02:56 +01:00
}
}
}
}
}
2022-07-13 08:11:00 +02:00
formData.weapons = this.actor.items.filter( item => item.type == 'weapon');
formData.armors = this.actor.items.filter( item => item.type == 'armor');
formData.totalEncumbrance = SoSUtility.computeEncumbrance(this.actor.items);
formData.wounds = duplicate(this.actor.system.wounds);
2021-05-22 23:20:23 +02:00
formData.isGM = game.user.isGM;
formData.currentWounds = this.actor.computeCurrentWounds();
2022-07-13 08:11:00 +02:00
formData.totalWounds = this.actor.system.scores.wound.value;
2021-05-22 23:20:23 +02:00
2022-07-13 08:11:00 +02:00
formData.subcultureList = this.actor.items.filter( item => item.type == 'subculture');
2021-05-22 23:20:23 +02:00
if ( formData.subculture != "" ) { // background.subculture contains the main subculture ID
2022-07-13 08:11:00 +02:00
formData.mainSubculture = formData.subcultureList.find( subc => subc._id == this.actor.system.subculture);
2021-03-12 15:03:35 +01:00
}
2022-07-13 08:11:00 +02:00
formData.languageList = this.actor.items.filter( item => item.type == 'language');
formData.weaknessList = this.actor.items.filter( item => item.type == 'weakness');
formData.geneline = this.actor.items.find( item => item.type == 'geneline');
2021-05-22 23:20:23 +02:00
formData.editStatSkill = this.options.editStatSkill;
2021-01-18 17:46:39 +01:00
2021-05-22 23:20:23 +02:00
console.log("stats", formData);
return formData;
2021-01-18 16:11:27 +01:00
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
2021-01-18 17:46:39 +01:00
//HtmlUtility._showControlWhen($(".gm-only"), game.user.isGM);
2021-01-18 16:11:27 +01:00
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
2021-05-22 23:20:23 +02:00
const item = this.actor.items.get(li.data("item-id"));
2021-01-18 16:11:27 +01:00
item.sheet.render(true);
});
2021-02-09 23:32:55 +01:00
html.find('.item-equip').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.equipObject( li.data("item-id") );
this.render(true);
});
html.find('.item-worn').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.wornObject( li.data("item-id") );
this.render(true);
});
2021-01-18 16:11:27 +01:00
// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
2021-02-22 20:32:12 +01:00
SoSUtility.confirmDelete(this, li);
2021-01-18 16:11:27 +01:00
});
2021-01-18 22:05:02 +01:00
html.find('.stat-label a').click((event) => {
let statName = event.currentTarget.attributes.name.value;
this.actor.rollStat(statName);
});
2021-01-24 23:18:50 +01:00
html.find('.skill-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
2021-05-23 11:45:50 +02:00
const skill = this.actor.items.get(li.data("item-id"));
2021-01-24 23:18:50 +01:00
this.actor.rollSkill(skill);
});
2021-02-11 00:07:13 +01:00
html.find('.weapon-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
2021-05-23 11:45:50 +02:00
const weapon = this.actor.items.get(li.data("item-id"));
2021-02-11 00:07:13 +01:00
this.actor.rollWeapon(weapon);
});
2021-02-09 23:32:55 +01:00
html.find('.skill-value').change((event) => {
let skillName = event.currentTarget.attributes.skillname.value;
//console.log("Competence changed :", skillName);
this.actor.updateSkill(skillName, parseInt(event.target.value));
});
html.find('.skill-xp').change((event) => {
let skillName = event.currentTarget.attributes.skillname.value;
//console.log("Competence changed :", skillName);
this.actor.updateSkillExperience(skillName, parseInt(event.target.value));
});
2021-02-16 21:14:13 +01:00
html.find('.wound-value').change((event) => {
let woundName = event.currentTarget.attributes.woundname.value;
//console.log("Competence changed :", skillName);
this.actor.updateWound(woundName, parseInt(event.target.value));
});
2021-01-31 17:39:37 +01:00
html.find('.reset-deck-full').click((event) => {
this.actor.resetDeckFull();
this.render(true);
});
html.find('.draw-new-edge').click((event) => {
this.actor.drawNewEdge();
this.render(true);
});
html.find('.reset-deck').click((event) => {
2021-01-19 22:54:53 +01:00
this.actor.resetDeck();
2021-01-18 22:05:02 +01:00
this.render(true);
});
2021-02-16 23:01:42 +01:00
html.find('.discard-card').click((event) => {
const cardName = $(event.currentTarget).data("discard");
this.actor.discardEdge( cardName );
});
2021-01-31 17:53:36 +01:00
html.find('.consequence-severity').click((event) => {
const li = $(event.currentTarget).parents(".item");
2021-05-22 23:42:53 +02:00
const item = this.actor.items.get(li.data("item-id"));
2021-01-31 17:53:36 +01:00
let severity = $(event.currentTarget).val();
2022-07-13 08:11:00 +02:00
this.actor.updateEmbeddedDocuments( "Item", [ { _id: item.id, 'system.severity': severity} ] );
2021-01-31 17:53:36 +01:00
this.render(true);
});
2021-01-18 22:05:02 +01:00
html.find('.lock-unlock-sheet').click((event) => {
this.options.editStatSkill = !this.options.editStatSkill;
this.render(true);
2021-01-19 22:54:53 +01:00
});
2021-01-21 17:16:01 +01:00
html.find('.item-link a').click((event) => {
const itemId = $(event.currentTarget).data("item-id");
const item = this.actor.getOwnedItem(itemId);
item.sheet.render(true);
});
2021-01-18 16:11:27 +01:00
}
2021-03-22 21:02:56 +01:00
/* -------------------------------------------- */
async _onDrop(event) {
let toSuper = await SoSUtility.processItemDropEvent(this, event);
if ( toSuper) {
super._onDrop(event);
}
}
2021-01-18 16:11:27 +01:00
/* -------------------------------------------- */
/** @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);
}
}