From e3d6a143f9bd542339b2976e1794e10eab91e35b Mon Sep 17 00:00:00 2001 From: city-unit <140349364+city-unit@users.noreply.github.com> Date: Tue, 1 Aug 2023 23:30:25 -0400 Subject: [PATCH] Add loading settings example --- index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/index.js b/index.js index 64307db..966c29e 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,19 @@ import { extension_settings, getContext, loadExtensionSettings } from "../../../ const extensionName = "example-extension"; const extensionFolderPath = `scripts/extensions/third-party/${extensionName}/`; const extensionSettings = extension_settings[extensionName]; +const defaultSettings = {}; + +/** + * Loads the extension settings if they exist, otherwise initializes them to the defaults. + */ +async function loadSettings() { + //Create the settings if they don't exist + extension_settings[extensionName] = extension_settings[extensionName] || {}; + if (Object.keys(extension_settings[extensionName]).length === 0) { + Object.assign(extension_settings[extensionName], defaultSettings); + } +} + function onButtonClick() { // This function is called when the button is clicked