Working on 0.8.x

- Finished the dialog for add new item on title and other advancements
- some documentation update
This commit is contained in:
Vlyan
2021-05-22 22:10:54 +02:00
parent 53f04e6cef
commit 90ccfd1d68
20 changed files with 167 additions and 51 deletions

View File

@@ -259,7 +259,7 @@ export class BaseSheetL5r5e extends ActorSheet {
/** /**
* Subscribe to events from the sheet. * Subscribe to events from the sheet.
* @param html HTML content of the sheet. * @param {jQuery} html HTML content of the sheet.
*/ */
activateListeners(html) { activateListeners(html) {
super.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-add").on("click", this._addSubItem.bind(this));
html.find(`.item-edit`).on("click", this._editSubItem.bind(this)); html.find(`.item-edit`).on("click", this._editSubItem.bind(this));
html.find(`.item-delete`).on("click", this._deleteSubItem.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 * 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<void>}
* @private * @private
*/ */
async _addSubItem(event) { async _createSubItem({ type, isEquipped = false, techniqueType = null }) {
event.preventDefault();
event.stopPropagation();
const type = $(event.currentTarget).data("item-type");
if (!type) { if (!type) {
return; 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", [ const created = await this.actor.createEmbeddedDocuments("Item", [
{ {
name: game.i18n.localize(titles[type]), name: game.i18n.localize(`ITEM.Type${type.capitalize()}`),
type: type, type: type,
img: `${CONFIG.l5r5e.paths.assets}icons/items/${type}.svg`, img: `${CONFIG.l5r5e.paths.assets}icons/items/${type}.svg`,
}, },
@@ -385,19 +371,17 @@ export class BaseSheetL5r5e extends ActorSheet {
} }
switch (item.data.type) { switch (item.data.type) {
case "item": // no break
case "armor": // no break case "armor": // no break
case "weapon": case "weapon":
if ($(event.currentTarget).data("item-eqquiped")) { item.data.data.equipped = isEquipped;
item.data.data.equipped = true;
}
break; break;
case "technique": { case "technique": {
// If technique, select the current type // If technique, select the current type
const techType = $(event.currentTarget).data("tech-type"); if (CONFIG.l5r5e.techniques.get(techniqueType)) {
if (CONFIG.l5r5e.techniques.get(techType)) { item.data.data.technique_type = techniqueType;
item.data.data.technique_type = techType; item.data.img = `${CONFIG.l5r5e.paths.assets}icons/techs/${techniqueType}.svg`;
item.data.img = `${CONFIG.l5r5e.paths.assets}icons/techs/${techType}.svg`;
} }
break; break;
} }
@@ -406,6 +390,40 @@ export class BaseSheetL5r5e extends ActorSheet {
item.sheet.render(true); item.sheet.render(true);
} }
/**
* Display a dialog to choose what Item to add
* @param {Event} event
* @return {Promise<void>}
* @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 * Edit a generic item with sub type
* @param {Event} event * @param {Event} event

View File

@@ -65,7 +65,7 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e {
/** /**
* Subscribe to events from the sheet. * Subscribe to events from the sheet.
* @param html HTML content of the sheet. * @param {jQuery} html HTML content of the sheet.
*/ */
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);

View File

@@ -154,6 +154,7 @@ export class TwentyQuestionsDialog extends FormApplication {
/** /**
* Listen to html elements * Listen to html elements
* @param {jQuery} html HTML content of the sheet.
* @override * @override
*/ */
activateListeners(html) { activateListeners(html) {

View File

@@ -23,7 +23,7 @@ L5R5E.techniques.set("ninjutsu", { type: "core", displayInTypes: true });
L5R5E.techniques.set("school_ability", { type: "school", displayInTypes: false }); L5R5E.techniques.set("school_ability", { type: "school", displayInTypes: false });
L5R5E.techniques.set("mastery_ability", { type: "school", displayInTypes: false }); L5R5E.techniques.set("mastery_ability", { type: "school", displayInTypes: false });
// Title // Title
L5R5E.techniques.set("title_ability", { type: "title", displayInTypes: false }); // L5R5E.techniques.set("title_ability", { type: "title", displayInTypes: false });
// Custom // Custom
L5R5E.techniques.set("specificity", { type: "custom", displayInTypes: false }); L5R5E.techniques.set("specificity", { type: "custom", displayInTypes: false });

View File

@@ -18,7 +18,7 @@ export class GmToolsDialog extends FormApplication {
return foundry.utils.mergeObject(super.defaultOptions, { return foundry.utils.mergeObject(super.defaultOptions, {
id: "l5r5e-gm-tools-dialog", id: "l5r5e-gm-tools-dialog",
classes: ["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"), title: game.i18n.localize("l5r5e.gm_toolbox.title"),
left: x - 512, left: x - 512,
top: y - 98, top: y - 98,
@@ -111,6 +111,7 @@ export class GmToolsDialog extends FormApplication {
/** /**
* Listen to html elements * Listen to html elements
* @param {jQuery} html HTML content of the sheet.
* @override * @override
*/ */
activateListeners(html) { activateListeners(html) {

View File

@@ -300,6 +300,7 @@ export class DicePickerDialog extends FormApplication {
/** /**
* Listen to html elements * Listen to html elements
* @param {jQuery} html HTML content of the sheet.
* @override * @override
*/ */
activateListeners(html) { activateListeners(html) {

View File

@@ -239,6 +239,7 @@ export class RollnKeepDialog extends FormApplication {
/** /**
* Listen to html elements * Listen to html elements
* @param {jQuery} html HTML content of the sheet.
* @override * @override
*/ */
activateListeners(html) { activateListeners(html) {

View File

@@ -39,6 +39,7 @@ export class HelpDialog extends FormApplication {
/** /**
* Listen to html elements * Listen to html elements
* @param {jQuery} html HTML content of the sheet.
* @override * @override
*/ */
activateListeners(html) { activateListeners(html) {

View File

@@ -6,6 +6,8 @@ import { ItemL5r5e } from "./item.js";
export class HelpersL5r5e { export class HelpersL5r5e {
/** /**
* Get Rings/Element for List / Select * Get Rings/Element for List / Select
* @param {Actor|null} actor
* @return {{id: string, label: *, value}[]}
*/ */
static getRingsList(actor = null) { static getRingsList(actor = null) {
return CONFIG.l5r5e.stances.map((e) => ({ return CONFIG.l5r5e.stances.map((e) => ({
@@ -17,6 +19,8 @@ export class HelpersL5r5e {
/** /**
* Get Skills for List / Select with groups * Get Skills for List / Select with groups
* @param {boolean} useGroup
* @return {{cat: any, id: any, label: *}[]}
*/ */
static getSkillsList(useGroup = false) { static getSkillsList(useGroup = false) {
if (!useGroup) { if (!useGroup) {
@@ -64,6 +68,8 @@ export class HelpersL5r5e {
/** /**
* Return the target object on a drag n drop event, or null if not found * Return the target object on a drag n drop event, or null if not found
* @param {DragEvent} event
* @return {Promise<null>}
*/ */
static async getDragnDropTargetObject(event) { static async getDragnDropTargetObject(event) {
const json = event.dataTransfer.getData("text/plain"); 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 * 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<null>}
*/ */
static async getObjectGameOrPack({ id, type, data = null, pack = null }) { static async getObjectGameOrPack({ id, type, data = null, pack = null }) {
let document = null; let document = null;
@@ -142,6 +153,8 @@ export class HelpersL5r5e {
/** /**
* Make a temporary item for compendium drag n drop * Make a temporary item for compendium drag n drop
* @param {ItemL5r5e|any[]} data
* @return {ItemL5r5e}
*/ */
static createItemFromCompendium(data) { static createItemFromCompendium(data) {
if ( if (
@@ -174,6 +187,8 @@ export class HelpersL5r5e {
/** /**
* Babele and properties specific * Babele and properties specific
* @param {Document} document
* @return {Promise<void>}
*/ */
static async refreshItemProperties(document) { static async refreshItemProperties(document) {
if (document.data.data.properties && typeof Babele !== "undefined") { if (document.data.data.properties && typeof Babele !== "undefined") {
@@ -191,6 +206,9 @@ export class HelpersL5r5e {
/** /**
* Convert (op), (ex)... to associated symbols for content/descriptions * 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) { static convertSymbols(text, toSymbol) {
CONFIG.l5r5e.symbols.forEach((cfg, tag) => { CONFIG.l5r5e.symbols.forEach((cfg, tag) => {
@@ -208,6 +226,8 @@ export class HelpersL5r5e {
/** /**
* Escape Regx characters * Escape Regx characters
* @param {string} str
* @return {string}
*/ */
static escapeRegExp(str) { static escapeRegExp(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -215,6 +235,8 @@ export class HelpersL5r5e {
/** /**
* Get the associated pack for a core item (time saving) * Get the associated pack for a core item (time saving)
* @param {string} documentId
* @return {string}
*/ */
static getPackNameForCoreItem(documentId) { static getPackNameForCoreItem(documentId) {
const core = new Map(); const core = new Map();
@@ -266,6 +288,38 @@ export class HelpersL5r5e {
}).render(true); }).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 * Notify Applications using Difficulty settings that the values was changed
*/ */

View File

@@ -131,14 +131,14 @@ export class ItemL5r5e extends Item {
* @param {boolean} save if we save in db or not (used internally) * @param {boolean} save if we save in db or not (used internally)
* @param {boolean} newId if we change the id * @param {boolean} newId if we change the id
* @param {boolean} addBonusToActor if we update the actor bonus for advancements * @param {boolean} addBonusToActor if we update the actor bonus for advancements
* @return {Promise<void>} * @return {Promise<string>}
*/ */
async addEmbedItem(item, { save = true, newId = true, addBonusToActor = true } = {}) { async addEmbedItem(item, { save = true, newId = true, addBonusToActor = true } = {}) {
if (!item) { if (!item) {
return; return;
} }
if (!(item instanceof Item) && item._id) { if (!(item instanceof Item) && item?.name && item?.type) {
// Data -> Item // Data -> Item
item = new ItemL5r5e(item); item = new ItemL5r5e(item);
} }
@@ -165,16 +165,17 @@ export class ItemL5r5e extends Item {
if (save) { if (save) {
await this.saveEmbedItems(); await this.saveEmbedItems();
} }
return item.data._id;
} }
/** /**
* Update a Embed Item * Update a Embed Item
* @param {ItemL5r5e} item Object to add * @param {ItemL5r5e} item Object to add
* @param {boolean} save if we save in db or not (used internally) * @param {boolean} save if we save in db or not (used internally)
* @return {Promise<void>} * @return {Promise<string>}
*/ */
async updateEmbedItem(item, { save = true } = {}) { async updateEmbedItem(item, { save = true } = {}) {
await this.addEmbedItem(item, { save, newId: false, addBonusToActor: false }); return await this.addEmbedItem(item, { save, newId: false, addBonusToActor: false });
} }
/** /**

View File

@@ -31,7 +31,7 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
/** /**
* Subscribe to events from the sheet. * Subscribe to events from the sheet.
* @param html HTML content of the sheet. * @param {jQuery} html HTML content of the sheet.
*/ */
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);

View File

@@ -50,7 +50,7 @@ export class ItemPatternSheetL5r5e extends ItemSheetL5r5e {
/** /**
* Subscribe to events from the sheet. * Subscribe to events from the sheet.
* @param html HTML content of the sheet. * @param {jQuery} html HTML content of the sheet.
*/ */
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);

View File

@@ -82,7 +82,8 @@ export class ItemSheetL5r5e extends ItemSheet {
/** /**
* Subscribe to events from the sheet. * Subscribe to events from the sheet.
* @param html HTML content of the sheet. * @param {jQuery} html HTML content of the sheet.
* @override
*/ */
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);
@@ -112,7 +113,7 @@ export class ItemSheetL5r5e extends ItemSheet {
/** /**
* Create drag-and-drop workflow handlers for this Application * Create drag-and-drop workflow handlers for this Application
* @return An array of DragDrop handlers * @return {DragDrop[]} An array of DragDrop handlers
*/ */
_createDragDropHandlers() { _createDragDropHandlers() {
return [ return [
@@ -160,6 +161,7 @@ export class ItemSheetL5r5e extends ItemSheet {
/** /**
* Add a property to the current item * Add a property to the current item
* @param {Item} item
* @private * @private
*/ */
_addProperty(item) { _addProperty(item) {
@@ -222,19 +224,19 @@ export class ItemSheetL5r5e extends ItemSheet {
/** /**
* Add a embed item * Add a embed item
* @param event * @param {Event} event
* @private * @private
*/ */
_addSubItem(event) { _addSubItem(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
const itemId = $(event.currentTarget).data("item-id"); 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 * Add a embed item
* @param event * @param {Event} event
* @private * @private
*/ */
_editSubItem(event) { _editSubItem(event) {
@@ -249,7 +251,7 @@ export class ItemSheetL5r5e extends ItemSheet {
/** /**
* Delete a embed item * Delete a embed item
* @param event * @param {Event} event
* @private * @private
*/ */
_deleteSubItem(event) { _deleteSubItem(event) {

View File

@@ -81,7 +81,7 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e {
/** /**
* Subscribe to events from the sheet. * Subscribe to events from the sheet.
* @param html HTML content of the sheet. * @param {jQuery} html HTML content of the sheet.
*/ */
activateListeners(html) { activateListeners(html) {
super.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-edit`).on("click", this._editSubItem.bind(this));
html.find(`.item-delete`).on("click", this._deleteSubItem.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<void>}
* @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);
}
}
} }

View File

@@ -19,7 +19,7 @@ import { RollL5r5e } from "./dice/roll.js";
import { DicePickerDialog } from "./dice/dice-picker-dialog.js"; import { DicePickerDialog } from "./dice/dice-picker-dialog.js";
import { RollnKeepDialog } from "./dice/roll-n-keep-dialog.js"; import { RollnKeepDialog } from "./dice/roll-n-keep-dialog.js";
import { CombatL5r5e } from "./combat.js"; import { CombatL5r5e } from "./combat.js";
import { GmToolsDialog } from "./dice/gm-tools-dialog.js"; import { GmToolsDialog } from "./dialogs/gm-tools-dialog.js";
// Items // Items
import { ItemL5r5e } from "./item.js"; import { ItemL5r5e } from "./item.js";
import { ItemSheetL5r5e } from "./items/item-sheet.js"; import { ItemSheetL5r5e } from "./items/item-sheet.js";

View File

@@ -63,7 +63,7 @@
</fieldset> </fieldset>
{{!-- Others progession (does not count in school xp) --}} {{!-- Others progession (does not count in school xp) --}}
<fieldset class="xp-spent xp-spent-body"> <fieldset class="xp-spent xp-spent-body">
<legend class="tools">{{localize 'l5r5e.advancements.title'}} <a data-item-type="advancement-others" class="advancement-others-control item-add" title="{{localize 'l5r5e.global.add'}}"><i class="fas fa-plus"></i></a></legend> <legend class="tools">{{localize 'l5r5e.advancements.title'}} <a class="advancement-others-control item-advancement-choose" title="{{localize 'l5r5e.global.add'}}"><i class="fas fa-plus"></i></a></legend>
<table> <table>
<thead class="flex"> <thead class="flex">
<tr class="flexrow row"> <tr class="flexrow row">

View File

@@ -0,0 +1,10 @@
<form id="choose-item-type-dialog" class="l5r5e choose-item-type-dialog" autocomplete="off">
<div class="form-group">
<label>{{localize "Type"}}</label>
<div class="form-fields">
<select name="type">
{{selectOptions types selected=type}}
</select>
</div>
</div>
</form>

View File

@@ -2,7 +2,7 @@
<legend class="section-header"> <legend class="section-header">
{{localize 'l5r5e.armors.title'}} {{localize 'l5r5e.armors.title'}}
{{#if options.editable}} {{#if options.editable}}
<a data-item-type="armor" data-item-eqquiped="true" class="armor-control item-add" title="{{localize 'l5r5e.global.add'}}"><i class="fas fa-plus"></i></a> <a data-item-type="armor" data-item-equipped="true" class="armor-control item-add" title="{{localize 'l5r5e.global.add'}}"><i class="fas fa-plus"></i></a>
{{/if}} {{/if}}
</legend> </legend>
<ul class="item-list"> <ul class="item-list">

View File

@@ -2,7 +2,7 @@
<legend class="section-header"> <legend class="section-header">
{{localize 'l5r5e.weapons.title'}} {{localize 'l5r5e.weapons.title'}}
{{#if options.editable}} {{#if options.editable}}
<a data-item-type="weapon" data-item-eqquiped="true" class="weapon-control item-add" title="{{localize 'l5r5e.global.add'}}"><i class="fas fa-plus"></i></a> <a data-item-type="weapon" data-item-equipped="true" class="weapon-control item-add" title="{{localize 'l5r5e.global.add'}}"><i class="fas fa-plus"></i></a>
{{/if}} {{/if}}
</legend> </legend>
<ul class="item-list"> <ul class="item-list">