Dice dialog v1 and Minus all key in template and long files
This commit is contained in:
@@ -6,7 +6,7 @@ import { RollL5r5e } from "./roll.js";
|
||||
|
||||
export class DicePickerDialog extends Application {
|
||||
/**
|
||||
* Current actor
|
||||
* Current Actor
|
||||
*/
|
||||
actor = {};
|
||||
|
||||
@@ -29,9 +29,11 @@ export class DicePickerDialog extends Application {
|
||||
id: "l5r5e-dice-picker-dialog",
|
||||
classes: ["l5r5e", "dice-picker-dialog"],
|
||||
template: "systems/l5r5e/templates/dice/dice-picker-dialog.html",
|
||||
width: 360,
|
||||
width: 400,
|
||||
// height: 400,
|
||||
// title: "L5R Dice Roller",
|
||||
actor: null,
|
||||
skillId: "",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,10 +45,15 @@ export class DicePickerDialog extends Application {
|
||||
super(options);
|
||||
|
||||
// Get Actor from: sheet, selected token, nothing
|
||||
this.actor = options?.actor || canvas.tokens.controlled[0]?.actor.data || null;
|
||||
const actor = options?.actor || canvas.tokens.controlled[0]?.actor || null;
|
||||
if (actor instanceof Actor) {
|
||||
this.actor = actor;
|
||||
}
|
||||
|
||||
console.log(this.actor); // TODO TMP
|
||||
|
||||
// Skill ?
|
||||
if (!!this.actor && !!options?.skillId) {
|
||||
if (options?.skillId) {
|
||||
this.setSkillData(options.skillId);
|
||||
}
|
||||
}
|
||||
@@ -56,7 +63,7 @@ export class DicePickerDialog extends Application {
|
||||
* @type {String}
|
||||
*/
|
||||
get title() {
|
||||
return `L5R Dice Roller` + (this.actor ? " - " + this.actor.name : "");
|
||||
return `L5R Dice Roller` + (this.actor ? " - " + this.actor.data.name : "");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,12 +123,22 @@ export class DicePickerDialog extends Application {
|
||||
return false;
|
||||
}
|
||||
|
||||
await new RollL5r5e(
|
||||
`${ring}dr[${approach}] + ${skill}ds` + (this.skillData.id ? `[${this.skillData.id}]` : "")
|
||||
)
|
||||
.roll()
|
||||
.toMessage();
|
||||
let formula = [];
|
||||
if (ring > 0) {
|
||||
formula.push(`${ring}dr`);
|
||||
}
|
||||
if (skill > 0) {
|
||||
formula.push(`${skill}ds`);
|
||||
}
|
||||
|
||||
const roll = await new RollL5r5e(formula.join("+"));
|
||||
|
||||
roll.l5r5e.stance = approach;
|
||||
roll.l5r5e.skillId = this.skillData.id;
|
||||
roll.l5r5e.actor = this.actor;
|
||||
|
||||
await roll.roll();
|
||||
await roll.toMessage();
|
||||
await this.close();
|
||||
});
|
||||
|
||||
@@ -138,22 +155,23 @@ export class DicePickerDialog extends Application {
|
||||
return;
|
||||
}
|
||||
|
||||
const skillData = {
|
||||
id: skillId.trim(),
|
||||
this.skillData = {
|
||||
id: skillId.toLowerCase().trim(),
|
||||
value: 0,
|
||||
cat: "",
|
||||
name: "",
|
||||
};
|
||||
|
||||
if (!this.actor) {
|
||||
const cat = RollL5r5e.getCategoryForSkillId(skillId);
|
||||
if (!this.actor || !cat) {
|
||||
return;
|
||||
}
|
||||
|
||||
skillData.cat = Object.keys(this.actor.data.skills).find((e) => !!this.actor.data.skills[e][skillData.id]);
|
||||
skillData.value = this.actor.data.skills[skillData.cat][skillData.id].value ?? 0;
|
||||
skillData.name = game.i18n.localize("L5r5e.Skills." + skillData.cat + "." + skillData.id);
|
||||
this.skillData.cat = cat;
|
||||
this.skillData.value = this.actor.data.data.skills[cat]?.[this.skillData.id].value || 0;
|
||||
this.skillData.name = game.i18n.localize("l5r5e.skills." + cat + "." + this.skillData.id);
|
||||
|
||||
return skillData;
|
||||
console.log("****** skillData", this.skillData, this.actor.data.data.skills);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,8 +182,8 @@ export class DicePickerDialog extends Application {
|
||||
return ["air", "earth", "fire", "water", "void"].map((e) => {
|
||||
return {
|
||||
id: e,
|
||||
label: game.i18n.localize(`L5r5e.Rings.${e.capitalize()}`),
|
||||
value: this.actor ? this.actor.data.rings[e] : 0,
|
||||
label: game.i18n.localize(`l5r5e.rings.${e}`),
|
||||
value: this.actor ? this.actor.data.data.rings[e] : 0,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -194,6 +194,11 @@ export class RollL5r5e extends Roll {
|
||||
this.roll();
|
||||
}
|
||||
|
||||
const skillName =
|
||||
game.i18n.translations.l5r5e.skills?.[RollL5r5e.getCategoryForSkillId(this.l5r5e.skillId)]?.[
|
||||
this.l5r5e.skillId
|
||||
] || "";
|
||||
|
||||
// Define chat data
|
||||
const chatData = {
|
||||
formula: isPrivate ? "???" : this._formula,
|
||||
@@ -207,7 +212,7 @@ export class RollL5r5e extends Roll {
|
||||
? {}
|
||||
: {
|
||||
stance: this.l5r5e.stance,
|
||||
skillId: this.l5r5e.skillId,
|
||||
skillName: skillName,
|
||||
dicesTypes: this.l5r5e.dicesTypes,
|
||||
summary: this.l5r5e.summary,
|
||||
dices: this.dice.map((d) => {
|
||||
@@ -266,6 +271,17 @@ export class RollL5r5e extends Roll {
|
||||
return create ? CONFIG.ChatMessage.entityClass.create(messageData, messageOptions) : messageData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the categoryId for the skillId
|
||||
* TODO in proper category helper ?
|
||||
* @param skillId
|
||||
*/
|
||||
static getCategoryForSkillId(skillId) {
|
||||
return Object.keys(game.i18n.translations.l5r5e.skills).find((e) => {
|
||||
return !!game.i18n.translations.l5r5e.skills?.[e]?.[skillId];
|
||||
});
|
||||
}
|
||||
|
||||
/** @override */
|
||||
static fromData(data) {
|
||||
const roll = super.fromData(data);
|
||||
|
||||
@@ -66,33 +66,27 @@ Hooks.once("init", async function () {
|
||||
});
|
||||
|
||||
Handlebars.registerHelper("localizeSkillCategory", function (skillName) {
|
||||
const key = "L5r5e.Skills." + skillName.charAt(0).toUpperCase() + skillName.slice(1) + ".Title";
|
||||
const key = "l5r5e.skills." + skillName.toLowerCase() + ".title";
|
||||
return game.i18n.localize(key);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper("localizeSkill", function (skillCategory, skillName) {
|
||||
const key =
|
||||
"L5r5e.Skills." +
|
||||
skillCategory.charAt(0).toUpperCase() +
|
||||
skillCategory.slice(1) +
|
||||
"." +
|
||||
skillName.charAt(0).toUpperCase() +
|
||||
skillName.slice(1);
|
||||
const key = "l5r5e.skills." + skillCategory.toLowerCase() + "." + skillName.toLowerCase();
|
||||
return game.i18n.localize(key);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper("localizeRing", function (ringName) {
|
||||
const key = "L5r5e.Rings." + ringName.charAt(0).toUpperCase() + ringName.slice(1);
|
||||
const key = "l5r5e.rings." + ringName.toLowerCase();
|
||||
return game.i18n.localize(key);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper("localizeRingTip", function (ringName) {
|
||||
const key = "L5r5e.Rings." + ringName.charAt(0).toUpperCase() + ringName.slice(1) + "Tip";
|
||||
const key = "l5r5e.rings." + ringName.toLowerCase() + "tip";
|
||||
return game.i18n.localize(key);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper("localizeStanceTip", function (ringName) {
|
||||
const key = "L5r5e.Conflict.Stances." + ringName.charAt(0).toUpperCase() + ringName.slice(1) + "Tip";
|
||||
const key = "l5r5e.conflict.stances." + ringName.toLowerCase() + "tip";
|
||||
return game.i18n.localize(key);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -133,6 +133,6 @@ export class ActorSheetL5r5e extends ActorSheet {
|
||||
async _onSkillClicked(skillId) {
|
||||
console.log("Clicked on skill " + skillId);
|
||||
|
||||
// TODO
|
||||
new game.l5r5e.DicePickerDialog({ skillId: skillId, actor: this.actor }).render();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user