From 40fa05d02b4db365bc97d17018d9a889499a6691 Mon Sep 17 00:00:00 2001 From: Melon-PieldeSapo Date: Sun, 31 Aug 2025 00:21:25 +0200 Subject: [PATCH 1/3] Error handling for skills drop on class sheet --- lang/en.json | 6 +++++- lang/pt-BR.json | 6 +++++- module/item/class-sheet.js | 22 ++++++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lang/en.json b/lang/en.json index bbf7592..543dacc 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1136,6 +1136,10 @@ "Hull": "Hull", "Modules": "Modules", "DeckPlan": "Deck Plan", - "Stock": "Stock" + "Stock": "Stock", + "Errors":{ + "SkillAlreadyInList":"This skill is already in the list.", + "NoDropTarget":"Something went wrong with the drop, please try again." + } } } diff --git a/lang/pt-BR.json b/lang/pt-BR.json index a78c497..c2741b7 100644 --- a/lang/pt-BR.json +++ b/lang/pt-BR.json @@ -1136,6 +1136,10 @@ "Hull": "Casco", "Modules": "módulos", "DeckPlan": "Planta do Convés", - "Stock": "Stock" + "Stock": "Stock", + "Errors":{ + "SkillAlreadyInList":"Essa habilidade já está na lista.", + "NoDropTarget":"Algo deu errado com o drop, tente novamente" + } } } diff --git a/module/item/class-sheet.js b/module/item/class-sheet.js index 6b3c137..46dd294 100644 --- a/module/item/class-sheet.js +++ b/module/item/class-sheet.js @@ -72,7 +72,10 @@ export class MothershipClassSheet extends MothershipItemSheet { const droppedObject = await fromUuid(droppedUuid.uuid); if (droppedObject.type == "skill"){ - //todo: add a check if the skill already exist in the list and dont add it, (by id or by name?) + if(event.currentTarget == null) { + ui.notifications.error(game.i18n.localize("Mosh.Errors.NoDropTarget")); + return this.render(false); + } console.log(event.currentTarget.id); if(event.currentTarget.id == "skills.fixed"){ let parent_fixed_or = event.target.closest('div[id="skills.fixed.or"]'); @@ -80,12 +83,20 @@ export class MothershipClassSheet extends MothershipItemSheet { if(parent_fixed_or){ let array_index = parent_fixed_or.getAttribute("index"); let skills = this.object.system.base_adjustment.skills_granted; + if(skills[array_index].includes(droppedObject.uuid)){ + ui.notifications.warn(game.i18n.localize("Mosh.Errors.SkillAlreadyInList")); + return this.render(false); + } skills[array_index].push(droppedObject.uuid); this.object.update({"system.base_adjustment.skills_granted":skills}); return this.render(false); }else{ let skills = this.object.system.base_adjustment.skills_granted; + if (skills.includes(droppedObject.uuid)){ + ui.notifications.warn(game.i18n.localize("Mosh.Errors.SkillAlreadyInList")); + return this.render(false); + } skills.push(droppedObject.uuid); this.object.update({"system.base_adjustment.skills_granted":skills}); return this.render(false); @@ -93,6 +104,10 @@ export class MothershipClassSheet extends MothershipItemSheet { } else if(event.currentTarget.id =="skills.common"){ let skills = this.object.system.common_skills; + if (skills.includes(droppedObject.uuid)){ + ui.notifications.warn(game.i18n.localize("Mosh.Errors.SkillAlreadyInList")); + return this.render(false); + } skills.push(droppedObject.uuid); this.object.update({"system.common_skills":skills}); return this.render(false); @@ -104,7 +119,10 @@ export class MothershipClassSheet extends MothershipItemSheet { let parent_index = parent.data("itemId"); let options = this.object.system.selected_adjustment.choose_skill_or; - + if(options[parent_index][index].from_list.includes(droppedObject.uuid)){ + ui.notifications.warn(game.i18n.localize("Mosh.Errors.SkillAlreadyInList")); + return this.render(false); + } options[parent_index][index].from_list.push(droppedObject.uuid); this.object.update({"system.selected_adjustment.choose_skill_or":options}); From c83c1cbb0093a6896db47ce7c5bf00a84ecd15e7 Mon Sep 17 00:00:00 2001 From: Melon-PieldeSapo Date: Sun, 31 Aug 2025 12:07:06 +0200 Subject: [PATCH 2/3] Add formatCreditsNumber function for future usage --- module/mosh.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/module/mosh.js b/module/mosh.js index 3048626..2690ee6 100644 --- a/module/mosh.js +++ b/module/mosh.js @@ -654,4 +654,30 @@ export async function fromIdUuid(id_uuid, options={}){ return game.macros.filter(i=> i.id == macroId)[0]; } +} + +/** + * This function will format a number into a more readable string with appropriate suffixes. + * For example, 1500 becomes "1.5K", 2000000 becomes "2M", etc. + * It handles numbers in the trillions (t), billions (b), millions (m), and thousands (k). + * It also handles negative numbers and zero. + * At the end it appends 'cr' to denote credits. + * @namespace formatCreditsNumber + * @param {int} num Credits number to format. + * @returns {string} Credits , formatted string with appropriate suffix. + */ +export function formatCreditsNumber(num) { + const absNum = Math.abs(num); + + if (absNum >= 1_000_000_000_000) { + return (num / 1_000_000_000_000).toFixed(1).replace(/\.0$/, '') + 'tcr'; + } else if (absNum >= 1_000_000_000) { + return (num / 1_000_000_000).toFixed(1).replace(/\.0$/, '') + 'bcr'; + } else if (absNum >= 1_000_000) { + return (num / 1_000_000).toFixed(1).replace(/\.0$/, '') + 'mcr'; + } else if (absNum >= 1_000) { + return (num / 1_000).toFixed(1).replace(/\.0$/, '') + 'kcr'; + } else { + return num.toString() + 'cr'; + } } \ No newline at end of file From 664f373e1d9b24add88acdf0d04898fd463f62af Mon Sep 17 00:00:00 2001 From: Melon-PieldeSapo Date: Sun, 31 Aug 2025 12:17:05 +0200 Subject: [PATCH 3/3] Remove error msg when dice-so-nice was not installed --- module/actor/actor.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/actor/actor.js b/module/actor/actor.js index 3edd98f..7681618 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -915,7 +915,7 @@ export class MothershipActor extends Actor { }, { keepId: true }); - if (game.modules.get("dice-so-nice").active) { + if (game.modules.get("dice-so-nice") && game.modules.get("dice-so-nice").active) { //log what was done console.log(`Rolled on table ID: ${tableId}, with: rollString:${rollString}, aimFor:${aimFor}, zeroBased:${zeroBased}, checkCrit:${checkCrit}, rollAgainst:${rollAgainst}, comparison:${comparison}`); //return messageData @@ -1895,7 +1895,7 @@ export class MothershipActor extends Actor { keepId: true }); //is DSN active? - if (game.modules.get("dice-so-nice").active) { + if (game.modules.get("dice-so-nice") && game.modules.get("dice-so-nice").active) { //log what was done console.log(`Rolled a check on: ${attribute}, with: rollString:${rollString}, aimFor:${aimFor}, skill:${skill}, skillValue:${skillValue}.`); //return messageData @@ -2235,7 +2235,7 @@ export class MothershipActor extends Actor { }, { keepId: true }); - if (game.modules.get("dice-so-nice").active) { + if (game.modules.get("dice-so-nice") && game.modules.get("dice-so-nice").active) { //log what was done console.log(`Modified actor: ${this.name}, with: fieldAddress:${fieldAddress}, modValue:${modValue}, modRollString:${modRollString}, outputChatMsg:${outputChatMsg}`); //return modification values