diff --git a/system/scripts/actors/base-sheet.js b/system/scripts/actors/base-sheet.js index 1405ac1..e59f729 100644 --- a/system/scripts/actors/base-sheet.js +++ b/system/scripts/actors/base-sheet.js @@ -259,7 +259,7 @@ export class BaseSheetL5r5e extends ActorSheet { /** * Subscribe to events from the sheet. - * @param html HTML content of the sheet. + * @param {jQuery} html HTML content of the sheet. */ activateListeners(html) { super.activateListeners(html); @@ -318,6 +318,9 @@ export class BaseSheetL5r5e extends ActorSheet { html.find(".item-add").on("click", this._addSubItem.bind(this)); html.find(`.item-edit`).on("click", this._editSubItem.bind(this)); html.find(`.item-delete`).on("click", this._deleteSubItem.bind(this)); + + // Others Advancements + html.find(".item-advancement-choose").on("click", this._showDialogAddSubItem.bind(this)); } /** @@ -336,37 +339,20 @@ export class BaseSheetL5r5e extends ActorSheet { /** * Add a generic item with sub type - * @param {Event} event + * @param {string} type Item sub type (armor, weapon, bond...) + * @param {boolean} isEquipped For item with prop "Equipped" set the value + * @param {string|null} techniqueType Technique subtype (kata, shuji...) + * @return {Promise} * @private */ - async _addSubItem(event) { - event.preventDefault(); - event.stopPropagation(); - - const type = $(event.currentTarget).data("item-type"); + async _createSubItem({ type, isEquipped = false, techniqueType = null }) { if (!type) { return; } - const titles = { - item: "ITEM.TypeItem", - armor: "ITEM.TypeArmor", - weapon: "ITEM.TypeWeapon", - technique: "ITEM.TypeTechnique", - peculiarity: "ITEM.TypePeculiarity", - advancement: "ITEM.TypeAdvancement", - title: "ITEM.TypeTitle", - bond: "ITEM.TypeBond", - item_pattern: "ITEM.TypeItem_pattern", - signature_scroll: "ITEM.TypeSignature_scroll", - }; - if (!titles[type]) { - return; - } - const created = await this.actor.createEmbeddedDocuments("Item", [ { - name: game.i18n.localize(titles[type]), + name: game.i18n.localize(`ITEM.Type${type.capitalize()}`), type: type, img: `${CONFIG.l5r5e.paths.assets}icons/items/${type}.svg`, }, @@ -385,19 +371,17 @@ export class BaseSheetL5r5e extends ActorSheet { } switch (item.data.type) { + case "item": // no break case "armor": // no break case "weapon": - if ($(event.currentTarget).data("item-eqquiped")) { - item.data.data.equipped = true; - } + item.data.data.equipped = isEquipped; break; case "technique": { // If technique, select the current type - const techType = $(event.currentTarget).data("tech-type"); - if (CONFIG.l5r5e.techniques.get(techType)) { - item.data.data.technique_type = techType; - item.data.img = `${CONFIG.l5r5e.paths.assets}icons/techs/${techType}.svg`; + if (CONFIG.l5r5e.techniques.get(techniqueType)) { + item.data.data.technique_type = techniqueType; + item.data.img = `${CONFIG.l5r5e.paths.assets}icons/techs/${techniqueType}.svg`; } break; } @@ -406,6 +390,40 @@ export class BaseSheetL5r5e extends ActorSheet { item.sheet.render(true); } + /** + * Display a dialog to choose what Item to add + * @param {Event} event + * @return {Promise} + * @private + */ + async _showDialogAddSubItem(event) { + game.l5r5e.HelpersL5r5e.showSubItemDialog(["bond", "title", "signature_scroll", "item_pattern"]).then( + (selectedType) => { + this._createSubItem({ type: selectedType }); + } + ); + } + + /** + * Add a generic item with sub type + * @param {Event} event + * @private + */ + async _addSubItem(event) { + event.preventDefault(); + event.stopPropagation(); + + const type = $(event.currentTarget).data("item-type"); + if (!type) { + return; + } + + const isEquipped = $(event.currentTarget).data("item-equipped") || false; + const techniqueType = $(event.currentTarget).data("tech-type") || null; + + return this._createSubItem({ type, isEquipped, techniqueType }); + } + /** * Edit a generic item with sub type * @param {Event} event diff --git a/system/scripts/actors/character-sheet.js b/system/scripts/actors/character-sheet.js index 42090a9..e6d1a5f 100644 --- a/system/scripts/actors/character-sheet.js +++ b/system/scripts/actors/character-sheet.js @@ -65,7 +65,7 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e { /** * Subscribe to events from the sheet. - * @param html HTML content of the sheet. + * @param {jQuery} html HTML content of the sheet. */ activateListeners(html) { super.activateListeners(html); diff --git a/system/scripts/actors/twenty-questions-dialog.js b/system/scripts/actors/twenty-questions-dialog.js index eae7f60..eee541f 100644 --- a/system/scripts/actors/twenty-questions-dialog.js +++ b/system/scripts/actors/twenty-questions-dialog.js @@ -154,6 +154,7 @@ export class TwentyQuestionsDialog extends FormApplication { /** * Listen to html elements + * @param {jQuery} html HTML content of the sheet. * @override */ activateListeners(html) { diff --git a/system/scripts/config.js b/system/scripts/config.js index 92f60f3..c8e3325 100644 --- a/system/scripts/config.js +++ b/system/scripts/config.js @@ -23,7 +23,7 @@ L5R5E.techniques.set("ninjutsu", { type: "core", displayInTypes: true }); L5R5E.techniques.set("school_ability", { type: "school", displayInTypes: false }); L5R5E.techniques.set("mastery_ability", { type: "school", displayInTypes: false }); // Title -L5R5E.techniques.set("title_ability", { type: "title", displayInTypes: false }); +// L5R5E.techniques.set("title_ability", { type: "title", displayInTypes: false }); // Custom L5R5E.techniques.set("specificity", { type: "custom", displayInTypes: false }); diff --git a/system/scripts/dice/gm-tools-dialog.js b/system/scripts/dialogs/gm-tools-dialog.js similarity index 97% rename from system/scripts/dice/gm-tools-dialog.js rename to system/scripts/dialogs/gm-tools-dialog.js index a931ebe..98fee78 100644 --- a/system/scripts/dice/gm-tools-dialog.js +++ b/system/scripts/dialogs/gm-tools-dialog.js @@ -18,7 +18,7 @@ export class GmToolsDialog extends FormApplication { return foundry.utils.mergeObject(super.defaultOptions, { id: "l5r5e-gm-tools-dialog", classes: ["l5r5e", "gm-tools-dialog"], - template: CONFIG.l5r5e.paths.templates + "dice/gm-tools-dialog.html", + template: CONFIG.l5r5e.paths.templates + "dialogs/gm-tools-dialog.html", title: game.i18n.localize("l5r5e.gm_toolbox.title"), left: x - 512, top: y - 98, @@ -111,6 +111,7 @@ export class GmToolsDialog extends FormApplication { /** * Listen to html elements + * @param {jQuery} html HTML content of the sheet. * @override */ activateListeners(html) { diff --git a/system/scripts/dice/dice-picker-dialog.js b/system/scripts/dice/dice-picker-dialog.js index 78a058a..35b9c12 100644 --- a/system/scripts/dice/dice-picker-dialog.js +++ b/system/scripts/dice/dice-picker-dialog.js @@ -300,6 +300,7 @@ export class DicePickerDialog extends FormApplication { /** * Listen to html elements + * @param {jQuery} html HTML content of the sheet. * @override */ activateListeners(html) { diff --git a/system/scripts/dice/roll-n-keep-dialog.js b/system/scripts/dice/roll-n-keep-dialog.js index 0d0d9b1..4df5505 100644 --- a/system/scripts/dice/roll-n-keep-dialog.js +++ b/system/scripts/dice/roll-n-keep-dialog.js @@ -239,6 +239,7 @@ export class RollnKeepDialog extends FormApplication { /** * Listen to html elements + * @param {jQuery} html HTML content of the sheet. * @override */ activateListeners(html) { diff --git a/system/scripts/help/help-dialog.js b/system/scripts/help/help-dialog.js index 4a435c5..5d0df3b 100644 --- a/system/scripts/help/help-dialog.js +++ b/system/scripts/help/help-dialog.js @@ -39,6 +39,7 @@ export class HelpDialog extends FormApplication { /** * Listen to html elements + * @param {jQuery} html HTML content of the sheet. * @override */ activateListeners(html) { diff --git a/system/scripts/helpers.js b/system/scripts/helpers.js index 665f4dc..8a89cf2 100644 --- a/system/scripts/helpers.js +++ b/system/scripts/helpers.js @@ -6,6 +6,8 @@ import { ItemL5r5e } from "./item.js"; export class HelpersL5r5e { /** * Get Rings/Element for List / Select + * @param {Actor|null} actor + * @return {{id: string, label: *, value}[]} */ static getRingsList(actor = null) { return CONFIG.l5r5e.stances.map((e) => ({ @@ -17,6 +19,8 @@ export class HelpersL5r5e { /** * Get Skills for List / Select with groups + * @param {boolean} useGroup + * @return {{cat: any, id: any, label: *}[]} */ static getSkillsList(useGroup = false) { if (!useGroup) { @@ -64,6 +68,8 @@ export class HelpersL5r5e { /** * Return the target object on a drag n drop event, or null if not found + * @param {DragEvent} event + * @return {Promise} */ static async getDragnDropTargetObject(event) { const json = event.dataTransfer.getData("text/plain"); @@ -76,6 +82,11 @@ export class HelpersL5r5e { /** * Return the object from Game or Pack by his ID, or null if not found + * @param {number} id + * @param {string} type + * @param {string|null} data + * @param {string|null} pack + * @return {Promise} */ static async getObjectGameOrPack({ id, type, data = null, pack = null }) { let document = null; @@ -142,6 +153,8 @@ export class HelpersL5r5e { /** * Make a temporary item for compendium drag n drop + * @param {ItemL5r5e|any[]} data + * @return {ItemL5r5e} */ static createItemFromCompendium(data) { if ( @@ -174,6 +187,8 @@ export class HelpersL5r5e { /** * Babele and properties specific + * @param {Document} document + * @return {Promise} */ static async refreshItemProperties(document) { if (document.data.data.properties && typeof Babele !== "undefined") { @@ -191,6 +206,9 @@ export class HelpersL5r5e { /** * Convert (op), (ex)... to associated symbols for content/descriptions + * @param {string} text Input text + * @param {boolean} toSymbol If True convert symbol to html (op), if false html to symbol + * @return {string} */ static convertSymbols(text, toSymbol) { CONFIG.l5r5e.symbols.forEach((cfg, tag) => { @@ -208,6 +226,8 @@ export class HelpersL5r5e { /** * Escape Regx characters + * @param {string} str + * @return {string} */ static escapeRegExp(str) { return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); @@ -215,6 +235,8 @@ export class HelpersL5r5e { /** * Get the associated pack for a core item (time saving) + * @param {string} documentId + * @return {string} */ static getPackNameForCoreItem(documentId) { const core = new Map(); @@ -266,6 +288,38 @@ export class HelpersL5r5e { }).render(true); } + /** + * Display a dialog to choose what Item type to add + * @param {string[]|null} types + * @return {Promise<*>} Return the item type choice (armor, bond...) + */ + static async showSubItemDialog(types = null) { + // If no types, get the full list + if (!types) { + types = game.system.entityTypes.Item; + } + const title = game.i18n.format("ENTITY.Create", { entity: game.i18n.localize("Item") }); + + // Render the template + const html = await renderTemplate(`${CONFIG.l5r5e.paths.templates}dialogs/choose-item-type-dialog.html`, { + type: null, + types: types.reduce((obj, t) => { + const label = CONFIG.Item.typeLabels[t] ?? t; + obj[t] = game.i18n.has(label) ? game.i18n.localize(label) : t; + return obj; + }, {}), + }); + + // Display the dialog + return Dialog.prompt({ + title: title, + content: html, + label: title, + callback: (html) => $(html).find("[name='type'] option:selected").val(), + rejectClose: false, + }); + } + /** * Notify Applications using Difficulty settings that the values was changed */ diff --git a/system/scripts/item.js b/system/scripts/item.js index 3967127..6931c26 100644 --- a/system/scripts/item.js +++ b/system/scripts/item.js @@ -131,14 +131,14 @@ export class ItemL5r5e extends Item { * @param {boolean} save if we save in db or not (used internally) * @param {boolean} newId if we change the id * @param {boolean} addBonusToActor if we update the actor bonus for advancements - * @return {Promise} + * @return {Promise} */ async addEmbedItem(item, { save = true, newId = true, addBonusToActor = true } = {}) { if (!item) { return; } - if (!(item instanceof Item) && item._id) { + if (!(item instanceof Item) && item?.name && item?.type) { // Data -> Item item = new ItemL5r5e(item); } @@ -165,16 +165,17 @@ export class ItemL5r5e extends Item { if (save) { await this.saveEmbedItems(); } + return item.data._id; } /** * Update a Embed Item * @param {ItemL5r5e} item Object to add * @param {boolean} save if we save in db or not (used internally) - * @return {Promise} + * @return {Promise} */ async updateEmbedItem(item, { save = true } = {}) { - await this.addEmbedItem(item, { save, newId: false, addBonusToActor: false }); + return await this.addEmbedItem(item, { save, newId: false, addBonusToActor: false }); } /** diff --git a/system/scripts/items/advancement-sheet.js b/system/scripts/items/advancement-sheet.js index 118a5d8..60362e1 100644 --- a/system/scripts/items/advancement-sheet.js +++ b/system/scripts/items/advancement-sheet.js @@ -31,7 +31,7 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e { /** * Subscribe to events from the sheet. - * @param html HTML content of the sheet. + * @param {jQuery} html HTML content of the sheet. */ activateListeners(html) { super.activateListeners(html); diff --git a/system/scripts/items/item-pattern-sheet.js b/system/scripts/items/item-pattern-sheet.js index 1cc35bd..e7f9f47 100644 --- a/system/scripts/items/item-pattern-sheet.js +++ b/system/scripts/items/item-pattern-sheet.js @@ -50,7 +50,7 @@ export class ItemPatternSheetL5r5e extends ItemSheetL5r5e { /** * Subscribe to events from the sheet. - * @param html HTML content of the sheet. + * @param {jQuery} html HTML content of the sheet. */ activateListeners(html) { super.activateListeners(html); diff --git a/system/scripts/items/item-sheet.js b/system/scripts/items/item-sheet.js index 391d027..eaae17e 100644 --- a/system/scripts/items/item-sheet.js +++ b/system/scripts/items/item-sheet.js @@ -82,7 +82,8 @@ export class ItemSheetL5r5e extends ItemSheet { /** * Subscribe to events from the sheet. - * @param html HTML content of the sheet. + * @param {jQuery} html HTML content of the sheet. + * @override */ activateListeners(html) { super.activateListeners(html); @@ -112,7 +113,7 @@ export class ItemSheetL5r5e extends ItemSheet { /** * Create drag-and-drop workflow handlers for this Application - * @return An array of DragDrop handlers + * @return {DragDrop[]} An array of DragDrop handlers */ _createDragDropHandlers() { return [ @@ -160,6 +161,7 @@ export class ItemSheetL5r5e extends ItemSheet { /** * Add a property to the current item + * @param {Item} item * @private */ _addProperty(item) { @@ -222,19 +224,19 @@ export class ItemSheetL5r5e extends ItemSheet { /** * Add a embed item - * @param event + * @param {Event} event * @private */ _addSubItem(event) { event.preventDefault(); event.stopPropagation(); const itemId = $(event.currentTarget).data("item-id"); - console.log("TODO _addSubItem", itemId); // TODO _addSubItem + console.warn("L5R5E | TODO ItemSheetL5r5e._addSubItem()", itemId); // TODO _addSubItem Currently not used, title override it } /** * Add a embed item - * @param event + * @param {Event} event * @private */ _editSubItem(event) { @@ -249,7 +251,7 @@ export class ItemSheetL5r5e extends ItemSheet { /** * Delete a embed item - * @param event + * @param {Event} event * @private */ _deleteSubItem(event) { diff --git a/system/scripts/items/title-sheet.js b/system/scripts/items/title-sheet.js index 4b86fd8..cea38d7 100644 --- a/system/scripts/items/title-sheet.js +++ b/system/scripts/items/title-sheet.js @@ -81,7 +81,7 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e { /** * Subscribe to events from the sheet. - * @param html HTML content of the sheet. + * @param {jQuery} html HTML content of the sheet. */ activateListeners(html) { super.activateListeners(html); @@ -96,4 +96,30 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e { html.find(`.item-edit`).on("click", this._editSubItem.bind(this)); html.find(`.item-delete`).on("click", this._deleteSubItem.bind(this)); } + + /** + * Display a dialog to choose what Item to add, and add it on this Item + * @param {Event} event + * @return {Promise} + * @private + */ + async _addSubItem(event) { + // Show Dialog + const selectedType = await game.l5r5e.HelpersL5r5e.showSubItemDialog(["advancement", "technique"]); + + // Create the new Item + const itemId = await this.document.addEmbedItem( + new game.l5r5e.ItemL5r5e({ + name: game.i18n.localize(`ITEM.Type${selectedType.capitalize()}`), + type: selectedType, + img: `${CONFIG.l5r5e.paths.assets}icons/items/${selectedType}.svg`, + }) + ); + + // Get the store object and display it + const item = this.document.items.get(itemId); + if (item) { + item.sheet.render(true); + } + } } diff --git a/system/scripts/main-l5r5e.js b/system/scripts/main-l5r5e.js index 8b51e82..5eec5fe 100644 --- a/system/scripts/main-l5r5e.js +++ b/system/scripts/main-l5r5e.js @@ -19,7 +19,7 @@ import { RollL5r5e } from "./dice/roll.js"; import { DicePickerDialog } from "./dice/dice-picker-dialog.js"; import { RollnKeepDialog } from "./dice/roll-n-keep-dialog.js"; import { CombatL5r5e } from "./combat.js"; -import { GmToolsDialog } from "./dice/gm-tools-dialog.js"; +import { GmToolsDialog } from "./dialogs/gm-tools-dialog.js"; // Items import { ItemL5r5e } from "./item.js"; import { ItemSheetL5r5e } from "./items/item-sheet.js"; diff --git a/system/templates/actors/character/experience.html b/system/templates/actors/character/experience.html index 85f7b7e..1e6a548 100644 --- a/system/templates/actors/character/experience.html +++ b/system/templates/actors/character/experience.html @@ -63,7 +63,7 @@ {{!-- Others progession (does not count in school xp) --}}
- {{localize 'l5r5e.advancements.title'}} + {{localize 'l5r5e.advancements.title'}} diff --git a/system/templates/dialogs/choose-item-type-dialog.html b/system/templates/dialogs/choose-item-type-dialog.html new file mode 100644 index 0000000..4b26209 --- /dev/null +++ b/system/templates/dialogs/choose-item-type-dialog.html @@ -0,0 +1,10 @@ + +
+ +
+ +
+
+ diff --git a/system/templates/dice/gm-tools-dialog.html b/system/templates/dialogs/gm-tools-dialog.html similarity index 100% rename from system/templates/dice/gm-tools-dialog.html rename to system/templates/dialogs/gm-tools-dialog.html diff --git a/system/templates/items/armor/armors.html b/system/templates/items/armor/armors.html index ba29423..068611a 100644 --- a/system/templates/items/armor/armors.html +++ b/system/templates/items/armor/armors.html @@ -2,7 +2,7 @@ {{localize 'l5r5e.armors.title'}} {{#if options.editable}} - + {{/if}}
    diff --git a/system/templates/items/weapon/weapons.html b/system/templates/items/weapon/weapons.html index 1a1b63e..f352256 100644 --- a/system/templates/items/weapon/weapons.html +++ b/system/templates/items/weapon/weapons.html @@ -2,7 +2,7 @@ {{localize 'l5r5e.weapons.title'}} {{#if options.editable}} - + {{/if}}