Moving live-player-endpoint

This commit is contained in:
Lukas Rieger (Blue) 2022-06-27 01:08:03 +02:00
parent e2af667e5e
commit f68547b7ff
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
7 changed files with 162 additions and 131 deletions

@ -1 +1 @@
Subproject commit 889d3cf94ce760a4c202735c7060df0744346d54 Subproject commit 25c4658de4c50d9ea83d9f324b2e7cbab36176fe

160
package-lock.json generated
View File

@ -1829,63 +1829,6 @@
"integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==",
"dev": true "dev": true
}, },
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"optional": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"optional": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"optional": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true,
"optional": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true,
"optional": true
},
"loader-utils": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.2.tgz",
"integrity": "sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==",
"dev": true,
"optional": true,
"requires": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^2.1.2"
}
},
"ssri": { "ssri": {
"version": "8.0.1", "version": "8.0.1",
"resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.1.tgz", "resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.1.tgz",
@ -1894,28 +1837,6 @@
"requires": { "requires": {
"minipass": "^3.1.1" "minipass": "^3.1.1"
} }
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"optional": true,
"requires": {
"has-flag": "^4.0.0"
}
},
"vue-loader-v16": {
"version": "npm:vue-loader@16.8.3",
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.8.3.tgz",
"integrity": "sha512-7vKN45IxsKxe5GcVCbc2qFU5aWzyiLrYJyUuMz4BQLKctCj/fmCa0w6fGiiQ2cLFetNcek1ppGJQDCup0c1hpA==",
"dev": true,
"optional": true,
"requires": {
"chalk": "^4.1.0",
"hash-sum": "^2.0.0",
"loader-utils": "^2.0.0"
}
} }
} }
}, },
@ -12003,6 +11924,87 @@
} }
} }
}, },
"vue-loader-v16": {
"version": "npm:vue-loader@16.8.3",
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.8.3.tgz",
"integrity": "sha512-7vKN45IxsKxe5GcVCbc2qFU5aWzyiLrYJyUuMz4BQLKctCj/fmCa0w6fGiiQ2cLFetNcek1ppGJQDCup0c1hpA==",
"dev": true,
"optional": true,
"requires": {
"chalk": "^4.1.0",
"hash-sum": "^2.0.0",
"loader-utils": "^2.0.0"
},
"dependencies": {
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"optional": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"optional": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"optional": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true,
"optional": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true,
"optional": true
},
"loader-utils": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.2.tgz",
"integrity": "sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==",
"dev": true,
"optional": true,
"requires": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^2.1.2"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"optional": true,
"requires": {
"has-flag": "^4.0.0"
}
}
}
},
"vue-style-loader": { "vue-style-loader": {
"version": "4.1.2", "version": "4.1.2",
"resolved": "https://registry.npmjs.org/vue-style-loader/-/vue-style-loader-4.1.2.tgz", "resolved": "https://registry.npmjs.org/vue-style-loader/-/vue-style-loader-4.1.2.tgz",

View File

@ -1 +0,0 @@
{}

View File

@ -24,7 +24,7 @@ export default {
}, },
methods: { methods: {
switchMap(mapId) { switchMap(mapId) {
this.$bluemap.switchMap(mapId, true); this.$bluemap.switchMap(mapId);
} }
} }
} }

View File

@ -89,7 +89,7 @@ export default {
await this.$bluemap.switchMap(matchingMap.data.id); await this.$bluemap.switchMap(matchingMap.data.id);
} }
if (follow && cm.controls && cm.controls.followPlayerMarker) { if (follow && cm.controls && cm.controls.followPlayerMarker && this.marker.visible) {
cm.controls.followPlayerMarker(this.marker); cm.controls.followPlayerMarker(this.marker);
} }

View File

