diff --git a/package-lock.json b/package-lock.json index c394c48f66e..85eba4b8904 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2381,9 +2381,9 @@ "dev": true }, "node_modules/follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "dev": true, "funding": [ { diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 6ae41404f89..0ebd972d4c8 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -56,6 +56,7 @@ import PokemonInfoContainer from './ui/pokemon-info-container'; import { biomeDepths } from './data/biomes'; import { initTouchControls } from './touch-controls'; import { UiTheme } from './enums/ui-theme'; +import CacheBustedLoaderPlugin from './plugins/cache-busted-loader-plugin'; export const bypassLogin = false; @@ -188,6 +189,8 @@ export default class BattleScene extends Phaser.Scene { this.phaseQueuePrepend = []; this.phaseQueuePrependSpliceIndex = -1; this.nextCommandPhaseQueue = []; + + Phaser.Plugins.PluginCache.register('Loader', CacheBustedLoaderPlugin, 'load'); } loadImage(key: string, folder: string, filename?: string) { @@ -266,6 +269,13 @@ export default class BattleScene extends Phaser.Scene { } preload() { + const indexFile = Array.from(document.querySelectorAll('script')).map(s => s.src).find(s => /\/index/.test(s)); + if (indexFile) { + const buildIdMatch = /index\-(.*?)\.js$/.exec(indexFile); + if (buildIdMatch) + this.load['cacheBuster'] = buildIdMatch[1]; + } + // Load menu images this.loadAtlas('bg', 'ui'); this.loadImage('command_fight_labels', 'ui'); diff --git a/src/plugins/cache-busted-loader-plugin.ts b/src/plugins/cache-busted-loader-plugin.ts new file mode 100644 index 00000000000..5a1cbf70a94 --- /dev/null +++ b/src/plugins/cache-busted-loader-plugin.ts @@ -0,0 +1,25 @@ +let cacheBuster = ''; + +export default class CacheBustedLoaderPlugin extends Phaser.Loader.LoaderPlugin { + constructor(scene: Phaser.Scene) { + super(scene) + } + + get cacheBuster() { + return cacheBuster + } + + set cacheBuster(version) { + cacheBuster = version + } + + addFile(file): void { + if (!Array.isArray(file)) + file = [ file ] + + if (cacheBuster) + file.forEach(item => item.url += '?v=' + cacheBuster); + + super.addFile(file); + } +} \ No newline at end of file