Skip to content

Commit

Permalink
Use the global cache-hash for settings and textures .json requests
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Feb 25, 2024
1 parent b437684 commit b02b91d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions BlueMapCommon/webapp/src/js/BlueMapApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();

Expand Down Expand Up @@ -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");
});
Expand Down
16 changes: 8 additions & 8 deletions BlueMapCommon/webapp/src/js/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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}`)
Expand All @@ -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}`)
Expand Down

0 comments on commit b02b91d

Please sign in to comment.