From 1f67a8b6c70dd0c2aa461c320b0983e231479f1c Mon Sep 17 00:00:00 2001 From: Chris Oelerich Date: Thu, 22 Aug 2024 17:04:05 -0400 Subject: [PATCH] Add Prettier Config (#14) * prettier config * Apply JavaScript formatting --------- Co-authored-by: ChunkLightTuna --- .prettierignore | 2 + .prettierrc | 16 + README.md | 2 +- languages/en.json | 2 +- module.json | 8 +- src/combat.mjs | 138 ++++--- src/constants.mjs | 626 +++++++++++++++++++++++++++++- src/module.mjs | 54 +-- src/monks_token_bar_hooks.mjs | 35 +- src/settings-form-application.mjs | 297 +++++++++----- src/settings.mjs | 2 +- src/sync.mjs | 278 +++++++------ src/util.mjs | 30 +- 13 files changed, 1148 insertions(+), 342 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1888b53 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +.github +templates diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..f8f651b --- /dev/null +++ b/.prettierrc @@ -0,0 +1,16 @@ +{ + "singleQuote": true, + "tabWidth": 4, + "trailingComma": "none", + "bracketSpacing": false, + "semi": false, + "arrowParens": "avoid", + "overrides": [ + { + "files": "*.json", + "options": { + "tabWidth": 2 + } + } + ] +} diff --git a/README.md b/README.md index 0dd7dab..d682e8b 100644 --- a/README.md +++ b/README.md @@ -24,4 +24,4 @@ _The following must be done by the owner of the Discord server you'd like to int Players should now be able to access characters they own in Foundry from Discord. If a PC is not showing up, ensure that player ownership has been assigned and that the character has a class, race and -background. \ No newline at end of file +background. diff --git a/languages/en.json b/languages/en.json index e0a0fb0..04c0287 100644 --- a/languages/en.json +++ b/languages/en.json @@ -91,4 +91,4 @@ "oronder.Combat-Channel-Label": "Channel where Combat Tracking Messages will be posted.", "oronder.Combat-Health-Estimate": "Combat Health Estimate", "oronder.Combat-Health-Estimate-Label": "Select whose health will be described(i.e. Healthy) rather than shown (HP 8/9)." -} \ No newline at end of file +} diff --git a/module.json b/module.json index b15376b..48c454f 100644 --- a/module.json +++ b/module.json @@ -37,12 +37,8 @@ } ] }, - "esmodules": [ - "dist/module.js" - ], - "styles": [ - "styles/module.css" - ], + "esmodules": ["dist/module.js"], + "styles": ["styles/module.css"], "languages": [ { "lang": "en", diff --git a/src/combat.mjs b/src/combat.mjs index 28f615e..916e36f 100644 --- a/src/combat.mjs +++ b/src/combat.mjs @@ -1,7 +1,12 @@ -import {autoResizeApplicationExisting, Logger} from "./util.mjs"; -import {combat_hooks, socket} from "./module.mjs"; -import {COMBAT_ENABLED, COMBAT_HEALTH_ESTIMATE, COMBAT_HEALTH_ESTIMATE_TYPE, MODULE_ID} from "./constants.mjs"; -import {actor_to_discord_ids} from "./sync.mjs"; +import {autoResizeApplicationExisting, Logger} from './util.mjs' +import {combat_hooks, socket} from './module.mjs' +import { + COMBAT_ENABLED, + COMBAT_HEALTH_ESTIMATE, + COMBAT_HEALTH_ESTIMATE_TYPE, + MODULE_ID +} from './constants.mjs' +import {actor_to_discord_ids} from './sync.mjs' const on_combat_start = async (combat, updateData) => { const roundRender = parse_combat_round({...combat, ...updateData}) @@ -15,16 +20,19 @@ const on_combat_turn = async (combat, updateData, updateOptions) => { } const on_combat_round = async (combat, updateData, updateOptions) => { if (updateOptions.direction < 1) return - const roundRender = parse_combat_round({...combat, ...updateData}, updateOptions) + const roundRender = parse_combat_round( + {...combat, ...updateData}, + updateOptions + ) const turnRender = parse_turn(combat, updateData) socket.emit('combat', roundRender + turnRender) } export function set_combat_hooks() { - Logger.info("Setting Combat Hooks.") + Logger.info('Setting Combat Hooks.') Logger.info(combat_hooks) - const turn_off_hook = (key) => { + const turn_off_hook = key => { if (combat_hooks[key]) { Hooks.off(key, combat_hooks[key]) combat_hooks[key] = undefined @@ -32,18 +40,18 @@ export function set_combat_hooks() { } // Turn off hooks - ["combatStart", "combatTurn", "combatRound"].forEach(turn_off_hook) + ;['combatStart', 'combatTurn', 'combatRound'].forEach(turn_off_hook) // Turn them back on if (game.settings.get(MODULE_ID, COMBAT_ENABLED)) { - combat_hooks.combatStart = Hooks.on("combatStart", on_combat_start) - combat_hooks.combatTurn = Hooks.on("combatTurn", on_combat_turn) - combat_hooks.combatRound = Hooks.on("combatRound", on_combat_round) + combat_hooks.combatStart = Hooks.on('combatStart', on_combat_start) + combat_hooks.combatTurn = Hooks.on('combatTurn', on_combat_turn) + combat_hooks.combatRound = Hooks.on('combatRound', on_combat_round) } } function get_effects_in_markdown(actor, token) { - let a = (token.document.actorLink) ? actor : token.actor + let a = token.document.actorLink ? actor : token.actor let addedEffects = new Map() let markdown = '' @@ -65,7 +73,8 @@ function parse_turn(combat, updateData) { const turn = c.turns[c.turn] const actor = Object.assign( game.actors.find(a => a.id === turn.actorId), - combat.combatants.find(cb => cb.tokenId === turn.tokenId)) + combat.combatants.find(cb => cb.tokenId === turn.tokenId) + ) if (actor.hidden) return '' @@ -75,9 +84,9 @@ function parse_turn(combat, updateData) { let output = '' if (discordId.length) - output += `${game.i18n.localize("oronder.Its-Your-Turn")} <@${discordId[0]}>\n` + output += `${game.i18n.localize('oronder.Its-Your-Turn')} <@${discordId[0]}>\n` output += '```md\n' - output += `# ${game.i18n.localize("oronder.Initiative")} ${actor.initiative} ${game.i18n.localize("oronder.Round")} ${c.round}\n` + output += `# ${game.i18n.localize('oronder.Initiative')} ${actor.initiative} ${game.i18n.localize('oronder.Round')} ${c.round}\n` if (turn.defeated) { output += `${actor.name} \n` @@ -85,7 +94,10 @@ function parse_turn(combat, updateData) { output += `${actor.name} \n` } else { const hp = get_health( - {...actor.system.attributes.hp, ...token.document.delta?.system?.attributes?.hp}, + { + ...actor.system.attributes.hp, + ...token.document.delta?.system?.attributes?.hp + }, healthSetting, actor.type ) @@ -98,7 +110,7 @@ function parse_turn(combat, updateData) { function parse_combat_round(combat) { // Get actors and token for each combatant by turn order - const parsed = combat.turns.map((c) => { + const parsed = combat.turns.map(c => { return { ...c, ix: c._id, @@ -108,17 +120,20 @@ function parse_combat_round(combat) { }) const healthSetting = game.settings.get(MODULE_ID, COMBAT_HEALTH_ESTIMATE) - let output = "```md\n" - output += `${game.i18n.localize("oronder.Current-Round")}: ${combat.round}\n` - output += "==================\n" + let output = '```md\n' + output += `${game.i18n.localize('oronder.Current-Round')}: ${combat.round}\n` + output += '==================\n' // Parse each combatant output += parsed.reduce((acc, c) => { // Hidden from Initiative if (c.hidden) return acc - const rawHp = {...c.actor.system.attributes.hp, ...c.token.document.delta?.system?.attributes?.hp} - const init = `${c.initiative || "XX"}`.padStart(3) + const rawHp = { + ...c.actor.system.attributes.hp, + ...c.token.document.delta?.system?.attributes?.hp + } + const init = `${c.initiative || 'XX'}`.padStart(3) // Combatant is marked as defeated in initative if (c.defeated) { @@ -130,42 +145,49 @@ function parse_combat_round(combat) { return acc + line } else { const hp = get_health(rawHp, healthSetting, c.actor.type) - const ac = c.actor.type === 'character' ? ` (AC ${c.actor.system.attributes.ac.value})` : '' + const ac = + c.actor.type === 'character' + ? ` (AC ${c.actor.system.attributes.ac.value})` + : '' return `${acc}${init}: ${c.name} <${hp}>${ac}\n${get_effects_in_markdown(c.actor, c.token)}` } }, '') - output += "```\n" + output += '```\n' return output } function get_health(hp, combatHealthSetting, actorType) { - const format_health = (hpObj) => { + const format_health = hpObj => { return `${hpObj.value}/${hpObj.max}${hpObj.temp ? `(${hpObj.temp})` : ''}` } - const get_health_estimate = (hp) => { - const pct = Math.round(hp.effectiveMax ? (hp.value / hp.effectiveMax) * 100 : 0, 0, 100); + const get_health_estimate = hp => { + const pct = Math.round( + hp.effectiveMax ? (hp.value / hp.effectiveMax) * 100 : 0, + 0, + 100 + ) switch (true) { case pct > 99: - return game.i18n.localize("oronder.Unharmed"); + return game.i18n.localize('oronder.Unharmed') case pct > 75: - return game.i18n.localize("oronder.Healthy"); + return game.i18n.localize('oronder.Healthy') case pct > 50: - return game.i18n.localize("oronder.Injured"); + return game.i18n.localize('oronder.Injured') case pct > 25: - return game.i18n.localize("oronder.Bloodied"); + return game.i18n.localize('oronder.Bloodied') case pct > 10: - return game.i18n.localize("oronder.Severe"); + return game.i18n.localize('oronder.Severe') case pct > 0: - return game.i18n.localize("oronder.Critical"); + return game.i18n.localize('oronder.Critical') default: - return game.i18n.localize("oronder.Dead"); + return game.i18n.localize('oronder.Dead') } } switch (combatHealthSetting) { case COMBAT_HEALTH_ESTIMATE_TYPE.Monsters: - return (actorType === "character") + return actorType === 'character' ? format_health(hp) : get_health_estimate(hp) case COMBAT_HEALTH_ESTIMATE_TYPE.All: @@ -173,25 +195,38 @@ function get_health(hp, combatHealthSetting, actorType) { case COMBAT_HEALTH_ESTIMATE_TYPE.None: return format_health(hp) default: - console.error(`Combat Health Setting(${combatHealthSetting}) is not supported.`) + console.error( + `Combat Health Setting(${combatHealthSetting}) is not supported.` + ) } } export function register_combat_settings_toggle() { - libWrapper.register('oronder', 'CombatTrackerConfig.prototype._updateObject', async function (wrapped, ...args) { - await game.settings.set(MODULE_ID, COMBAT_ENABLED, this.form.elements.oronder_combat_tracker_toggle.checked) - set_combat_hooks() - return wrapped(...args) - }, 'WRAPPER') + libWrapper.register( + 'oronder', + 'CombatTrackerConfig.prototype._updateObject', + async function (wrapped, ...args) { + await game.settings.set( + MODULE_ID, + COMBAT_ENABLED, + this.form.elements.oronder_combat_tracker_toggle.checked + ) + set_combat_hooks() + return wrapped(...args) + }, + 'WRAPPER' + ) Hooks.on('renderCombatTrackerConfig', async (application, $html, _) => { - $('
', {class: "form-group"}) + $('
', {class: 'form-group'}) .append( - $("