-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix hook updater, add settings cache
- Loading branch information
Showing
5 changed files
with
91 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
export const MODULE = 'macro-creation-tweaks'; | ||
export const log = game?.pf2emhl?.mhlog ?? ((logable) => console.log(logable)); | ||
import { updateHooks } from "./hooks.mjs"; | ||
|
||
export const MODULE_ID = "macro-creation-tweaks"; | ||
export const SETTINGS = { | ||
"append-number": { | ||
config: true, | ||
default: true, | ||
hint: "MacroCreationTweaks.Setting.AppendNumber.Hint", | ||
name: "MacroCreationTweaks.Setting.AppendNumber.Name", | ||
scope: "world", | ||
type: Boolean, | ||
onChange: updateHooks, | ||
}, | ||
"delete-empty": { | ||
config: true, | ||
default: true, | ||
hint: "MacroCreationTweaks.Setting.DeleteEmpty.Hint", | ||
name: "MacroCreationTweaks.Setting.DeleteEmpty.Name", | ||
scope: "world", | ||
type: Boolean, | ||
onChange: updateHooks, | ||
}, | ||
"change-default-type": { | ||
config: true, | ||
default: true, | ||
hint: "MacroCreationTweaks.Setting.ChangeDefaultType.Hint", | ||
name: "MacroCreationTweaks.Setting.ChangeDefaultType.Name", | ||
scope: "world", | ||
type: Boolean, | ||
onChange: updateHooks, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import { MODULE } from "./constants.mjs"; | ||
import { updateHooks } from "./hooks.mjs"; | ||
import { registerSettings } from "./settings.mjs"; | ||
export const getModule = () => game.modules.get(MODULE); | ||
import { MODULE_ID } from "./constants.mjs"; | ||
import { updateHooks, HOOKS } from "./hooks.mjs"; | ||
import { registerSettings, updateSettingsCache } from "./settings.mjs"; | ||
export const MODULE = () => game.modules.get(MODULE_ID); | ||
|
||
Hooks.once("init", () => { | ||
const modObject = getModule(); | ||
const modObject = MODULE(); | ||
game.mct = { | ||
updateHooks, | ||
updateSettingsCache, | ||
modObject, | ||
HOOKS, | ||
}; | ||
modObject.hookIDs ??= {}; | ||
modObject.settings ??= {}; | ||
registerSettings(); | ||
}); | ||
Hooks.once("setup", () => { | ||
updateSettingsCache(); | ||
updateHooks(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,30 @@ | ||
import { MODULE } from "./constants.mjs"; | ||
import { updateHooks } from "./hooks.mjs"; | ||
import { MODULE_ID, SETTINGS } from "./constants.mjs"; | ||
import { MODULE } from "./init.mjs"; | ||
|
||
export function setting(path) { | ||
return game.settings.get(MODULE, path); | ||
} | ||
export function registerSettings() { | ||
game.settings.register(MODULE, "append-number", { | ||
config: true, | ||
default: true, | ||
hint: "MacroCreationTweaks.Setting.AppendNumber.Hint", | ||
name: "MacroCreationTweaks.Setting.AppendNumber.Name", | ||
scope: "world", | ||
type: Boolean, | ||
onChange: updateHooks, | ||
}); | ||
game.settings.register(MODULE, "delete-empty", { | ||
config: true, | ||
default: true, | ||
hint: "MacroCreationTweaks.Setting.DeleteEmpty.Hint", | ||
name: "MacroCreationTweaks.Setting.DeleteEmpty.Name", | ||
scope: "world", | ||
type: Boolean, | ||
onChange: updateHooks, | ||
}); | ||
game.settings.register(MODULE, "change-default-type", { | ||
config: true, | ||
default: true, | ||
hint: "MacroCreationTweaks.Setting.ChangeDefaultType.Hint", | ||
name: "MacroCreationTweaks.Setting.ChangeDefaultType.Name", | ||
scope: "world", | ||
type: Boolean, | ||
onChange: updateHooks, | ||
}); | ||
for (const [setting, data] of Object.entries(SETTINGS)) { | ||
const settingPath = setting.replace("_", "."); | ||
fu.setProperty(MODULE().settings, settingPath, data?.default ?? null); | ||
const originalOnChange = data?.onChange ?? null; | ||
data.onChange = (value) => { | ||
fu.setProperty(MODULE().settings, settingPath, value); | ||
if (originalOnChange) originalOnChange(value); | ||
}; | ||
game.settings.register(MODULE_ID, setting, data); | ||
} | ||
} | ||
|
||
export function updateSettingsCache() { | ||
const modSettings = MODULE().settings; | ||
for (const setting of Object.keys(SETTINGS)) { | ||
const settingPath = setting.replace("_", "."); | ||
const value = game.settings.get(MODULE_ID, setting); | ||
fu.setProperty(modSettings, settingPath, value); | ||
} | ||
} | ||
|
||
export function setting(key) { | ||
const settingPath = key.replace("_", "."); | ||
const cached = fu.getProperty(MODULE().settings, settingPath); | ||
return cached !== undefined ? cached : game.settings.get(MODULE_ID, key); | ||
} |