sorting with local and npc fix

This commit is contained in:
Vlyan
2022-02-10 19:27:41 +01:00
parent 39129ddd6f
commit c0c3f13a46
4 changed files with 53 additions and 20 deletions

View File

@@ -196,7 +196,11 @@ export class DicePickerDialog extends FormApplication {
}
this.object.skill.list = this.parseSkillsList(skillsList);
if (this.object.skill.list.length > 0) {
this.skillId = this.object.skill.list[0];
if (this.actorIsPc) {
this.skillId = this.object.skill.list[0].id;
} else {
this.skillCatId = this.object.skill.list[0].id;
}
}
}
@@ -348,7 +352,11 @@ export class DicePickerDialog extends FormApplication {
html.find("select[name=skill]").on("change", async (event) => {
event.preventDefault();
event.stopPropagation();
this.skillId = event.target.value;
if (this.actorIsPc) {
this.skillId = event.target.value;
} else {
this.skillCatId = event.target.value;
}
this.render(false);
});
@@ -728,20 +736,34 @@ export class DicePickerDialog extends FormApplication {
*/
parseSkillsList(skillList) {
const categories = game.l5r5e.HelpersL5r5e.getCategoriesSkillsList();
const out = new Set();
// Sanitize and uniques values
const unqSkillList = new Set();
skillList.split(",").forEach((s) => {
s = s.trim();
if (CONFIG.l5r5e.skills.has(s)) {
out.add(this.actorIsPc ? s : CONFIG.l5r5e.skills.get(s));
unqSkillList.add(this.actorIsPc ? s : CONFIG.l5r5e.skills.get(s));
} else if (categories.has(s)) {
if (this.actorIsPc) {
categories.get(s).forEach((e) => out.add(e));
categories.get(s).forEach((e) => unqSkillList.add(e));
} else {
out.add(s);
unqSkillList.add(s);
}
}
});
return [...out];
// Sort by the translated label
const array = [...unqSkillList].map((id) => {
return {
id: id,
label: this.actorIsPc
? game.i18n.localize(`l5r5e.skills.${CONFIG.l5r5e.skills.get(id)}.${id}`)
: game.i18n.localize(`l5r5e.skills.${id}.title`),
};
});
array.sort((a, b) => a.label.localeCompare(b.label));
return array;
}
}

File diff suppressed because one or more lines are too long

View File

@@ -95,6 +95,7 @@
}
select {
text-align: center;
width: 134px;
}
img {

View File

@@ -23,14 +23,22 @@
{{#if data.skill.list}}
{{#if actorIsPc}}
<label>{{localizeSkill data.skill.cat 'title'}}</label>
<select class="attribute-dtype" name="skill">
{{#select data.skill.id}}
{{#each data.skill.list as |item|}}
<option value="{{item.id}}">{{item.label}}</option>
{{/each}}
{{/select}}
</select>
{{else}}
<select class="attribute-dtype" name="skill">
{{#select data.skill.cat}}
{{#each data.skill.list as |item|}}
<option value="{{item.id}}">{{item.label}}</option>
{{/each}}
{{/select}}
</select>
{{/if}}
<select class="attribute-dtype" name="skill">
{{#select data.skill.id}}
{{#each data.skill.list as |id|}}
<option value="{{id}}">{{localizeSkillId id}}</option>
{{/each}}
{{/select}}
</select>
{{else}}
<label>{{localizeSkill data.skill.cat 'title'}}</label>
{{#if actorIsPc}}
@@ -39,11 +47,13 @@
</div>
{{/if}}
{{/if}}
<label id="stance_label">{{localizeSkill data.skill.cat data.ring.id}}</label>
<div id="skill_default_value" class="dice-container pointer-choice">
<img src="systems/l5r5e/assets/dices/default/skill_blank.svg" alt="1">
<div class="dice-value">
<span class="dice-skill" type="text" name="skill_{{data.skill.name}}">{{data.skill.defaultValue}}</span>
<div>
<label id="stance_label">{{localizeSkill data.skill.cat data.ring.id}}</label>
<div id="skill_default_value" class="dice-container pointer-choice">
<img src="systems/l5r5e/assets/dices/default/skill_blank.svg" alt="1">
<div class="dice-value">
<span class="dice-skill" type="text" name="skill_{{data.skill.name}}">{{data.skill.defaultValue}}</span>
</div>
</div>
</div>
{{else}}