fix tech sheet

This commit is contained in:
Vlyan
2023-03-15 15:01:40 +01:00
parent 823b883d4e
commit a24e775001
8 changed files with 81 additions and 46 deletions

View File

@@ -4,6 +4,7 @@ Date format : day/month/year
## 2.0.0 - xx/xx/2023 - Skill list
- Skills are now items, this can break things update with caution. Save before upgrading !
- Added a new dialog settings to configure default skills list.
- Fix lists not showing correctly in journal (#44 thx to Bragma).
## 1.9.4 - 31/12/2022 - Last bugfixes of the Year !
- Fix prepared settings bugs (trackers icons sometimes disappears).

View File

@@ -90,7 +90,7 @@ export class ActorL5r5e extends Actor {
static async addSkillsFromDefaultList(docData) {
console.log(`L5R5E | Adding default skills to ${docData.name}`);
const skillList = await game.l5r5e.HelpersL5r5e.getDefaultSkillsItems();
const skillList = await game.l5r5e.HelpersL5r5e.getSkillsItemsList();
skillList.forEach(item => {
// Get the json data and replace the object id/rank

View File

@@ -110,7 +110,7 @@ export class DicePickerDialog extends FormApplication {
* ex: new game.l5r5e.DicePickerDialog({skillId: 'aesthetics', ringId: 'water', actor: game.user.character}).render(true);
*
* Options :
* actor {Actor} Any `Actor` object instance. Ex : `game.user.character`, `canvas.tokens.controlled[0].actor`
* actor {ActorL5r5e} Any `Actor` object instance. Ex : `game.user.character`, `canvas.tokens.controlled[0].actor`
* actorId {string} This is the `id` not the `uuid` of an actor. Ex : "AbYgKrNwWeAxa9jT"
* actorName {string} Careful this is case-sensitive. Ex : "Isawa Aki"
* difficulty {number} `1` to `9`
@@ -274,19 +274,21 @@ export class DicePickerDialog extends FormApplication {
if (!skillsList) {
return;
}
this.object.skill.list = this.parseSkillsList(skillsList);
if (this.object.skill.list.length > 0) {
// Set 1st skill
if (this.useCategory) {
this.skillCatId = this.object.skill.list[0].id;
} else {
this.skillId = this.object.skill.list[0].id;
this.parseSkillsList(skillsList).then((list) => {
this.object.skill.list = list;
if (this.object.skill.list.length > 0) {
// Set 1st skill
if (this.useCategory) {
this.skillCatId = this.object.skill.list[0].id;
} else {
this.skillId = this.object.skill.list[0].id;
}
// Remove the list if only one item
if (this.object.skill.list.length === 1) {
this.object.skill.list = null;
}
}
// Remove the list if only one item
if (this.object.skill.list.length === 1) {
this.object.skill.list = null;
}
}
});
}
/**
@@ -833,10 +835,10 @@ export class DicePickerDialog extends FormApplication {
* NPC : shrink to category names
*
* @param {string} skillList
* @return {string[]}
* @returns {Promise<{id: *, label: string}[]>}
*/
parseSkillsList(skillList) {
const categories = game.l5r5e.HelpersL5r5e.getCategoriesSkillsList();
async parseSkillsList(skillList) {
const categories = await game.l5r5e.HelpersL5r5e.getCategoriesSkillsList();
// Sanitize and uniques values
const unqSkillList = new Set();

View File

@@ -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

View File

@@ -9,7 +9,7 @@ export class ItemL5r5e extends Item {
/**
* Return the linked Actor instance if any (current or embed)
* @return {Actor|null}
* @return {ActorL5r5e|null}
*/
get actor() {
return super.actor || game.actors.get(this.system.parent_id?.actor_id) || null;
@@ -61,7 +61,11 @@ export class ItemL5r5e extends Item {
*/
static async create(data, context = {}) {
if (data.img === undefined) {
data.img = `${CONFIG.l5r5e.paths.assets}icons/items/${data.type}.svg`;
if (data.type === 'technique') {
data.img = `${CONFIG.l5r5e.paths.assets}icons/techs/kata.svg`;
} else {
data.img = `${CONFIG.l5r5e.paths.assets}icons/items/${data.type}.svg`;
}
}
return super.create(data, context);
}

View File

@@ -29,7 +29,7 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e {
// Sanitize Difficulty and Skill list
sheetData.data.system.difficulty = TechniqueSheetL5r5e.formatDifficulty(sheetData.data.system.difficulty);
sheetData.data.system.skill = TechniqueSheetL5r5e.translateSkillsList(
TechniqueSheetL5r5e.formatSkillList(sheetData.data.system.skill.split(",")),
await TechniqueSheetL5r5e.formatSkillList(sheetData.data.system.skill.split(",")),
false
).join(", ");
@@ -54,9 +54,9 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e {
// Sanitize Difficulty and Skill list
formData["system.difficulty"] = TechniqueSheetL5r5e.formatDifficulty(formData["system.difficulty"]);
formData["system.skill"] = TechniqueSheetL5r5e.formatSkillList(
formData["system.skill"] = (await TechniqueSheetL5r5e.formatSkillList(
TechniqueSheetL5r5e.translateSkillsList(formData["system.skill"].split(","), true)
).join(",");
)).join(",");
return super._updateObject(event, formData);
}
@@ -143,13 +143,13 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e {
/**
* Sanitize the technique skill list
* @param {string[]} skillList
* @return {string[]}
* @returns {Promise<string|*[]>}
*/
static formatSkillList(skillList) {
static async formatSkillList(skillList) {
if (!skillList) {
return "";
}
const categories = game.l5r5e.HelpersL5r5e.getCategoriesSkillsList();
const categories = await game.l5r5e.HelpersL5r5e.getCategoriesSkillsList(this.actor);
// List categories
const unqCatList = new Set();

View File

@@ -56,7 +56,7 @@ export class DefaultSkillsDialogL5r5e extends FormApplication {
*/
async getData(options = null) {
// Transform skills uuids to items by categories
let skillList = await game.l5r5e.HelpersL5r5e.getDefaultSkillsItems();
let skillList = await game.l5r5e.HelpersL5r5e.getSkillsItemsList();
skillList = game.l5r5e.HelpersL5r5e.splitSkillByCategory(skillList);
return {

View File

@@ -118,9 +118,9 @@ export class SocketHandlerL5r5e {
* }
* });
*
* @param {User[]} users Users list to trigger the DP (will be reduce to id for network perf.)
* @param {Actor[]} actors Actors list to trigger the DP (will be reduce to uuid for network perf.)
* @param {Object} dpOptions Any DicePickerDialog.options
* @param {User[]} users Users list to trigger the DP (will be reduced to id for network perf.)
* @param {ActorL5r5e[]} actors Actors list to trigger the DP (will be reduced to uuid for network perf.)
* @param {Object} dpOptions Any DicePickerDialog.options
*/
openDicePicker({ users = [], actors = [], dpOptions = {} }) {
// At least one user or one actor