Load icons during initial setup and allow hot-reloading icons
This commit is contained in:
parent
b9ed3289dc
commit
a657b2e3e8
6 changed files with 49 additions and 44 deletions
|
|
@ -1,34 +1,41 @@
|
|||
import * as hbs from "../handlebars.mjs";
|
||||
|
||||
const loaders = {
|
||||
svg(data) {
|
||||
const iconName = data.path.split(`/`).slice(-1)[0].slice(0, -4);
|
||||
console.log(`.dungeon | hot-reloading icon: ${iconName}`);
|
||||
CONFIG.CACHE.icons[iconName] = data.content;
|
||||
},
|
||||
hbs(data) {
|
||||
if (!hbs.partials.some(p => data.path.endsWith(p))) {
|
||||
return true;
|
||||
};
|
||||
|
||||
// Compile the new template data.
|
||||
let template;
|
||||
try {
|
||||
template = Handlebars.compile(data.content);
|
||||
} catch (err) {
|
||||
return console.error(err);
|
||||
};
|
||||
|
||||
// Re-register our new partial template & cache it.
|
||||
const alias = data.path
|
||||
.split(`/`)
|
||||
.pop()
|
||||
.split(`.`)
|
||||
.slice(0, -1)
|
||||
.reverse()
|
||||
.join(`.`);
|
||||
const templateName = `dotdungeon.${alias}`;
|
||||
Handlebars.registerPartial(templateName, template);
|
||||
_templateCache[templateName] = template;
|
||||
|
||||
return false;
|
||||
},
|
||||
};
|
||||
|
||||
Hooks.on(`hotReload`, async (data) => {
|
||||
if (data.extension !== 'hbs') {
|
||||
return true;
|
||||
};
|
||||
|
||||
if (!hbs.partials.some(p => data.path.endsWith(p))) {
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
// Compile the new template data.
|
||||
let template;
|
||||
try {
|
||||
template = Handlebars.compile(data.content);
|
||||
} catch (err) {
|
||||
return console.error(err);
|
||||
};
|
||||
|
||||
// Re-register our new partial template & cache it.
|
||||
const alias = data.path
|
||||
.split(`/`)
|
||||
.pop()
|
||||
.split(`.`)
|
||||
.slice(0, -1)
|
||||
.reverse()
|
||||
.join(`.`);
|
||||
const templateName = `dotdungeon.${alias}`;
|
||||
Handlebars.registerPartial(templateName, template);
|
||||
_templateCache[templateName] = template;
|
||||
|
||||
return false;
|
||||
if (!loaders[data.extension]) return;
|
||||
return loaders[data.extension](data);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue