20q now working, step one yaw !

This commit is contained in:
Vlyan
2020-12-22 18:45:58 +01:00
parent 3e1f8f7d98
commit 56f10432de
8 changed files with 122 additions and 123 deletions

View File

@@ -19,6 +19,12 @@
"def.chat.pref": "Default Chat Prefix", "def.chat.pref": "Default Chat Prefix",
"spe.chat.pref": "If specified, this string will be prefixed to all chat messages that are not already commands (such as /emote.)", "spe.chat.pref": "If specified, this string will be prefixed to all chat messages that are not already commands (such as /emote.)",
"l5r5e": { "l5r5e": {
"global": {
"add": "Add",
"edit": "Edit",
"delete": "Delete",
"drop_here": "Drop here"
},
"logo": { "logo": {
"title": "Need help?", "title": "Need help?",
"content": "Follow the guide :", "content": "Follow the guide :",
@@ -101,7 +107,6 @@
"supernatural": "supernatural", "supernatural": "supernatural",
"equipped": "Equipped" "equipped": "Equipped"
}, },
"add": "Add",
"items": "Items", "items": "Items",
"feats": "Feats", "feats": "Feats",
"techniques": { "techniques": {

View File

@@ -19,12 +19,18 @@
"def.chat.pref": "Prefijo del chat por defecto", "def.chat.pref": "Prefijo del chat por defecto",
"spe.chat.pref": "Si está configurado, la cadena será prefijada para todos los mensajes de chat que no sean ya comandos (como /emote.)", "spe.chat.pref": "Si está configurado, la cadena será prefijada para todos los mensajes de chat que no sean ya comandos (como /emote.)",
"l5r5e": { "l5r5e": {
"global": {
"add": "Add",
"edit": "Edit",
"delete": "Delete",
"drop_here": "Drop here"
},
"logo": { "logo": {
"título": "¿Necesitas ayuda?", "títle": "¿Necesitas ayuda?",
"contenido": "Sigue la guía :", "content": "Sigue la guía :",
"Edge": "Ir a la página web de Edge-Studio", "edge": "Ir a la página web de Edge-Studio",
"conducir": "¿Comprar un PDF del juego?", "drive": "¿Comprar un PDF del juego?",
"Discordia": "Discordia oficial de FoundryVTT", "discord": "Discordia oficial de FoundryVTT",
"src": "systems/l5r5e/assets/l5r-logo.webp", "src": "systems/l5r5e/assets/l5r-logo.webp",
"alt": "Ayuda en línea", "alt": "Ayuda en línea",
"edge-info": "tu navegador abrirá la página web de EDGE STUDIO", "edge-info": "tu navegador abrirá la página web de EDGE STUDIO",
@@ -38,7 +44,7 @@
"title": "Anillos", "title": "Anillos",
"earth": "Tierra", "earth": "Tierra",
"air": "Aire", "air": "Aire",
"WATER": "Agua", "water": "Agua",
"fire": "Fuego", "fire": "Fuego",
"void": "Vacío" "void": "Vacío"
}, },
@@ -92,7 +98,6 @@
"sheathed": "Equipped / Sheathed", "sheathed": "Equipped / Sheathed",
"readied": "Readied", "readied": "Readied",
"category": "Category", "category": "Category",
"power": "Power",
"deadliness": "Deadliness", "deadliness": "Deadliness",
"grips": "Grips" "grips": "Grips"
}, },
@@ -102,7 +107,6 @@
"supernatural": "supernatural", "supernatural": "supernatural",
"equipped": "Equipped" "equipped": "Equipped"
}, },
"add": "Add",
"items": "Equipo", "items": "Equipo",
"feats": "Feats", "feats": "Feats",
"techniques": { "techniques": {
@@ -203,7 +207,8 @@
"void": "Subsistir" "void": "Subsistir"
} }
}, },
"conflict": { "attributes": {
"title": "Attributes",
"endurance": "Aguante", "endurance": "Aguante",
"endurancetip": "(Tierra + Fuego) x2", "endurancetip": "(Tierra + Fuego) x2",
"composure": "Compostura", "composure": "Compostura",
@@ -216,7 +221,7 @@
"fatigue": "Fatiga", "fatigue": "Fatiga",
"strife": "Conflicto" "strife": "Conflicto"
}, },
"attributes": { "conflict": {
"title": "Enfrentamiento", "title": "Enfrentamiento",
"stance": "Actitud", "stance": "Actitud",
"stances": { "stances": {

View File

@@ -22,7 +22,8 @@
"global": { "global": {
"add": "Ajouter", "add": "Ajouter",
"edit": "Modifier", "edit": "Modifier",
"delete": "Supprimer" "delete": "Supprimer",
"drop_here": "Déposez ici"
}, },
"logo": { "logo": {
"title": "Besoin d'aide ?", "title": "Besoin d'aide ?",

View File

@@ -94,30 +94,14 @@ export class TwentyQuestionsDialog extends FormApplication {
noHonorSkillsList: ["commerce", "skulduggery", "medicine", "seafaring", "survival", "labor"], 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,
cache: this.cache, 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,
}; };
} }
/**
* Render the dialog
* @param force
* @param options
* @returns {Application}
*/
render(force, options) {
options = {
...options,
};
if (force === undefined) {
force = true;
}
return super.render(force, options);
}
/** /**
* Listen to html elements * Listen to html elements
* @override * @override
@@ -132,15 +116,15 @@ export class TwentyQuestionsDialog extends FormApplication {
// Delete a dnd element // Delete a dnd element
html.find(`.property-delete`).on("click", (event) => { html.find(`.property-delete`).on("click", (event) => {
const stepName = $(event.currentTarget).parents(".tq-drag-n-drop")[0].name; const stepKey = $(event.currentTarget).parents(".tq-drag-n-drop").data("step");
const itemId = $(event.currentTarget).parents(".property").data("propertyId"); const itemId = $(event.currentTarget).parents(".property").data("propertyId");
this._deleteOwnedItem(stepName, itemId); this._deleteOwnedItem(stepKey, itemId);
this.render(false); this.render(false);
}); });
// Submit button // Submit button
html.find("#generate").on("click", async (event) => { html.find("#generate").on("click", async (event) => {
this.object.toActor(this.actor); await this.object.toActor(this.actor, flattenObject(this.cache));
await this.close({ submit: true, force: true }); await this.close({ submit: true, force: true });
}); });
} }
@@ -152,8 +136,9 @@ export class TwentyQuestionsDialog extends FormApplication {
if (!["item", "technique", "peculiarity"].includes(type)) { if (!["item", "technique", "peculiarity"].includes(type)) {
return; return;
} }
if (event.target.name === "undefined") { const stepKey = $(event.target).data("step");
console.log("event.target.name is undefined"); if (!stepKey) {
console.log("event stepKey is undefined");
return; return;
} }
@@ -167,14 +152,19 @@ export class TwentyQuestionsDialog extends FormApplication {
} }
// Get item // Get item
const item = game.items.get(data.id); const item = game.items.get(data.id);
if (!item || item.data.type !== type) { if (
!item ||
(type !== "item" && item.data.type !== type) ||
(type === "item" && !["item", "weapon", "armor"].includes(item.data.type))
) {
console.log("forbidden item for this drop zone", type, item.data.type);
return; return;
} }
// Add the item (step and cache) // Add the item (step and cache)
this._addOwnedItem(item, event.target.name); this._addOwnedItem(item, stepKey);
// TODO specific event (no added honor if tech selected etc) // TODO specific event (no added honor if tech selected etc)
console.log(this.object.data.step3.techniques, this.cache); console.log(this.object.data, this.cache);
this.render(false); this.render(false);
} catch (err) { } catch (err) {
@@ -217,9 +207,9 @@ export class TwentyQuestionsDialog extends FormApplication {
this.cache = {}; this.cache = {};
TwentyQuestions.itemsList.forEach((stepName) => { TwentyQuestions.itemsList.forEach((stepName) => {
// Check if current step value is a array // Check if current step value is a array
const store = getProperty(this.object.data, stepName); let step = getProperty(this.object.data, stepName);
if (!store || !Array.isArray(store)) { if (!step || !Array.isArray(step)) {
setProperty(this.object.data, stepName, []); step = [];
} }
// Init cache if not exist // Init cache if not exist
@@ -227,16 +217,17 @@ export class TwentyQuestionsDialog extends FormApplication {
setProperty(this.cache, stepName, []); setProperty(this.cache, stepName, []);
} }
// Get linked Item, and store it in cache // Get linked Item, and store it in cache (delete null value and old items)
const step = getProperty(this.object.data, stepName); const newStep = [];
step.forEach((id, idx) => { step.forEach((id) => {
const item = game.items.get(id); const item = game.items.get(id);
if (!item) { if (!id || !item) {
step.splice(idx, 1);
return; return;
} }
newStep.push(id);
getProperty(this.cache, stepName).push(item); getProperty(this.cache, stepName).push(item);
}); });
setProperty(this.object.data, stepName, newStep);
}); });
} }
@@ -263,12 +254,12 @@ export class TwentyQuestionsDialog extends FormApplication {
_deleteOwnedItem(stepName, itemId) { _deleteOwnedItem(stepName, itemId) {
// Delete from current step // Delete from current step
let step = getProperty(this.object.data, stepName); let step = getProperty(this.object.data, stepName);
step = step.filter((e) => e !== itemId); step = step.filter((e) => !!e && e !== itemId);
setProperty(this.object.data, stepName, step); setProperty(this.object.data, stepName, step);
// Delete from cache // Delete from cache
let cache = getProperty(this.cache, stepName); let cache = getProperty(this.cache, stepName);
cache = cache.filter((e) => e.id !== itemId); cache = cache.filter((e) => !!e && e.id !== itemId);
setProperty(this.cache, stepName, cache); setProperty(this.cache, stepName, cache);
} }
} }

View File

@@ -28,7 +28,18 @@ export class TwentyQuestions {
/** /**
* Shortcut for all Items to build cache * Shortcut for all Items to build cache
*/ */
static itemsList = ["step3.techniques"]; static itemsList = [
"step3.techniques",
"step3.school_ability",
"step3.equipment",
"step9.distinction",
"step10.adversity",
"step11.passion",
"step12.anxiety",
"step13.advantage",
"step13.disadvantage",
"step16.item",
];
/** /**
* Steps datas * Steps datas
@@ -94,25 +105,25 @@ export class TwentyQuestions {
}, },
step9: { step9: {
success: "", success: "",
distinction: "", distinction: [],
}, },
step10: { step10: {
difficulty: "", difficulty: "",
adversity: "", adversity: [],
}, },
step11: { step11: {
calms: "", calms: "",
passion: "", passion: [],
}, },
step12: { step12: {
worries: "", worries: "",
anxiety: "", anxiety: [],
}, },
step13: { step13: {
most_learn: "", most_learn: "",
skill: "", skill: "",
advantage: "", advantage: [],
disadvantage: "", disadvantage: [],
}, },
step14: { step14: {
first_sight: "", first_sight: "",
@@ -123,7 +134,7 @@ export class TwentyQuestions {
}, },
step16: { step16: {
relations: "", relations: "",
item: "", item: [],
}, },
step17: { step17: {
parents_pov: "", parents_pov: "",
@@ -155,10 +166,7 @@ export class TwentyQuestions {
* Update object with form data * Update object with form data
*/ */
updateFromForm(formData) { updateFromForm(formData) {
this.data = { this.data = mergeObject(this.data, expandObject(formData));
...this.data,
...expandObject(formData),
};
} }
/** /**
@@ -199,7 +207,7 @@ export class TwentyQuestions {
/** /**
* Fill a actor data from this object * Fill a actor data from this object
*/ */
toActor(actor) { async toActor(actor, itemsCache) {
const actorDatas = actor.data.data; const actorDatas = actor.data.data;
const formData = this.data; const formData = this.data;
@@ -254,13 +262,26 @@ export class TwentyQuestions {
} }
}); });
// TODO Items references // Clear and add items to actor
const deleteIds = actor.data.items.map((e) => e._id);
await actor.deleteEmbeddedEntity("OwnedItem", deleteIds);
// Add items in 20Q to actor
Object.values(itemsCache).forEach((types) => {
types.forEach((item) => {
const itemData = duplicate(item.data);
if (itemData.data?.bought_at_rank) {
itemData.data.bought_at_rank = 0;
}
actor.createEmbeddedEntity("OwnedItem", duplicate(itemData));
});
});
// Update actor // Update actor
actor.update({ actor.update({
name: (formData.step2.family + " " + formData.step19.firstname).trim(), name: (formData.step2.family + " " + formData.step19.firstname).trim(),
data: actorDatas, data: actorDatas,
}); // , { diff: true } });
// TODO Tmp // TODO Tmp
console.log(actor); console.log(actor);

View File

@@ -14,6 +14,7 @@ export const PreloadTemplates = async function () {
"systems/l5r5e/templates/actors/character/techniques.html", "systems/l5r5e/templates/actors/character/techniques.html",
"systems/l5r5e/templates/actors/character/experience.html", "systems/l5r5e/templates/actors/character/experience.html",
"systems/l5r5e/templates/actors/character/advancement.html", "systems/l5r5e/templates/actors/character/advancement.html",
"systems/l5r5e/templates/actors/character/twenty-questions-item.html",
// npc // npc
"systems/l5r5e/templates/actors/npc/identity.html", "systems/l5r5e/templates/actors/npc/identity.html",
"systems/l5r5e/templates/actors/npc/narrative.html", "systems/l5r5e/templates/actors/npc/narrative.html",

View File

@@ -0,0 +1,11 @@
<fieldset data-step="{{stepName}}" class="tq-drag-n-drop">
<ul class="item-list">
{{#each itemsList as |item id|}}
{{> 'systems/l5r5e/templates/items/property/property-entry.html' item=item id=id }}
{{/each}}
</ul>
</fieldset>
<fieldset class="{{itemType}}" data-step="{{stepName}}" style="min-height: 50px">
<legend class="section-header"><i class="fa fa-arrow-down" aria-hidden="true"></i> {{ localize 'l5r5e.global.drop_here' }}</legend>
</fieldset>

View File

@@ -1,5 +1,7 @@
<form class="l5r5e dice-picker-dialog" autocomplete="off"> <form class="l5r5e dice-picker-dialog" autocomplete="off">
<div id="errors" class="errors">{{json errors}}</div> {{#if errors}}
<div id="errors" class="errors">{{errors}}</div>
{{/if}}
<h1>{{localize 'l5r5e.twenty_questions.title'}}</h1> <h1>{{localize 'l5r5e.twenty_questions.title'}}</h1>
<div> <div>
@@ -236,36 +238,18 @@
</div> </div>
<div> <div>
{{localize 'l5r5e.twenty_questions.startech'}} {{localize 'l5r5e.twenty_questions.startech'}}
<fieldset name="step3.techniques" class="tq-drag-n-drop"> {{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step3.techniques stepName='step3.techniques' itemType='techniques' }}
<ul class="item-list">
{{#each cache.step3.techniques as |item id|}}
{{> 'systems/l5r5e/templates/items/property/property-entry.html' item=item id=id }}
{{/each}}
</ul>
</fieldset>
<fieldset class="techniques" name="step3.techniques" style="min-height: 50px">
<legend class="section-header"><i class="fa fa-arrow-down" aria-hidden="true"></i> {{ localize 'l5r5e.drophere' }}</legend>
</fieldset>
</div> </div>
<div> <div>
<label>
{{localize 'l5r5e.twenty_questions.schoolab'}} {{localize 'l5r5e.twenty_questions.schoolab'}}
<textarea name="step3.school_ability">{{data.step3.school_ability}}</textarea> {{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step3.school_ability stepName='step3.school_ability' itemType='techniques' }}
</label>
<!-- TODO Drag n drop tech d'école-->
</div> </div>
<div> <div>
<label>
{{localize 'l5r5e.twenty_questions.outfit'}} {{localize 'l5r5e.twenty_questions.outfit'}}
<textarea name="step3.equipment">{{data.step3.equipment}}</textarea> {{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step3.equipment stepName='step3.equipment' itemType='items' }}
</label>
<!-- TODO Drag n drop equipment-->
</div> </div>
</div> </div>
<div> <div>
@@ -382,11 +366,8 @@
<textarea name="step9.success">{{data.step9.success}}</textarea> <textarea name="step9.success">{{data.step9.success}}</textarea>
</label> </label>
<label>
{{localize 'l5r5e.twenty_questions.distinction'}} {{localize 'l5r5e.twenty_questions.distinction'}}
<textarea name="step9.distinction">{{data.step9.distinction}}</textarea> {{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step9.distinction stepName='step9.distinction' itemType='peculiarities' }}
</label>
<!-- TODO Drag n drop disadv/distinction-->
</div> </div>
<div> <div>
<label> <label>
@@ -394,11 +375,8 @@
<textarea name="step10.difficulty">{{data.step10.difficulty}}</textarea> <textarea name="step10.difficulty">{{data.step10.difficulty}}</textarea>
</label> </label>
<label>
{{localize 'l5r5e.twenty_questions.adversity'}} {{localize 'l5r5e.twenty_questions.adversity'}}
<textarea name="step10.adversity">{{data.step10.adversity}}</textarea> {{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step10.adversity stepName='step10.adversity' itemType='peculiarities' }}
</label>
<!-- TODO Drag n drop disadv/adversity-->
</div> </div>
<div> <div>
<label> <label>
@@ -406,11 +384,8 @@
<textarea name="step11.calms">{{data.step11.calms}}</textarea> <textarea name="step11.calms">{{data.step11.calms}}</textarea>
</label> </label>
<label>
{{localize 'l5r5e.twenty_questions.passion'}} {{localize 'l5r5e.twenty_questions.passion'}}
<textarea name="step11.passion">{{data.step11.passion}}</textarea> {{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step11.passion stepName='step11.passion' itemType='peculiarities' }}
</label>
<!-- TODO Drag n drop disadv/passion-->
</div> </div>
<div> <div>
<label> <label>
@@ -418,11 +393,8 @@
<textarea name="step12.worries">{{data.step12.worries}}</textarea> <textarea name="step12.worries">{{data.step12.worries}}</textarea>
</label> </label>
<label>
{{localize 'l5r5e.twenty_questions.anxiety'}} {{localize 'l5r5e.twenty_questions.anxiety'}}
<textarea name="step12.anxiety">{{data.step12.anxiety}}</textarea> {{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step12.anxiety stepName='step12.anxiety' itemType='peculiarities' }}
</label>
<!-- TODO Drag n drop disadv/anxiety-->
</div> </div>
<div> <div>
<label> <label>
@@ -449,18 +421,12 @@
{{localize 'l5r5e.twenty_questions.or'}} {{localize 'l5r5e.twenty_questions.or'}}
<label>
{{localize 'l5r5e.twenty_questions.advant'}} {{localize 'l5r5e.twenty_questions.advant'}}
<textarea name="step13.advantage">{{data.step13.advantage}}</textarea> {{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step13.advantage stepName='step13.advantage' itemType='peculiarities' }}
</label>
<!-- TODO Drag n drop advantage-->
</div> </div>
<div> <div>
<label>
{{localize 'l5r5e.twenty_questions.disadvant'}} {{localize 'l5r5e.twenty_questions.disadvant'}}
<textarea name="step13.disadvantage">{{data.step13.disadvantage}}</textarea> {{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step13.disadvantage stepName='step13.disadvantage' itemType='peculiarities' }}
</label>
<!-- TODO Drag n drop disadvantage-->
</div> </div>
</div> </div>
@@ -474,8 +440,7 @@
<label> <label>
{{localize 'l5r5e.twenty_questions.accoutr'}} {{localize 'l5r5e.twenty_questions.accoutr'}}
<textarea name="step14.special_features">{{data.step14.special_features}}</textarea> {{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step14.special_features stepName='step14.special_features' itemType='items' }}
<!-- TODO Drag n drop equipment ? -->
</label> </label>
</div> </div>
<div> <div>
@@ -492,8 +457,7 @@
<label> <label>
{{localize 'l5r5e.twenty_questions.object'}} {{localize 'l5r5e.twenty_questions.object'}}
<textarea name="step16.item">{{data.step16.item}}</textarea> {{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step16.item stepName='step16.item' itemType='items' }}
<!-- TODO Drag n drop item-->
</label> </label>
</div> </div>