Added a icon for "void point used" in chat log

Better workflow for DicePicker
This commit is contained in:
Vlyan
2021-01-04 13:54:49 +01:00
parent 404509a998
commit ca9dbc1f24
8 changed files with 131 additions and 154 deletions

View File

@@ -88,7 +88,8 @@
"strives": "Strives", "strives": "Strives",
"difficulty": "TN", "difficulty": "TN",
"difficulty_hidden": "TN ???", "difficulty_hidden": "TN ???",
"dicepicker": "Dice Picker" "dicepicker": "Dice Picker",
"void_point_used": "Void point used"
}, },
"dicepicker": { "dicepicker": {
"difficulty_title": "Difficulty", "difficulty_title": "Difficulty",

View File

@@ -88,7 +88,8 @@
"strives": "Strives", "strives": "Strives",
"difficulty": "TN", "difficulty": "TN",
"difficulty_hidden": "TN ???", "difficulty_hidden": "TN ???",
"dicepicker": "Dice Picker" "dicepicker": "Dice Picker",
"void_point_used": "Void point used"
}, },
"dicepicker": { "dicepicker": {
"difficulty_title": "Difficulty", "difficulty_title": "Difficulty",

View File

@@ -88,7 +88,8 @@
"strives": "Conflits", "strives": "Conflits",
"difficulty": "ND", "difficulty": "ND",
"difficulty_hidden": "ND ???", "difficulty_hidden": "ND ???",
"dicepicker": "Dice Picker" "dicepicker": "Dice Picker",
"void_point_used": "Point de vide utilisé"
}, },
"dicepicker": { "dicepicker": {
"difficulty_title": "Difficulté", "difficulty_title": "Difficulté",

View File

@@ -160,6 +160,7 @@ export class TwentyQuestionsDialog extends FormApplication {
// Heritage Roll (step 18) // Heritage Roll (step 18)
html.find(".inline-roll").on("click", (event) => { html.find(".inline-roll").on("click", (event) => {
event.preventDefault();
event.stopPropagation(); event.stopPropagation();
const diceRoll = $(event.currentTarget); const diceRoll = $(event.currentTarget);
const stepKey = diceRoll.data("step"); const stepKey = diceRoll.data("step");

View File

@@ -11,26 +11,25 @@ export class DicePickerDialog extends FormApplication {
_actor = null; _actor = null;
/** /**
* Preset ring (attribute / approach) * Payload Object
*/ */
_ringId = null; object = {
ring: {
/** id: null,
* Preset Skill (and data from actor if actor provided) value: 1,
*/ },
_skillData = { skill: {
id: "", id: "",
value: 0, value: 0,
cat: "", default_value: 0,
name: "", cat: "",
}; name: "",
},
/** difficulty: {
* Difficulty value: 2,
*/ hidden: false,
_difficulty = { },
difficulty: 2, useVoidPoint: false,
isHidden: false,
}; };
/** /**
@@ -133,7 +132,13 @@ export class DicePickerDialog extends FormApplication {
* @param actor * @param actor
*/ */
set actor(actor) { set actor(actor) {
this._actor = actor instanceof Actor && actor.owner ? actor : null; if (!actor || !(actor instanceof Actor) || !actor.owner) {
return;
}
this._actor = actor;
if (this.object.ring.id === null) {
this.ringId = this._actor.data.data.stance;
}
} }
/** /**
@@ -141,7 +146,7 @@ export class DicePickerDialog extends FormApplication {
* @param ringId * @param ringId
*/ */
set ringId(ringId) { set ringId(ringId) {
this._ringId = CONFIG.l5r5e.stances.includes(ringId) || null; this.object.ring.id = CONFIG.l5r5e.stances.includes(ringId) ? ringId : "void";
} }
/** /**
@@ -153,7 +158,7 @@ export class DicePickerDialog extends FormApplication {
return; return;
} }
this._skillData = { this.object.skill = {
id: skillId.toLowerCase().trim(), id: skillId.toLowerCase().trim(),
value: 0, value: 0,
cat: "", cat: "",
@@ -172,11 +177,11 @@ export class DicePickerDialog extends FormApplication {
return; return;
} }
this._skillData = { this.object.skill = {
...this._skillData, ...this.object.skill,
value: 0, value: 0,
cat: skillCatId.toLowerCase().trim(), cat: skillCatId.toLowerCase().trim(),
name: game.i18n.localize("l5r5e.skills." + skillCatId + "." + (this._skillData.id || "title")), name: game.i18n.localize("l5r5e.skills." + skillCatId + "." + (this.object.skill.id || "title")),
}; };
if (!this._actor) { if (!this._actor) {
@@ -184,12 +189,14 @@ export class DicePickerDialog extends FormApplication {
} }
switch (this._actor.data.type) { switch (this._actor.data.type) {
case "character": case "character":
this._skillData.value = this._actor.data.data.skills[skillCatId]?.[this._skillData.id] || 0; this.object.skill.value = this._actor.data.data.skills[skillCatId]?.[this.object.skill.id] || 0;
this.object.skill.default_value = this.object.skill.value;
break; break;
case "npc": case "npc":
// Skill value is in categories for npc // Skill value is in categories for npc
this._skillData.value = this._actor.data.data.skills[skillCatId] || 0; this.object.skill.value = this._actor.data.data.skills[skillCatId] || 0;
this.object.skill.default_value = this.object.skill.value;
break; break;
} }
} }
@@ -201,9 +208,9 @@ export class DicePickerDialog extends FormApplication {
set difficulty(difficulty) { set difficulty(difficulty) {
difficulty = parseInt(difficulty) || null; difficulty = parseInt(difficulty) || null;
if (difficulty < 0) { if (difficulty < 0) {
difficulty = null; difficulty = 2;
} }
this._difficulty.difficulty = difficulty; this.object.difficulty.value = difficulty;
} }
/** /**
@@ -211,7 +218,7 @@ export class DicePickerDialog extends FormApplication {
* @param isHidden * @param isHidden
*/ */
set difficultyHidden(isHidden) { set difficultyHidden(isHidden) {
this._difficulty.isHidden = !!isHidden; this.object.difficulty.hidden = !!isHidden;
} }
/** /**
@@ -231,12 +238,11 @@ export class DicePickerDialog extends FormApplication {
return { return {
...super.getData(options), ...super.getData(options),
ringsList: game.l5r5e.HelpersL5r5e.getRingsList(this._actor), ringsList: game.l5r5e.HelpersL5r5e.getRingsList(this._actor),
dicesList: [0, 1, 2, 3, 4, 5, 6], data: this.object,
skillData: this._skillData,
actor: this._actor, actor: this._actor,
actorIsPc: !this._actor || this._actor.data?.type === "character", actorIsPc: !this._actor || this._actor.data?.type === "character",
difficulty: this._difficulty, canUseVoidPoint:
canUseVoidPoint: !this._actor || this._actor.data.data.void_points.value > 0, this.object.difficulty.hidden || !this._actor || this._actor.data.data.void_points.value > 0,
}; };
} }
@@ -265,88 +271,55 @@ export class DicePickerDialog extends FormApplication {
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);
// On change approaches // Select Ring
html.find('input[name="approach"]').on("click", async (event) => { html.find('input[name="approach"]').on("click", async (event) => {
$("#ring_value").val(event.target.value); this.object.ring.id = event.target.dataset.ringid;
$(".ring-selection").removeClass("ring-selected"); this.object.ring.value = event.target.value;
$("." + event.target.dataset.ringid).addClass("ring-selected"); this.render(false);
$("#stance_label").html(
game.i18n.localize("l5r5e.skills." + this._skillData.cat + "." + event.target.dataset.ringid)
);
}); });
// ****************** DIFF ****************** // Quantity change for difficulty, ring and skill
// Difficulty - Add button html.find(".quantity").on("click", async (event) => {
html.find("#diff_add").on("click", async (event) => {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
this._difficulty.difficulty = this._quantityChange("#diff_value", 1); const data = $(event.currentTarget);
this._quantityChange(data.data("item"), data.data("value"));
this.render(false);
}); });
// Difficulty - Subtract button // Click on the Default Skill Dice
html.find("#diff_sub").on("click", async (event) => {
event.preventDefault();
event.stopPropagation();
this._difficulty.difficulty = this._quantityChange("#diff_value", -1);
});
// Difficulty - hidden checkbox
html.find("#diff_hidden").on("click", async (event) => {
this._difficulty.isHidden = !this._difficulty.isHidden;
$("#difficulty_picker").toggle();
});
// ****************** RING ******************
// Ring - Add button
html.find("#ring_add").on("click", async (event) => {
event.preventDefault();
event.stopPropagation();
this._quantityChange("#ring_value", 1);
});
// Ring - Subtract button
html.find("#ring_sub").on("click", async (event) => {
event.preventDefault();
event.stopPropagation();
this._quantityChange("#ring_value", -1);
});
// Ring - Spend a Void point checkbox
html.find("#use_void_point").on("click", async (event) => {
this._quantityChange("#ring_value", event.target.checked ? 1 : -1);
html.find("#use_void_point").attr("checked", event.target.checked);
});
// ****************** SKILL ******************
// Skill - Add button
html.find("#skill_add").on("click", async (event) => {
event.preventDefault();
event.stopPropagation();
this._quantityChange("#skill_value", 1);
});
// Skill - Subtract button
html.find("#skill_sub").on("click", async (event) => {
event.preventDefault();
event.stopPropagation();
this._quantityChange("#skill_value", -1);
});
// Skill - Default Dice div
html.find("#skill_default_value").on("click", async (event) => { html.find("#skill_default_value").on("click", async (event) => {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
$("#skill_value").val(this._skillData.value); this.object.skill.value = this.object.skill.default_value;
this.render(false);
}); });
// ****************** INIT ****************** // Spend a Void point checkbox
// Select current actor's stance html.find("#use_void_point").on("click", async (event) => {
html.find(`.approach_${this._actor ? this._actor.data.data.stance : "void"}`) event.preventDefault();
.first() event.stopPropagation();
.trigger("click"); this.object.useVoidPoint = event.target.checked;
this._quantityChange("ring", this.object.useVoidPoint ? 1 : -1);
this.render(false);
});
// Set skill point // Difficulty Hidden
html.find("#skill_value").val(this._skillData.value); html.find("#diff_hidden").on("click", async (event) => {
event.preventDefault();
event.stopPropagation();
this.object.difficulty.hidden = !this.object.difficulty.hidden;
if (
this.object.useVoidPoint &&
!this.object.difficulty.hidden &&
!!this._actor &&
this._actor.data.data.void_points.value < 1
) {
this.object.useVoidPoint = false;
this._quantityChange("ring", -1);
}
this.render(false);
});
} }
/** /**
@@ -357,20 +330,16 @@ export class DicePickerDialog extends FormApplication {
* @override * @override
*/ */
async _updateObject(event, formData) { async _updateObject(event, formData) {
const approach = $(".ring-selection.ring-selected > input").data("ringid") || null; if (this.object.skill.value < 1 && this.object.ring.value < 1) {
const ring = formData.ring || null;
const skill = formData.skill || null;
if (!approach || !skill || !ring || (skill < 1 && ring < 1)) {
return false; return false;
} }
let formula = []; let formula = [];
if (ring > 0) { if (this.object.ring.value > 0) {
formula.push(`${ring}dr`); formula.push(`${this.object.ring.value}dr`);
} }
if (skill > 0) { if (this.object.skill.value > 0) {
formula.push(`${skill}ds`); formula.push(`${this.object.skill.value}ds`);
} }
// Update Actor // Update Actor
@@ -381,12 +350,12 @@ export class DicePickerDialog extends FormApplication {
// actorData.stance = approach; // actorData.stance = approach;
// If hidden add 1 void pt // If hidden add 1 void pt
if (this._difficulty.isHidden) { if (this.object.difficulty.hidden) {
actorData.void_points.value = Math.min(actorData.void_points.value + 1, actorData.void_points.max); actorData.void_points.value = Math.min(actorData.void_points.value + 1, actorData.void_points.max);
} }
// If Void point is used, minus the actor // If Void point is used, minus the actor
if (formData.use_void_point) { if (this.object.useVoidPoint) {
actorData.void_points.value = Math.max(actorData.void_points.value - 1, 0); actorData.void_points.value = Math.max(actorData.void_points.value - 1, 0);
} }
@@ -400,11 +369,12 @@ export class DicePickerDialog extends FormApplication {
const roll = await new RollL5r5e(formula.join("+")); const roll = await new RollL5r5e(formula.join("+"));
roll.actor = this._actor; roll.actor = this._actor;
roll.l5r5e.stance = approach; roll.l5r5e.stance = this.object.ring.id;
roll.l5r5e.skillId = this._skillData.id; roll.l5r5e.skillId = this.object.skill.id;
roll.l5r5e.skillCatId = this._skillData.cat; roll.l5r5e.skillCatId = this.object.skill.cat;
roll.l5r5e.summary.difficulty = this._difficulty.difficulty; roll.l5r5e.summary.difficulty = this.object.difficulty.value;
roll.l5r5e.summary.difficultyHidden = this._difficulty.isHidden; roll.l5r5e.summary.difficultyHidden = this.object.difficulty.hidden;
roll.l5r5e.summary.voidPointUsed = this.object.useVoidPoint;
await roll.roll(); await roll.roll();
await roll.toMessage(); await roll.toMessage();
@@ -415,11 +385,8 @@ export class DicePickerDialog extends FormApplication {
* Change quantity between 0-9 on the element, and return the new value * Change quantity between 0-9 on the element, and return the new value
* @private * @private
*/ */
_quantityChange(elmtSelector, add) { _quantityChange(element, add) {
const elmt = $(elmtSelector); this.object[element].value = Math.max(Math.min(parseInt(this.object[element].value) + add, 9), 0);
const value = Math.max(Math.min(parseInt(elmt.val()) + add, 9), 0);
elmt.val(value);
return value;
} }
/** /**
@@ -435,13 +402,13 @@ export class DicePickerDialog extends FormApplication {
name = this._actor.name; name = this._actor.name;
} }
if (this._skillData.id) { if (this.object.skill.id) {
params.skillId = this._skillData.id; params.skillId = this.object.skill.id;
} else if (this._skillData.cat) { } else if (this.object.skill.cat) {
params.skillCatId = this._skillData.cat; params.skillCatId = this.object.skill.cat;
} }
if (this._skillData.name) { if (this.object.skill.name) {
name = name + " - " + this._skillData.name; name = name + " - " + this.object.skill.name;
} }
let command = `new game.l5r5e.DicePickerDialog(${JSON.stringify(params)}).render(true);`; let command = `new game.l5r5e.DicePickerDialog(${JSON.stringify(params)}).render(true);`;

View File

@@ -26,6 +26,7 @@ export class RollL5r5e extends Roll {
explosive: 0, explosive: 0,
opportunity: 0, opportunity: 0,
strife: 0, strife: 0,
voidPointUsed: false,
}, },
}; };

View File

@@ -32,6 +32,9 @@
{{else}} {{else}}
{{localize 'l5r5e.chatdices.difficulty'}} {{l5r5e.summary.difficulty}} {{localize 'l5r5e.chatdices.difficulty'}} {{l5r5e.summary.difficulty}}
{{/if}} {{/if}}
{{#if l5r5e.summary.voidPointUsed}}
<br><i class="i_void" title="{{localize 'l5r5e.chatdices.void_point_used'}}"></i>
{{/if}}
</span> </span>
</header> </header>
</div> </div>

View File

@@ -1,6 +1,6 @@
<form class="l5r5e dice-picker-dialog" autocomplete="off"> <form class="l5r5e dice-picker-dialog" autocomplete="off">
<table> <table>
<!-- First line--> {{!-- First line--}}
<tr> <tr>
<td class="profil center"> <td class="profil center">
<img class="profile-img" <img class="profile-img"
@@ -15,7 +15,7 @@
<ul class="rings"> <ul class="rings">
{{#each ringsList}} {{#each ringsList}}
<li id="{{this.id}}"> <li id="{{this.id}}">
<label class="attribute-label {{this.id}} centered-input ring-selection pointer-choice"> <label class="attribute-label {{this.id}} centered-input ring-selection pointer-choice {{#ifCond ../data.ring.id '==' this.id}}ring-selected{{/ifCond}}">
<i class="i_{{this.id}}"></i> <i class="i_{{this.id}}"></i>
<strong>{{this.label}}</strong> <strong>{{this.label}}</strong>
<input class="centered-input approach_{{this.id}}" <input class="centered-input approach_{{this.id}}"
@@ -31,24 +31,24 @@
</ul> </ul>
</td> </td>
<td class="skill"> <td class="skill">
{{#if skillData.name}} {{#if data.skill.name}}
<div> <div>
<label>{{localizeSkill skillData.cat 'title'}}</label> <label>{{localizeSkill data.skill.cat 'title'}}</label>
</div> </div>
{{#if actorIsPc}} {{#if actorIsPc}}
<div> <div>
<label>{{skillData.name}}</label> <label>{{data.skill.name}}</label>
</div> </div>
{{/if}} {{/if}}
<div> <div>
<label id="stance_label">unknown</label> <label id="stance_label">{{localizeSkill data.skill.cat data.ring.id}}</label>
</div> </div>
<div id="skill_default_value" class="dice-container pointer-choice"> <div id="skill_default_value" class="dice-container pointer-choice">
<img src="systems/l5r5e/assets/dices/default/skill_blank.svg" alt="1"> <img src="systems/l5r5e/assets/dices/default/skill_blank.svg" alt="1">
<div class="dice-value"> <div class="dice-value">
<span class="dice-skill" type="text" name="skill_{{skillData.name}}">{{skillData.value}}</span> <span class="dice-skill" type="text" name="skill_{{data.skill.name}}">{{data.skill.default_value}}</span>
</div> </div>
</div> </div>
{{else}} {{else}}
@@ -63,7 +63,7 @@
</td> </td>
</tr> </tr>
<!-- Second line--> {{!-- Second line--}}
<tr> <tr>
<td> <td>
{{localize "l5r5e.dicepicker.difficulty_title"}} {{localize "l5r5e.dicepicker.difficulty_title"}}
@@ -76,80 +76,82 @@
</td> </td>
</tr> </tr>
<!-- Third line--> {{!-- Third line--}}
<tr> <tr>
<td> <td>
{{^if data.difficulty.hidden}}
<div id="difficulty_picker"> <div id="difficulty_picker">
<div class="third"> <div class="third">
<i id="diff_sub" class="quantity pointer-choice fa fa-minus-square"></i> <i class="quantity pointer-choice fa fa-minus-square" data-item="difficulty" data-value="-1"></i>
</div> </div>
<div class="third"> <div class="third">
<div class="dice-container"> <div class="dice-container">
<img src="systems/l5r5e/assets/dices/default/3d/blank.png" alt="1"> <img src="systems/l5r5e/assets/dices/default/3d/blank.png" alt="1">
<div class="dice-value"> <div class="dice-value">
<input id="diff_value" class="input-dice" type="text" name="diff" value="{{difficulty.difficulty}}" readonly="readonly"> <input class="input-dice" type="text" name="difficulty.value" value="{{data.difficulty.value}}" readonly="readonly">
</div> </div>
</div> </div>
</div> </div>
<div class="third"> <div class="third">
<i id="diff_add" class="quantity pointer-choice fa fa-plus-square"></i> <i class="quantity pointer-choice fa fa-plus-square" data-item="difficulty" data-value="1"></i>
</div> </div>
</div> </div>
{{/if}}
</td> </td>
<td> <td>
<div class="third"> <div class="third">
<i id="ring_sub" class="quantity pointer-choice fa fa-minus-square"></i> <i class="quantity pointer-choice fa fa-minus-square" data-item="ring" data-value="-1"></i>
</div> </div>
<div class="third"> <div class="third">
<div class="dice-container"> <div class="dice-container">
<img src="systems/l5r5e/assets/dices/default/ring_blank.svg" alt="1"> <img src="systems/l5r5e/assets/dices/default/ring_blank.svg" alt="1">
<div class="dice-value"> <div class="dice-value">
<input id="ring_value" class="input-dice input-dice-ring" type="text" name="ring" value="0" readonly="readonly"> <input class="input-dice input-dice-ring" type="text" name="ring.value" value="{{data.ring.value}}" readonly="readonly">
</div> </div>
</div> </div>
</div> </div>
<div class="third"> <div class="third">
<i id="ring_add" class="quantity pointer-choice fa fa-plus-square"></i> <i class="quantity pointer-choice fa fa-plus-square" data-item="ring" data-value="1"></i>
</div> </div>
</td> </td>
<td> <td>
<div class="third"> <div class="third">
<i id="skill_sub" class="quantity pointer-choice fa fa-minus-square"></i> <i class="quantity pointer-choice fa fa-minus-square" data-item="skill" data-value="-1"></i>
</div> </div>
<div class="third"> <div class="third">
<div class="dice-container"> <div class="dice-container">
<img src="systems/l5r5e/assets/dices/default/skill_blank.svg" alt="1"> <img src="systems/l5r5e/assets/dices/default/skill_blank.svg" alt="1">
<div class="dice-value"> <div class="dice-value">
<input id="skill_value" class="input-dice input-dice-skill" type="text" name="skill" value="{{skillData.value}}" readonly="readonly"> <input class="input-dice input-dice-skill" type="text" name="skill.value" value="{{data.skill.value}}" readonly="readonly">
</div> </div>
</div> </div>
</div> </div>
<div class="third"> <div class="third">
<i id="skill_add" class="quantity pointer-choice fa fa-plus-square"></i> <i class="quantity pointer-choice fa fa-plus-square" data-item="skill" data-value="1"></i>
</div> </div>
</td> </td>
</tr> </tr>
<!-- Fourth line --> {{!-- Fourth line--}}
<tr> <tr>
<td> <td>
<label> <label>
<input type="checkbox" id="diff_hidden" name="diff_hidden" value="1"> <input type="checkbox" id="diff_hidden" name="difficulty.hidden" value="1" {{checked data.difficulty.hidden}}>
{{localize 'l5r5e.dicepicker.difficulty_hidden_label'}} {{localize 'l5r5e.dicepicker.difficulty_hidden_label'}}
</label> </label>
</td> </td>
<td> <td>
{{#if canUseVoidPoint}} {{#if canUseVoidPoint}}
<label> <label>
<input type="checkbox" id="use_void_point" name="use_void_point" value="1"> <input type="checkbox" id="use_void_point" name="useVoidPoint" value="1" {{checked data.useVoidPoint}}>
{{localize 'l5r5e.dicepicker.use_void_point_label'}} {{localize 'l5r5e.dicepicker.use_void_point_label'}}
</label> </label>
{{/if}} {{/if}}