20Q added a summary
Some language refactoring Allow toggle even without editing perm Fix DnD on school rank with npc as they don't have it
This commit is contained in:
@@ -109,7 +109,9 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
case "advancement": // no break
|
||||
case "peculiarity":
|
||||
// Modify the bought at rank to the current actor rank
|
||||
item.data.data.bought_at_rank = this.actor.data.data.identity.school_rank;
|
||||
if (this.actor.data.data.identity?.school_rank) {
|
||||
item.data.data.bought_at_rank = this.actor.data.data.identity.school_rank;
|
||||
}
|
||||
break;
|
||||
|
||||
case "technique":
|
||||
@@ -161,7 +163,9 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
}
|
||||
|
||||
// Modify the bought at rank to the current actor rank
|
||||
item.data.data.bought_at_rank = this.actor.data.data.identity.school_rank;
|
||||
if (this.actor.data.data.identity?.school_rank) {
|
||||
item.data.data.bought_at_rank = this.actor.data.data.identity.school_rank;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -180,6 +184,13 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// Toggle
|
||||
html.find(".toggle-on-click").on("click", (event) => {
|
||||
const elmt = $(event.currentTarget).data("toggle");
|
||||
const tgt = html.find("." + elmt);
|
||||
tgt.hasClass("toggle-active") ? tgt.removeClass("toggle-active") : tgt.addClass("toggle-active");
|
||||
});
|
||||
|
||||
// *** Everything below here is only needed if the sheet is editable ***
|
||||
if (!this.options.editable) {
|
||||
return;
|
||||
@@ -201,13 +212,6 @@ export class BaseSheetL5r5e extends ActorSheet {
|
||||
event.target.select();
|
||||
});
|
||||
|
||||
// Toggle
|
||||
html.find(".toggle-on-click").on("click", (event) => {
|
||||
const elmt = $(event.currentTarget).data("toggle");
|
||||
const tgt = html.find("." + elmt);
|
||||
tgt.hasClass("toggle-active") ? tgt.removeClass("toggle-active") : tgt.addClass("toggle-active");
|
||||
});
|
||||
|
||||
// *** Items : add, edit, delete ***
|
||||
html.find(".item-add").on("click", (event) => {
|
||||
this._addSubItem(event);
|
||||
|
||||
@@ -13,9 +13,15 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
actor = null;
|
||||
|
||||
/**
|
||||
* Errors
|
||||
* Summary & Errors
|
||||
*/
|
||||
errors = [];
|
||||
summary = {
|
||||
errors: [],
|
||||
summary: {
|
||||
rings: [],
|
||||
skills: [],
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Cache for items (techniques, adv...)
|
||||
@@ -68,7 +74,7 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
super({}, options);
|
||||
this.actor = actor;
|
||||
this.object = new TwentyQuestions(actor);
|
||||
this.errors = this.object.validateForm();
|
||||
this.summary = this.object.validateForm();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,8 +130,10 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
techniquesList: CONFIG.l5r5e.techniques,
|
||||
data: this.object.data,
|
||||
cache: this.cache,
|
||||
errors: this.errors.join(", "),
|
||||
hasErrors: this.errors.length > 0,
|
||||
summary: {
|
||||
...this.summary,
|
||||
errors: this.summary.errors.join(", "),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -136,6 +144,13 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// Toggle
|
||||
html.find(".toggle-on-click").on("click", (event) => {
|
||||
const elmt = $(event.currentTarget).data("toggle");
|
||||
const tgt = html.find("." + elmt);
|
||||
tgt.hasClass("toggle-active") ? tgt.removeClass("toggle-active") : tgt.addClass("toggle-active");
|
||||
});
|
||||
|
||||
// *** Everything below here is only needed if the sheet is editable ***
|
||||
if (!this.options.editable) {
|
||||
return;
|
||||
@@ -288,8 +303,8 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
// Update 20Q object data
|
||||
this.object.updateFromForm(formData);
|
||||
|
||||
// Get errors if any
|
||||
this.errors = this.object.validateForm();
|
||||
// Get errors if any, and redo summary table
|
||||
this.summary = this.object.validateForm();
|
||||
|
||||
// Store this form datas in actor
|
||||
this.actor.data.data.twenty_questions = this.object.data;
|
||||
|
||||
@@ -287,33 +287,56 @@ export class TwentyQuestions {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a array of errors, empty array if no errors founds
|
||||
* Return summary and errors if any
|
||||
*/
|
||||
validateForm() {
|
||||
const errors = [];
|
||||
const out = {
|
||||
errors: [],
|
||||
summary: {
|
||||
rings: [],
|
||||
skills: [],
|
||||
},
|
||||
};
|
||||
|
||||
// Rings & Skills, 3pt max for each
|
||||
const rings = this._checkRingsOrSkills("ringList", 2); // ring start at 1
|
||||
const rings = this._summariesRingsOrSkills("ringList");
|
||||
for (const key in rings) {
|
||||
errors.push(`${game.i18n.localize("l5r5e.rings." + key)} (${rings[key]})`);
|
||||
// ring start at 1
|
||||
rings[key] = rings[key] + 1;
|
||||
const label = `${game.i18n.localize("l5r5e.rings." + key)} (${rings[key]})`;
|
||||
if (rings[key] > 3) {
|
||||
out.errors.push(label);
|
||||
}
|
||||
out.summary.rings.push(label);
|
||||
}
|
||||
|
||||
const skills = this._checkRingsOrSkills("skillList", 3); // skill start at 0
|
||||
const skills = this._summariesRingsOrSkills("skillList");
|
||||
for (const key in skills) {
|
||||
errors.push(
|
||||
`${game.i18n.localize("l5r5e.skills." + CONFIG.l5r5e.skills.get(key) + "." + key)} (${skills[key]})`
|
||||
);
|
||||
// skill start at 0
|
||||
const label = `${game.i18n.localize("l5r5e.skills." + CONFIG.l5r5e.skills.get(key) + "." + key)} (${
|
||||
skills[key]
|
||||
})`;
|
||||
if (rings[key] > 3) {
|
||||
out.errors.push(label);
|
||||
}
|
||||
out.summary.skills.push(label);
|
||||
}
|
||||
|
||||
return errors;
|
||||
out.summary.rings.sort((a, b) => {
|
||||
return a.localeCompare(b);
|
||||
});
|
||||
out.summary.skills.sort((a, b) => {
|
||||
return a.localeCompare(b);
|
||||
});
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of exceeded ring/skill
|
||||
* Return a list of ring/skill
|
||||
*/
|
||||
_checkRingsOrSkills(listName, max) {
|
||||
_summariesRingsOrSkills(listName) {
|
||||
const store = {};
|
||||
const exceed = {};
|
||||
TwentyQuestions[listName].forEach((formName) => {
|
||||
const id = getProperty(this.data, formName);
|
||||
if (!id || id === "none") {
|
||||
@@ -323,10 +346,7 @@ export class TwentyQuestions {
|
||||
store[id] = 0;
|
||||
}
|
||||
store[id] = store[id] + 1;
|
||||
if (store[id] > max) {
|
||||
exceed[id] = store[id];
|
||||
}
|
||||
});
|
||||
return exceed;
|
||||
return store;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,13 @@ export class ItemSheetL5r5e extends ItemSheet {
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// Toggle
|
||||
html.find(".toggle-on-click").on("click", (event) => {
|
||||
const elmt = $(event.currentTarget).data("toggle");
|
||||
const tgt = html.find("." + elmt);
|
||||
tgt.hasClass("toggle-active") ? tgt.removeClass("toggle-active") : tgt.addClass("toggle-active");
|
||||
});
|
||||
|
||||
// Everything below here is only needed if the sheet is editable
|
||||
if (!this.options.editable) {
|
||||
return;
|
||||
@@ -93,13 +100,6 @@ export class ItemSheetL5r5e extends ItemSheet {
|
||||
event.target.select();
|
||||
});
|
||||
|
||||
// Toggle
|
||||
html.find(".toggle-on-click").on("click", (event) => {
|
||||
const elmt = $(event.currentTarget).data("toggle");
|
||||
const tgt = html.find("." + elmt);
|
||||
tgt.hasClass("toggle-active") ? tgt.removeClass("toggle-active") : tgt.addClass("toggle-active");
|
||||
});
|
||||
|
||||
// Delete a property
|
||||
html.find(`.property-delete`).on("click", (event) => {
|
||||
const li = $(event.currentTarget).parents(".property");
|
||||
|
||||
Reference in New Issue
Block a user