mirror of
https://github.com/BlueMap-Minecraft/BlueMapWeb.git
synced 2025-01-08 16:17:42 +01:00
Move player-head-url and improve various things
This commit is contained in:
parent
a5c1356c00
commit
bdf89ed5b2
@ -194,13 +194,7 @@ export class Map {
|
||||
loadMapArea(x, z, hiresViewDistance, lowresViewDistance) {
|
||||
if (!this.isLoaded) return;
|
||||
|
||||
const hiresX = Math.floor((x - this.data.hires.translate.x) / this.data.hires.tileSize.x);
|
||||
const hiresZ = Math.floor((z - this.data.hires.translate.z) / this.data.hires.tileSize.z);
|
||||
const hiresViewX = Math.floor(hiresViewDistance / this.data.hires.tileSize.x);
|
||||
const hiresViewZ = Math.floor(hiresViewDistance / this.data.hires.tileSize.z);
|
||||
this.hiresTileManager.loadAroundTile(hiresX, hiresZ, hiresViewX, hiresViewZ);
|
||||
|
||||
for (let i = 0; i < this.lowresTileManager.length; i++) {
|
||||
for (let i = this.lowresTileManager.length - 1; i >= 0; i--) {
|
||||
const lod = i + 1;
|
||||
const scale = Math.pow(this.data.lowres.lodFactor, lod - 1);
|
||||
const lowresX = Math.floor(x / (this.data.lowres.tileSize.x * scale));
|
||||
@ -209,6 +203,12 @@ export class Map {
|
||||
const lowresViewZ = Math.floor(lowresViewDistance / this.data.lowres.tileSize.z);
|
||||
this.lowresTileManager[i].loadAroundTile(lowresX, lowresZ, lowresViewX, lowresViewZ);
|
||||
}
|
||||
|
||||
const hiresX = Math.floor((x - this.data.hires.translate.x) / this.data.hires.tileSize.x);
|
||||
const hiresZ = Math.floor((z - this.data.hires.translate.z) / this.data.hires.tileSize.z);
|
||||
const hiresViewX = Math.floor(hiresViewDistance / this.data.hires.tileSize.x);
|
||||
const hiresViewZ = Math.floor(hiresViewDistance / this.data.hires.tileSize.z);
|
||||
this.hiresTileManager.loadAroundTile(hiresX, hiresZ, hiresViewX, hiresViewZ);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,17 +22,9 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
import {FileLoader, Scene} from "three";
|
||||
import {FileLoader} from "three";
|
||||
import {MarkerSet} from "./MarkerSet";
|
||||
import {alert, generateCacheHash} from "../util/Utils";
|
||||
import {PlayerMarkerSet} from "./PlayerMarkerSet";
|
||||
|
||||
export const MarkerFileType = {
|
||||
NORMAL: 1,
|
||||
PLAYER: 2,
|
||||
}
|
||||
|
||||
export const PLAYER_MARKER_SET_ID = "bm-players";
|
||||
|
||||
/**
|
||||
* A manager for loading and updating markers from a file
|
||||
@ -43,15 +35,13 @@ export class MarkerManager {
|
||||
* @constructor
|
||||
* @param root {MarkerSet} - The scene to which all markers will be added
|
||||
* @param fileUrl {string} - The marker file from which this manager updates its markers
|
||||
* @param fileType {number} - The type of the marker-file, see MarkerManager.NORMAL and MarkerManager.PLAYER
|
||||
* @param events {EventTarget}
|
||||
*/
|
||||
constructor(root, fileUrl, fileType, events = null) {
|
||||
constructor(root, fileUrl, events = null) {
|
||||
Object.defineProperty(this, 'isMarkerManager', {value: true});
|
||||
|
||||
this.root = root;
|
||||
this.fileUrl = fileUrl;
|
||||
this.fileType = fileType;
|
||||
this.events = events;
|
||||
this.disposed = false;
|
||||
|
||||
@ -97,59 +87,10 @@ export class MarkerManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @protected
|
||||
* @param markerData
|
||||
*/
|
||||
updateFromData(markerData) {
|
||||
switch (this.fileType) {
|
||||
case MarkerFileType.NORMAL: return this.updateFromDataNormal(markerData);
|
||||
case MarkerFileType.PLAYER: return this.updateFromDataPlayer(markerData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param markerData
|
||||
* @returns {boolean}
|
||||
*/
|
||||
updateFromDataNormal(markerData) {
|
||||
this.root.updateMarkerSetsFromData(markerData, [PLAYER_MARKER_SET_ID, "bm-popup-set"]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param markerFileData
|
||||
* @returns {boolean}
|
||||
*/
|
||||
updateFromDataPlayer(markerFileData) {
|
||||
let playerMarkerSet = this.getPlayerMarkerSet();
|
||||
return playerMarkerSet.updateFromPlayerData(markerFileData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @returns {PlayerMarkerSet}
|
||||
*/
|
||||
getPlayerMarkerSet() {
|
||||
/** @type {PlayerMarkerSet} */
|
||||
let playerMarkerSet = /** @type {PlayerMarkerSet} */ this.root.markerSets.get(PLAYER_MARKER_SET_ID);
|
||||
|
||||
if (!playerMarkerSet) {
|
||||
playerMarkerSet = new PlayerMarkerSet(PLAYER_MARKER_SET_ID);
|
||||
this.root.add(playerMarkerSet);
|
||||
}
|
||||
|
||||
return playerMarkerSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerUuid {string}
|
||||
* @returns {PlayerMarker | undefined}
|
||||
*/
|
||||
getPlayerMarker(playerUuid) {
|
||||
return this.getPlayerMarkerSet().getPlayerMarker(playerUuid)
|
||||
}
|
||||
updateFromData(markerData) {}
|
||||
|
||||
/**
|
||||
* Stops automatic-updates and disposes all markersets and markers managed by this manager
|
||||
|
51
src/markers/NormalMarkerManager.js
Normal file
51
src/markers/NormalMarkerManager.js
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of BlueMap, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
import { MarkerManager } from "./MarkerManager";
|
||||
import { PLAYER_MARKER_SET_ID } from "./PlayerMarkerManager";
|
||||
|
||||
export class NormalMarkerManager extends MarkerManager {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param root {MarkerSet} - The scene to which all markers will be added
|
||||
* @param fileUrl {string} - The marker file from which this manager updates its markers
|
||||
* @param events {EventTarget}
|
||||
*/
|
||||
constructor(root, fileUrl, events = null) {
|
||||
super(root, fileUrl, events);
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @override
|
||||
* @param markerData
|
||||
* @returns {boolean}
|
||||
*/
|
||||
updateFromData(markerData) {
|
||||
this.root.updateMarkerSetsFromData(markerData, [PLAYER_MARKER_SET_ID, "bm-popup-set"]);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -31,18 +31,20 @@ export class PlayerMarker extends Marker {
|
||||
/**
|
||||
* @param markerId {string}
|
||||
* @param playerUuid {string}
|
||||
* @param playerHead {string}
|
||||
*/
|
||||
constructor(markerId, playerUuid) {
|
||||
constructor(markerId, playerUuid, playerHead = "assets/steve.png") {
|
||||
super(markerId);
|
||||
Object.defineProperty(this, 'isPlayerMarker', {value: true});
|
||||
this.data.type = "player";
|
||||
|
||||
this.data.playerUuid = playerUuid;
|
||||
this.data.name = playerUuid;
|
||||
this.data.playerHead = playerHead;
|
||||
|
||||
this.elementObject = new CSS2DObject(htmlToElement(`
|
||||
<div id="bm-marker-${this.data.id}" class="bm-marker-${this.data.type}">
|
||||
<img src="assets/playerheads/${this.data.playerUuid}.png" alt="playerhead" draggable="false">
|
||||
<img src="${this.data.playerHead}" alt="playerhead" draggable="false">
|
||||
<div class="bm-player-name"></div>
|
||||
</div>
|
||||
`));
|
||||
|
80
src/markers/PlayerMarkerManager.js
Normal file
80
src/markers/PlayerMarkerManager.js
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is part of BlueMap, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
import { PlayerMarkerSet } from "./PlayerMarkerSet";
|
||||
import { MarkerManager } from "./MarkerManager";
|
||||
|
||||
export const PLAYER_MARKER_SET_ID = "bm-players";
|
||||
|
||||
export class PlayerMarkerManager extends MarkerManager {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param root {MarkerSet} - The scene to which all markers will be added
|
||||
* @param fileUrl {string} - The marker file from which this manager updates its markers
|
||||
* @param playerheadsUrl {string} - The url from which playerhead images should be loaded
|
||||
* @param events {EventTarget}
|
||||
*/
|
||||
constructor(root, fileUrl, playerheadsUrl, events = null) {
|
||||
super(root, fileUrl, events);
|
||||
|
||||
this.playerheadsUrl = playerheadsUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @override
|
||||
* @param markerFileData
|
||||
* @returns {boolean}
|
||||
*/
|
||||
updateFromData(markerFileData) {
|
||||
let playerMarkerSet = this.getPlayerMarkerSet();
|
||||
return playerMarkerSet.updateFromPlayerData(markerFileData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @returns {PlayerMarkerSet}
|
||||
*/
|
||||
getPlayerMarkerSet() {
|
||||
/** @type {PlayerMarkerSet} */
|
||||
let playerMarkerSet = /** @type {PlayerMarkerSet} */ this.root.markerSets.get(PLAYER_MARKER_SET_ID);
|
||||
|
||||
if (!playerMarkerSet) {
|
||||
playerMarkerSet = new PlayerMarkerSet(PLAYER_MARKER_SET_ID, this.playerheadsUrl);
|
||||
this.root.add(playerMarkerSet);
|
||||
}
|
||||
|
||||
return playerMarkerSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerUuid {string}
|
||||
* @returns {PlayerMarker | undefined}
|
||||
*/
|
||||
getPlayerMarker(playerUuid) {
|
||||
return this.getPlayerMarkerSet().getPlayerMarker(playerUuid)
|
||||
}
|
||||
|
||||
}
|
@ -29,11 +29,13 @@ import {PlayerMarker} from "./PlayerMarker";
|
||||
|
||||
export class PlayerMarkerSet extends MarkerSet {
|
||||
|
||||
constructor(id) {
|
||||
constructor(id, playerheadsUrl) {
|
||||
super(id);
|
||||
this.data.label = "Player";
|
||||
this.data.toggleable = true;
|
||||
this.data.defaultHide = false;
|
||||
|
||||
this.data.playerheadsUrl = playerheadsUrl;
|
||||
}
|
||||
|
||||
updateFromPlayerData(data) {
|
||||
@ -76,7 +78,7 @@ export class PlayerMarkerSet extends MarkerSet {
|
||||
// create new if not existent of wrong type
|
||||
if (!marker || !marker.isPlayerMarker) {
|
||||
if (marker) this.remove(marker);
|
||||
marker = new PlayerMarker(markerId, playerUuid);
|
||||
marker = new PlayerMarker(markerId, playerUuid, `${this.data.playerheadsUrl}${playerUuid}.png`);
|
||||
this.add(marker);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user