working on 20Q

This commit is contained in:
Vlyan
2020-12-22 11:26:55 +01:00
parent 4161f396c7
commit 80c03b90df
6 changed files with 83 additions and 83 deletions

View File

@@ -272,7 +272,8 @@
"object": "Item (Rarity 7 or lower)", "object": "Item (Rarity 7 or lower)",
"d10r1": "D10 Result (1/2)", "d10r1": "D10 Result (1/2)",
"d10r2": "D10 Result (2/2)", "d10r2": "D10 Result (2/2)",
"generchar": "Generate a new character", "generchar": "Generate the character",
"generchar_disclaimer": "Warning, this will erase character's current datas !",
"part1": { "part1": {
"title": "Part I: Core Identity (Clan and Family)", "title": "Part I: Core Identity (Clan and Family)",
"q1": "1. What clan does your character belong to ? (p. 41)", "q1": "1. What clan does your character belong to ? (p. 41)",

View File

@@ -272,7 +272,8 @@
"object": "Item (Rarity 7 or lower)", "object": "Item (Rarity 7 or lower)",
"d10r1": "D10 Result (1/2)", "d10r1": "D10 Result (1/2)",
"d10r2": "D10 Result (2/2)", "d10r2": "D10 Result (2/2)",
"generchar": "Generate a new character", "generchar": "Generate the character",
"generchar_disclaimer": "Warning, this will erase character's current datas !",
"part1": { "part1": {
"title": "Part I: Core Identity (Clan and Family)", "title": "Part I: Core Identity (Clan and Family)",
"q1": "1. What clan does your character belong to ? (p. 41)", "q1": "1. What clan does your character belong to ? (p. 41)",

View File

@@ -276,7 +276,8 @@
"object": "Objet (Rareté inférieur ou égale à 7)", "object": "Objet (Rareté inférieur ou égale à 7)",
"d10r1": "Résultat du 1er D10", "d10r1": "Résultat du 1er D10",
"d10r2": "Résultat du 2eme D10", "d10r2": "Résultat du 2eme D10",
"generchar": "Générer un nouveau personnage", "generchar": "Générer le personnage",
"generchar_disclaimer": "Attention cela écrasera les données de votre personnage actuel !",
"part1": { "part1": {
"title": "Partie I: Identité (clan et famille)", "title": "Partie I: Identité (clan et famille)",
"q1": "1. A quel clan appartient votre personnage ? (p. 41)", "q1": "1. A quel clan appartient votre personnage ? (p. 41)",

View File

@@ -11,7 +11,10 @@ export class TwentyQuestionsDialog extends FormApplication {
*/ */
actor = null; actor = null;
errors = []; /**
* Errors object
*/
errors = {};
/** /**
* Assign the default options * Assign the default options
@@ -26,6 +29,9 @@ export class TwentyQuestionsDialog extends FormApplication {
width: 600, width: 600,
height: 600, height: 600,
resizable: true, resizable: true,
closeOnSubmit: false,
submitOnClose: true,
submitOnChange: true,
}); });
} }
@@ -36,6 +42,7 @@ export class TwentyQuestionsDialog extends FormApplication {
super(options); super(options);
this.actor = actor; this.actor = actor;
this.object = new TwentyQuestions(actor); this.object = new TwentyQuestions(actor);
this.errors = this.object.validateForm();
} }
/** /**
@@ -78,8 +85,11 @@ export class TwentyQuestionsDialog extends FormApplication {
...super.getData(options), ...super.getData(options),
ringsList: game.l5r5e.HelpersL5r5e.getRingsList(), ringsList: game.l5r5e.HelpersL5r5e.getRingsList(),
skillsList: game.l5r5e.HelpersL5r5e.getSkillsList(true), skillsList: game.l5r5e.HelpersL5r5e.getSkillsList(true),
noHonorSkillsList: ["commerce", "skulduggery", "medicine", "seafaring", "survival", "labor"],
techniquesList: CONFIG.l5r5e.techniques, techniquesList: CONFIG.l5r5e.techniques,
data: this.object.data, data: this.object.data,
errors: this.errors,
hasErrors: Object.keys(this.errors).length > 0,
}; };
} }
@@ -113,22 +123,10 @@ export class TwentyQuestionsDialog extends FormApplication {
return; return;
} }
// Check rings total
html.find(".ring-select").on("change", async (event) => {
const sum = this._summarySelects(html, ".ring-select");
// sum = Map(4) {"void" => 2, "water" => 1, "fire" => 1, "earth" => 1}
console.log(sum);
});
// Check skills total
html.find(".skill-select").on("change", async (event) => {
const sum = this._summarySelects(html, ".skill-select");
console.log(sum);
});
// Submit button // Submit button
html.find("#generate").on("click", async (event) => { html.find("#generate").on("click", async (event) => {
this.submit(); this.object.toActor(this.actor);
await this.close({ submit: true, force: true });
}); });
} }
@@ -164,11 +162,6 @@ export class TwentyQuestionsDialog extends FormApplication {
return false; return false;
} }
// _canDragDrop(event) {
// console.log("*** _canDragDrop event", event);
// return false;
// }
/** /**
* This method is called upon form submission after form data is validated * This method is called upon form submission after form data is validated
* @param event The initial triggering submission event * @param event The initial triggering submission event
@@ -177,30 +170,22 @@ export class TwentyQuestionsDialog extends FormApplication {
* @override * @override
*/ */
async _updateObject(event, formData) { async _updateObject(event, formData) {
// Update 20Q object data
this.object.updateFromForm(formData); this.object.updateFromForm(formData);
this.object.toActor(this.actor);
return this.close();
}
/** // Get errors if any
* Return a map of skill/ring with count this.errors = this.object.validateForm();
* @private
*/ // Only on close/submit
_summarySelects(html, selector) { if (event.type === "submit") {
return html // Store this form datas in actor
.find(selector) this.actor.data.data.twenty_questions = this.object.data;
.get() this.actor.update({
.reduce((acc, curr) => { data: {
curr = curr.value; twenty_questions: this.object.data,
if (curr === "none") { },
return acc; });
} }
let val = acc.get(curr); this.render(false);
if (!val) {
val = 0;
}
acc.set(curr, val + 1);
return acc;
}, new Map());
} }
} }

View File

@@ -198,10 +198,6 @@ export class TwentyQuestions {
const actorDatas = actor.data.data; const actorDatas = actor.data.data;
const formData = this.data; const formData = this.data;
// Store this form datas
// TODO maybe elsewhere than in the actor ?
actorDatas.twenty_questions = this.data;
// Update the actor real datas // Update the actor real datas
actorDatas.zeni = formData.step2.wealth; actorDatas.zeni = formData.step2.wealth;
actorDatas.identity = { actorDatas.identity = {
@@ -236,7 +232,9 @@ export class TwentyQuestions {
CONFIG.l5r5e.stances.forEach((ring) => (actorDatas.rings[ring] = 1)); CONFIG.l5r5e.stances.forEach((ring) => (actorDatas.rings[ring] = 1));
TwentyQuestions.ringList.forEach((formName) => { TwentyQuestions.ringList.forEach((formName) => {
const ring = getProperty(this.data, formName); const ring = getProperty(this.data, formName);
actorDatas.rings[ring] = actorDatas.rings[ring] + 1; if (ring !== "none") {
actorDatas.rings[ring] = actorDatas.rings[ring] + 1;
}
}); });
// Skills - Reset to 0, and apply modifiers // Skills - Reset to 0, and apply modifiers
@@ -246,7 +244,9 @@ export class TwentyQuestions {
TwentyQuestions.skillList.forEach((formName) => { TwentyQuestions.skillList.forEach((formName) => {
const skillId = getProperty(this.data, formName); const skillId = getProperty(this.data, formName);
const skillCat = CONFIG.l5r5e.skills.get(skillId); const skillCat = CONFIG.l5r5e.skills.get(skillId);
actorDatas.skills[skillCat][skillId] = actorDatas.skills[skillCat][skillId] + 1; if (skillId !== "none") {
actorDatas.skills[skillCat][skillId] = actorDatas.skills[skillCat][skillId] + 1;
}
}); });
// TODO Items references // TODO Items references
@@ -261,29 +261,35 @@ export class TwentyQuestions {
console.log(actor); console.log(actor);
} }
// checkRings() { /**
// const rings = {}; * Return a array of errors, empty array if no errors founds
// const exceed = {}; */
// CONFIG.l5r5e.stances.forEach(ring => rings[ring] = 1); validateForm() {
// TwentyQuestions.ringList.forEach((formName) => { // Rings & Skills
// const ring = getProperty(this.data, formName); const rings = this._checkRingsOrSkills("ringList", 2); // ring start at 1
// rings[ring] = rings[ring] + 1; const skills = this._checkRingsOrSkills("skillList", 3); // skill start at 0
//
// console.log(rings); // TODO Techniques / peculiarities
//
// if (rings[ring] > 3) { return { ...rings, ...skills };
// exceed[ring] = ring; }
// }
// }); /**
// return exceed; * Return a list of exceeded ring/skill
// } */
// _checkRingsOrSkills(listName, max) {
// checkSkills() { const store = {};
// const skills = {}; const exceed = {};
// TwentyQuestions.skillList.forEach((formName) => { TwentyQuestions[listName].forEach((formName) => {
// const skillId = getProperty(this.data, formName); const id = getProperty(this.data, formName);
// const skillCat = CONFIG.l5r5e.skills.get(skillId); if (!store[id]) {
// actorDatas.skills[skillCat][skillId] = actorDatas.skills[skillCat][skillId] + 1; store[id] = 0;
// }); }
// } store[id] = store[id] + 1;
if (store[id] > max) {
exceed[id] = store[id];
}
});
return exceed;
}
} }

View File

@@ -1,4 +1,5 @@
<form class="l5r5e dice-picker-dialog" autocomplete="off"> <form class="l5r5e dice-picker-dialog" autocomplete="off">
<div id="errors" class="errors">{{json errors}}</div>
<h1>{{localize 'l5r5e.twenty_questions.title'}}</h1> <h1>{{localize 'l5r5e.twenty_questions.title'}}</h1>
<div> <div>
@@ -354,12 +355,8 @@
<select name="step8.skill" class="skill-select"> <select name="step8.skill" class="skill-select">
{{#select data.step8.skill}} {{#select data.step8.skill}}
<option value="none">{{localize 'l5r5e.twenty_questions.choosef'}}</option> <option value="none">{{localize 'l5r5e.twenty_questions.choosef'}}</option>
{{#each skillsList as |skills catId|}} {{#each noHonorSkillsList as |skillId|}}
<optgroup label="{{localizeSkill catId 'title'}}"> <option value="{{skillId}}">{{localizeSkillId skillId}}</option>
{{#each skills as |obj|}}
<option value="{{obj.id}}">{{obj.label}}</option>
{{/each}}
</optgroup>
{{/each}} {{/each}}
{{/select}} {{/select}}
</select> </select>
@@ -561,9 +558,18 @@
</label> </label>
</div> </div>
<hr>
{{#if hasErrors}}
corriger les erreurs pour poursuivre !
{{else}}
<div class="form-group footer"> <div class="form-group footer">
<div id="generchar_disclaimer">
{{localize 'l5r5e.twenty_questions.generchar_disclaimer'}}
</div>
<button name="generate" id="generate" type="button"> <button name="generate" id="generate" type="button">
{{localize 'l5r5e.twenty_questions.generchar'}} <i class='fas fa-arrow-circle-right'></i> {{localize 'l5r5e.twenty_questions.generchar'}} <i class='fas fa-arrow-circle-right'></i>
</button> </button>
</div> </div>
{{/if}}
</form> </form>