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

View File

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

View File

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

View File

@@ -94,30 +94,14 @@ export class TwentyQuestionsDialog extends FormApplication {
noHonorSkillsList: ["commerce", "skulduggery", "medicine", "seafaring", "survival", "labor"],
techniquesList: CONFIG.l5r5e.techniques,
data: this.object.data,
errors: this.errors,
hasErrors: Object.keys(this.errors).length > 0,
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
* @override
@@ -132,15 +116,15 @@ export class TwentyQuestionsDialog extends FormApplication {
// Delete a dnd element
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");
this._deleteOwnedItem(stepName, itemId);
this._deleteOwnedItem(stepKey, itemId);
this.render(false);
});
// Submit button
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 });
});
}
@@ -152,8 +136,9 @@ export class TwentyQuestionsDialog extends FormApplication {
if (!["item", "technique", "peculiarity"].includes(type)) {
return;
}
if (event.target.name === "undefined") {
console.log("event.target.name is undefined");
const stepKey = $(event.target).data("step");
if (!stepKey) {
console.log("event stepKey is undefined");
return;
}
@@ -167,14 +152,19 @@ export class TwentyQuestionsDialog extends FormApplication {
}
// Get item
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;
}
// 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)
console.log(this.object.data.step3.techniques, this.cache);
console.log(this.object.data, this.cache);
this.render(false);
} catch (err) {
@@ -217,9 +207,9 @@ export class TwentyQuestionsDialog extends FormApplication {
this.cache = {};
TwentyQuestions.itemsList.forEach((stepName) => {
// Check if current step value is a array
const store = getProperty(this.object.data, stepName);
if (!store || !Array.isArray(store)) {
setProperty(this.object.data, stepName, []);
let step = getProperty(this.object.data, stepName);
if (!step || !Array.isArray(step)) {
step = [];
}
// Init cache if not exist
@@ -227,16 +217,17 @@ export class TwentyQuestionsDialog extends FormApplication {
setProperty(this.cache, stepName, []);
}
// Get linked Item, and store it in cache
const step = getProperty(this.object.data, stepName);
step.forEach((id, idx) => {
// 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 (!item) {
step.splice(idx, 1);
if (!id || !item) {
return;
}
newStep.push(id);
getProperty(this.cache, stepName).push(item);
});
setProperty(this.object.data, stepName, newStep);
});
}
@@ -263,12 +254,12 @@ export class TwentyQuestionsDialog extends FormApplication {
_deleteOwnedItem(stepName, itemId) {
// Delete from current step
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);
// Delete from cache
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);
}
}

View File

