From bfc0a381a803ee984ac08da8464ab60cf8137c53 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Tue, 28 Sep 2021 18:54:51 +0100 Subject: [PATCH] Respect pl3xmap show-armor setting --- src/components/map/marker/PlayerMarker.vue | 1 + src/index.d.ts | 1 + src/leaflet/icon/PlayerIcon.ts | 32 ++++++++++++++-------- src/leaflet/marker/PlayerMarker.ts | 2 ++ src/providers/Pl3xmapMapProvider.ts | 1 + src/util/dynmap.ts | 1 + 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/components/map/marker/PlayerMarker.vue b/src/components/map/marker/PlayerMarker.vue index 993cba4..5ec1371 100644 --- a/src/components/map/marker/PlayerMarker.vue +++ b/src/components/map/marker/PlayerMarker.vue @@ -52,6 +52,7 @@ export default defineComponent({ showSkinFace: componentSettings.value!.showSkinFaces, showBody: componentSettings.value!.showBodies, showHealth: componentSettings.value!.showHealth, + showArmor: componentSettings.value!.showArmor, pane: 'players', }), diff --git a/src/index.d.ts b/src/index.d.ts index 9606d3f..8cc862b 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -323,6 +323,7 @@ interface LiveAtlasPlayerMarkerConfig { showBodies: boolean; showSkinFaces: boolean; showHealth: boolean; + showArmor: boolean; smallFaces: boolean; } diff --git a/src/leaflet/icon/PlayerIcon.ts b/src/leaflet/icon/PlayerIcon.ts index 77696b6..7c95b36 100644 --- a/src/leaflet/icon/PlayerIcon.ts +++ b/src/leaflet/icon/PlayerIcon.ts @@ -46,6 +46,7 @@ export interface PlayerIconOptions extends BaseIconOptions { showSkinFace: boolean, showBody: boolean, showHealth: boolean, + showArmor: boolean, } export class PlayerIcon extends Layer implements Icon { @@ -120,24 +121,25 @@ export class PlayerIcon extends Layer implements Icon { if (this.options.showHealth) { this._playerHealth = document.createElement('div'); this._playerHealth.className = 'player__health'; - - this._playerArmor = document.createElement('div'); - this._playerArmor.className = 'player__armor'; + this._playerHealth.hidden = true; this._playerHealthBar = document.createElement('div'); this._playerHealthBar.className = 'player__health-bar'; + this._playerHealth.appendChild(this._playerHealthBar); + this._playerInfo.appendChild(this._playerHealth); + } + + if (this.options.showArmor) { + this._playerArmor = document.createElement('div'); + this._playerArmor.className = 'player__armor'; + this._playerArmor.hidden = true; + this._playerArmorBar = document.createElement('div'); this._playerArmorBar.className = 'player__armor-bar'; - this._playerHealth.appendChild(this._playerHealthBar); this._playerArmor.appendChild(this._playerArmorBar); - this._playerInfo.appendChild(this._playerHealth); this._playerInfo.appendChild(this._playerArmor); - - this._playerHealth.hidden = this._playerArmor.hidden = true; - } else { - this._playerName.classList.add('playerNameNoHealth'); } this._container.style.marginTop = `-${offset}px`; @@ -161,13 +163,19 @@ export class PlayerIcon extends Layer implements Icon { } if(this.options.showHealth) { - if (this._player.health !== undefined && this._player.armor !== undefined) { + if (this._player.health !== undefined) { this._playerHealth!.hidden = false; - this._playerArmor!.hidden = false; this._playerHealthBar!.style.width = Math.ceil(this._player.health * 2.5) + 'px'; - this._playerArmorBar!.style.width = Math.ceil(this._player.armor * 2.5) + 'px'; } else { this._playerHealth!.hidden = true; + } + } + + if(this.options.showArmor) { + if(this._player.armor !== undefined) { + this._playerArmor!.hidden = false; + this._playerArmorBar!.style.width = Math.ceil(this._player.armor * 2.5) + 'px'; + } else { this._playerArmor!.hidden = true; } } diff --git a/src/leaflet/marker/PlayerMarker.ts b/src/leaflet/marker/PlayerMarker.ts index 7ab2a6b..733b83a 100644 --- a/src/leaflet/marker/PlayerMarker.ts +++ b/src/leaflet/marker/PlayerMarker.ts @@ -25,6 +25,7 @@ export interface PlayerMarkerOptions extends MarkerOptions { showSkinFace: boolean, showBody: boolean, showHealth: boolean, + showArmor: boolean, } export class PlayerMarker extends Marker { @@ -43,6 +44,7 @@ export class PlayerMarker extends Marker { showSkinFace: options.showSkinFace, showBody: options.showBody, showHealth: options.showHealth, + showArmor: options.showArmor, }); Util.setOptions(this, options); diff --git a/src/providers/Pl3xmapMapProvider.ts b/src/providers/Pl3xmapMapProvider.ts index 8c9d9ad..1d28080 100644 --- a/src/providers/Pl3xmapMapProvider.ts +++ b/src/providers/Pl3xmapMapProvider.ts @@ -93,6 +93,7 @@ export default class Pl3xmapMapProvider extends MapProvider { showBodies: false, showSkinFaces: true, showHealth: !!worldResponse.player_tracker?.nameplates?.show_health, + showArmor: !!worldResponse.player_tracker?.nameplates?.show_armor, smallFaces: true, } } else { diff --git a/src/util/dynmap.ts b/src/util/dynmap.ts index 7853ace..fad7cce 100644 --- a/src/util/dynmap.ts +++ b/src/util/dynmap.ts @@ -153,6 +153,7 @@ export function buildComponents(response: any): LiveAtlasComponentConfig { showBodies: component.showplayerbody || false, showSkinFaces: component.showplayerfaces || false, showHealth: component.showplayerhealth || false, + showArmor: component.showplayerhealth || false, smallFaces: component.smallplayerfaces || false, }