Remove icon preloading from the systems in favour of the async web component
This commit is contained in:
parent
6b80f3530d
commit
8aff8b0fda
4 changed files with 2 additions and 59 deletions
|
|
@ -110,9 +110,6 @@ Hooks.once(`init`, async () => {
|
||||||
hbs.registerHandlebarsHelpers();
|
hbs.registerHandlebarsHelpers();
|
||||||
hbs.preloadHandlebarsTemplates();
|
hbs.preloadHandlebarsTemplates();
|
||||||
registerCustomComponents();
|
registerCustomComponents();
|
||||||
|
|
||||||
CONFIG.CACHE ??= {};
|
|
||||||
CONFIG.CACHE.icons = await hbs.preloadIcons();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,25 +43,6 @@ export const preAliasedPartials = {
|
||||||
"dotdungeon.pc.v2.foil": "actors/char-sheet/v2/partials/inventory/items/untyped.v2.pc.hbs",
|
"dotdungeon.pc.v2.foil": "actors/char-sheet/v2/partials/inventory/items/untyped.v2.pc.hbs",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const icons = [
|
|
||||||
`caret-right.svg`,
|
|
||||||
`caret-down.svg`,
|
|
||||||
`garbage-bin.svg`,
|
|
||||||
`chat-bubble.svg`,
|
|
||||||
`dice/d4.svg`,
|
|
||||||
`dice/d6.svg`,
|
|
||||||
`dice/d8.svg`,
|
|
||||||
`dice/d10.svg`,
|
|
||||||
`dice/d12.svg`,
|
|
||||||
`dice/d20.svg`,
|
|
||||||
`create.svg`,
|
|
||||||
`close.svg`,
|
|
||||||
`edit.svg`,
|
|
||||||
`sheet.svg`,
|
|
||||||
`minus.svg`,
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
export async function registerHandlebarsHelpers() {
|
export async function registerHandlebarsHelpers() {
|
||||||
Handlebars.registerHelper(helpers);
|
Handlebars.registerHelper(helpers);
|
||||||
};
|
};
|
||||||
|
|
@ -97,38 +78,3 @@ export async function preloadHandlebarsTemplates() {
|
||||||
console.groupEnd();
|
console.groupEnd();
|
||||||
return loadTemplates(paths);
|
return loadTemplates(paths);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads all of the icons that are needed in the handlebars templating to make
|
|
||||||
* the sheet look nicer.
|
|
||||||
*
|
|
||||||
* @returns An object containing icon names to the corresponding HTML data for
|
|
||||||
* displaying the icon
|
|
||||||
*/
|
|
||||||
export async function preloadIcons() {
|
|
||||||
const pathPrefix = `systems/dotdungeon/assets/`
|
|
||||||
const parsedIcons = {};
|
|
||||||
|
|
||||||
for (const icon of icons) {
|
|
||||||
const iconName = icon.split(`/`).slice(-1)[0].slice(0, -4);
|
|
||||||
if (icon.endsWith(`.svg`)) {
|
|
||||||
try {
|
|
||||||
const response = await fetchWithTimeout(`${pathPrefix}${icon}`);
|
|
||||||
if (response.status !== 200) { continue };
|
|
||||||
const svgData = await response.text();
|
|
||||||
parsedIcons[iconName] = svgData;
|
|
||||||
} catch {
|
|
||||||
console.error(`.dungeon | Failed to fetch/parse icon: ${icon}`);
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else if (icon.endsWith(`.png`)) {
|
|
||||||
parsedIcons[iconName] = `<img alt="" src="${pathPrefix}${icon}">`;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.warn(`.dungeon | Icon "${icon}" failed to be handled by a loader`)
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
return parsedIcons;
|
|
||||||
};
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ export class GenericActorSheet extends ActorSheet {
|
||||||
|
|
||||||
ctx.actor = this.actor;
|
ctx.actor = this.actor;
|
||||||
ctx.config = DOTDUNGEON;
|
ctx.config = DOTDUNGEON;
|
||||||
ctx.icons = CONFIG.CACHE.icons;
|
ctx.icons = {};
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ export class GenericItemSheet extends ItemSheet {
|
||||||
ctx.flags = this.item.flags;
|
ctx.flags = this.item.flags;
|
||||||
|
|
||||||
ctx.config = DOTDUNGEON;
|
ctx.config = DOTDUNGEON;
|
||||||
ctx.icons = CONFIG.CACHE.icons;
|
ctx.icons = {};
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue