LiveAtlas/src/components/chat/ChatMessage.vue

129 lines
3.3 KiB
Vue
Raw Normal View History

2020-12-31 13:05:54 +00:00
<!--
2022-02-21 21:53:49 +00:00
- Copyright 2022 James Lyne
2020-12-31 13:05:54 +00:00
-
2021-07-25 14:12:40 +00:00
- 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
2020-12-31 13:05:54 +00:00
-
2021-07-25 14:12:40 +00:00
- http://www.apache.org/licenses/LICENSE-2.0
2020-12-31 13:05:54 +00:00
-
2021-07-25 14:12:40 +00:00
- 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-31 13:05:54 +00:00
-->
<template>
<li :class="`message message--${message.type}`">
<PlayerImage v-if="showFace && message.playerAccount" :player="message.playerAccount" width="16" height="16" class="message__face" />
<span v-if="messageChannel" class="message__channel" v-html="messageChannel"></span>
2020-12-31 13:05:54 +00:00
<span v-if="showSender" class="message__sender" v-html="message.playerName"></span>
<span class="message__content" v-html="messageContent"></span>
</li>
</template>
<script lang="ts">
import {defineComponent, computed} from "@vue/runtime-core";
2020-12-31 13:05:54 +00:00
import {useStore} from "@/store";
2021-07-25 13:53:45 +00:00
import {LiveAtlasChat} from "@/index";
import PlayerImage from "@/components/PlayerImage.vue";
2020-12-31 13:05:54 +00:00
export default defineComponent({
components: {PlayerImage},
2020-12-31 13:05:54 +00:00
props: {
message: {
2021-07-25 13:53:45 +00:00
type: Object as () => LiveAtlasChat,
2020-12-31 13:05:54 +00:00
required: true,
}
},
setup(props) {
const store = useStore();
let showFace = computed(() => store.state.components.chatBox?.showPlayerFaces && props.message.playerAccount),
2020-12-31 23:30:58 +00:00
showSender = computed(() => props.message.playerName && props.message.type === 'chat'),
messageChannel = computed(() => props.message.type === 'chat' ? props.message.channel : undefined),
2020-12-31 13:05:54 +00:00
messageContent = computed(() => {
switch(props.message.type) {
case 'chat':
return props.message.message;
case 'playerjoin':
if(props.message.playerName) {
2021-05-20 15:13:25 +00:00
return store.state.messages.chatPlayerJoin
2020-12-31 13:05:54 +00:00
.replace('%playername%', props.message.playerName);
} else {
2021-05-20 15:13:25 +00:00
return store.state.messages.chatAnonymousJoin;
2020-12-31 13:05:54 +00:00
}
case 'playerleave':
if(props.message.playerName) {
2021-05-20 15:13:25 +00:00
return store.state.messages.chatPlayerQuit
2020-12-31 13:05:54 +00:00
.replace('%playername%', props.message.playerName);
} else {
2021-05-20 15:13:25 +00:00
return store.state.messages.chatAnonymousQuit;
2020-12-31 13:05:54 +00:00
}
}
})
return {
2021-01-07 22:37:53 +00:00
showFace,
2020-12-31 13:05:54 +00:00
showSender,
messageChannel,
2020-12-31 13:05:54 +00:00
messageContent
}
}
})
</script>
<style lang="scss">
.message {
.message__face {
display: inline-block;
vertical-align: baseline;
margin-right: 0.5rem;
}
.message__channel,
2020-12-31 13:05:54 +00:00
.message__sender {
margin-right: 0.5rem;
word-wrap: break-word;
}
.message__channel {
&:not(:empty):before {
content: '[';
}
&:not(:empty):after {
content: ']';
}
}
2020-12-31 13:05:54 +00:00
.message__sender {
2020-12-31 23:30:58 +00:00
&:not(:empty):after {
2020-12-31 13:05:54 +00:00
content: ': ';
}
}
.message__content {
word-wrap: break-word;
}
2020-12-31 23:30:58 +00:00
&.message--playerjoin,
&.message--playerleave {
font-style: italic;
2020-12-31 13:05:54 +00:00
}
@media (max-width: 320px) {
2020-12-31 13:05:54 +00:00
&.message--chat {
.message__sender:after {
content: none;
}
.message__content {
display: block;
2021-05-15 22:24:29 +00:00
color: var(--text-emphasis);
2020-12-31 13:05:54 +00:00
}
}
}
}
</style>