From e98bf676809d6037a3726eb4b5d92a4383497045 Mon Sep 17 00:00:00 2001 From: Vlyan Date: Tue, 29 Dec 2020 10:21:34 +0100 Subject: [PATCH] Add a macro creator for dice roller Some english fix --- system/lang/en-en.json | 9 +-- system/lang/es-es.json | 3 +- system/lang/fr-fr.json | 3 +- system/scripts/dice/dice-picker-dialog.js | 75 ++++++++++++++++++++--- 4 files changed, 75 insertions(+), 15 deletions(-) diff --git a/system/lang/en-en.json b/system/lang/en-en.json index a5a345a..7ae0c09 100644 --- a/system/lang/en-en.json +++ b/system/lang/en-en.json @@ -86,7 +86,8 @@ "difficulty_title": "Difficulty", "difficulty_hidden_label": "Hide TN", "use_void_point_label": "Spend a Void point", - "roll_label": "Roll" + "roll_label": "Roll", + "bt_add_macro": "Add a macro" }, "max": "Max", "current": "Current", @@ -122,7 +123,7 @@ "title": "Techniques", "title_new": "New Technique", "not_allowed": "Your character does not use this type of technique.", - "type": "Type accessible", + "type": "Allowed Techniques", "kata": "Kata", "kiho": "Kihõ", "invocation": "Invocation", @@ -172,13 +173,13 @@ "title": "Martial", "fitness": "Fitness", "melee": "Martial Arts [Melee]", - "ranged": "Martial Arts [Melee]", + "ranged": "Martial Arts [Ranged]", "unarmed": "Martial Arts [Unarmed]", "meditation": "Meditation", "tactics": "Tactics", "air": "Feint", "earth": "Withstand", - "fire": "Overwelm", + "fire": "Overwhelm", "water": "Shift", "void": "Sacrifice" }, diff --git a/system/lang/es-es.json b/system/lang/es-es.json index 4773398..29fa169 100644 --- a/system/lang/es-es.json +++ b/system/lang/es-es.json @@ -86,7 +86,8 @@ "difficulty_title": "Difficulty", "difficulty_hidden_label": "Hide TN", "use_void_point_label": "Spend a Void point", - "roll_label": "Roll" + "roll_label": "Roll", + "bt_add_macro": "Add a macro" }, "max": "Max", "current": "Actuales", diff --git a/system/lang/fr-fr.json b/system/lang/fr-fr.json index 44eac89..a0f00e5 100644 --- a/system/lang/fr-fr.json +++ b/system/lang/fr-fr.json @@ -86,7 +86,8 @@ "difficulty_title": "Difficulté", "difficulty_hidden_label": "ND Caché", "use_void_point_label": "Dépenser un point de Vide", - "roll_label": "Lancer" + "roll_label": "Lancer", + "bt_add_macro": "Ajouter une macro" }, "max": "Max", "current": "Actuel", diff --git a/system/scripts/dice/dice-picker-dialog.js b/system/scripts/dice/dice-picker-dialog.js index ba702f1..75184f5 100644 --- a/system/scripts/dice/dice-picker-dialog.js +++ b/system/scripts/dice/dice-picker-dialog.js @@ -54,6 +54,25 @@ export class DicePickerDialog extends FormApplication { }); } + /** + * Add a create macro button on top of sheet + * @override + */ + _getHeaderButtons() { + let buttons = super._getHeaderButtons(); + + buttons.unshift({ + label: game.i18n.localize("l5r5e.dicepicker.bt_add_macro"), + class: "bt-add-macro", + icon: "fas fa-star", + onclick: async () => { + await this._createMacro(); + }, + }); + + return buttons; + } + /** * Create dialog * @@ -402,13 +421,51 @@ export class DicePickerDialog extends FormApplication { return value; } - // /** - // * Return a reference to the target attribute - // * @type {String} - // */ - // get attribute() { - // console.log('L5R.DicePickerDialog.attribute', this); // TODO tmp - // - // return this.options.name; - // } + /** + * Create a macro on the first empty space in player's bar + * @private + */ + async _createMacro() { + const params = {}; + let name = "DicePicker"; + + if (this._actor?._id) { + params.actorId = this._actor._id; + name = this._actor.name; + } + + if (this._skillData.id) { + params.skillId = this._skillData.id; + } else if (this._skillData.cat) { + params.skillCatId = this._skillData.cat; + } + if (this._skillData.name) { + name = name + " - " + this._skillData.name; + } + + let command = `new game.l5r5e.DicePickerDialog(${JSON.stringify(params)}).render(true);`; + + let macro = game.macros.entities.find((m) => m.data.name === name && m.data.command === command); + if (!macro) { + macro = await Macro.create({ + name: name, + type: "script", + scope: "global", + command: command, + img: this._actor?.img ? this._actor.img : "systems/l5r5e/assets/dices/default/ring_et.svg", + }); + } + + // Search for slot (Fix for FVTT) + // slot = false will normally do the 1st available, but always return 0 + const slot = Array.fromRange(50).find((i) => { + if (i < 1) { + return false; + } + return !(i in game.user.data.hotbar); + }); + + // return game.user.assignHotbarMacro(macro, false); // 1st available + return game.user.assignHotbarMacro(macro, slot); + } }