2020-12-16 16:54:41 +00:00
|
|
|
<!--
|
|
|
|
- Copyright 2020 James Lyne
|
|
|
|
-
|
|
|
|
- Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
- you may not use this file except in compliance with the License.
|
|
|
|
- You may obtain a copy of the License at
|
|
|
|
-
|
|
|
|
- http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
-
|
|
|
|
- Unless required by applicable law or agreed to in writing, software
|
|
|
|
- distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
- See the License for the specific language governing permissions and
|
|
|
|
- limitations under the License.
|
|
|
|
-->
|
|
|
|
|
2020-12-01 23:20:38 +00:00
|
|
|
<template>
|
2021-05-28 13:50:32 +00:00
|
|
|
<input :id="`player-${player.account}`" type="radio" name="player" v-bind:value="player.account" v-model="followTarget"
|
2021-05-27 23:13:46 +00:00
|
|
|
@click.prevent="onInputClick" />
|
|
|
|
<label :for="`player-${player.account}`"
|
|
|
|
:class="{'player': true, 'player--hidden' : !!player.hidden, 'player--other-world': otherWorld}" :title="title"
|
|
|
|
@click.prevent="onLabelClick">
|
2021-05-25 22:28:43 +00:00
|
|
|
<img width="16" height="16" class="player__icon" :src="image" alt="" aria-hidden="true" />
|
2021-05-27 23:13:46 +00:00
|
|
|
<span class="player__name" v-html="player.name"></span>
|
|
|
|
</label>
|
2020-12-01 23:20:38 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-12-23 03:07:44 +00:00
|
|
|
import {defineComponent, computed, ref, onMounted} from 'vue';
|
2020-12-01 23:20:38 +00:00
|
|
|
import {DynmapPlayer} from "@/dynmap";
|
|
|
|
import {useStore} from "@/store";
|
|
|
|
import {MutationTypes} from "@/store/mutation-types";
|
2021-01-26 20:37:29 +00:00
|
|
|
import {getMinecraftHead} from '@/util';
|
2021-05-15 19:25:03 +00:00
|
|
|
import defaultImage from '@/assets/images/player_face.png';
|
2020-12-13 13:23:32 +00:00
|
|
|
|
2020-12-01 23:20:38 +00:00
|
|
|
export default defineComponent({
|
|
|
|
name: 'PlayerListItem',
|
|
|
|
props: {
|
|
|
|
player: {
|
|
|
|
type: Object as () => DynmapPlayer,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
2020-12-23 03:07:19 +00:00
|
|
|
setup(props) {
|
|
|
|
const store = useStore(),
|
|
|
|
otherWorld = computed(() => {
|
|
|
|
return store.state.configuration.grayHiddenPlayers
|
|
|
|
&& (!store.state.currentWorld || store.state.currentWorld.name !== props.player.location.world);
|
|
|
|
}),
|
|
|
|
|
|
|
|
title = computed(() => {
|
|
|
|
if(props.player.hidden) {
|
2021-05-20 15:39:41 +00:00
|
|
|
return store.state.messages.playersTitleHidden;
|
2020-12-23 03:07:19 +00:00
|
|
|
} else if(otherWorld.value) {
|
2021-05-20 15:39:41 +00:00
|
|
|
return store.state.messages.playersTitleOtherWorld;
|
2020-12-23 03:07:19 +00:00
|
|
|
} else {
|
2021-05-20 15:39:41 +00:00
|
|
|
return store.state.messages.playersTitle;
|
2020-12-23 03:07:19 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2021-05-28 13:50:32 +00:00
|
|
|
followTarget = computed(() => store.state.followTarget ? store.state.followTarget.account : undefined),
|
2021-05-27 23:13:46 +00:00
|
|
|
|
2020-12-23 03:07:19 +00:00
|
|
|
pan = () => {
|
|
|
|
if(!props.player.hidden) {
|
|
|
|
store.commit(MutationTypes.CLEAR_FOLLOW_TARGET, undefined);
|
|
|
|
store.commit(MutationTypes.SET_PAN_TARGET, props.player);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
follow = () => store.commit(MutationTypes.SET_FOLLOW_TARGET, props.player),
|
|
|
|
|
2021-05-27 23:13:46 +00:00
|
|
|
onInputClick = (e: MouseEvent) => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2020-12-23 03:07:19 +00:00
|
|
|
if(e.shiftKey) {
|
|
|
|
follow();
|
2021-05-27 23:13:46 +00:00
|
|
|
} else {
|
|
|
|
pan();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onLabelClick = (e: MouseEvent) => {
|
|
|
|
if(e.shiftKey || e.detail === 2) {
|
|
|
|
follow();
|
2020-12-23 03:07:19 +00:00
|
|
|
} else {
|
2021-05-26 17:49:11 +00:00
|
|
|
pan();
|
2020-12-23 03:07:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let image = ref(defaultImage);
|
|
|
|
|
2020-12-23 03:07:44 +00:00
|
|
|
onMounted(() => {
|
|
|
|
if(store.state.components.playerMarkers && store.state.components.playerMarkers.showSkinFaces) {
|
2021-01-26 20:37:29 +00:00
|
|
|
getMinecraftHead(props.player, '16').then((result) => image.value = result.src).catch(() => {});
|
2020-12-23 03:07:44 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-12-13 13:23:32 +00:00
|
|
|
return {
|
2020-12-23 03:07:19 +00:00
|
|
|
image,
|
|
|
|
title,
|
|
|
|
otherWorld,
|
2021-05-27 23:13:46 +00:00
|
|
|
followTarget,
|
|
|
|
onInputClick,
|
|
|
|
onLabelClick
|
2020-12-13 13:23:32 +00:00
|
|
|
}
|
|
|
|
},
|
2020-12-01 23:20:38 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-05-27 23:13:46 +00:00
|
|
|
@import '../../scss/mixins';
|
|
|
|
|
2020-12-01 23:20:38 +00:00
|
|
|
.player {
|
|
|
|
.player__icon {
|
|
|
|
position: absolute;
|
|
|
|
display: block;
|
|
|
|
top: 0;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0.7rem;
|
|
|
|
pointer-events: none;
|
|
|
|
margin: auto;
|
2021-05-24 16:34:15 +00:00
|
|
|
z-index: 2;
|
2020-12-01 23:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.player__name {
|
2021-05-27 23:13:46 +00:00
|
|
|
padding-left: 2.7rem;
|
2020-12-01 23:20:38 +00:00
|
|
|
}
|
2020-12-18 16:04:06 +00:00
|
|
|
|
|
|
|
&.player--hidden {
|
|
|
|
.player__icon {
|
|
|
|
filter: grayscale(1);
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.player--other-world {
|
|
|
|
.player__icon {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
|
2021-05-15 22:24:29 +00:00
|
|
|
.player__name {
|
|
|
|
color: var(--text-disabled);
|
|
|
|
}
|
2020-12-18 16:04:06 +00:00
|
|
|
}
|
2020-12-01 23:20:38 +00:00
|
|
|
}
|
2021-06-13 00:06:58 +00:00
|
|
|
</style>
|