Use the global cache-hash for settings and textures .json requests

This commit is contained in:
Lukas Rieger (Blue) 2024-02-25 01:00:20 +01:00
parent b437684dbb
commit b02b91d3bb
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6
2 changed files with 12 additions and 12 deletions

View File

@ -154,6 +154,9 @@ export class BlueMapApp {
await this.mapViewer.switchMap(null);
oldMaps.forEach(map => map.dispose());
// load user settings
await this.loadUserSettings();
// load maps
this.maps = await this.loadMaps();
for (let map of this.maps) {
@ -180,9 +183,6 @@ export class BlueMapApp {
if(this.updateLoop) clearTimeout(this.updateLoop);
this.updateLoop = setTimeout(this.update, 1000);
// load user settings
await this.loadUserSettings();
// save user settings
this.saveUserSettings();
@ -303,7 +303,7 @@ export class BlueMapApp {
let map = new BlueMapMap(mapId, this.dataUrl + mapId + "/", this.loadBlocker, this.mapViewer.events);
maps.push(map);
await map.loadSettings()
await map.loadSettings(this.mapViewer.tileCacheHash)
.catch(error => {
alert(this.events, `Failed to load settings for map '${map.data.id}':` + error, "warning");
});

View File

@ -105,8 +105,8 @@ export class Map {
load(hiresVertexShader, hiresFragmentShader, lowresVertexShader, lowresFragmentShader, uniforms, tileCacheHash = 0) {
this.unload()
let settingsPromise = this.loadSettings();
let textureFilePromise = this.loadTexturesFile();
let settingsPromise = this.loadSettings(tileCacheHash);
let textureFilePromise = this.loadTexturesFile(tileCacheHash);
this.lowresMaterial = this.createLowresMaterial(lowresVertexShader, lowresFragmentShader, uniforms);
@ -134,8 +134,8 @@ export class Map {
* Loads the settings of this map
* @returns {Promise<void>}
*/
loadSettings() {
return this.loadSettingsFile()
loadSettings(tileCacheHash) {
return this.loadSettingsFile(tileCacheHash)
.then(worldSettings => {
this.data.name = worldSettings.name ? worldSettings.name : this.data.name;
@ -223,13 +223,13 @@ export class Map {
* Loads the settings.json file for this map
* @returns {Promise<Object>}
*/
loadSettingsFile() {
loadSettingsFile(tileCacheHash) {
return new Promise((resolve, reject) => {
alert(this.events, `Loading settings for map '${this.data.id}'...`, "fine");
let loader = new FileLoader();
loader.setResponseType("json");
loader.load(this.data.settingsUrl + "?" + generateCacheHash(),
loader.load(this.data.settingsUrl + "?" + tileCacheHash,
resolve,
() => {},
() => reject(`Failed to load the settings.json for map: ${this.data.id}`)
@ -241,13 +241,13 @@ export class Map {
* Loads the textures.json file for this map
* @returns {Promise<Object>}
*/
loadTexturesFile() {
loadTexturesFile(tileCacheHash) {
return new Promise((resolve, reject) => {
alert(this.events, `Loading textures for map '${this.data.id}'...`, "fine");
let loader = new FileLoader();
loader.setResponseType("json");
loader.load(this.data.texturesUrl + "?" + generateCacheHash(),
loader.load(this.data.texturesUrl + "?" + tileCacheHash,
resolve,
() => {},
() => reject(`Failed to load the textures.json for map: ${this.data.id}`)