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 ## 2.0.0 - xx/xx/2023 - Skill list
- Skills are now items, this can break things update with caution. Save before upgrading ! - Skills are now items, this can break things update with caution. Save before upgrading !
- Added a new dialog settings to configure default skills list. - 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 ! ## 1.9.4 - 31/12/2022 - Last bugfixes of the Year !
- Fix prepared settings bugs (trackers icons sometimes disappears). - Fix prepared settings bugs (trackers icons sometimes disappears).

View File

@@ -90,7 +90,7 @@ export class ActorL5r5e extends Actor {
static async addSkillsFromDefaultList(docData) { static async addSkillsFromDefaultList(docData) {
console.log(`L5R5E | Adding default skills to ${docData.name}`); 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 => { skillList.forEach(item => {
// Get the json data and replace the object id/rank // 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); * ex: new game.l5r5e.DicePickerDialog({skillId: 'aesthetics', ringId: 'water', actor: game.user.character}).render(true);
* *
* Options : * 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" * actorId {string} This is the `id` not the `uuid` of an actor. Ex : "AbYgKrNwWeAxa9jT"
* actorName {string} Careful this is case-sensitive. Ex : "Isawa Aki" * actorName {string} Careful this is case-sensitive. Ex : "Isawa Aki"
* difficulty {number} `1` to `9` * difficulty {number} `1` to `9`
@@ -274,19 +274,21 @@ export class DicePickerDialog extends FormApplication {
if (!skillsList) { if (!skillsList) {
return; return;
} }
this.object.skill.list = this.parseSkillsList(skillsList); this.parseSkillsList(skillsList).then((list) => {
if (this.object.skill.list.length > 0) { this.object.skill.list = list;
// Set 1st skill if (this.object.skill.list.length > 0) {
if (this.useCategory) { // Set 1st skill
this.skillCatId = this.object.skill.list[0].id; if (this.useCategory) {
} else { this.skillCatId = this.object.skill.list[0].id;
this.skillId = 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 * NPC : shrink to category names
* *
* @param {string} skillList * @param {string} skillList
* @return {string[]} * @returns {Promise<{id: *, label: string}[]>}
*/ */
parseSkillsList(skillList) { async parseSkillsList(skillList) {
const categories = game.l5r5e.HelpersL5r5e.getCategoriesSkillsList(); const categories = await game.l5r5e.HelpersL5r5e.getCategoriesSkillsList();
// Sanitize and uniques values // Sanitize and uniques values
const unqSkillList = new Set(); const unqSkillList = new Set();

View File

@@ -4,7 +4,7 @@
export class HelpersL5r5e { export class HelpersL5r5e {
/** /**
* Get Rings/Element for List / Select * Get Rings/Element for List / Select
* @param {Actor|null} actor * @param {ActorL5r5e|null} actor
* @return {{id: string, label: *, value}[]} * @return {{id: string, label: *, value}[]}
*/ */
static getRingsList(actor = null) { 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[]>} * @returns {Promise<Item[]>}
*/ */
static async getDefaultSkillsItems() { static async getSkillsItemsList(actor = null) {
let skillList = game.settings.get(CONFIG.l5r5e.systemName, "defaultSkillsList") || []; const skillList = [];
// If empty, refill with default values // If actor provided, get the skills preferably from it
if (foundry.utils.isEmpty(skillList)) { if (actor instanceof Actor && actor?.isCharacter) {
skillList = HelpersL5r5e.getDefaultSkillsUuidFromPack(); actor.items
await game.settings.set(CONFIG.l5r5e.systemName, "defaultSkillsList", skillList); .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 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() { static async getCategoriesSkillsList(actor = null) {
console.warn('@deprecated hardcoded skills - helpers.getCategoriesSkillsList()'); // TODO @deprecated hardcoded skills 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)) { if (acc.has(cat)) {
acc.set(cat, [...acc.get(cat), id]); acc.set(cat, [...acc.get(cat), id]);
} else { } else {
acc.set(cat, [id]); acc.set(cat, [id]);
} }
return acc; });
}, new Map());
return acc;
} }
/** /**
@@ -495,8 +523,8 @@ export class HelpersL5r5e {
/** /**
* Subscribe to common events from the sheet. * Subscribe to common events from the sheet.
* @param {jQuery} html HTML content of the sheet. * @param {jQuery} html HTML content of the sheet.
* @param {Actor} actor Actor Object * @param {ActorL5r5e} actor Actor Object
*/ */
static commonListeners(html, actor = null) { static commonListeners(html, actor = null) {
// Toggle // Toggle

View File

@@ -9,7 +9,7 @@ export class ItemL5r5e extends Item {
/** /**
* Return the linked Actor instance if any (current or embed) * Return the linked Actor instance if any (current or embed)
* @return {Actor|null} * @return {ActorL5r5e|null}
*/ */
get actor() { get actor() {
return super.actor || game.actors.get(this.system.parent_id?.actor_id) || null; 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 = {}) { static async create(data, context = {}) {
if (data.img === undefined) { 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); return super.create(data, context);
} }

View File

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

View File

@@ -56,7 +56,7 @@ export class DefaultSkillsDialogL5r5e extends FormApplication {
*/ */
async getData(options = null) { async getData(options = null) {
// Transform skills uuids to items by categories // 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); skillList = game.l5r5e.HelpersL5r5e.splitSkillByCategory(skillList);
return { 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 {User[]} users Users list to trigger the DP (will be reduced to id for network perf.)
* @param {Actor[]} actors Actors list to trigger the DP (will be reduce to uuid 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 * @param {Object} dpOptions Any DicePickerDialog.options
*/ */
openDicePicker({ users = [], actors = [], dpOptions = {} }) { openDicePicker({ users = [], actors = [], dpOptions = {} }) {
// At least one user or one actor // At least one user or one actor