Added Army/Cohort/Fortification raw sheet and js

This commit is contained in:
Vlyan
2021-10-01 19:51:43 +02:00
parent 0491bcc96e
commit b5a21f950e
30 changed files with 1288 additions and 576 deletions

View File

@@ -0,0 +1,17 @@
import { ItemSheetL5r5e } from "./item-sheet.js";
/**
* @extends {ItemSheetL5r5e}
*/
export class ArmyCohortSheetL5r5e extends ItemSheetL5r5e {
/** @override */
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["l5r5e", "sheet", "army-cohort"],
template: CONFIG.l5r5e.paths.templates + "items/army-cohort/army-cohort-sheet.html",
width: 520,
height: 480,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }],
});
}
}

View File

@@ -0,0 +1,17 @@
import { ItemSheetL5r5e } from "./item-sheet.js";
/**
* @extends {ItemSheetL5r5e}
*/
export class ArmyFortificationSheetL5r5e extends ItemSheetL5r5e {
/** @override */
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["l5r5e", "sheet", "army-fortification"],
template: CONFIG.l5r5e.paths.templates + "items/army-fortification/army-fortification-sheet.html",
width: 520,
height: 480,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }],
});
}
}

View File

@@ -0,0 +1,166 @@
/**
* Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet}
*/
export class BaseItemSheetL5r5e extends ItemSheet {
/** @override */
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["l5r5e", "sheet", "item"],
//template: CONFIG.l5r5e.paths.templates + "items/item/item-sheet.html",
width: 520,
height: 480,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }],
});
}
/**
* Add the SendToChat button on top of sheet
* @override
*/
_getHeaderButtons() {
let buttons = super._getHeaderButtons();
// Send To Chat
buttons.unshift({
label: game.i18n.localize("l5r5e.global.send_to_chat"),
class: "send-to-chat",
icon: "fas fa-comment-dots",
onclick: () =>
game.l5r5e.HelpersL5r5e.debounce(
"send2chat-" + this.object.id,
() => game.l5r5e.HelpersL5r5e.sendToChat(this.object),
2000,
true
)(),
});
return buttons;
}
/**
* @return {Object|Promise}
*/
async getData(options = {}) {
const sheetData = await super.getData(options);
sheetData.data.dtypes = ["String", "Number", "Boolean"];
// Fix editable
sheetData.editable = this.isEditable;
sheetData.options.editable = sheetData.editable;
return sheetData;
}
/**
* Activate a named TinyMCE text editor
* @param {string} name The named data field which the editor modifies.
* @param {object} options TinyMCE initialization options passed to TextEditor.create
* @param {string} initialContent Initial text content for the editor area.
* @override
*/
activateEditor(name, options = {}, initialContent = "") {
if (name === "data.description" && initialContent) {
initialContent = game.l5r5e.HelpersL5r5e.convertSymbols(initialContent, false);
}
super.activateEditor(name, options, initialContent);
}
/**
* This method is called upon form submission after form data is validated
* @param event {Event} The initial triggering submission event
* @param formData {Object} The object of validated form data with which to update the object
* @returns {Promise} A Promise which resolves once the update operation has completed
* @override
*/
async _updateObject(event, formData) {
if (formData["data.description"]) {
// Base links (Journal, compendiums...)
formData["data.description"] = TextEditor.enrichHTML(formData["data.description"]);
// L5R Symbols
formData["data.description"] = game.l5r5e.HelpersL5r5e.convertSymbols(formData["data.description"], true);
}
return super._updateObject(event, formData);
}
/**
* Subscribe to events from the sheet.
* @param {jQuery} html HTML content of the sheet.
* @override
*/
activateListeners(html) {
super.activateListeners(html);
// Commons
game.l5r5e.HelpersL5r5e.commonListeners(html, this.actor);
// Everything below here is only needed if the sheet is editable
if (!this.isEditable) {
return;
}
// On focus on one numeric element, select all text for better experience
html.find(".select-on-focus").on("focus", (event) => {
event.preventDefault();
event.stopPropagation();
event.target.select();
});
}
/**
* Add a embed item
* @param {Event} event
* @private
*/
_addSubItem(event) {
event.preventDefault();
event.stopPropagation();
const itemId = $(event.currentTarget).data("item-id");
console.warn("L5R5E | TODO ItemSheetL5r5e._addSubItem()", itemId); // TODO _addSubItem Currently not used, title override it
}
/**
* Add a embed item
* @param {Event} event
* @private
*/
_editSubItem(event) {
event.preventDefault();
event.stopPropagation();
const itemId = $(event.currentTarget).data("item-id");
const item = this.document.items.get(itemId);
if (item) {
item.sheet.render(true);
}
}
/**
* Delete a embed item
* @param {Event} event
* @private
*/
_deleteSubItem(event) {
event.preventDefault();
event.stopPropagation();
const itemId = $(event.currentTarget).data("item-id");
const item = this.document.getEmbedItem(itemId);
if (!item) {
return;
}
const callback = async () => {
this.document.deleteEmbedItem(itemId);
};
// Holing Ctrl = without confirm
if (event.ctrlKey) {
return callback();
}
game.l5r5e.HelpersL5r5e.confirmDeleteDialog(
game.i18n.format("l5r5e.global.delete_confirm", { name: item.name }),
callback
);
}
}

