2020-05-11 12:21:18 +00:00
|
|
|
|
|
|
|
import { BladesSheet } from "./blades-sheet.js";
|
|
|
|
|
2020-04-24 15:30:51 +00:00
|
|
|
/**
|
2020-05-11 12:21:18 +00:00
|
|
|
* @extends {BladesSheet}
|
2020-04-24 15:30:51 +00:00
|
|
|
*/
|
2020-05-11 12:21:18 +00:00
|
|
|
export class BladesCrewSheet extends BladesSheet {
|
2020-04-24 15:30:51 +00:00
|
|
|
|
|
|
|
/** @override */
|
|
|
|
static get defaultOptions() {
|
|
|
|
return mergeObject(super.defaultOptions, {
|
|
|
|
classes: ["blades-in-the-dark", "sheet", "actor"],
|
|
|
|
template: "systems/blades-in-the-dark/templates/crew-sheet.html",
|
2021-03-04 06:44:24 +00:00
|
|
|
width: 940,
|
2020-04-29 12:41:36 +00:00
|
|
|
height: 1020,
|
2020-04-29 12:04:49 +00:00
|
|
|
tabs: [{navSelector: ".tabs", contentSelector: ".tab-content", initial: "turfs"}]
|
2020-04-24 15:30:51 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
getData() {
|
|
|
|
const data = super.getData();
|
|
|
|
|
2020-04-27 13:58:52 +00:00
|
|
|
// Calculate Turfs amount.
|
|
|
|
// We already have Lair, so set to -1.
|
2020-07-24 10:39:22 +00:00
|
|
|
let turfs_amount = 0
|
2020-04-27 13:58:52 +00:00
|
|
|
|
|
|
|
data.items.forEach(item => {
|
|
|
|
|
|
|
|
if (item.type === "crew_type") {
|
|
|
|
// Object.entries(item.data.turfs).forEach(turf => {turfs_amount += (turf.value === true) ? 1 : 0});
|
|
|
|
Object.entries(item.data.turfs).forEach(([key, turf]) => {
|
2020-08-21 09:39:16 +00:00
|
|
|
if (turf.name === 'BITD.Turf') {
|
|
|
|
turfs_amount += (turf.value === true) ? 1 : 0;
|
|
|
|
}
|
2020-04-27 13:58:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
data.data.turfs_amount = turfs_amount;
|
|
|
|
|
2020-04-24 15:30:51 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
|
|
|
|
// Everything below here is only needed if the sheet is editable
|
|
|
|
if (!this.options.editable) return;
|
|
|
|
|
|
|
|
// Update Inventory Item
|
2020-05-04 10:10:57 +00:00
|
|
|
html.find('.item-sheet-open').click(ev => {
|
2020-04-24 15:30:51 +00:00
|
|
|
const element = $(ev.currentTarget).parents(".item");
|
|
|
|
const item = this.actor.getOwnedItem(element.data("itemId"));
|
|
|
|
item.sheet.render(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Delete Inventory Item
|
|
|
|
html.find('.item-delete').click(ev => {
|
|
|
|
const element = $(ev.currentTarget).parents(".item");
|
|
|
|
this.actor.deleteOwnedItem(element.data("itemId"));
|
|
|
|
element.slideUp(200, () => this.render(false));
|
|
|
|
});
|
2020-04-25 11:32:34 +00:00
|
|
|
|
2020-05-04 10:10:57 +00:00
|
|
|
// Add a new Cohort
|
|
|
|
html.find('.add-item').click(ev => {
|
|
|
|
BladesHelpers._addOwnedItem(ev, this.actor);
|
|
|
|
});
|
|
|
|
|
2020-04-25 11:32:34 +00:00
|
|
|
// Toggle Turf
|
|
|
|
html.find('.turf-select').click(ev => {
|
|
|
|
const element = $(ev.currentTarget).parents(".item");
|
|
|
|
|
|
|
|
let item_id = element.data("itemId")
|
|
|
|
let turf_id = $(ev.currentTarget).data("turfId");
|
|
|
|
let turf_current_status = $(ev.currentTarget).data("turfStatus");
|
|
|
|
let turf_checkbox_name = 'data.turfs.' + turf_id + '.value';
|
|
|
|
|
|
|
|
this.actor.updateEmbeddedEntity('OwnedItem', {
|
|
|
|
_id: item_id,
|
|
|
|
[turf_checkbox_name]: !turf_current_status});
|
|
|
|
this.render(false);
|
|
|
|
});
|
2020-05-04 10:10:57 +00:00
|
|
|
|
|
|
|
// Cohort Block Harm handler
|
|
|
|
html.find('.cohort-block-harm input[type="radio"]').change(ev => {
|
|
|
|
const element = $(ev.currentTarget).parents(".item");
|
|
|
|
|
|
|
|
let item_id = element.data("itemId")
|
|
|
|
let harm_id = $(ev.currentTarget).val();
|
|
|
|
|
|
|
|
this.actor.updateEmbeddedEntity('OwnedItem', {
|
|
|
|
_id: item_id,
|
|
|
|
"data.harm": [harm_id]});
|
|
|
|
this.render(false);
|
|
|
|
});
|
2020-04-24 15:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-05-04 10:10:57 +00:00
|
|
|
/* Form Submission */
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/** @override */
|
2020-11-04 12:37:28 +00:00
|
|
|
async _updateObject(event, formData) {
|
2020-05-04 10:10:57 +00:00
|
|
|
|
|
|
|
// Update the Item
|
|
|
|
super._updateObject(event, formData);
|
|
|
|
|
2020-05-18 13:59:47 +00:00
|
|
|
if (event.target && event.target.name === "data.tier") {
|
2020-05-04 10:10:57 +00:00
|
|
|
this.render(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
2020-04-24 15:30:51 +00:00
|
|
|
|
|
|
|
}
|