From 0d897cff137ea21b636d215db2be035303fa572f Mon Sep 17 00:00:00 2001 From: Eunomiac Date: Sun, 29 Oct 2023 04:26:44 -0400 Subject: [PATCH] SonarCloud fixes to BladesRoll.ts --- VSC Workspace.lnk | Bin 0 -> 1881 bytes module/BladesRoll.js | 84 ++++++++++++-------------------------- ts/BladesRoll.ts | 95 ++++++++++++------------------------------- 3 files changed, 50 insertions(+), 129 deletions(-) create mode 100644 VSC Workspace.lnk diff --git a/VSC Workspace.lnk b/VSC Workspace.lnk new file mode 100644 index 0000000000000000000000000000000000000000..9e969d1331d5797a5669a2637cef923786aee920 GIT binary patch literal 1881 zcmbtVZD<>19RFo@)=sTgXiKJbYl|qhOHDTCw$tfsZdqn))0ZSS%GE8soV06_iNflV=^p=&=q_EaiTcz_uO4x8XXEg$MgR` z&)t*X@BjLwAAqNM86|MemI%E|-Ol;ZYi~U`ow?-s)q3a5!z(U(`ewcwx>iqJ?;P|v zsw_{|HDmSQeB{gaMR`&>dg&H)`~8Pk;sHh0%7-e8y$INw+32li6Jj~T${~pc)ZwR3 zUye+N$JD|@Jv`C-*xi&jm47JPt5;WdBZeFdSd_pP$_egLeAZztdWa>~YvAK9fQ_8% zc&-@(F7HCzd{)A6F_8gem$z%^%4~`E`~9nU-u2by6yl`?1;Z#J0sf3=`(3o#)o;3* zphSYPC%5jSV<{K${?O#965@|Fh`l!IcXP*~z=Vzh()1vM{D1Oj12(`<1TRKi8)Wr^ zsDwew+->N22Bp`v;git%6JzRnJDT|x;n8h2b47GdT)-eBX<|1m&|M3>c*;c{RlPeU zbZ`VC!n=@*yl-H|Xvw?fzX`mnHC3^;)92}c^8^v0r`wrI7@r9Jc|!AKDbtIAdNOS~;C!C@#>l^lDe%y6Ya zFgzzj)oA~Ez6!0GJ~)>D9N#n~Ay>@hjdYGRUb47?ciy)6VilHHF1Ma%4HY@_v@~tk zQ!Ac!QTx>54hcpfW9EG0sYKFXtvumk`(yXMKc>DYi_Uv{v5~S%09K90^P=lSyiMZz zFwS@-7<PDO#4LjXK}K?wPaHZJdHdXeZjh z8LnG61@YpaE%OrfXb zbF-;c$A8J@pTpEi$F%?L{!W&eOq|NqsgZtpVL4Z6I5NSH}-RvlbjF_nbbhiHDoB#HGD=`~@Bb%rLBZDKSThq#^1KIG2@RpuqoAwDl({p_<9C+sUHyS=$5bsOlFQ=)5`2YX_ literal 0 HcmV?d00001 diff --git a/module/BladesRoll.js b/module/BladesRoll.js index 5c34fdc6..ae82062b 100644 --- a/module/BladesRoll.js +++ b/module/BladesRoll.js @@ -1232,7 +1232,7 @@ class BladesRoll extends DocumentSheet { const userFlagData = {}; Object.entries(userIDs) .forEach(([rollPermission, idsArray]) => { - for (const id in idsArray) { + for (const id of idsArray) { userFlagData[id] = rollPermission; } }); @@ -1257,7 +1257,7 @@ class BladesRoll extends DocumentSheet { const userFlagData = {}; Object.entries(userIDs) .forEach(([rollPermission, idsArray]) => { - for (const id in idsArray) { + for (const id of idsArray) { userFlagData[id] = rollPermission; } }); @@ -1280,7 +1280,7 @@ class BladesRoll extends DocumentSheet { const userFlagData = {}; Object.entries(userIDs) .forEach(([rollPermission, idsArray]) => { - for (const id in idsArray) { + for (const id of idsArray) { userFlagData[id] = rollPermission; } }); @@ -1309,7 +1309,7 @@ class BladesRoll extends DocumentSheet { const userFlagData = {}; Object.entries(userIDs) .forEach(([rollPermission, idsArray]) => { - for (const id in idsArray) { + for (const id of idsArray) { userFlagData[id] = rollPermission; } }); @@ -1358,12 +1358,12 @@ class BladesRoll extends DocumentSheet { if (!BladesRollPrimary.IsValidData(rollPrimaryData)) { throw new Error("[BladesRoll.NewRoll()] A valid source of PrimaryDocData must be provided to construct a roll."); } - const rollID = randomID(); + const rID = randomID(); let userIDs; let flagUpdateData; switch (config.rollType) { case RollType.Action: { - ({ userIDs, flagUpdateData } = await BladesRoll.PrepareActionRoll(rollID, { + ({ userIDs, flagUpdateData } = await BladesRoll.PrepareActionRoll(rID, { ...config, rollUserID: rollUser.id, rollPrimaryData @@ -1371,7 +1371,7 @@ class BladesRoll extends DocumentSheet { break; } case RollType.Resistance: { - ({ userIDs, flagUpdateData } = await BladesRoll.PrepareResistanceRoll(rollID, { + ({ userIDs, flagUpdateData } = await BladesRoll.PrepareResistanceRoll(rID, { ...config, rollUserID: rollUser.id, rollPrimaryData @@ -1379,7 +1379,7 @@ class BladesRoll extends DocumentSheet { break; } case RollType.Fortune: { - ({ userIDs, flagUpdateData } = await BladesRoll.PrepareFortuneRoll(rollID, { + ({ userIDs, flagUpdateData } = await BladesRoll.PrepareFortuneRoll(rID, { ...config, rollUserID: rollUser.id, rollPrimaryData @@ -1387,7 +1387,7 @@ class BladesRoll extends DocumentSheet { break; } case RollType.IndulgeVice: { - ({ userIDs, flagUpdateData } = await BladesRoll.PrepareIndulgeViceRoll(rollID, { + ({ userIDs, flagUpdateData } = await BladesRoll.PrepareIndulgeViceRoll(rID, { ...config, rollUserID: rollUser.id, rollPrimaryData @@ -1397,10 +1397,10 @@ class BladesRoll extends DocumentSheet { } eLog.checkLog3("bladesRoll", "BladesRoll.NewRoll()", { userIDs, flagUpdateData, rollPrimaryData: flagUpdateData.rollPrimaryData }); await rollUser.setFlag(C.SYSTEM_ID, "rollCollab", flagUpdateData); - socketlib.system.executeForUsers("constructRollCollab", userIDs[RollPermissions.GM], { userID: rollUser.id, rollID, rollPermission: RollPermissions.GM }); - socketlib.system.executeForUsers("constructRollCollab", userIDs[RollPermissions.Primary], { userID: rollUser.id, rollID, rollPermission: RollPermissions.Primary }); - socketlib.system.executeForUsers("constructRollCollab", userIDs[RollPermissions.Observer], { userID: rollUser.id, rollID, rollPermission: RollPermissions.Observer }); - socketlib.system.executeForUsers("constructRollCollab", userIDs[RollPermissions.Participant], { userID: rollUser.id, rollID, rollPermission: RollPermissions.Participant }); + socketlib.system.executeForUsers("constructRollCollab", userIDs[RollPermissions.GM], { userID: rollUser.id, rollID: rID, rollPermission: RollPermissions.GM }); + socketlib.system.executeForUsers("constructRollCollab", userIDs[RollPermissions.Primary], { userID: rollUser.id, rollID: rID, rollPermission: RollPermissions.Primary }); + socketlib.system.executeForUsers("constructRollCollab", userIDs[RollPermissions.Observer], { userID: rollUser.id, rollID: rID, rollPermission: RollPermissions.Observer }); + socketlib.system.executeForUsers("constructRollCollab", userIDs[RollPermissions.Participant], { userID: rollUser.id, rollID: rID, rollPermission: RollPermissions.Participant }); } rollID; @@ -1670,7 +1670,7 @@ class BladesRoll extends DocumentSheet { const cType = cData.type; const rType = C.ResistedConsequenceTypes[cType] ?? undefined; const resistOptions = cData.resistOptions ?? {}; - for (const rName in rNames) { + for (const rName of rNames) { resistOptions[rName] = { name: rName }; if (rType) { resistOptions[rName].type = rType; @@ -2301,11 +2301,12 @@ class BladesRoll extends DocumentSheet { return this.parseResistanceRollCostsHTML(this.getStressCosts(rollCosts), this.getSpecArmorCost(rollCosts)); } case RollType.Fortune: { - return this.parseFortuneRollCostsHTML(this.getStressCosts(rollCosts), this.getSpecArmorCost(rollCosts)); + return this.parseFortuneRollCostsHTML(); } case RollType.IndulgeVice: { - return this.parseIndulgeViceRollCostsHTML(this.getStressCosts(rollCosts), this.getSpecArmorCost(rollCosts)); + return this.parseIndulgeViceRollCostsHTML(); } + default: return false; } } parseActionRollCostsHTML(stressCosts, specArmorCost) { @@ -2349,46 +2350,11 @@ class BladesRoll extends DocumentSheet { ].filter(line => Boolean(line)).join("") }; } - parseFortuneRollCostsHTML(stressCosts, specArmorCost) { - const footerLabelStrings = [ - "( Resisting Costs" - ]; - if (specArmorCost) { - footerLabelStrings.push("your Special Armor )"); - } - else { - footerLabelStrings.push("(6 - Best Die) Stress,
or Clears 1 Stress on a Critical Success )"); - } - return { - footerLabel: footerLabelStrings.join(" "), - tooltip: [ - "

Roll Costs

    ", - ...stressCosts.map(costData => `
  • ${costData.label}: ${costData.costAmount} Stress
  • `), - specArmorCost ? `
  • ${specArmorCost.label}: Special Armor
  • ` : null, - "
" - ].filter(line => Boolean(line)).join("") - }; + parseFortuneRollCostsHTML() { + return { footerLabel: "Fortune Cost Label", tooltip: "Fortune Cost Tooltip" }; } - parseIndulgeViceRollCostsHTML(stressCosts, specArmorCost) { - if (specArmorCost || stressCosts.length > 0) { - const totalStressCost = this.getTotalStressCost(stressCosts); - return { - footerLabel: [ - "( Roll Costs", - totalStressCost > 0 ? `${totalStressCost} Stress` : null, - specArmorCost && totalStressCost ? "and" : null, - specArmorCost ? "your Special Armor" : null, - ")" - ].filter(line => Boolean(line)).join(" "), - tooltip: [ - "

Roll Costs

    ", - ...stressCosts.map(costData => `
  • ${costData.label}: ${costData.costAmount} Stress
  • `), - specArmorCost ? `
  • ${specArmorCost.label}: Special Armor
  • ` : null, - "
" - ].filter(line => Boolean(line)).join("") - }; - } - return undefined; + parseIndulgeViceRollCostsHTML() { + return { footerLabel: "Indulge Vice Cost Label", tooltip: "Indulge Vice Cost Tooltip" }; } _dieVals; @@ -2610,7 +2576,7 @@ class BladesRoll extends DocumentSheet { const factorToggleData = this.document.getFlag(C.SYSTEM_ID, "rollCollab.rollFactorToggles"); const [thisSource, thisFactor, thisToggle] = target.split(/\./).slice(-3); if (!["isActive", "isPrimary", "isDominant", "highFavorsPC"].includes(thisToggle)) { - return this.document.setFlag(C.SYSTEM_ID, `rollCollab.${target}`, value) + await this.document.setFlag(C.SYSTEM_ID, `rollCollab.${target}`, value) .then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } factorToggleData[thisSource][thisFactor] = { @@ -2646,7 +2612,7 @@ class BladesRoll extends DocumentSheet { } default: break; } - return this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollFactorToggles", factorToggleData) + await this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollFactorToggles", factorToggleData) .then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } async _gmControlSelect(event) { @@ -2659,9 +2625,9 @@ class BladesRoll extends DocumentSheet { return; } if (selectedOption === "false") { - return this.document.unsetFlag(C.SYSTEM_ID, `rollCollab.rollParticipantData.${section}.${subSection}`); + await this.document.unsetFlag(C.SYSTEM_ID, `rollCollab.rollParticipantData.${section}.${subSection}`); } - return this.addRollParticipant(selectedOption, section, subSection); + await this.addRollParticipant(selectedOption, section, subSection); } get resistanceStressCost() { const dieVals = this.dieVals; diff --git a/ts/BladesRoll.ts b/ts/BladesRoll.ts index f8eb7309..21323346 100644 --- a/ts/BladesRoll.ts +++ b/ts/BladesRoll.ts @@ -1473,7 +1473,7 @@ class BladesRoll extends DocumentSheet { const userFlagData: Record = {}; (Object.entries(userIDs) as Array<[RollPermissions, string[]]>) .forEach(([rollPermission, idsArray]) => { - for (const id in idsArray) { + for (const id of idsArray) { userFlagData[id] = rollPermission; } }); @@ -1512,7 +1512,7 @@ class BladesRoll extends DocumentSheet { const userFlagData: Record = {}; (Object.entries(userIDs) as Array<[RollPermissions, string[]]>) .forEach(([rollPermission, idsArray]) => { - for (const id in idsArray) { + for (const id of idsArray) { userFlagData[id] = rollPermission; } }); @@ -1546,7 +1546,7 @@ class BladesRoll extends DocumentSheet { const userFlagData: Record = {}; (Object.entries(userIDs) as Array<[RollPermissions, string[]]>) .forEach(([rollPermission, idsArray]) => { - for (const id in idsArray) { + for (const id of idsArray) { userFlagData[id] = rollPermission; } }); @@ -1591,7 +1591,7 @@ class BladesRoll extends DocumentSheet { const userFlagData: Record = {}; (Object.entries(userIDs) as Array<[RollPermissions, string[]]>) .forEach(([rollPermission, idsArray]) => { - for (const id in idsArray) { + for (const id of idsArray) { userFlagData[id] = rollPermission; } }); @@ -1663,7 +1663,7 @@ class BladesRoll extends DocumentSheet { } // Create a random ID for storing the roll instance - const rollID = randomID(); + const rID = randomID(); // Derive user flag data depending on given roll type and subtype let userIDs: Record; @@ -1672,7 +1672,7 @@ class BladesRoll extends DocumentSheet { switch (config.rollType) { case RollType.Action: { ({userIDs, flagUpdateData} = await BladesRoll.PrepareActionRoll( - rollID, + rID, { ...config, rollUserID: rollUser.id, @@ -1683,7 +1683,7 @@ class BladesRoll extends DocumentSheet { } case RollType.Resistance: { ({userIDs, flagUpdateData} = await BladesRoll.PrepareResistanceRoll( - rollID, + rID, { ...config, rollUserID: rollUser.id, @@ -1694,7 +1694,7 @@ class BladesRoll extends DocumentSheet { } case RollType.Fortune: { ({userIDs, flagUpdateData} = await BladesRoll.PrepareFortuneRoll( - rollID, + rID, { ...config, rollUserID: rollUser.id, @@ -1705,7 +1705,7 @@ class BladesRoll extends DocumentSheet { } case RollType.IndulgeVice: { ({userIDs, flagUpdateData} = await BladesRoll.PrepareIndulgeViceRoll( - rollID, + rID, { ...config, rollUserID: rollUser.id, @@ -1725,19 +1725,19 @@ class BladesRoll extends DocumentSheet { // Send out socket calls to all users to see the roll. socketlib.system.executeForUsers("constructRollCollab", userIDs[RollPermissions.GM], - {userID: rollUser.id, rollID, rollPermission: RollPermissions.GM} + {userID: rollUser.id, rollID: rID, rollPermission: RollPermissions.GM} ); socketlib.system.executeForUsers("constructRollCollab", userIDs[RollPermissions.Primary], - {userID: rollUser.id, rollID, rollPermission: RollPermissions.Primary} + {userID: rollUser.id, rollID: rID, rollPermission: RollPermissions.Primary} ); socketlib.system.executeForUsers("constructRollCollab", userIDs[RollPermissions.Observer], - {userID: rollUser.id, rollID, rollPermission: RollPermissions.Observer} + {userID: rollUser.id, rollID: rID, rollPermission: RollPermissions.Observer} ); socketlib.system.executeForUsers("constructRollCollab", userIDs[RollPermissions.Participant], - {userID: rollUser.id, rollID, rollPermission: RollPermissions.Participant} + {userID: rollUser.id, rollID: rID, rollPermission: RollPermissions.Participant} ); } // #endregion @@ -2071,7 +2071,7 @@ class BladesRoll extends DocumentSheet { const cType = cData.type as keyof typeof C["ResistedConsequenceTypes"]; const rType = C.ResistedConsequenceTypes[cType] ?? undefined; const resistOptions = cData.resistOptions ?? {}; - for (const rName in rNames) { + for (const rName of rNames) { resistOptions[rName] = {name: rName}; if (rType) { resistOptions[rName].type = rType; @@ -2946,17 +2946,12 @@ class BladesRoll extends DocumentSheet { ); } case RollType.Fortune: { - return this.parseFortuneRollCostsHTML( - this.getStressCosts(rollCosts), - this.getSpecArmorCost(rollCosts) - ); + return this.parseFortuneRollCostsHTML(); } case RollType.IndulgeVice: { - return this.parseIndulgeViceRollCostsHTML( - this.getStressCosts(rollCosts), - this.getSpecArmorCost(rollCosts) - ); + return this.parseIndulgeViceRollCostsHTML(); } + default: return false as never; } } @@ -3015,52 +3010,12 @@ class BladesRoll extends DocumentSheet { }; } - private parseFortuneRollCostsHTML( - stressCosts: BladesRoll.CostData[], - specArmorCost?: BladesRoll.CostData - ): {footerLabel: string, tooltip: string} | undefined { - const footerLabelStrings: string[] = [ - "( Resisting Costs" - ]; - if (specArmorCost) { - footerLabelStrings.push("your Special Armor )"); - } else { - footerLabelStrings.push("(6 - Best Die) Stress,
or Clears 1 Stress on a Critical Success )"); - } - return { - footerLabel: footerLabelStrings.join(" "), - tooltip: [ - "

Roll Costs

    ", - ...stressCosts.map(costData => `
  • ${costData.label}: ${costData.costAmount} Stress
  • `), - specArmorCost ? `
  • ${specArmorCost.label}: Special Armor
  • ` : null, - "
" - ].filter(line => Boolean(line)).join("") - }; + private parseFortuneRollCostsHTML(): {footerLabel: string, tooltip: string} | undefined { + return {footerLabel: "Fortune Cost Label", tooltip: "Fortune Cost Tooltip"}; } - private parseIndulgeViceRollCostsHTML( - stressCosts: BladesRoll.CostData[], - specArmorCost?: BladesRoll.CostData - ): {footerLabel: string, tooltip: string} | undefined { - if (specArmorCost || stressCosts.length > 0) { - const totalStressCost = this.getTotalStressCost(stressCosts); - return { - footerLabel: [ - "( Roll Costs", - totalStressCost > 0 ? `${totalStressCost} Stress` : null, - specArmorCost && totalStressCost ? "and" : null, - specArmorCost ? "your Special Armor" : null, - ")" - ].filter(line => Boolean(line)).join(" "), - tooltip: [ - "

Roll Costs

    ", - ...stressCosts.map(costData => `
  • ${costData.label}: ${costData.costAmount} Stress
  • `), - specArmorCost ? `
  • ${specArmorCost.label}: Special Armor
  • ` : null, - "
" - ].filter(line => Boolean(line)).join("") - }; - } - return undefined; + private parseIndulgeViceRollCostsHTML(): {footerLabel: string, tooltip: string} | undefined { + return {footerLabel: "Indulge Vice Cost Label", tooltip: "Indulge Vice Cost Tooltip"}; } // #endregion @@ -3329,7 +3284,7 @@ class BladesRoll extends DocumentSheet { // If thisToggle is unrecognized, just toggle whatever value target points at if (!["isActive", "isPrimary", "isDominant", "highFavorsPC"].includes(thisToggle)) { - return this.document.setFlag(C.SYSTEM_ID, `rollCollab.${target}`, value) + await this.document.setFlag(C.SYSTEM_ID, `rollCollab.${target}`, value) .then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } @@ -3373,7 +3328,7 @@ class BladesRoll extends DocumentSheet { default: break; } - return this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollFactorToggles", factorToggleData) + await this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollFactorToggles", factorToggleData) .then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } @@ -3386,9 +3341,9 @@ class BladesRoll extends DocumentSheet { if (typeof selectedOption !== "string") { return; } if (selectedOption === "false") { - return this.document.unsetFlag(C.SYSTEM_ID, `rollCollab.rollParticipantData.${section}.${subSection}`); + await this.document.unsetFlag(C.SYSTEM_ID, `rollCollab.rollParticipantData.${section}.${subSection}`); } - return this.addRollParticipant(selectedOption, section, subSection); + await this.addRollParticipant(selectedOption, section, subSection); } get resistanceStressCost(): number {