@ -77,7 +77,7 @@ export class BlueMapApp {
/** @type Map<BlueMapMap> */ /** @type Map<BlueMapMap> */
this.mapsMap = new Map(); this.mapsMap = new Map();
this.dataUrl = "data/"; this.dataUrl = "maps/";
this.mainMenu = new MainMenu(); this.mainMenu = new MainMenu();
@ -163,55 +163,68 @@ export class BlueMapApp {
} }
async followPlayerMarkerWorld() { async followPlayerMarkerWorld() {
let player = this.mapViewer.controlsManager.controls ? /** @type {PlayerLike} */
this.mapViewer.controlsManager.controls.data.followingPlayer : let player = this.mapViewer.controlsManager.controls?.data.followingPlayer;
false;
if (this.mapViewer.map && player) { if (this.mapViewer.map && player) {
if (player.world !== this.mapViewer.map.data.world){ if (player.foreign){
/** @type BlueMapMap */ let matchingMap = await this.findPlayerMap(player.playerUuid)
let matchingMap = null; if (matchingMap) {
for (let map of this.maps) { this.mainMenu.closeAll();
if (map.data.world === player.world) { await this.switchMap(matchingMap.data.id, false);
let playerMarker = this.playerMarkerManager.getPlayerMarker(player.playerUuid);
if (playerMarker && this.mapViewer.controlsManager.controls.followPlayerMarker)
this.mapViewer.controlsManager.controls.followPlayerMarker(playerMarker);
} else {
if (this.mapViewer.controlsManager.controls.stopFollowingPlayerMarker)
this.mapViewer.controlsManager.controls.stopFollowingPlayerMarker();
}
}
}
}
async findPlayerMap(playerUuid) {
/** @type BlueMapMap */
let matchingMap = null;
// search for the map that contains the player
if (this.maps.length < 20) {
for (let map of this.maps) {
let playerData = await this.loadPlayerData(map);
if (!Array.isArray(playerData.players)) continue;
for (let p of playerData.players) {
if (p.uuid === playerUuid && !p.foreign) {
matchingMap = map; matchingMap = map;
break; break;
} }
} }
if (!matchingMap) { if (matchingMap) break;
if (this.mapViewer.controlsManager.controls.stopFollowingPlayerMarker)
this.mapViewer.controlsManager.controls.stopFollowingPlayerMarker();
return;
}
await this.switchMap(matchingMap.data.id);
} }
} }
return matchingMap;
} }
/** /**
* @param mapId {String} * @param mapId {String}
* @param resetCameraIfNewWorld {boolean} * @param resetCamera {boolean}
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
switchMap(mapId, resetCameraIfNewWorld = false) { async switchMap(mapId, resetCamera = true) {
let map = this.mapsMap.get(mapId); let map = this.mapsMap.get(mapId);
if (!map) return Promise.reject(`There is no map with the id "${mapId}" loaded!`); if (!map) return Promise.reject(`There is no map with the id "${mapId}" loaded!`);
let oldWorld = this.mapViewer.map ? this.mapViewer.map.data.world : null; await this.mapViewer.switchMap(map)
return this.mapViewer.switchMap(map).then(() => {
if (map) {
this.initPlayerMarkerManager();
this.initMarkerFileManager();
if (resetCameraIfNewWorld && map.data.world !== oldWorld) { if (resetCamera) this.resetCamera();
this.resetCamera(); this.updatePageAddress();
}
}
this.updatePageAddress(); await Promise.all([
}); this.initPlayerMarkerManager(),
this.initMarkerFileManager()
]);
} }
resetCamera() { resetCamera() {
@ -277,7 +290,7 @@ export class BlueMapApp {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let loader = new FileLoader(); let loader = new FileLoader();
loader.setResponseType("json"); loader.setResponseType("json");
loader.load(this.dataUrl + "settings.json?" + generateCacheHash(), loader.load("settings.json?" + generateCacheHash(),
resolve, resolve,
() => {}, () => {},
() => reject("Failed to load the settings.json!") () => reject("Failed to load the settings.json!")
@ -285,17 +298,37 @@ export class BlueMapApp {
}); });
} }
initPlayerMarkerManager() { /**
if (!this.mapViewer.map) return; * @param map {BlueMapMap}
* @returns {Promise<Object>}
*/
loadPlayerData(map) {
return new Promise((resolve, reject) => {
let loader = new FileLoader();
loader.setResponseType("json");
loader.load(map.data.dataUrl + "live/players?" + generateCacheHash(),
fileData => {
if (!fileData) reject(`Failed to parse '${this.fileUrl}'!`);
else resolve(fileData);
},
() => {},
() => reject(`Failed to load '${this.fileUrl}'!`)
)
});
}
if (this.playerMarkerManager) { initPlayerMarkerManager() {
this.playerMarkerManager.worldId = this.mapViewer.map.data.world; if (this.playerMarkerManager){
} else { this.playerMarkerManager.clear();
this.playerMarkerManager = new PlayerMarkerManager(this.mapViewer.markers, "live/players", this.mapViewer.map.data.world, this.events); this.playerMarkerManager.dispose()
} }
const map = this.mapViewer.map;
if (!map) return;
this.playerMarkerManager = new PlayerMarkerManager(this.mapViewer.markers, map.data.dataUrl + "live/players", this.events);
this.playerMarkerManager.setAutoUpdateInterval(0); this.playerMarkerManager.setAutoUpdateInterval(0);
this.playerMarkerManager.update() return this.playerMarkerManager.update()
.then(() => { .then(() => {
this.playerMarkerManager.setAutoUpdateInterval(1000); this.playerMarkerManager.setAutoUpdateInterval(1000);
}) })
@ -312,10 +345,11 @@ export class BlueMapApp {
this.markerFileManager.dispose(); this.markerFileManager.dispose();
} }
if (!this.mapViewer.map) return; const map = this.mapViewer.map;
if (!map) return;
this.markerFileManager = new MarkerFileManager(this.mapViewer.markers, "data/markers.json", this.mapViewer.map.data.id, this.events); this.markerFileManager = new MarkerFileManager(this.mapViewer.markers, map.data.dataUrl + "markers.json", map.data.id, this.events);
this.markerFileManager.update() return this.markerFileManager.update()
.then(() => { .then(() => {
this.markerFileManager.setAutoUpdateInterval(1000 * 10); this.markerFileManager.setAutoUpdateInterval(1000 * 10);
}) })
@ -586,7 +620,7 @@ export class BlueMapApp {
} }
loadPageAddress = async () => { loadPageAddress = async () => {
let hash = window.location.hash.substring(1) || this.settings.startLocation; let hash = window.location.hash?.substring(1) || this.settings.startLocation || "";
let values = hash.split(":"); let values = hash.split(":");
if (values.length !== 10) return false; if (values.length !== 10) return false;

View File

@ -5,18 +5,14 @@ module.exports = {
publicPath: './', publicPath: './',
devServer: { devServer: {
proxy: { proxy: {
'/data': { '/maps': {
target: 'https://bluecolored.de/bluemap-dev', target: 'https://localhost:8100',
changeOrigin: true, changeOrigin: true,
}, },
'/assets/playerheads': { '/assets/playerheads': {
target: 'https://bluecolored.de/bluemap', target: 'https://bluecolored.de/bluemap',
changeOrigin: true, changeOrigin: true,
}, }
'/live': {
target: 'https://bluecolored.de/bluemap',
changeOrigin: true,
},
} }
} }
} }