@@ -28,7 +28,18 @@ export class TwentyQuestions {
/**
* 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
@@ -94,25 +105,25 @@ export class TwentyQuestions {
},
step9: {
success: "",
distinction: "",
distinction: [],
},
step10: {
difficulty: "",
adversity: "",
adversity: [],
},
step11: {
calms: "",
passion: "",
passion: [],
},
step12: {
worries: "",
anxiety: "",
anxiety: [],
},
step13: {
most_learn: "",
skill: "",
advantage: "",
disadvantage: "",
advantage: [],
disadvantage: [],
},
step14: {
first_sight: "",
@@ -123,7 +134,7 @@ export class TwentyQuestions {
},
step16: {
relations: "",
item: "",
item: [],
},
step17: {
parents_pov: "",
@@ -155,10 +166,7 @@ export class TwentyQuestions {
* Update object with form data
*/
updateFromForm(formData) {
this.data = {
...this.data,
...expandObject(formData),
};
this.data = mergeObject(this.data, expandObject(formData));
}
/**
@@ -199,7 +207,7 @@ export class TwentyQuestions {
/**
* Fill a actor data from this object
*/
toActor(actor) {
async toActor(actor, itemsCache) {
const actorDatas = actor.data.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
actor.update({
name: (formData.step2.family + " " + formData.step19.firstname).trim(),
data: actorDatas,
}); // , { diff: true }
});
// TODO Tmp
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/experience.html",
"systems/l5r5e/templates/actors/character/advancement.html",
"systems/l5r5e/templates/actors/character/twenty-questions-item.html",
// npc
"systems/l5r5e/templates/actors/npc/identity.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">
<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>
<div>
@@ -236,36 +238,18 @@
</div>
<div>
{{localize 'l5r5e.twenty_questions.startech'}}
<fieldset name="step3.techniques" class="tq-drag-n-drop">
<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>
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step3.techniques stepName='step3.techniques' itemType='techniques' }}
</div>
<div>
<label>
{{localize 'l5r5e.twenty_questions.schoolab'}}
<textarea name="step3.school_ability">{{data.step3.school_ability}}</textarea>
</label>
<!-- TODO Drag n drop tech d'école-->
{{localize 'l5r5e.twenty_questions.schoolab'}}
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step3.school_ability stepName='step3.school_ability' itemType='techniques' }}
</div>
<div>
<label>
{{localize 'l5r5e.twenty_questions.outfit'}}
<textarea name="step3.equipment">{{data.step3.equipment}}</textarea>
</label>
<!-- TODO Drag n drop equipment-->
{{localize 'l5r5e.twenty_questions.outfit'}}
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step3.equipment stepName='step3.equipment' itemType='items' }}
</div>
</div>
<div>
@@ -382,11 +366,8 @@
<textarea name="step9.success">{{data.step9.success}}</textarea>
</label>
<label>
{{localize 'l5r5e.twenty_questions.distinction'}}
<textarea name="step9.distinction">{{data.step9.distinction}}</textarea>
</label>
<!-- TODO Drag n drop disadv/distinction-->
{{localize 'l5r5e.twenty_questions.distinction'}}
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step9.distinction stepName='step9.distinction' itemType='peculiarities' }}
</div>
<div>
<label>
@@ -394,11 +375,8 @@
<textarea name="step10.difficulty">{{data.step10.difficulty}}</textarea>
</label>
<label>
{{localize 'l5r5e.twenty_questions.adversity'}}
<textarea name="step10.adversity">{{data.step10.adversity}}</textarea>
</label>
<!-- TODO Drag n drop disadv/adversity-->
{{localize 'l5r5e.twenty_questions.adversity'}}
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step10.adversity stepName='step10.adversity' itemType='peculiarities' }}
</div>
<div>
<label>
@@ -406,11 +384,8 @@
<textarea name="step11.calms">{{data.step11.calms}}</textarea>
</label>
<label>
{{localize 'l5r5e.twenty_questions.passion'}}
<textarea name="step11.passion">{{data.step11.passion}}</textarea>
</label>
<!-- TODO Drag n drop disadv/passion-->
{{localize 'l5r5e.twenty_questions.passion'}}
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step11.passion stepName='step11.passion' itemType='peculiarities' }}
</div>
<div>
<label>
@@ -418,11 +393,8 @@
<textarea name="step12.worries">{{data.step12.worries}}</textarea>
</label>
<label>
{{localize 'l5r5e.twenty_questions.anxiety'}}
<textarea name="step12.anxiety">{{data.step12.anxiety}}</textarea>
</label>
<!-- TODO Drag n drop disadv/anxiety-->
{{localize 'l5r5e.twenty_questions.anxiety'}}
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step12.anxiety stepName='step12.anxiety' itemType='peculiarities' }}
</div>
<div>
<label>
@@ -449,18 +421,12 @@
{{localize 'l5r5e.twenty_questions.or'}}
<label>
{{localize 'l5r5e.twenty_questions.advant'}}
<textarea name="step13.advantage">{{data.step13.advantage}}</textarea>
</label>
<!-- TODO Drag n drop advantage-->
{{localize 'l5r5e.twenty_questions.advant'}}
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step13.advantage stepName='step13.advantage' itemType='peculiarities' }}
</div>
<div>
<label>
{{localize 'l5r5e.twenty_questions.disadvant'}}
<textarea name="step13.disadvantage">{{data.step13.disadvantage}}</textarea>
</label>
<!-- TODO Drag n drop disadvantage-->
{{localize 'l5r5e.twenty_questions.disadvant'}}
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step13.disadvantage stepName='step13.disadvantage' itemType='peculiarities' }}
</div>
</div>
@@ -474,8 +440,7 @@
<label>
{{localize 'l5r5e.twenty_questions.accoutr'}}
<textarea name="step14.special_features">{{data.step14.special_features}}</textarea>
<!-- TODO Drag n drop equipment ? -->
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step14.special_features stepName='step14.special_features' itemType='items' }}
</label>
</div>
<div>
@@ -492,8 +457,7 @@
<label>
{{localize 'l5r5e.twenty_questions.object'}}
<textarea name="step16.item">{{data.step16.item}}</textarea>
<!-- TODO Drag n drop item-->
{{> 'systems/l5r5e/templates/actors/character/twenty-questions-item.html' itemsList=cache.step16.item stepName='step16.item' itemType='items' }}
</label>
</div>