LiveAtlas/src/components/sidebar/PlayerListItem.vue

92 lines
2.2 KiB
Vue
Raw Normal View History

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>
<li class="player">
2020-12-13 13:23:32 +00:00
<img width="16" height="16" class="player__icon" :src="playerImage" alt="" />
2020-12-01 23:20:38 +00:00
<button class="player__name" type="button" title="Click to center on player&#10;Double-click to follow player"
@click.prevent="pan"
@keydown="onKeydown"
@dblclick.prevent="follow" v-html="player.name"></button>
2020-12-01 23:20:38 +00:00
</li>
</template>
<script lang="ts">
import {defineComponent} from 'vue';
import {DynmapPlayer} from "@/dynmap";
import {useStore} from "@/store";
import {MutationTypes} from "@/store/mutation-types";
2020-12-13 13:23:32 +00:00
const playerImage = require('@/assets/images/player_face.png');
2020-12-01 23:20:38 +00:00
export default defineComponent({
name: 'PlayerListItem',
props: {
player: {
type: Object as () => DynmapPlayer,
required: true
}
},
2020-12-13 13:23:32 +00:00
data() {
return {
playerImage: playerImage,
}
},
2020-12-01 23:20:38 +00:00
methods: {
follow() {
useStore().commit(MutationTypes.FOLLOW_PLAYER, this.player);
},
pan() {
useStore().commit(MutationTypes.FOLLOW_PLAYER, this.player);
useStore().commit(MutationTypes.CLEAR_FOLLOW, undefined);
},
onKeydown(e: KeyboardEvent) {
if(e.key !== ' ') {
return;
}
e.shiftKey ? this.follow() : this.pan();
}
}
});
</script>
<style lang="scss" scoped>
.player {
position: relative;
display: block;
line-height: 3rem;
.player__icon {
position: absolute;
display: block;
top: 0;
bottom: 0;
left: 0.7rem;
pointer-events: none;
margin: auto;
2020-12-13 13:23:32 +00:00
z-index: 1;
2020-12-01 23:20:38 +00:00
}
.player__name {
2020-12-13 13:31:38 +00:00
padding: 0.8rem 0 0.7rem 3.5rem;
2020-12-01 23:20:38 +00:00
text-align: left;
margin: 0;
width: 100%;
height: 100%;
}
}
</style>