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() {
|
2021-05-25 10:27:40 +00:00
|
|
|
return foundry.utils.mergeObject(super.defaultOptions, {
|
2023-11-28 22:06:09 +00:00
|
|
|
classes: ["beam-saber", "sheet", "actor", "crew"],
|
|
|
|
template: "systems/beam-saber/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 */
|
2022-09-03 15:44:26 +00:00
|
|
|
getData(options) {
|
|
|
|
const superData = super.getData( options );
|
|
|
|
const sheetData = superData.data;
|
|
|
|
sheetData.owner = superData.owner;
|
|
|
|
sheetData.editable = superData.editable;
|
|
|
|
sheetData.isGM = game.user.isGM;
|
2020-04-24 15:30:51 +00:00
|
|
|
|
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
|
|
|
|
2022-09-03 15:44:26 +00:00
|
|
|
sheetData.items.forEach(item => {
|
2020-04-27 13:58:52 +00:00
|
|
|
|
|
|
|
if (item.type === "crew_type") {
|
|
|
|
// Object.entries(item.data.turfs).forEach(turf => {turfs_amount += (turf.value === true) ? 1 : 0});
|
2022-09-03 15:44:26 +00:00
|
|
|
Object.entries(item.system.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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2022-09-03 15:44:26 +00:00
|
|
|
sheetData.system.turfs_amount = turfs_amount;
|
2020-04-27 13:58:52 +00:00
|
|
|
|
2022-09-03 15:44:26 +00:00
|
|
|
return sheetData;
|
2020-04-24 15:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
|
|
|
|
// Everything below here is only needed if the sheet is editable
|
|
|
|
if (!this.options.editable) return;
|
|
|
|
|
2023-07-19 02:29:52 +00:00
|
|
|
// Add Crew Type
|
|
|
|
html.find(".crew-class").click(this._onItemAddClick.bind(this));
|
|
|
|
|
2020-04-24 15:30:51 +00:00
|
|
|
// 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");
|
2021-05-25 10:27:40 +00:00
|
|
|
const item = this.actor.items.get(element.data("itemId"));
|
2020-04-24 15:30:51 +00:00
|
|
|
item.sheet.render(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Delete Inventory Item
|
2021-05-25 10:27:40 +00:00
|
|
|
html.find('.item-delete').click( async ev => {
|
2020-04-24 15:30:51 +00:00
|
|
|
const element = $(ev.currentTarget).parents(".item");
|
2021-05-25 10:27:40 +00:00
|
|
|
await this.actor.deleteEmbeddedDocuments("Item", [element.data("itemId")]);
|
2020-04-24 15:30:51 +00:00
|
|
|
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
|
2021-05-25 10:27:40 +00:00
|
|
|
html.find('.turf-select').click( async ev => {
|
2020-04-25 11:32:34 +00:00
|
|
|
const element = $(ev.currentTarget).parents(".item");
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-04-25 11:32:34 +00:00
|
|
|
let item_id = element.data("itemId")
|
|
|
|
let turf_id = $(ev.currentTarget).data("turfId");
|
|
|
|
let turf_current_status = $(ev.currentTarget).data("turfStatus");
|
2022-09-03 15:44:26 +00:00
|
|
|
let turf_checkbox_name = 'system.turfs.' + turf_id + '.value';
|
2020-04-25 11:32:34 +00:00
|
|
|
|
2021-05-25 10:27:40 +00:00
|
|
|
await this.actor.updateEmbeddedDocuments('Item', [{
|
2020-04-25 11:32:34 +00:00
|
|
|
_id: item_id,
|
2021-05-25 10:27:40 +00:00
|
|
|
[turf_checkbox_name]: !turf_current_status}]);
|
2020-04-25 11:32:34 +00:00
|
|
|
this.render(false);
|
|
|
|
});
|
2020-05-04 10:10:57 +00:00
|
|
|
|
|
|
|
// Cohort Block Harm handler
|
2021-05-25 10:27:40 +00:00
|
|
|
html.find('.cohort-block-harm input[type="radio"]').change( async ev => {
|
2020-05-04 10:10:57 +00:00
|
|
|
const element = $(ev.currentTarget).parents(".item");
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-05-04 10:10:57 +00:00
|
|
|
let item_id = element.data("itemId")
|
|
|
|
let harm_id = $(ev.currentTarget).val();
|
|
|
|
|
2021-05-25 10:27:40 +00:00
|
|
|
await this.actor.updateEmbeddedDocuments('Item', [{
|
2020-05-04 10:10:57 +00:00
|
|
|
_id: item_id,
|
2022-09-03 15:44:26 +00:00
|
|
|
"system.harm": [harm_id]}]);
|
2020-05-04 10:10:57 +00:00
|
|
|
this.render(false);
|
|
|
|
});
|
2020-04-24 15:30:51 +00:00
|
|
|
}
|
|
|
|
|
2023-07-19 02:29:52 +00:00
|
|
|
|
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
|
2021-05-25 10:27:40 +00:00
|
|
|
await super._updateObject(event, formData);
|
2020-05-04 10:10:57 +00:00
|
|
|
|
2022-09-03 15:44:26 +00:00
|
|
|
if (event.target && event.target.name === "system.tier") {
|
2020-05-04 10:10:57 +00:00
|
|
|
this.render(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
2020-04-24 15:30:51 +00:00
|
|
|
|
|
|
|
}
|