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:
parent
db41a585e6
commit
b3e593897b
3
src/index.d.ts
vendored
3
src/index.d.ts
vendored
@ -184,7 +184,6 @@ interface LiveAtlasMapProvider {
|
|||||||
logout(): void;
|
logout(): void;
|
||||||
register(formData: FormData): void;
|
register(formData: FormData): void;
|
||||||
|
|
||||||
getPlayerHeadUrl(entry: HeadQueueEntry): string;
|
|
||||||
getTilesUrl(): string;
|
getTilesUrl(): string;
|
||||||
getMarkerIconUrl(icon: string): string;
|
getMarkerIconUrl(icon: string): string;
|
||||||
}
|
}
|
||||||
@ -265,6 +264,7 @@ interface LiveAtlasComponentConfig {
|
|||||||
markers?: LiveAtlasPlayerMarkerConfig;
|
markers?: LiveAtlasPlayerMarkerConfig;
|
||||||
showImages: boolean;
|
showImages: boolean;
|
||||||
grayHiddenPlayers: boolean;
|
grayHiddenPlayers: boolean;
|
||||||
|
imageUrl: (entry: HeadQueueEntry) => string;
|
||||||
};
|
};
|
||||||
coordinatesControl?: CoordinatesControlOptions;
|
coordinatesControl?: CoordinatesControlOptions;
|
||||||
clockControl?: ClockControlOptions;
|
clockControl?: ClockControlOptions;
|
||||||
@ -285,6 +285,7 @@ interface LiveAtlasPartialComponentConfig {
|
|||||||
markers?: LiveAtlasPlayerMarkerConfig;
|
markers?: LiveAtlasPlayerMarkerConfig;
|
||||||
showImages?: boolean;
|
showImages?: boolean;
|
||||||
grayHiddenPlayers?: boolean;
|
grayHiddenPlayers?: boolean;
|
||||||
|
imageUrl?: (entry: HeadQueueEntry) => string;
|
||||||
};
|
};
|
||||||
coordinatesControl?: CoordinatesControlOptions;
|
coordinatesControl?: CoordinatesControlOptions;
|
||||||
clockControl?: ClockControlOptions;
|
clockControl?: ClockControlOptions;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
HeadQueueEntry, LiveAtlasMarker,
|
LiveAtlasMarker,
|
||||||
LiveAtlasMarkerSet,
|
LiveAtlasMarkerSet,
|
||||||
LiveAtlasPlayer,
|
LiveAtlasPlayer,
|
||||||
LiveAtlasWorldDefinition
|
LiveAtlasWorldDefinition
|
||||||
@ -33,7 +33,6 @@ import {
|
|||||||
buildMessagesConfig,
|
buildMessagesConfig,
|
||||||
buildServerConfig, buildUpdates, buildWorlds
|
buildServerConfig, buildUpdates, buildWorlds
|
||||||
} from "@/util/dynmap";
|
} from "@/util/dynmap";
|
||||||
import {getImagePixelSize} from "@/util";
|
|
||||||
import {MarkerSet} from "dynmap";
|
import {MarkerSet} from "dynmap";
|
||||||
import {DynmapUrlConfig} from "@/dynmap";
|
import {DynmapUrlConfig} from "@/dynmap";
|
||||||
import ConfigurationError from "@/errors/ConfigurationError";
|
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_MAX_PLAYERS, response.maxcount || 0);
|
||||||
this.store.commit(MutationTypes.SET_SERVER_MESSAGES, buildMessagesConfig(response));
|
this.store.commit(MutationTypes.SET_SERVER_MESSAGES, buildMessagesConfig(response));
|
||||||
this.store.commit(MutationTypes.SET_WORLDS, buildWorlds(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);
|
this.store.commit(MutationTypes.SET_LOGGED_IN, response.loggedin || false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,17 +312,6 @@ export default class DynmapMapProvider extends MapProvider {
|
|||||||
return this.config.tiles;
|
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 {
|
getMarkerIconUrl(icon: string): string {
|
||||||
return `${this.config.markers}_markers_/${icon}.png`;
|
return `${this.config.markers}_markers_/${icon}.png`;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ export default abstract class MapProvider implements LiveAtlasMapProvider {
|
|||||||
abstract startUpdates(): void;
|
abstract startUpdates(): void;
|
||||||
abstract stopUpdates(): void;
|
abstract stopUpdates(): void;
|
||||||
|
|
||||||
abstract getPlayerHeadUrl(head: HeadQueueEntry): string;
|
|
||||||
abstract getTilesUrl(): string;
|
abstract getTilesUrl(): string;
|
||||||
abstract getMarkerIconUrl(icon: string): string;
|
abstract getMarkerIconUrl(icon: string): string;
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
HeadQueueEntry,
|
|
||||||
LiveAtlasAreaMarker,
|
LiveAtlasAreaMarker,
|
||||||
LiveAtlasCircleMarker,
|
LiveAtlasCircleMarker,
|
||||||
LiveAtlasComponentConfig,
|
LiveAtlasComponentConfig,
|
||||||
@ -33,7 +32,7 @@ import LiveAtlasMapDefinition from "@/model/LiveAtlasMapDefinition";
|
|||||||
import {MutationTypes} from "@/store/mutation-types";
|
import {MutationTypes} from "@/store/mutation-types";
|
||||||
import MapProvider from "@/providers/MapProvider";
|
import MapProvider from "@/providers/MapProvider";
|
||||||
import {ActionTypes} from "@/store/action-types";
|
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 {LiveAtlasMarkerType} from "@/util/markers";
|
||||||
import {PointTuple} from "leaflet";
|
import {PointTuple} from "leaflet";
|
||||||
import ConfigurationError from "@/errors/ConfigurationError";
|
import ConfigurationError from "@/errors/ConfigurationError";
|
||||||
@ -121,7 +120,9 @@ export default class Pl3xmapMapProvider extends MapProvider {
|
|||||||
components: {
|
components: {
|
||||||
players: {
|
players: {
|
||||||
markers: undefined,
|
markers: undefined,
|
||||||
|
imageUrl: getDefaultMinecraftHead,
|
||||||
grayHiddenPlayers: true,
|
grayHiddenPlayers: true,
|
||||||
|
showImages: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -136,6 +137,11 @@ export default class Pl3xmapMapProvider extends MapProvider {
|
|||||||
|
|
||||||
this.worldPlayerUpdateIntervals.set(world.name, updateInterval);
|
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 = {
|
worldConfig.components.players!.markers = {
|
||||||
hideByDefault: !!worldResponse.player_tracker?.default_hidden,
|
hideByDefault: !!worldResponse.player_tracker?.default_hidden,
|
||||||
layerName: worldResponse.player_tracker?.label || '',
|
layerName: worldResponse.player_tracker?.label || '',
|
||||||
@ -204,6 +210,7 @@ export default class Pl3xmapMapProvider extends MapProvider {
|
|||||||
|
|
||||||
players: {
|
players: {
|
||||||
markers: undefined, //Configured per-world
|
markers: undefined, //Configured per-world
|
||||||
|
imageUrl: getDefaultMinecraftHead,
|
||||||
|
|
||||||
//Not configurable
|
//Not configurable
|
||||||
showImages: true,
|
showImages: true,
|
||||||
@ -593,11 +600,6 @@ export default class Pl3xmapMapProvider extends MapProvider {
|
|||||||
return `${this.config}tiles/`;
|
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 {
|
getMarkerIconUrl(icon: string): string {
|
||||||
return `${this.config}images/icon/registered/${icon}.png`;
|
return `${this.config}images/icon/registered/${icon}.png`;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ import {
|
|||||||
LiveAtlasUIModal,
|
LiveAtlasUIModal,
|
||||||
LiveAtlasSidebarSectionState, LiveAtlasMarker, LiveAtlasMapViewTarget
|
LiveAtlasSidebarSectionState, LiveAtlasMarker, LiveAtlasMapViewTarget
|
||||||
} from "@/index";
|
} from "@/index";
|
||||||
import {getGlobalMessages} from "@/util";
|
import {getDefaultMinecraftHead, getGlobalMessages} from "@/util";
|
||||||
import {getServerMapProvider} from "@/util/config";
|
import {getServerMapProvider} from "@/util/config";
|
||||||
|
|
||||||
export type CurrentMapPayload = {
|
export type CurrentMapPayload = {
|
||||||
@ -551,7 +551,12 @@ export const mutations: MutationTree<State> & Mutations = {
|
|||||||
state.configuration.title = '';
|
state.configuration.title = '';
|
||||||
|
|
||||||
state.components.markers.showLabels= false;
|
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.coordinatesControl = undefined;
|
||||||
state.components.clockControl = undefined;
|
state.components.clockControl = undefined;
|
||||||
state.components.linkControl = false;
|
state.components.linkControl = false;
|
||||||
|
@ -39,7 +39,7 @@ import {
|
|||||||
LiveAtlasMarker, LiveAtlasMapViewTarget
|
LiveAtlasMarker, LiveAtlasMapViewTarget
|
||||||
} from "@/index";
|
} from "@/index";
|
||||||
import LiveAtlasMapDefinition from "@/model/LiveAtlasMapDefinition";
|
import LiveAtlasMapDefinition from "@/model/LiveAtlasMapDefinition";
|
||||||
import {getMessages} from "@/util";
|
import {getDefaultMinecraftHead, getMessages} from "@/util";
|
||||||
|
|
||||||
export type State = {
|
export type State = {
|
||||||
version: string;
|
version: string;
|
||||||
@ -155,6 +155,9 @@ export const state: State = {
|
|||||||
|
|
||||||
// ("showplayerfacesinmenu" setting in dynmap)
|
// ("showplayerfacesinmenu" setting in dynmap)
|
||||||
showImages: false,
|
showImages: false,
|
||||||
|
|
||||||
|
// (world-settings.x.player-tracker.heads-url in squaremap)
|
||||||
|
imageUrl: getDefaultMinecraftHead,
|
||||||
},
|
},
|
||||||
|
|
||||||
//Optional "coords" component. Adds control showing coordinates on map mouseover
|
//Optional "coords" component. Adds control showing coordinates on map mouseover
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import defaultImage from '@/assets/images/player_face.png';
|
||||||
import {useStore} from "@/store";
|
import {useStore} from "@/store";
|
||||||
import LiveAtlasMapDefinition from "@/model/LiveAtlasMapDefinition";
|
import LiveAtlasMapDefinition from "@/model/LiveAtlasMapDefinition";
|
||||||
import {
|
import {
|
||||||
@ -113,6 +114,10 @@ export const getMinecraftHead = (player: LiveAtlasPlayer | string, size: LiveAtl
|
|||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getDefaultMinecraftHead = () => {
|
||||||
|
return defaultImage;
|
||||||
|
}
|
||||||
|
|
||||||
const tickHeadQueue = () => {
|
const tickHeadQueue = () => {
|
||||||
if(headsLoading.size > 8 || !headQueue.length) {
|
if(headsLoading.size > 8 || !headQueue.length) {
|
||||||
return;
|
return;
|
||||||
@ -121,7 +126,7 @@ const tickHeadQueue = () => {
|
|||||||
const head = headQueue.pop() as HeadQueueEntry;
|
const head = headQueue.pop() as HeadQueueEntry;
|
||||||
|
|
||||||
headsLoading.add(head.cacheKey);
|
headsLoading.add(head.cacheKey);
|
||||||
head.image.src = useStore().state.currentMapProvider!.getPlayerHeadUrl(head);
|
head.image.src = useStore().state.components.players.imageUrl(head);
|
||||||
|
|
||||||
tickHeadQueue();
|
tickHeadQueue();
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {DynmapMarkerSetUpdate, DynmapMarkerUpdate, DynmapTileUpdate} from "@/dynmap";
|
import {DynmapMarkerSetUpdate, DynmapMarkerUpdate, DynmapTileUpdate, DynmapUrlConfig} from "@/dynmap";
|
||||||
import {
|
import {
|
||||||
LiveAtlasAreaMarker,
|
LiveAtlasAreaMarker,
|
||||||
LiveAtlasChat,
|
LiveAtlasChat,
|
||||||
@ -31,7 +31,7 @@ import {
|
|||||||
import {getPoints} from "@/util/areas";
|
import {getPoints} from "@/util/areas";
|
||||||
import {
|
import {
|
||||||
decodeHTMLEntities,
|
decodeHTMLEntities,
|
||||||
endWorldNameRegex, getBounds,
|
endWorldNameRegex, getBounds, getImagePixelSize,
|
||||||
getMiddle,
|
getMiddle,
|
||||||
netherWorldNameRegex,
|
netherWorldNameRegex,
|
||||||
stripHTML,
|
stripHTML,
|
||||||
@ -157,7 +157,7 @@ export function buildWorlds(response: Configuration): Array<LiveAtlasWorldDefini
|
|||||||
return Array.from(worlds.values());
|
return Array.from(worlds.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildComponents(response: Configuration): LiveAtlasComponentConfig {
|
export function buildComponents(response: Configuration, config: DynmapUrlConfig): LiveAtlasComponentConfig {
|
||||||
const components: LiveAtlasComponentConfig = {
|
const components: LiveAtlasComponentConfig = {
|
||||||
markers: {
|
markers: {
|
||||||
showLabels: false,
|
showLabels: false,
|
||||||
@ -167,6 +167,16 @@ export function buildComponents(response: Configuration): LiveAtlasComponentConf
|
|||||||
players: {
|
players: {
|
||||||
markers: undefined,
|
markers: undefined,
|
||||||
grayHiddenPlayers: false,
|
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,
|
showImages: response.showplayerfacesinmenu || false,
|
||||||
},
|
},
|
||||||
coordinatesControl: undefined,
|
coordinatesControl: undefined,
|
||||||
|
Loading…
Reference in New Issue
Block a user