From b3e593897b1a3b15301939a62dbb7f38b7a07a87 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Sat, 5 Feb 2022 17:31:07 +0000 Subject: [PATCH] Replace MapProvider.getPlayerHeadUrl method with imageUrl property in players component - imageUrl expects a function taking a HeadQueueEntry and returning a string - The dynmap provider has fixed logic for image URLs, but squaremap can vary per world. - Changes to imageUrl do not yet trigger image updates or head cache clearing --- src/index.d.ts | 3 ++- src/providers/DynmapMapProvider.ts | 16 ++-------------- src/providers/MapProvider.ts | 1 - src/providers/Pl3xmapMapProvider.ts | 16 +++++++++------- src/store/mutations.ts | 9 +++++++-- src/store/state.ts | 5 ++++- src/util.ts | 7 ++++++- src/util/dynmap.ts | 16 +++++++++++++--- 8 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index 25015e2..b4f9c4f 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -184,7 +184,6 @@ interface LiveAtlasMapProvider { logout(): void; register(formData: FormData): void; - getPlayerHeadUrl(entry: HeadQueueEntry): string; getTilesUrl(): string; getMarkerIconUrl(icon: string): string; } @@ -265,6 +264,7 @@ interface LiveAtlasComponentConfig { markers?: LiveAtlasPlayerMarkerConfig; showImages: boolean; grayHiddenPlayers: boolean; + imageUrl: (entry: HeadQueueEntry) => string; }; coordinatesControl?: CoordinatesControlOptions; clockControl?: ClockControlOptions; @@ -285,6 +285,7 @@ interface LiveAtlasPartialComponentConfig { markers?: LiveAtlasPlayerMarkerConfig; showImages?: boolean; grayHiddenPlayers?: boolean; + imageUrl?: (entry: HeadQueueEntry) => string; }; coordinatesControl?: CoordinatesControlOptions; clockControl?: ClockControlOptions; diff --git a/src/providers/DynmapMapProvider.ts b/src/providers/DynmapMapProvider.ts index 11b43b8..69955a5 100644 --- a/src/providers/DynmapMapProvider.ts +++ b/src/providers/DynmapMapProvider.ts @@ -15,7 +15,7 @@ */ import { - HeadQueueEntry, LiveAtlasMarker, + LiveAtlasMarker, LiveAtlasMarkerSet, LiveAtlasPlayer, LiveAtlasWorldDefinition @@ -33,7 +33,6 @@ import { buildMessagesConfig, buildServerConfig, buildUpdates, buildWorlds } from "@/util/dynmap"; -import {getImagePixelSize} from "@/util"; import {MarkerSet} from "dynmap"; import {DynmapUrlConfig} from "@/dynmap"; import ConfigurationError from "@/errors/ConfigurationError"; @@ -140,7 +139,7 @@ export default class DynmapMapProvider extends MapProvider { this.store.commit(MutationTypes.SET_MAX_PLAYERS, response.maxcount || 0); this.store.commit(MutationTypes.SET_SERVER_MESSAGES, buildMessagesConfig(response)); this.store.commit(MutationTypes.SET_WORLDS, buildWorlds(response)); - this.store.commit(MutationTypes.SET_COMPONENTS, buildComponents(response)); + this.store.commit(MutationTypes.SET_COMPONENTS, buildComponents(response, this.config)); this.store.commit(MutationTypes.SET_LOGGED_IN, response.loggedin || false); } @@ -313,17 +312,6 @@ export default class DynmapMapProvider extends MapProvider { return this.config.tiles; } - getPlayerHeadUrl(head: HeadQueueEntry): string { - const baseUrl = `${this.config.markers}faces/`; - - if(head.size === 'body') { - return `${baseUrl}body/${head.name}.png`; - } - - const pixels = getImagePixelSize(head.size); - return `${baseUrl}${pixels}x${pixels}/${head.name}.png`; - } - getMarkerIconUrl(icon: string): string { return `${this.config.markers}_markers_/${icon}.png`; } diff --git a/src/providers/MapProvider.ts b/src/providers/MapProvider.ts index 01f70d3..6ac6122 100644 --- a/src/providers/MapProvider.ts +++ b/src/providers/MapProvider.ts @@ -37,7 +37,6 @@ export default abstract class MapProvider implements LiveAtlasMapProvider { abstract startUpdates(): void; abstract stopUpdates(): void; - abstract getPlayerHeadUrl(head: HeadQueueEntry): string; abstract getTilesUrl(): string; abstract getMarkerIconUrl(icon: string): string; diff --git a/src/providers/Pl3xmapMapProvider.ts b/src/providers/Pl3xmapMapProvider.ts index 8164637..e5e3f38 100644 --- a/src/providers/Pl3xmapMapProvider.ts +++ b/src/providers/Pl3xmapMapProvider.ts @@ -15,7 +15,6 @@ */ import { - HeadQueueEntry, LiveAtlasAreaMarker, LiveAtlasCircleMarker, LiveAtlasComponentConfig, @@ -33,7 +32,7 @@ import LiveAtlasMapDefinition from "@/model/LiveAtlasMapDefinition"; import {MutationTypes} from "@/store/mutation-types"; import MapProvider from "@/providers/MapProvider"; import {ActionTypes} from "@/store/action-types"; -import {getBoundsFromPoints, getMiddle, stripHTML, titleColoursRegex} from "@/util"; +import {getBoundsFromPoints, getDefaultMinecraftHead, getMiddle, stripHTML, titleColoursRegex} from "@/util"; import {LiveAtlasMarkerType} from "@/util/markers"; import {PointTuple} from "leaflet"; import ConfigurationError from "@/errors/ConfigurationError"; @@ -121,7 +120,9 @@ export default class Pl3xmapMapProvider extends MapProvider { components: { players: { markers: undefined, + imageUrl: getDefaultMinecraftHead, grayHiddenPlayers: true, + showImages: true, } }, }; @@ -136,6 +137,11 @@ export default class Pl3xmapMapProvider extends MapProvider { this.worldPlayerUpdateIntervals.set(world.name, updateInterval); + if(worldResponse.player_tracker?.nameplates?.heads_url) { + worldConfig.components.players!.imageUrl = entry => + worldResponse.player_tracker.nameplates.heads_url.replace('{uuid}', entry.uuid); + } + worldConfig.components.players!.markers = { hideByDefault: !!worldResponse.player_tracker?.default_hidden, layerName: worldResponse.player_tracker?.label || '', @@ -204,6 +210,7 @@ export default class Pl3xmapMapProvider extends MapProvider { players: { markers: undefined, //Configured per-world + imageUrl: getDefaultMinecraftHead, //Not configurable showImages: true, @@ -593,11 +600,6 @@ export default class Pl3xmapMapProvider extends MapProvider { return `${this.config}tiles/`; } - getPlayerHeadUrl(head: HeadQueueEntry): string { - //TODO: Listen to config - return 'https://mc-heads.net/avatar/{uuid}/16'.replace('{uuid}', head.uuid || ''); - } - getMarkerIconUrl(icon: string): string { return `${this.config}images/icon/registered/${icon}.png`; } diff --git a/src/store/mutations.ts b/src/store/mutations.ts index 5b60459..df691ea 100644 --- a/src/store/mutations.ts +++ b/src/store/mutations.ts @@ -40,7 +40,7 @@ import { LiveAtlasUIModal, LiveAtlasSidebarSectionState, LiveAtlasMarker, LiveAtlasMapViewTarget } from "@/index"; -import {getGlobalMessages} from "@/util"; +import {getDefaultMinecraftHead, getGlobalMessages} from "@/util"; import {getServerMapProvider} from "@/util/config"; export type CurrentMapPayload = { @@ -551,7 +551,12 @@ export const mutations: MutationTree & Mutations = { state.configuration.title = ''; state.components.markers.showLabels= false; - state.components.players.markers = undefined; + state.components.players = { + markers: undefined, + showImages: true, + grayHiddenPlayers: true, + imageUrl: getDefaultMinecraftHead, + }; state.components.coordinatesControl = undefined; state.components.clockControl = undefined; state.components.linkControl = false; diff --git a/src/store/state.ts b/src/store/state.ts index 55bbf6d..e866426 100644 --- a/src/store/state.ts +++ b/src/store/state.ts @@ -39,7 +39,7 @@ import { LiveAtlasMarker, LiveAtlasMapViewTarget } from "@/index"; import LiveAtlasMapDefinition from "@/model/LiveAtlasMapDefinition"; -import {getMessages} from "@/util"; +import {getDefaultMinecraftHead, getMessages} from "@/util"; export type State = { version: string; @@ -155,6 +155,9 @@ export const state: State = { // ("showplayerfacesinmenu" setting in dynmap) showImages: false, + + // (world-settings.x.player-tracker.heads-url in squaremap) + imageUrl: getDefaultMinecraftHead, }, //Optional "coords" component. Adds control showing coordinates on map mouseover diff --git a/src/util.ts b/src/util.ts index b51b6ba..de6837c 100644 --- a/src/util.ts +++ b/src/util.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import defaultImage from '@/assets/images/player_face.png'; import {useStore} from "@/store"; import LiveAtlasMapDefinition from "@/model/LiveAtlasMapDefinition"; import { @@ -113,6 +114,10 @@ export const getMinecraftHead = (player: LiveAtlasPlayer | string, size: LiveAtl return promise; } +export const getDefaultMinecraftHead = () => { + return defaultImage; +} + const tickHeadQueue = () => { if(headsLoading.size > 8 || !headQueue.length) { return; @@ -121,7 +126,7 @@ const tickHeadQueue = () => { const head = headQueue.pop() as HeadQueueEntry; headsLoading.add(head.cacheKey); - head.image.src = useStore().state.currentMapProvider!.getPlayerHeadUrl(head); + head.image.src = useStore().state.components.players.imageUrl(head); tickHeadQueue(); } diff --git a/src/util/dynmap.ts b/src/util/dynmap.ts index b895a6d..c88d067 100644 --- a/src/util/dynmap.ts +++ b/src/util/dynmap.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {DynmapMarkerSetUpdate, DynmapMarkerUpdate, DynmapTileUpdate} from "@/dynmap"; +import {DynmapMarkerSetUpdate, DynmapMarkerUpdate, DynmapTileUpdate, DynmapUrlConfig} from "@/dynmap"; import { LiveAtlasAreaMarker, LiveAtlasChat, @@ -31,7 +31,7 @@ import { import {getPoints} from "@/util/areas"; import { decodeHTMLEntities, - endWorldNameRegex, getBounds, + endWorldNameRegex, getBounds, getImagePixelSize, getMiddle, netherWorldNameRegex, stripHTML, @@ -157,7 +157,7 @@ export function buildWorlds(response: Configuration): Array { + const baseUrl = `${config.markers}faces/`; + + if(entry.size === 'body') { + return `${baseUrl}body/${entry.name}.png`; + } + + const pixels = getImagePixelSize(entry.size); + return `${baseUrl}${pixels}x${pixels}/${entry.name}.png`; + }, showImages: response.showplayerfacesinmenu || false, }, coordinatesControl: undefined,