fix tech sheet
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
export class HelpersL5r5e {
|
||||
/**
|
||||
* Get Rings/Element for List / Select
|
||||
* @param {Actor|null} actor
|
||||
* @param {ActorL5r5e|null} actor
|
||||
* @return {{id: string, label: *, value}[]}
|
||||
*/
|
||||
static getRingsList(actor = null) {
|
||||
@@ -24,19 +24,41 @@ export class HelpersL5r5e {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return default skill items list
|
||||
* Return the skill items list for this actor or from the default (settings)
|
||||
* @param {ActorL5r5e} actor If actor provided, get the skills preferably from it
|
||||
* @returns {Promise<Item[]>}
|
||||
*/
|
||||
static async getDefaultSkillsItems() {
|
||||
let skillList = game.settings.get(CONFIG.l5r5e.systemName, "defaultSkillsList") || [];
|
||||
static async getSkillsItemsList(actor = null) {
|
||||
const skillList = [];
|
||||
|
||||
// If empty, refill with default values
|
||||
if (foundry.utils.isEmpty(skillList)) {
|
||||
skillList = HelpersL5r5e.getDefaultSkillsUuidFromPack();
|
||||
await game.settings.set(CONFIG.l5r5e.systemName, "defaultSkillsList", skillList);
|
||||
// If actor provided, get the skills preferably from it
|
||||
if (actor instanceof Actor && actor?.isCharacter) {
|
||||
actor.items
|
||||
.filter(item => item.type === "skill")
|
||||
.forEach(item => skillList.push(item))
|
||||
}
|
||||
|
||||
return await Promise.all(skillList.map(async uuid => await fromUuid(uuid)));
|
||||
// Get the default list from settings
|
||||
let defaultList = game.settings.get(CONFIG.l5r5e.systemName, "defaultSkillsList") || [];
|
||||
|
||||
// If empty, refill with default values
|
||||
if (foundry.utils.isEmpty(defaultList)) {
|
||||
defaultList = HelpersL5r5e.getDefaultSkillsUuidFromPack();
|
||||
await game.settings.set(CONFIG.l5r5e.systemName, "defaultSkillsList", defaultList);
|
||||
}
|
||||
|
||||
defaultList = await Promise.all(defaultList.map(async uuid => await fromUuid(uuid)));
|
||||
|
||||
|
||||
// Merge the two list by name
|
||||
const namesList = skillList.map(item => item.name);
|
||||
defaultList.forEach(item => {
|
||||
if (item && !namesList.includes(item.name)) {
|
||||
skillList.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
return skillList;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,19 +116,25 @@ export class HelpersL5r5e {
|
||||
|
||||
/**
|
||||
* Return Categories and Skill names in it
|
||||
* @return {Map}
|
||||
* @param {ActorL5r5e} actor If actor provided, get the skills preferably from it
|
||||
* @returns {Promise<Map>}
|
||||
*/
|
||||
static getCategoriesSkillsList() {
|
||||
console.warn('@deprecated hardcoded skills - helpers.getCategoriesSkillsList()'); // TODO @deprecated hardcoded skills
|
||||
static async getCategoriesSkillsList(actor = null) {
|
||||
const skillList = await HelpersL5r5e.getSkillsItemsList(actor);
|
||||
const acc = new Map();
|
||||
|
||||
skillList.forEach((item) => {
|
||||
const id = item.name;
|
||||
const cat = item.system.category;
|
||||
|
||||
return Array.from(CONFIG.l5r5e.skills).reduce((acc, [id, cat]) => {
|
||||
if (acc.has(cat)) {
|
||||
acc.set(cat, [...acc.get(cat), id]);
|
||||
} else {
|
||||
acc.set(cat, [id]);
|
||||
}
|
||||
return acc;
|
||||
}, new Map());
|
||||
});
|
||||
|
||||
return acc;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -495,8 +523,8 @@ export class HelpersL5r5e {
|
||||
|
||||
/**
|
||||
* Subscribe to common events from the sheet.
|
||||
* @param {jQuery} html HTML content of the sheet.
|
||||
* @param {Actor} actor Actor Object
|
||||
* @param {jQuery} html HTML content of the sheet.
|
||||
* @param {ActorL5r5e} actor Actor Object
|
||||
*/
|
||||
static commonListeners(html, actor = null) {
|
||||
// Toggle
|
||||
|
||||
Reference in New Issue
Block a user