Add a macro creator for dice roller

Some english fix
This commit is contained in:
Vlyan
2020-12-29 10:21:34 +01:00
parent 345b3200c0
commit e98bf67680
4 changed files with 75 additions and 15 deletions

View File

@@ -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"
},

View File

@@ -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",

View File

@@ -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",

View File

@@ -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);
}
}