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
This commit is contained in:
James Lyne 2022-02-05 17:31:07 +00:00
parent db41a585e6
commit b3e593897b
8 changed files with 43 additions and 30 deletions

3
src/index.d.ts vendored
View File

@ -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;

View File

@ -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`;
}

View File

@ -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;

View File

@ -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`;
}

View File

@ -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<State> & 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;

View File

@ -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

View File

@ -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();
}

View File

@ -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<LiveAtlasWorldDefini
return Array.from(worlds.values());
}
export function buildComponents(response: Configuration): LiveAtlasComponentConfig {
export function buildComponents(response: Configuration, config: DynmapUrlConfig): LiveAtlasComponentConfig {
const components: LiveAtlasComponentConfig = {
markers: {
showLabels: false,
@ -167,6 +167,16 @@ export function buildComponents(response: Configuration): LiveAtlasComponentConf
players: {
markers: undefined,
grayHiddenPlayers: false,
imageUrl: entry => {
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,