pokerogue/src/plugins/cache-busted-loader-plugin.ts
2024-04-23 22:00:23 -04:00

30 lines
685 B
TypeScript

let manifest: object;
export default class CacheBustedLoaderPlugin extends Phaser.Loader.LoaderPlugin {
constructor(scene: Phaser.Scene) {
super(scene)
}
get manifest() {
return manifest;
}
set manifest(manifestObj: object) {
manifest = manifestObj;
}
addFile(file): void {
if (!Array.isArray(file))
file = [ file ];
file.forEach(item => {
if (manifest) {
const timestamp = manifest[`/${item.url.replace(/\/\//g, '/')}` ];
if (timestamp)
item.url += `?t=${timestamp}`;
}
});
super.addFile(file);
}
}