refactor: extract and apply a dedicated UI resource refresh function for settings changes
This commit is contained in:
parent
217d6c9222
commit
3feb1d016f
1 changed files with 9 additions and 8 deletions
|
|
@ -3,6 +3,10 @@ const MODULE_ID = 'dh-feartrackerplus';
|
||||||
Hooks.once('init', () => {
|
Hooks.once('init', () => {
|
||||||
console.log(`${MODULE_ID} | Initializing Daggerheart Fear Tracker Plus`);
|
console.log(`${MODULE_ID} | Initializing Daggerheart Fear Tracker Plus`);
|
||||||
|
|
||||||
|
const refreshFearTracker = () => {
|
||||||
|
if (ui.resources?.render) ui.resources.render();
|
||||||
|
};
|
||||||
|
|
||||||
// Register Settings
|
// Register Settings
|
||||||
game.settings.register(MODULE_ID, 'iconType', {
|
game.settings.register(MODULE_ID, 'iconType', {
|
||||||
name: 'Icon Source',
|
name: 'Icon Source',
|
||||||
|
|
@ -15,10 +19,7 @@ Hooks.once('init', () => {
|
||||||
'custom': 'Custom FontAwesome Class'
|
'custom': 'Custom FontAwesome Class'
|
||||||
},
|
},
|
||||||
default: 'preset',
|
default: 'preset',
|
||||||
onChange: () => {
|
onChange: refreshFearTracker
|
||||||
// Force re-render if possible, or let the hook handle it on next update
|
|
||||||
if (ui.apps) Object.values(ui.apps).forEach(app => app.render?.());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
game.settings.register(MODULE_ID, 'presetIcon', {
|
game.settings.register(MODULE_ID, 'presetIcon', {
|
||||||
|
|
@ -40,7 +41,7 @@ Hooks.once('init', () => {
|
||||||
'fa-radiation': 'Radiation'
|
'fa-radiation': 'Radiation'
|
||||||
},
|
},
|
||||||
default: 'fa-skull',
|
default: 'fa-skull',
|
||||||
onChange: () => { if (ui.apps) Object.values(ui.apps).forEach(app => app.render?.()); }
|
onChange: refreshFearTracker
|
||||||
});
|
});
|
||||||
|
|
||||||
game.settings.register(MODULE_ID, 'customIcon', {
|
game.settings.register(MODULE_ID, 'customIcon', {
|
||||||
|
|
@ -50,7 +51,7 @@ Hooks.once('init', () => {
|
||||||
config: true,
|
config: true,
|
||||||
type: String,
|
type: String,
|
||||||
default: 'fa-solid fa-dragon',
|
default: 'fa-solid fa-dragon',
|
||||||
onChange: () => { if (ui.apps) Object.values(ui.apps).forEach(app => app.render?.()); }
|
onChange: refreshFearTracker
|
||||||
});
|
});
|
||||||
|
|
||||||
game.settings.register(MODULE_ID, 'fullColor', {
|
game.settings.register(MODULE_ID, 'fullColor', {
|
||||||
|
|
@ -60,7 +61,7 @@ Hooks.once('init', () => {
|
||||||
config: true,
|
config: true,
|
||||||
type: String,
|
type: String,
|
||||||
default: '#ff0000',
|
default: '#ff0000',
|
||||||
onChange: () => { if (ui.apps) Object.values(ui.apps).forEach(app => app.render?.()); }
|
onChange: refreshFearTracker
|
||||||
});
|
});
|
||||||
|
|
||||||
game.settings.register(MODULE_ID, 'emptyColor', {
|
game.settings.register(MODULE_ID, 'emptyColor', {
|
||||||
|
|
@ -70,7 +71,7 @@ Hooks.once('init', () => {
|
||||||
config: true,
|
config: true,
|
||||||
type: String,
|
type: String,
|
||||||
default: '#444444',
|
default: '#444444',
|
||||||
onChange: () => { if (ui.apps) Object.values(ui.apps).forEach(app => app.render?.()); }
|
onChange: refreshFearTracker
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue