From 2754781efd36c0faff9704105f662aab4f2cd13c Mon Sep 17 00:00:00 2001 From: jalensailin Date: Thu, 28 Sep 2023 20:48:42 -0400 Subject: [PATCH] manually fix most of remaining ESLint errors; everything still works in my testing --- module/actor/actor-sheet.js | 19 ++-- module/actor/actor.js | 4 +- module/deltagreen.js | 172 +++++++++++++++--------------- module/item/item-sheet.js | 5 +- module/item/item.js | 2 +- module/other/stat-parser-macro.js | 12 ++- module/other/utility-functions.js | 2 +- module/roll/roll.js | 18 ++-- module/settings.js | 6 +- module/templates.js | 6 +- 10 files changed, 135 insertions(+), 111 deletions(-) diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index d8b7b0e..e55927d 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -10,7 +10,7 @@ import { * Extend the basic ActorSheet with some very simple modifications * @extends {ActorSheet} */ -export class DeltaGreenActorSheet extends ActorSheet { +export default class DeltaGreenActorSheet extends ActorSheet { /** @override */ static get defaultOptions() { return mergeObject(super.defaultOptions, { @@ -62,7 +62,7 @@ export class DeltaGreenActorSheet extends ActorSheet { const data = super.getData(); // Prepare items. - if (this.actor.type == "agent") { + if (this.actor.type === "agent") { this._prepareCharacterItems(data); } @@ -673,7 +673,8 @@ export class DeltaGreenActorSheet extends ActorSheet { if ( newSkillLabel !== null && newSkillLabel !== "" && - (newSkillGroup !== null) & (newSkillGroup !== "") + newSkillGroup !== null && + newSkillGroup !== "" ) { const updatedData = duplicate(this.actor.system); @@ -710,13 +711,13 @@ export class DeltaGreenActorSheet extends ActorSheet { system: {}, }; - if (type == "weapon") { + if (type === "weapon") { // itemData.system.skill = "firearms"; //default skill to firearms, since that will be most common // itemData.system.expense = "Standard"; - } else if (type == "armor") { + } else if (type === "armor") { // itemData.system.armor = 3; // itemData.system.expense = "Standard"; - } else if (type == "bond") { + } else if (type === "bond") { // try to default bonds for an agent to their current CHA itemData.system.score = this.object.system.statistics.cha.value; // Can vary, but at character creation starting bond score is usually agent's charisma // itemData.img = "icons/svg/mystery-man.svg" @@ -785,7 +786,7 @@ export class DeltaGreenActorSheet extends ActorSheet { default: break; } - return this.processRoll(event, roll, rollOptions); + this.processRoll(event, roll, rollOptions); } /** @@ -793,6 +794,8 @@ export class DeltaGreenActorSheet extends ActorSheet { * Broke this logic out from `_onRoll()` so that other files can call it, * namely the macro logic. * + * TODO: Move this logic to the roll.js. + * * @param {Event} event The originating click event * @param {Event} roll The roll to show a dialog for and then send to chat. * @async @@ -814,7 +817,7 @@ export class DeltaGreenActorSheet extends ActorSheet { // Evaluate the roll. await roll.evaluate({ async: true }); // Send the roll to chat. - return roll.toChat(); + roll.toChat(); } _resetBreakingPoint(event) { diff --git a/module/actor/actor.js b/module/actor/actor.js index ba84d40..2277226 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -1,8 +1,10 @@ +/* global Actor Item mergeObject game */ + /** * Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system. * @extends {Actor} */ -export class DeltaGreenActor extends Actor { +export default class DeltaGreenActor extends Actor { /** * Augment the basic actor data with additional dynamic data. */ diff --git a/module/deltagreen.js b/module/deltagreen.js index 367b531..2e913da 100644 --- a/module/deltagreen.js +++ b/module/deltagreen.js @@ -1,17 +1,17 @@ -/* globals $ Hooks game CONFIG Actors Items ActorSheet ItemSheet Handlebars Macro ChatMessage ui duplicate */ +/* globals $ Hooks game CONFIG Actors Items ActorSheet ItemSheet Handlebars Macro ChatMessage ui duplicate arguments */ // Import Modules -import { DeltaGreenActor } from "./actor/actor.js"; -import { DeltaGreenActorSheet } from "./actor/actor-sheet.js"; -import { DeltaGreenItem } from "./item/item.js"; -import { DeltaGreenItemSheet } from "./item/item-sheet.js"; +import DeltaGreenActor from "./actor/actor.js"; +import DeltaGreenActorSheet from "./actor/actor-sheet.js"; +import DeltaGreenItem from "./item/item.js"; +import DeltaGreenItemSheet from "./item/item-sheet.js"; import * as DGRolls from "./roll/roll.js"; -import { registerSystemSettings } from "./settings.js"; -import { preloadHandlebarsTemplates } from "./templates.js"; -import { ParseDeltaGreenStatBlock } from "./other/stat-parser-macro.js"; +import registerSystemSettings from "./settings.js"; +import preloadHandlebarsTemplates from "./templates.js"; +import ParseDeltaGreenStatBlock from "./other/stat-parser-macro.js"; import DGUtils from "./other/utility-functions.js"; -Hooks.once("init", async function () { +Hooks.once("init", async () => { game.deltagreen = { DeltaGreenActor, DeltaGreenItem, @@ -59,17 +59,17 @@ Hooks.once("init", async function () { }, ); - Handlebars.registerHelper("concat", function () { + Handlebars.registerHelper("concat", (...args) => { let outStr = ""; - for (let arg in arguments) { - if (typeof arguments[arg] !== "object") { - outStr += arguments[arg]; + for (const arg in args) { + if (typeof args[arg] !== "object") { + outStr += args[arg]; } } return outStr; }); - Handlebars.registerHelper("toLowerCase", function (str) { + Handlebars.registerHelper("toLowerCase", (str) => { try { return str.toLowerCase(); } catch (error) { @@ -77,7 +77,7 @@ Hooks.once("init", async function () { } }); - Handlebars.registerHelper("toUpperCase", function (str) { + Handlebars.registerHelper("toUpperCase", (str) => { try { return str.toUpperCase(); } catch (error) { @@ -85,54 +85,50 @@ Hooks.once("init", async function () { } }); - Handlebars.registerHelper("if_eq", function (a, b, opts) { - if (a == b) { - return opts.fn(this); - } else { - return opts.inverse(this); - } - }); - - Handlebars.registerHelper("if_not_eq", function (a, b, opts) { - if (a != b) { + Handlebars.registerHelper("if_eq", (a, b, opts) => { + if (a === b) { return opts.fn(this); } return opts.inverse(this); }); - Handlebars.registerHelper("if_gt", function (a, b, trueVal, falseVal) { - if (a > b) { - return trueVal; - } else { - return falseVal; + Handlebars.registerHelper("if_not_eq", (a, b, opts) => { + if (a !== b) { + return opts.fn(this); } + return opts.inverse(this); }); - Handlebars.registerHelper("cite_ahb", function (page) { + Handlebars.registerHelper("if_gt", (a, b, trueVal, falseVal) => { + if (a > b) { + return trueVal; + } + return falseVal; + }); + + Handlebars.registerHelper("cite_ahb", (page) => { return `See page ${page} of the Agent's Handbook.`; }); - Handlebars.registerHelper("formatLethality", function (lethality) { + Handlebars.registerHelper("formatLethality", (lethality) => { if (lethality > 0) { - return `${lethality.toString() }%`; - } else { - return ""; + return `${lethality.toString()}%`; } + return ""; }); // Is this used anywhere? Handlebars.registerHelper( "getActorSkillProp", - function (actorData, skillName, prop) { + (actorData, skillName, prop) => { try { - if (skillName != "" && prop != "") { - const skills = actorData.data.skills; - let skill = skills[skillName]; + if (skillName !== "" && prop !== "") { + const { skills } = actorData.data; + const skill = skills[skillName]; const propVal = skill[prop]; return propVal; - } else { - return ""; } + return ""; } catch (ex) { console.log(ex); return ""; @@ -140,25 +136,25 @@ Hooks.once("init", async function () { }, ); - Handlebars.registerHelper("getAvailableRollModes", function () { + Handlebars.registerHelper("getAvailableRollModes", () => { try { return CONFIG.Dice.rollModes; } catch (error) { - console.log(error); + return console.log(error); } }); - Handlebars.registerHelper("getDefaultRollMode", function () { + Handlebars.registerHelper("getDefaultRollMode", () => { try { return game.settings.get("core", "rollMode"); } catch (error) { - console.log(error); + return console.log(error); } }); Handlebars.registerHelper( "calculateHandToHandCombatDamageFormulaBonus", - function (strength) { + (strength) => { try { let bonus = ""; @@ -174,12 +170,12 @@ Hooks.once("init", async function () { return bonus; } catch (error) { - console.log(error); + return console.log(error); } }, ); - Handlebars.registerHelper("localizeWeaponSkill", function (skill) { + Handlebars.registerHelper("localizeWeaponSkill", (skill) => { let label = skill; try { @@ -189,7 +185,7 @@ Hooks.once("init", async function () { if (skill === "DG.Skills.custom") { label = game.i18n.localize("DG.ItemWindow.Custom"); } else { - label = game.i18n.localize(`DG.Skills.${ skill}`); + label = game.i18n.localize(`DG.Skills.${skill}`); } } catch (error) { console.log(error); @@ -200,18 +196,16 @@ Hooks.once("init", async function () { Handlebars.registerHelper( "hideSkillBasedOnProficiencyAndUserChoice", - function (hideUntrainedSkills, proficiency) { + (hideUntrainedSkills, proficiency) => { let showValue = true; try { if (hideUntrainedSkills === false) { showValue = true; + } else if (proficiency > 0) { + showValue = true; } else { - if (proficiency > 0) { - showValue = true; - } else { - showValue = false; - } + showValue = false; } } catch (error) { console.log(error); @@ -223,10 +217,12 @@ Hooks.once("init", async function () { // looks at system setting for what font to use and returns the class that is then used in the handlebars template that // generates the character sheet. - Handlebars.registerHelper("getFontFamilySystemSettingClass", function () { + Handlebars.registerHelper("getFontFamilySystemSettingClass", () => { const setting = game.settings.get("deltagreen", "characterSheetFont"); - const characterSheetStyle = game.settings.get("deltagreen", "characterSheetStyle"); + const characterSheetStyle = game.settings.get( + "deltagreen", + "characterSheetStyle", ); /* @@ -263,20 +259,22 @@ Hooks.once("init", async function () { */ }); - Handlebars.registerHelper("getCharacterSheetStyle", function () { - const characterSheetStyle = game.settings.get("deltagreen", "characterSheetStyle"); + Handlebars.registerHelper("getCharacterSheetStyle", () => { + const characterSheetStyle = game.settings.get( + "deltagreen", + "characterSheetStyle", ); if (characterSheetStyle === "cowboy") { return "cowboy-style"; - } else if (characterSheetStyle === "outlaw") { - return "outlaw-style"; - } else { - return "program-style"; } + if (characterSheetStyle === "outlaw") { + return "outlaw-style"; + } + return "program-style"; }); - Handlebars.registerHelper("keepSanityPrivate", function () { + Handlebars.registerHelper("keepSanityPrivate", () => { let setting = false; try { @@ -293,13 +291,16 @@ Hooks.once("init", async function () { }); }); -Handlebars.registerHelper("playerHasGamemasterPrivileges", function () { +Handlebars.registerHelper("playerHasGamemasterPrivileges", () => { return game.user.isGM; }); -Handlebars.registerHelper("showImpossibleLandscapesContent", function () { +Handlebars.registerHelper("showImpossibleLandscapesContent", () => { let result = false; - const setting = game.settings.get("deltagreen", "showImpossibleLandscapesContent"); + const setting = game.settings.get( + "deltagreen", + "showImpossibleLandscapesContent", + ); if (game.user.isGM === true && setting === true) { result = true; @@ -308,7 +309,7 @@ Handlebars.registerHelper("showImpossibleLandscapesContent", function () { return result; }); -Hooks.once("ready", async function () { +Hooks.once("ready", async () => { // Wait to register hotbar drop hook on ready so that modules could register earlier if they want to Hooks.on("hotbarDrop", (bar, data, slot) => createDeltaGreenMacro(data, slot), @@ -318,7 +319,7 @@ Hooks.once("ready", async function () { Hooks.on("ready", () => { // let backgroundImageSetting = game.settings.get("deltagreen", "characterSheetBackgroundImageSetting"); // let characterSheetStyle = game.settings.get("deltagreen", "characterSheetStyle"); - //let customCss = ""; + // let customCss = ""; // let customStyle = document.createElement("style"); // customStyle.id = "dg-custom-css"; /* @@ -372,10 +373,12 @@ Hooks.on("preCreateItem", (item) => { }); Hooks.on("renderSidebarTab", async (app, html) => { - if (app.options.id == "actors") { - const button = $("") + if (app.options.id === "actors") { + const button = $( + "", + ); - button.click(function () { + button.click(() => { ParseDeltaGreenStatBlock(); }); @@ -384,7 +387,7 @@ Hooks.on("renderSidebarTab", async (app, html) => { }); // Note - this event is fired on ALL connected clients... -Hooks.on("createActor", async function (actor, options, userId) { +Hooks.on("createActor", async (actor, options, userId) => { try { // use this to trap on if this hook is firing for the same user that triggered the create // can put logic specific to a particular user session below @@ -397,7 +400,9 @@ Hooks.on("createActor", async function (actor, options, userId) { console.log("createActor Hook"); const artLabel = game.i18n.translations.DG?.TypeSkills?.Art ?? "Art"; - const paintingLabel = game.i18n.translations.DG?.TypeSkills?.Subskills?.Painting ?? "Painting"; + const paintingLabel = + game.i18n.translations.DG?.TypeSkills?.Subskills?.Painting ?? + "Painting"; const updatedData = duplicate(actor.system); updatedData.typedSkills.tskill_01.group = artLabel; @@ -438,22 +443,21 @@ async function createDeltaGreenMacro(data, slot) { // Create the macro command let command = "// Uncomment line below to also roll skill check if desired."; - command += "\n" + `//game.deltagreen.rollItemSkillCheckMacro("${item._id}");`; - command += "\n" + `game.deltagreen.rollItemMacro("${item._id}");`; + command += `\n//game.deltagreen.rollItemSkillCheckMacro("${item._id}");`; + command += `\ngame.deltagreen.rollItemMacro("${item._id}");`; // let macro = game.macros.entities.find(m => (m.name === data.name) && (m.command === command)); // if (!macro) { const macro = await Macro.create({ - name: data.itemData.name, - type: "script", - img: data.itemData.img, - command: command, - flags: { "deltagreen.itemMacro": true } - }); + name: data.itemData.name, + type: "script", + img: data.itemData.img, + command, + flags: { "deltagreen.itemMacro": true }, + }); // } game.user.assignHotbarMacro(macro, slot); - return false; } /** @@ -538,6 +542,6 @@ function rollSkillMacro(skillName) { {}, { rollType: "skill", key: skillName, actor }, ); - actor.sheet.processRoll({}, roll); + return actor.sheet.processRoll({}, roll); // sendPercentileTestToChat(actor, translatedSkillLabel, skill.proficiency); } diff --git a/module/item/item-sheet.js b/module/item/item-sheet.js index 771ed7d..84d0207 100644 --- a/module/item/item-sheet.js +++ b/module/item/item-sheet.js @@ -1,8 +1,10 @@ +/* global ItemSheet mergeObject TextEditor */ + /** * Extend the basic ItemSheet with some very simple modifications * @extends {ItemSheet} */ -export class DeltaGreenItemSheet extends ItemSheet { +export default class DeltaGreenItemSheet extends ItemSheet { /** @override */ static get defaultOptions() { return mergeObject(super.defaultOptions, { @@ -57,6 +59,7 @@ export class DeltaGreenItemSheet extends ItemSheet { super.activateListeners(html); // Everything below here is only needed if the sheet is editable + // eslint-disable-next-line no-useless-return if (!this.options.editable) return; // Roll handlers, click handlers, etc. would go here. diff --git a/module/item/item.js b/module/item/item.js index 82527bf..740d577 100644 --- a/module/item/item.js +++ b/module/item/item.js @@ -6,7 +6,7 @@ import { DGDamageRoll, DGLethalityRoll } from "../roll/roll.js"; * Extend the basic Item with some very simple modifications. * @extends {Item} */ -export class DeltaGreenItem extends Item { +export default class DeltaGreenItem extends Item { /** * Augment the basic Item data model with additional dynamic data. */ diff --git a/module/other/stat-parser-macro.js b/module/other/stat-parser-macro.js index 63ee711..c2b2161 100644 --- a/module/other/stat-parser-macro.js +++ b/module/other/stat-parser-macro.js @@ -1,3 +1,5 @@ +/* global Dialog Actor */ + // call this within a world as: game.deltagreen.ParseDeltaGreenStatBlock() function GetTypeSkillRatingsFromInput(inputText) { const matchStr = @@ -11,6 +13,9 @@ function GetTypeSkillRatingsFromInput(inputText) { let match; try { + // This is probably one of the few times where its recommended to assign within a while loop. + // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec + // eslint-disable-next-line no-cond-assign while ((match = re.exec(inputText))) { matches.push({ group: match[1], @@ -86,8 +91,7 @@ async function RegexParseNpcStatBlock(inputStr, actorType) { tempStr = inputStr.split(/\r?\n/); if (tempStr.length > 1) { - actorData.name = tempStr[0]; - shortDescription = tempStr[1]; + [actorData.name, shortDescription] = tempStr; } else { actorData.name = "Unknown"; } @@ -353,7 +357,7 @@ async function RegexParseNpcStatBlock(inputStr, actorType) { arr = GetTypeSkillRatingsFromInput(inputStr); - for (let index = 0; index < arr.length; ++index) { + for (let index = 0; index < arr.length; index += 1) { const element = arr[index]; actorData.data.typedSkills[`tskill_${index.toString()}`] = element; } @@ -403,6 +407,6 @@ async function GetUserInput() { }).render(true); } -export async function ParseDeltaGreenStatBlock() { +export default async function ParseDeltaGreenStatBlock() { GetUserInput(); } diff --git a/module/other/utility-functions.js b/module/other/utility-functions.js index e358f57..75db6c5 100644 --- a/module/other/utility-functions.js +++ b/module/other/utility-functions.js @@ -12,7 +12,7 @@ export default class DGUtils { static localizeWithFallback(key, fallback) { try { const translatedValue = game.i18n.localize(key); - if (translatedValue != key) { + if (translatedValue !== key) { return translatedValue; } console.warn(`Untranslated localization key '${key}'.`); diff --git a/module/roll/roll.js b/module/roll/roll.js index 169a6ba..11a4f2e 100644 --- a/module/roll/roll.js +++ b/module/roll/roll.js @@ -1,3 +1,4 @@ +/* eslint-disable max-classes-per-file */ /* globals game Roll ChatMessage AudioHelper renderTemplate Dialog */ import DGUtils from "../other/utility-functions.js"; @@ -151,10 +152,10 @@ export class DGPercentileRoll extends DGRoll { const template = "systems/deltagreen/templates/dialog/modify-percentile-roll.html"; - const html = await renderTemplate(template, backingData); + const content = await renderTemplate(template, backingData); return new Promise((resolve, reject) => { new Dialog({ - content: html, + content, title: DGUtils.localizeWithFallback( "DG.ModifySkillRollDialogue.Title", "Modify Roll", @@ -171,11 +172,14 @@ export class DGPercentileRoll extends DGRoll { const plusMinus = html.find("[name='plusOrMinus']").val(); - if (targetModifier.trim() != "" && !isNaN(targetModifier)) { + if ( + targetModifier.trim() !== "" && + !Number.isNaN(targetModifier) + ) { targetModifier = Math.abs(parseInt(targetModifier)); if (plusMinus === "-") { - targetModifier = -1 * targetModifier; + targetModifier *= -1; } } resolve({ targetModifier, rollMode }); @@ -520,10 +524,10 @@ export class DGDamageRoll extends DGRoll { }, }; - const html = await renderTemplate(template, backingData); + const content = await renderTemplate(template, backingData); return new Promise((resolve, reject) => { new Dialog({ - content: html, + content, title: game.i18n.localize("DG.ModifySkillRollDialogue.Title"), default: "roll", buttons: { @@ -544,7 +548,7 @@ export class DGDamageRoll extends DGRoll { } let newFormula = ""; - if (outerModifier.trim() != "") { + if (outerModifier.trim() !== "") { newFormula += `${outerModifier}(${modifiedBaseRoll}${innerModifier.trim()})`; } else { newFormula += modifiedBaseRoll + innerModifier.trim(); diff --git a/module/settings.js b/module/settings.js index 005e425..1b6cfcd 100644 --- a/module/settings.js +++ b/module/settings.js @@ -1,4 +1,6 @@ -export const registerSystemSettings = function () { +/* global game */ + +export default function registerSystemSettings() { game.settings.register("deltagreen", "characterSheetStyle", { name: "Character Sheet Style", hint: "Choose how actor sheets should be styled. 'Program' is a more modern government style, where 'Cowboy/Outlaw' is an older, grittier looking typewriter style.", @@ -99,4 +101,4 @@ export const registerSystemSettings = function () { // console.log(value) }, }); -}; +} diff --git a/module/templates.js b/module/templates.js index 9f479e2..33c6e19 100644 --- a/module/templates.js +++ b/module/templates.js @@ -1,9 +1,11 @@ +/* global loadTemplates */ + /** * Define a set of template paths to pre-load * Pre-loaded templates are compiled and cached for fast access when rendering * @return {Promise} */ -export const preloadHandlebarsTemplates = async function () { +export default async function preloadHandlebarsTemplates() { return loadTemplates([ "systems/deltagreen/templates/actor/actor-sheet.html", "systems/deltagreen/templates/actor/limited-sheet.html", @@ -14,4 +16,4 @@ export const preloadHandlebarsTemplates = async function () { "systems/deltagreen/templates/actor/vehicle-sheet.html", "systems/deltagreen/templates/actor/help-and-licensing-partial.html", ]); -}; +}