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_title": "Difficulty",
"difficulty_hidden_label": "Hide TN", "difficulty_hidden_label": "Hide TN",
"use_void_point_label": "Spend a Void point", "use_void_point_label": "Spend a Void point",
"roll_label": "Roll" "roll_label": "Roll",
"bt_add_macro": "Add a macro"
}, },
"max": "Max", "max": "Max",
"current": "Current", "current": "Current",
@@ -122,7 +123,7 @@
"title": "Techniques", "title": "Techniques",
"title_new": "New Technique", "title_new": "New Technique",
"not_allowed": "Your character does not use this type of technique.", "not_allowed": "Your character does not use this type of technique.",
"type": "Type accessible", "type": "Allowed Techniques",
"kata": "Kata", "kata": "Kata",
"kiho": "Kihõ", "kiho": "Kihõ",
"invocation": "Invocation", "invocation": "Invocation",
@@ -172,13 +173,13 @@
"title": "Martial", "title": "Martial",
"fitness": "Fitness", "fitness": "Fitness",
"melee": "Martial Arts [Melee]", "melee": "Martial Arts [Melee]",
"ranged": "Martial Arts [Melee]", "ranged": "Martial Arts [Ranged]",
"unarmed": "Martial Arts [Unarmed]", "unarmed": "Martial Arts [Unarmed]",
"meditation": "Meditation", "meditation": "Meditation",
"tactics": "Tactics", "tactics": "Tactics",
"air": "Feint", "air": "Feint",
"earth": "Withstand", "earth": "Withstand",
"fire": "Overwelm", "fire": "Overwhelm",
"water": "Shift", "water": "Shift",
"void": "Sacrifice" "void": "Sacrifice"
}, },

View File

@@ -86,7 +86,8 @@
"difficulty_title": "Difficulty", "difficulty_title": "Difficulty",
"difficulty_hidden_label": "Hide TN", "difficulty_hidden_label": "Hide TN",
"use_void_point_label": "Spend a Void point", "use_void_point_label": "Spend a Void point",
"roll_label": "Roll" "roll_label": "Roll",
"bt_add_macro": "Add a macro"
}, },
"max": "Max", "max": "Max",
"current": "Actuales", "current": "Actuales",

View File

@@ -86,7 +86,8 @@
"difficulty_title": "Difficulté", "difficulty_title": "Difficulté",
"difficulty_hidden_label": "ND Caché", "difficulty_hidden_label": "ND Caché",
"use_void_point_label": "Dépenser un point de Vide", "use_void_point_label": "Dépenser un point de Vide",
"roll_label": "Lancer" "roll_label": "Lancer",
"bt_add_macro": "Ajouter une macro"
}, },
"max": "Max", "max": "Max",
"current": "Actuel", "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 * Create dialog
* *
@@ -402,13 +421,51 @@ export class DicePickerDialog extends FormApplication {
return value; return value;
} }
// /** /**
// * Return a reference to the target attribute * Create a macro on the first empty space in player's bar
// * @type {String} * @private
// */ */
// get attribute() { async _createMacro() {
// console.log('L5R.DicePickerDialog.attribute', this); // TODO tmp const params = {};
// let name = "DicePicker";
// return this.options.name;
// } 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);
}
} }