Skip to content

Commit

Permalink
Added whitespace trim to save name settings.
Browse files Browse the repository at this point in the history
Formatted saves-settings with new prettier config
orffen#69
  • Loading branch information
DC23 committed Nov 27, 2024
1 parent 9bb24a6 commit 103581b
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions module/settings/saves-settings.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import { Helpers } from './helpers.mjs'
import { objectsShallowEqual } from '../helpers/settings.mjs'
import { SYSTEM_ID, SETTINGS } from './settings.mjs'

Expand All @@ -13,15 +12,15 @@ export function registerSavesSettings () {
hint: 'BASICFANTASYRPG.Settings.SavesMenu.hint',
icon: 'fas fa-cog',
type: SavesSettings,
restricted: true // GM-only
restricted: true, // GM-only
})

// the settings object
game.settings.register(SYSTEM_ID, SETTINGS.SAVES_SETTINGS, {
scope: 'world',
config: false,
type: Object,
default: SavesSettings.defaultSaves
default: SavesSettings.defaultSaves,
})
}

Expand All @@ -31,9 +30,7 @@ class SavesSettings extends FormApplication {
if (!SavesSettings.#defaultSaves) {
SavesSettings.#defaultSaves = {}
saves.forEach(s => {
SavesSettings.#defaultSaves[s] = game.i18n.localize(
`BASICFANTASYRPG.Save${s.capitalize()}`
)
SavesSettings.#defaultSaves[s] = game.i18n.localize(`BASICFANTASYRPG.Save${s.capitalize()}`)
})
}
return SavesSettings.#defaultSaves
Expand All @@ -45,7 +42,7 @@ class SavesSettings extends FormApplication {
width: 400,
template: `systems/${SYSTEM_ID}/templates/settings/saves-settings.hbs`,
id: SETTINGS.SAVES_MENU,
title: 'BASICFANTASYRPG.Settings.SavesMenu.name'
title: 'BASICFANTASYRPG.Settings.SavesMenu.name',
})
}

Expand All @@ -57,7 +54,7 @@ class SavesSettings extends FormApplication {
data[i] = {
id: v,
label: SavesSettings.defaultSaves[v],
value: initialValues[v]
value: initialValues[v],
}
})
return data
Expand All @@ -67,7 +64,10 @@ class SavesSettings extends FormApplication {
const data = foundry.utils.expandObject(formData)
const current = game.settings.get(SYSTEM_ID, SETTINGS.SAVES_SETTINGS)

// todo: trim whitespace from each string & escape html
// todo: escape html
for (let [k, v] of Object.entries(data)) {
data[k] = v.trim()
}

if (!objectsShallowEqual(data, current)) {
game.settings.set(SYSTEM_ID, SETTINGS.SAVES_SETTINGS, data)
Expand All @@ -85,9 +85,7 @@ class SavesSettings extends FormApplication {
saves.forEach(id => {
const element = $(event.delegateTarget).find(`[name=${id}]`)
if (element && element.length > 0) {
element[0].value = game.i18n.localize(
`BASICFANTASYRPG.Save${id.capitalize()}`
)
element[0].value = game.i18n.localize(`BASICFANTASYRPG.Save${id.capitalize()}`)
}
})
}
Expand Down

0 comments on commit 103581b

Please sign in to comment.