Some checks on 20Q
Fix a bug with babele on drop a compendium in 20q
This commit is contained in:
@@ -285,7 +285,7 @@
|
||||
"incskill3": "Skill increases (3-5)",
|
||||
"choosem": "Pick one",
|
||||
"choosef": "Pick one",
|
||||
"money": "Starting wealth :",
|
||||
"money": "Starting wealth in Koku :",
|
||||
"glory": "Glory :",
|
||||
"school": "School :",
|
||||
"status": "Status",
|
||||
|
||||
@@ -285,7 +285,7 @@
|
||||
"incskill3": "Skill increases (3-5)",
|
||||
"choosem": "Pick one",
|
||||
"choosef": "Pick one",
|
||||
"money": "Starting wealth :",
|
||||
"money": "Starting wealth in Koku :",
|
||||
"glory": "Glory :",
|
||||
"school": "School :",
|
||||
"status": "Status",
|
||||
|
||||
@@ -285,7 +285,7 @@
|
||||
"incskill3": "Augmentations de compétences (3-5)",
|
||||
"choosem": "En choisir un",
|
||||
"choosef": "En choisir une",
|
||||
"money": "Fortune de départ :",
|
||||
"money": "Fortune de départ en Koku :",
|
||||
"glory": "Gloire :",
|
||||
"school": "École :",
|
||||
"status": "Statut",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { HelpersL5r5e } from "../helpers.js";
|
||||
import { TwentyQuestions } from "./twenty-questions.js";
|
||||
|
||||
/**
|
||||
@@ -12,14 +13,14 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
actor = null;
|
||||
|
||||
/**
|
||||
* Errors object
|
||||
* Errors
|
||||
*/
|
||||
errors = {};
|
||||
errors = [];
|
||||
|
||||
/**
|
||||
* Cache for items (techniques, adv...)
|
||||
*/
|
||||
cache = {};
|
||||
cache = null;
|
||||
|
||||
/**
|
||||
* Assign the default options
|
||||
@@ -67,7 +68,15 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
this.actor = actor;
|
||||
this.object = new TwentyQuestions(actor);
|
||||
this.errors = this.object.validateForm();
|
||||
this._constructCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct async cache here
|
||||
* @override
|
||||
*/
|
||||
async _render(force = false, options = {}) {
|
||||
await this._constructCache();
|
||||
return super._render(force, options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,7 +114,7 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
* @param options
|
||||
* @return {Object}
|
||||
*/
|
||||
getData(options = null) {
|
||||
async getData(options = null) {
|
||||
return {
|
||||
...super.getData(options),
|
||||
ringsList: game.l5r5e.HelpersL5r5e.getRingsList(),
|
||||
@@ -114,10 +123,8 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
techniquesList: CONFIG.l5r5e.techniques,
|
||||
data: this.object.data,
|
||||
cache: this.cache,
|
||||
errors: Object.keys(this.errors)
|
||||
.map((key) => `${game.i18n.localize("l5r5e.rings." + key)} (${this.errors[key]})`)
|
||||
.join(", "), // TODO better msg :D
|
||||
hasErrors: Object.keys(this.errors).length > 0,
|
||||
errors: this.errors.join(", "),
|
||||
hasErrors: this.errors.length > 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -138,7 +145,7 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
const stepKey = $(event.currentTarget).parents(".tq-drag-n-drop").data("step");
|
||||
const itemId = $(event.currentTarget).parents(".property").data("propertyId");
|
||||
this._deleteOwnedItem(stepKey, itemId);
|
||||
this.render(false);
|
||||
this.submit();
|
||||
});
|
||||
|
||||
// Submit button
|
||||
@@ -176,10 +183,7 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
// Add the item (step and cache)
|
||||
this._addOwnedItem(item, stepKey);
|
||||
|
||||
// TODO specific event (no added honor if tech selected etc)
|
||||
// console.log(this.object.data, this.cache);
|
||||
|
||||
this.render(false);
|
||||
this.submit();
|
||||
} catch (err) {
|
||||
console.warn(err);
|
||||
}
|
||||
@@ -194,14 +198,19 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
* @override
|
||||
*/
|
||||
async _updateObject(event, formData) {
|
||||
// Check "Or" conditions
|
||||
formData["step7.social_add_glory"] = formData["step7.skill"] === "none" ? 5 : 0;
|
||||
formData["step8.social_add_honor"] = formData["step8.skill"] === "none" ? 10 : 0;
|
||||
if (formData["step13.skill"] !== "none" && this.object.data.step13.advantage.length > 0) {
|
||||
formData["step13.skill"] = "none";
|
||||
}
|
||||
|
||||
// Update 20Q object data
|
||||
this.object.updateFromForm(formData);
|
||||
|
||||
// Get errors if any
|
||||
this.errors = this.object.validateForm();
|
||||
|
||||
// Only on close/submit
|
||||
// if (event.type === "submit") {
|
||||
// Store this form datas in actor
|
||||
this.actor.data.data.twenty_questions = this.object.data;
|
||||
this.actor.update({
|
||||
@@ -209,16 +218,16 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
twenty_questions: this.object.data,
|
||||
},
|
||||
});
|
||||
// }
|
||||
|
||||
this.render(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the cache tree with Items full object
|
||||
*/
|
||||
_constructCache() {
|
||||
async _constructCache() {
|
||||
this.cache = {};
|
||||
TwentyQuestions.itemsList.forEach((stepName) => {
|
||||
for (const stepName of TwentyQuestions.itemsList) {
|
||||
// Check if current step value is a array
|
||||
let step = getProperty(this.object.data, stepName);
|
||||
if (!step || !Array.isArray(step)) {
|
||||
@@ -232,16 +241,19 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
|
||||
// Get linked Item, and store it in cache (delete null value and old items)
|
||||
const newStep = [];
|
||||
step.forEach((id) => {
|
||||
const item = game.items.get(id);
|
||||
if (!id || !item) {
|
||||
return;
|
||||
for (const id of step) {
|
||||
if (!id) {
|
||||
continue;
|
||||
}
|
||||
const item = await HelpersL5r5e.getObjectGameOrPack(id, "Item");
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
newStep.push(id);
|
||||
getProperty(this.cache, stepName).push(item);
|
||||
});
|
||||
}
|
||||
setProperty(this.object.data, stepName, newStep);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,15 +50,15 @@ export class TwentyQuestions {
|
||||
clan: "",
|
||||
ring: "",
|
||||
skill: "",
|
||||
social_status: 0,
|
||||
social_status: 30,
|
||||
},
|
||||
step2: {
|
||||
family: "",
|
||||
ring: "",
|
||||
skill1: "",
|
||||
skill2: "",
|
||||
wealth: 0,
|
||||
social_glory: 0,
|
||||
wealth: 3,
|
||||
social_glory: 39,
|
||||
},
|
||||
step3: {
|
||||
school: "",
|
||||
@@ -82,7 +82,7 @@ export class TwentyQuestions {
|
||||
techniques: [],
|
||||
school_ability: [],
|
||||
equipment: [],
|
||||
social_honor: 0,
|
||||
social_honor: 30,
|
||||
},
|
||||
step4: {
|
||||
stand_out: "",
|
||||
@@ -97,12 +97,12 @@ export class TwentyQuestions {
|
||||
step7: {
|
||||
clan_relations: "",
|
||||
skill: "",
|
||||
social_add_glory: null,
|
||||
social_add_glory: 0,
|
||||
},
|
||||
step8: {
|
||||
bushido: "",
|
||||
skill: "",
|
||||
social_add_honor: null,
|
||||
social_add_honor: 0,
|
||||
},
|
||||
step9: {
|
||||
success: "",
|
||||
@@ -213,7 +213,7 @@ export class TwentyQuestions {
|
||||
const formData = this.data;
|
||||
|
||||
// Update the actor real datas
|
||||
actorDatas.zeni = formData.step2.wealth;
|
||||
actorDatas.zeni = Math.floor(formData.step2.wealth * 50);
|
||||
actorDatas.identity = {
|
||||
...actorDatas.identity,
|
||||
clan: formData.step1.clan,
|
||||
@@ -274,7 +274,7 @@ export class TwentyQuestions {
|
||||
if (itemData.data?.bought_at_rank) {
|
||||
itemData.data.bought_at_rank = 0;
|
||||
}
|
||||
actor.createEmbeddedEntity("OwnedItem", duplicate(itemData));
|
||||
actor.createEmbeddedEntity("OwnedItem", itemData);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -292,13 +292,22 @@ export class TwentyQuestions {
|
||||
* Return a array of errors, empty array if no errors founds
|
||||
*/
|
||||
validateForm() {
|
||||
// Rings & Skills
|
||||
const errors = [];
|
||||
|
||||
// Rings & Skills, 3pt max for each
|
||||
const rings = this._checkRingsOrSkills("ringList", 2); // ring start at 1
|
||||
for (const key in rings) {
|
||||
errors.push(`${game.i18n.localize("l5r5e.rings." + key)} (${rings[key]})`);
|
||||
}
|
||||
|
||||
const skills = this._checkRingsOrSkills("skillList", 3); // skill start at 0
|
||||
for (const key in skills) {
|
||||
errors.push(
|
||||
`${game.i18n.localize("l5r5e.skills." + CONFIG.l5r5e.skills.get(key) + "." + key)} (${skills[key]})`
|
||||
);
|
||||
}
|
||||
|
||||
// TODO Techniques / peculiarities
|
||||
|
||||
return { ...rings, ...skills };
|
||||
return errors;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -97,6 +97,12 @@ export class HelpersL5r5e {
|
||||
|
||||
// Unknown pack object, iterate all packs
|
||||
for (const comp of game.packs) {
|
||||
// TODO Bug with babele if "comp.getEntity(id)" return null...
|
||||
const babeleFix = (await comp.getIndex()).some((e) => e._id === id);
|
||||
if (!babeleFix) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const data = await comp.getEntity(id);
|
||||
if (data) {
|
||||
return HelpersL5r5e.createItemFromCompendium(data);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -17,4 +17,16 @@
|
||||
.dropbox {
|
||||
min-height: 75px;
|
||||
}
|
||||
.errors {
|
||||
position: sticky;
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
z-index: 999;
|
||||
display: block;
|
||||
width: 100%;
|
||||
background-color: $l5r5e-red;
|
||||
border: 1px solid $dark-red;
|
||||
border-radius: 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
{{/each}}
|
||||
</ul>
|
||||
</fieldset>
|
||||
|
||||
{{#ifCond itemsList.length '<' hideDndAt}}
|
||||
<fieldset class="{{itemType}} dropbox" data-step="{{stepName}}">
|
||||
<legend class="section-header"><i class="fa fa-arrow-down" aria-hidden="true"></i> {{ localize 'l5r5e.global.drop_here' }}</legend>
|
||||
</fieldset>
|
||||
{{/ifCond}}
|
||||
@@ -121,7 +121,7 @@
|
||||
<label>
|
||||
{{localize 'l5r5e.twenty_questions.money'}}
|
||||
<br>
|
||||
<input type="text" name="step2.wealth" value="{{data.step2.wealth}}" data-dtype="Number"
|
||||
<input type="number" name="step2.wealth" value="{{data.step2.wealth}}" data-dtype="Number"
|
||||
placeholder="0">
|
||||
</label>
|
||||
<br>
|
||||
@@ -265,18 +265,18 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="fifty">
|
||||
{{localize 'l5r5e.twenty_questions.startech'}}
|
||||
<br>
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step3.techniques stepName='step3.techniques' itemType='techniques' }}
|
||||
<br>
|
||||
{{localize 'l5r5e.twenty_questions.schoolab'}}
|
||||
<br>
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step3.school_ability stepName='step3.school_ability' itemType='techniques' }}
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step3.school_ability stepName='step3.school_ability' itemType='techniques' hideDndAt=1 }}
|
||||
<br>
|
||||
{{localize 'l5r5e.twenty_questions.startech'}}
|
||||
<br>
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step3.techniques stepName='step3.techniques' itemType='techniques' hideDndAt=5 }}
|
||||
</td>
|
||||
<td class="fifty">
|
||||
{{localize 'l5r5e.twenty_questions.outfit'}}
|
||||
<br>
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step3.equipment stepName='step3.equipment' itemType='items' }}
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step3.equipment stepName='step3.equipment' itemType='items' hideDndAt=10 }}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -359,7 +359,7 @@
|
||||
{{localize 'l5r5e.twenty_questions.incglory'}}
|
||||
<br>
|
||||
<input type="number" name="step7.social_add_glory" value="{{data.step7.social_add_glory}}"
|
||||
data-dtype="Number" placeholder="0">
|
||||
data-dtype="Number" placeholder="0" disabled>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -396,7 +396,7 @@
|
||||
{{localize 'l5r5e.twenty_questions.inchonor'}}
|
||||
<br>
|
||||
<input type="number" name="step8.social_add_honor" value="{{data.step8.social_add_honor}}"
|
||||
data-dtype="Number" placeholder="0">
|
||||
data-dtype="Number" placeholder="0" disabled>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -414,7 +414,7 @@
|
||||
<br>
|
||||
{{localize 'l5r5e.twenty_questions.distinction'}}
|
||||
<br>
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step9.distinction stepName='step9.distinction' itemType='peculiarities' }}
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step9.distinction stepName='step9.distinction' itemType='peculiarities' hideDndAt=1 }}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@@ -425,7 +425,7 @@
|
||||
<br>
|
||||
{{localize 'l5r5e.twenty_questions.adversity'}}
|
||||
<br>
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step10.adversity stepName='step10.adversity' itemType='peculiarities' }}
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step10.adversity stepName='step10.adversity' itemType='peculiarities' hideDndAt=1 }}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@@ -436,7 +436,7 @@
|
||||
<br>
|
||||
{{localize 'l5r5e.twenty_questions.passion'}}
|
||||
<br>
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step11.passion stepName='step11.passion' itemType='peculiarities' }}
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step11.passion stepName='step11.passion' itemType='peculiarities' hideDndAt=1 }}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@@ -447,7 +447,7 @@
|
||||
<br>
|
||||
{{localize 'l5r5e.twenty_questions.anxiety'}}
|
||||
<br>
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step12.anxiety stepName='step12.anxiety' itemType='peculiarities' }}
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step12.anxiety stepName='step12.anxiety' itemType='peculiarities' hideDndAt=1 }}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@@ -466,6 +466,7 @@
|
||||
<select name="step13.skill" class="skill-select">
|
||||
{{#select data.step13.skill}}
|
||||
<option value="none">{{localize 'l5r5e.twenty_questions.choosef'}}</option>
|
||||
{{#ifCond cache.step13.advantage.length '==' '0'}}
|
||||
{{#each skillsList as |skills catId|}}
|
||||
<optgroup label="{{localizeSkill catId 'title'}}">
|
||||
{{#each skills as |obj|}}
|
||||
@@ -473,6 +474,7 @@
|
||||
{{/each}}
|
||||
</optgroup>
|
||||
{{/each}}
|
||||
{{/ifCond}}
|
||||
{{/select}}
|
||||
</select>
|
||||
</label>
|
||||
@@ -483,7 +485,7 @@
|
||||
<td class="">
|
||||
{{localize 'l5r5e.twenty_questions.advant'}}
|
||||
<br>
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step13.advantage stepName='step13.advantage' itemType='peculiarities' }}
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step13.advantage stepName='step13.advantage' itemType='peculiarities' hideDndAt=1 }}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -491,7 +493,7 @@
|
||||
<br>
|
||||
{{localize 'l5r5e.twenty_questions.disadvant'}}
|
||||
<br>
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step13.disadvantage stepName='step13.disadvantage' itemType='peculiarities' }}
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step13.disadvantage stepName='step13.disadvantage' itemType='peculiarities' hideDndAt=1 }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -506,7 +508,7 @@
|
||||
<label>
|
||||
{{localize 'l5r5e.twenty_questions.accoutr'}}
|
||||
<br>
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step14.special_features stepName='step14.special_features' itemType='items' }}
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step14.special_features stepName='step14.special_features' itemType='items' hideDndAt=1 }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
@@ -526,7 +528,7 @@
|
||||
<label>
|
||||
{{localize 'l5r5e.twenty_questions.object'}}
|
||||
<br>
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step16.item stepName='step16.item' itemType='items' }}
|
||||
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step16.item stepName='step16.item' itemType='items' hideDndAt=1 }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user