feat: add cameo feature

This commit is contained in:
Settel 2022-09-11 21:32:08 +02:00
parent 3e20b783ee
commit 9e0403cbf2
5 changed files with 48 additions and 8 deletions

View File

@ -50,6 +50,7 @@ $button-caution-hover-text-color: $button-caution-text-color;
// Topbar // Topbar
$topbar-background-color: #006898; $topbar-background-color: #006898;
$topbar-separator-color: #ffffff; $topbar-separator-color: #ffffff;
$topbar-cameo-background-color: #602838;
// Alert // Alert
$alert-background-color: #A06060; $alert-background-color: #A06060;

View File

@ -1,5 +1,5 @@
<template> <template>
<div v-if="user.name" class="topbar__container"> <div v-if="user.name" class="topbar__container" :class="{ 'topbar__container__cameo': user.userInfo.isCameo }">
<div class="topbar__username"> <div class="topbar__username">
{{ user.name }} {{ user.name }}
</div> </div>
@ -23,9 +23,10 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { useRouter } from '#app' import { navigateTo } from '#app'
import useAuth from '@/composables/useAuth'; import useAuth from '@/composables/useAuth';
import useI18n from '@/composables/useI18n'; import useI18n from '@/composables/useI18n';
import useEngine from '@/composables/useEngine';
import { useUserinfoStore } from "@/stores/UserinfoStore" import { useUserinfoStore } from "@/stores/UserinfoStore"
import { useGameinfoStore } from "@/stores/GameinfoStore" import { useGameinfoStore } from "@/stores/GameinfoStore"
@ -36,9 +37,16 @@ const { $t } = useI18n({
const user = useUserinfoStore() const user = useUserinfoStore()
const game = useGameinfoStore() const game = useGameinfoStore()
const { logout } = useAuth()
const { logoutCameo } = useEngine()
const actionLogout = async () => { const actionLogout = async () => {
await useAuth().logout() if (user.userInfo.isCameo) {
useRouter().push('/') await logoutCameo()
navigateTo('/admin')
} else {
await logout()
navigateTo('/')
}
} }
</script> </script>
@ -56,6 +64,10 @@ const actionLogout = async () => {
font-family: $font-primary; font-family: $font-primary;
font-weight: bold; font-weight: bold;
cursor: default; cursor: default;
&__cameo {
background-color: $topbar-cameo-background-color;
}
} }
&__username, &__username,

View File

@ -8,7 +8,7 @@
<th class="gameinfos-tile__table-head">{{ $t('num-players')}}</th> <th class="gameinfos-tile__table-head">{{ $t('num-players')}}</th>
<th class="gameinfos-tile__table-head">{{ $t('gamemasters')}}</th> <th class="gameinfos-tile__table-head">{{ $t('gamemasters')}}</th>
</tr> </tr>
<tr class="gameinfos-tile__row" v-for="game in games" :key="game.id"> <tr class="gameinfos-tile__row" v-for="game in games" :key="game.id" @click="selectGame(game)">
<td class="gameinfos-tile__cell">{{ game.name }}</td> <td class="gameinfos-tile__cell">{{ game.name }}</td>
<td class="gameinfos-tile__cell">{{ game.lang }}</td> <td class="gameinfos-tile__cell">{{ game.lang }}</td>
<td class="gameinfos-tile__cell">{{ game.state }}</td> <td class="gameinfos-tile__cell">{{ game.state }}</td>
@ -20,10 +20,11 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { navigateTo } from "#app"
import { ref } from 'vue' import { ref } from 'vue'
import useI18n from '@/composables/useI18n' import useI18n from '@/composables/useI18n'
import useEngine from '@/composables/useEngine' import useEngine from '@/composables/useEngine'
import { GameInfo } from '@/composables/engine.d' import type { GameInfo } from '@/composables/engine.d'
const { $t } = useI18n({ const { $t } = useI18n({
'team-name': { en: 'Team name', de: 'Teamname' }, 'team-name': { en: 'Team name', de: 'Teamname' },
@ -33,8 +34,20 @@ const { $t } = useI18n({
gamemasters: { en: 'Gamemaster(s)', de: 'Gamemaster(s)' }, gamemasters: { en: 'Gamemaster(s)', de: 'Gamemaster(s)' },
}) })
const games = ref(await useEngine().fetchGameInfos()) const { fetchGameInfos, cameo } = useEngine()
const games = ref(await fetchGameInfos())
const getGamemastersFromGame = (game: GameInfo) => game.players.filter((player) => player.role === 'gamemaster').map((player) => player.name) const getGamemastersFromGame = (game: GameInfo) => game.players.filter((player) => player.role === 'gamemaster').map((player) => player.name)
const selectGame = async (game: GameInfo): Promise<void> => {
for (const player of game.players) {
if (player.role === 'gamemaster') {
await cameo(player.authcode)
break
}
}
navigateTo('/gamemaster')
}
</script> </script>
<style lang="scss"> <style lang="scss">

View File

@ -56,3 +56,13 @@ export async function fetchGameInfos(this: EngineContext): Promise<GameInfos> {
const resp = await this.callApi('/api/games') as { games: GameInfos } const resp = await this.callApi('/api/games') as { games: GameInfos }
return resp.games return resp.games
} }
export async function cameo(this: EngineContext, authcode: string): Promise<void> {
await this.callApi('/api/cameo', {
code: authcode,
})
}
export async function logoutCameo(this: EngineContext): Promise<void> {
await this.callApi('/api/cameo')
}

View File

@ -3,7 +3,7 @@ import { callApi, QueryParams } from '@/composables/engine/callApi'
import { start, stop } from '@/composables/engine/startStop' import { start, stop } from '@/composables/engine/startStop'
import { fetchUpdate } from '@/composables/engine/fetchUpdate' import { fetchUpdate } from '@/composables/engine/fetchUpdate'
import { loadQuotes, getQuotesRef, deleteQuote, saveQuote } from '@/composables/engine/quotes' import { loadQuotes, getQuotesRef, deleteQuote, saveQuote } from '@/composables/engine/quotes'
import { fetchGameInfo, fetchGameInfos, setGameLang, setGameName, savePlayer, deletePlayer, createGame } from '@/composables/engine/gameManagement' import { fetchGameInfo, fetchGameInfos, setGameLang, setGameName, savePlayer, deletePlayer, createGame, cameo, logoutCameo } from '@/composables/engine/gameManagement'
import { collectQuotes, startGame, continueGame, resetGame, finishGame } from '@/composables/engine/gameState' import { collectQuotes, startGame, continueGame, resetGame, finishGame } from '@/composables/engine/gameState'
import { saveSelection } from '@/composables/engine/play' import { saveSelection } from '@/composables/engine/play'
import type { Quotes, GameInfo, GameInfos, PlayerEdit, Lang, CreateGameStatus } from '@/composables/engine.d' import type { Quotes, GameInfo, GameInfos, PlayerEdit, Lang, CreateGameStatus } from '@/composables/engine.d'
@ -44,6 +44,8 @@ export interface useEngine {
savePlayer: (player: PlayerEdit) => Promise<void> savePlayer: (player: PlayerEdit) => Promise<void>
deletePlayer: (id: string) => Promise<void> deletePlayer: (id: string) => Promise<void>
createGame: (name: string, teamname: string, lang: Lang) => Promise<CreateGameStatus> createGame: (name: string, teamname: string, lang: Lang) => Promise<CreateGameStatus>
cameo: (authcode: string) => Promise<void>
logoutCameo: () => Promise<void>
} }
export default (): useEngine => { export default (): useEngine => {
@ -84,5 +86,7 @@ export default (): useEngine => {
savePlayer: (player: PlayerEdit) => savePlayer.apply(context, [player]), savePlayer: (player: PlayerEdit) => savePlayer.apply(context, [player]),
deletePlayer: (id: string) => deletePlayer.apply(context, [id]), deletePlayer: (id: string) => deletePlayer.apply(context, [id]),
createGame: (name: string, teamname: string, lang: Lang) => createGame.apply(context, [name, teamname, lang]), createGame: (name: string, teamname: string, lang: Lang) => createGame.apply(context, [name, teamname, lang]),
cameo: (authcode: string) => cameo.apply(context,[authcode]),
logoutCameo: () => logoutCameo.apply(context),
} }
} }