View File

@@ -1,8 +1,10 @@
import { BaseItemSheetL5r5e } from "./base-item-sheet.js";
/**
* Extend the basic ItemSheet with some very simple modifications
* Extend BaseItemSheetL5r5e with modifications for objects
* @extends {ItemSheet}
*/
export class ItemSheetL5r5e extends ItemSheet {
export class ItemSheetL5r5e extends BaseItemSheetL5r5e {
/** @override */
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
@@ -14,46 +16,17 @@ export class ItemSheetL5r5e extends ItemSheet {
});
}
/**
* Add the SendToChat button on top of sheet
* @override
*/
_getHeaderButtons() {
let buttons = super._getHeaderButtons();
// Send To Chat
buttons.unshift({
label: game.i18n.localize("l5r5e.global.send_to_chat"),
class: "send-to-chat",
icon: "fas fa-comment-dots",
onclick: () =>
game.l5r5e.HelpersL5r5e.debounce(
"send2chat-" + this.object.id,
() => game.l5r5e.HelpersL5r5e.sendToChat(this.object),
2000,
true
)(),
});
return buttons;
}
/**
* @return {Object|Promise}
*/
async getData(options = {}) {
const sheetData = await super.getData(options);
sheetData.data.dtypes = ["String", "Number", "Boolean"];
sheetData.data.ringsList = game.l5r5e.HelpersL5r5e.getRingsList();
// Prepare Properties (id/name => object)
await this._prepareProperties(sheetData);
// Fix editable
sheetData.editable = this.isEditable;
sheetData.options.editable = sheetData.editable;
return sheetData;
}
@@ -79,37 +52,6 @@ export class ItemSheetL5r5e extends ItemSheet {
}
}
/**
* Activate a named TinyMCE text editor
* @param {string} name The named data field which the editor modifies.
* @param {object} options TinyMCE initialization options passed to TextEditor.create
* @param {string} initialContent Initial text content for the editor area.
* @override
*/
activateEditor(name, options = {}, initialContent = "") {
if (name === "data.description" && initialContent) {
initialContent = game.l5r5e.HelpersL5r5e.convertSymbols(initialContent, false);
}
super.activateEditor(name, options, initialContent);
}
/**
* This method is called upon form submission after form data is validated
* @param event {Event} The initial triggering submission event
* @param formData {Object} The object of validated form data with which to update the object
* @returns {Promise} A Promise which resolves once the update operation has completed
* @override
*/
async _updateObject(event, formData) {
if (formData["data.description"]) {
// Base links (Journal, compendiums...)
formData["data.description"] = TextEditor.enrichHTML(formData["data.description"]);
// L5R Symbols
formData["data.description"] = game.l5r5e.HelpersL5r5e.convertSymbols(formData["data.description"], true);
}
return super._updateObject(event, formData);
}
/**
* Subscribe to events from the sheet.
* @param {jQuery} html HTML content of the sheet.
@@ -118,21 +60,11 @@ export class ItemSheetL5r5e extends ItemSheet {
activateListeners(html) {
super.activateListeners(html);
// Commons
game.l5r5e.HelpersL5r5e.commonListeners(html, this.actor);
// Everything below here is only needed if the sheet is editable
if (!this.isEditable) {
return;
}
// On focus on one numeric element, select all text for better experience
html.find(".select-on-focus").on("focus", (event) => {
event.preventDefault();
event.stopPropagation();
event.target.select();
});
// Delete a property
html.find(`.property-delete`).on("click", this._deleteProperty.bind(this));
}
@@ -260,60 +192,4 @@ export class ItemSheetL5r5e extends ItemSheet {
callback
);
}
/**
* Add a embed item
* @param {Event} event
* @private
*/
_addSubItem(event) {
event.preventDefault();
event.stopPropagation();
const itemId = $(event.currentTarget).data("item-id");
console.warn("L5R5E | TODO ItemSheetL5r5e._addSubItem()", itemId); // TODO _addSubItem Currently not used, title override it
}
/**
* Add a embed item
* @param {Event} event
* @private
*/
_editSubItem(event) {
event.preventDefault();
event.stopPropagation();
const itemId = $(event.currentTarget).data("item-id");
const item = this.document.items.get(itemId);
if (item) {
item.sheet.render(true);
}
}
/**
* Delete a embed item
* @param {Event} event
* @private
*/
_deleteSubItem(event) {
event.preventDefault();
event.stopPropagation();
const itemId = $(event.currentTarget).data("item-id");
const item = this.document.getEmbedItem(itemId);
if (!item) {
return;
}
const callback = async () => {
this.document.deleteEmbedItem(itemId);
};
// Holing Ctrl = without confirm
if (event.ctrlKey) {
return callback();
}
game.l5r5e.HelpersL5r5e.confirmDeleteDialog(
game.i18n.format("l5r5e.global.delete_confirm", { name: item.name }),
callback
);
}
}