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

179 lines
6.6 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
});
}
/* -------------------------------------------- */
getData() {
let data = super.getData();
2021-01-18 22:05:02 +01:00
data.data.edgecard = this.actor.getEdgesCard();
2021-02-16 22:04:59 +01:00
data.data.deckSize = this.actor.getDeckSize();
2021-01-21 17:16:01 +01:00
data.data.skills = this.actor.data.items.filter( item => item.type == 'skill').sort( (a, b) => {
if ( a.name > b.name ) return 1;
return -1;
});
data.data.skill1 = data.data.skills.slice(0, Math.ceil(data.data.skills.length/2) )
data.data.skill2 = data.data.skills.slice(Math.ceil(data.data.skills.length/2), data.data.skills.length )
2021-01-31 17:23:14 +01:00
data.data.consequences = this.actor.data.items.filter( item => item.type == 'consequence').sort( (a, b) => {
if ( a.name > b.name ) return 1;
return -1;
});
2021-02-09 23:32:55 +01:00
data.data.gears = this.actor.data.items.filter( item => item.type == 'gear');
data.data.weapons = this.actor.data.items.filter( item => item.type == 'weapon');
data.data.armors = this.actor.data.items.filter( item => item.type == 'armor');
data.data.totalEncumbrance = SoSUtility.computeEncumbrance(this.actor.data.items);
2021-02-16 21:14:13 +01:00
data.data.wounds = duplicate(this.actor.data.data.wounds);
data.data.isGM = game.user.isGM;
data.data.currentWounds = this.actor.computeCurrentWounds();
data.data.totalWounds = this.actor.data.data.scores.wound.value;
2021-02-09 23:32:55 +01:00
2021-01-21 17:16:01 +01:00
data.data.subculture = this.actor.data.items.find( item => item.type == 'subculture');
data.data.geneline = this.actor.data.items.find( item => item.type == 'geneline');
2021-01-18 22:05:02 +01:00
data.data.editStatSkill = this.options.editStatSkill;
2021-01-18 17:46:39 +01:00
console.log("stats", data);
//data.stats = duplicate(this.actor.stats);
//data.scores = duplicate(this.actor.scores);
2021-01-18 16:11:27 +01:00
return data;
}
/* -------------------------------------------- */
async _onDrop(event) {
super._onDrop(event);
}
/* -------------------------------------------- */
/** @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");
const item = this.actor.getOwnedItem(li.data("item-id"));
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");
const skill = this.actor.getOwnedItem(li.data("item-id"));
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");
const weapon = this.actor.getOwnedItem(li.data("item-id"));
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");
const item = this.actor.getOwnedItem(li.data("item-id"));
let severity = $(event.currentTarget).val();
this.actor.updateOwnedItem( { _id: item._id, 'data.severity': severity});
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
}
/* -------------------------------------------- */
/** @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);
}
}