|
1 | 1 | <script setup lang="ts">
|
2 |
| -import {inject} from "vue"; |
| 2 | +import {inject, ref} from "vue"; |
3 | 3 | import {Team} from "@/proto/ssl_gc_common";
|
4 | 4 | import type {ControlApi} from "@/providers/controlApi/ControlApi";
|
| 5 | +import TeamInput from "@/components/common/TeamInput.vue"; |
| 6 | +import FieldHalfInput from "@/components/team/FieldHalfInput.vue"; |
| 7 | +import {opponent} from "@/helpers"; |
| 8 | +import {useMatchStateStore} from "@/store/matchState"; |
5 | 9 |
|
6 | 10 | const control = inject<ControlApi>('control-api')
|
| 11 | +const matchStore = useMatchStateStore() |
7 | 12 |
|
8 |
| -const update = () => { |
9 |
| - const value = Math.random() < 0.5 |
10 |
| - control?.UpdateTeamState({ |
11 |
| - forTeam: Team.YELLOW, |
12 |
| - onPositiveHalf: value, |
13 |
| - }) |
| 13 | +const showDialog = ref(false) |
| 14 | +const team = ref(Team.YELLOW) |
| 15 | +
|
| 16 | +const randomize = (counter: number) => { |
| 17 | + if (Math.random() < 0.5) { |
| 18 | + team.value = Team.YELLOW |
| 19 | + } else { |
| 20 | + team.value = Team.BLUE |
| 21 | + } |
| 22 | + if (counter > 0) { |
| 23 | + setTimeout(() => randomize(counter - 1), 100) |
| 24 | + } |
| 25 | +} |
| 26 | +
|
| 27 | +function accept() { |
| 28 | + const firstKickoffTeam = opponent(team.value); |
| 29 | + if (matchStore.matchState.firstKickoffTeam !== firstKickoffTeam) { |
| 30 | + control?.UpdateMatchConfig({ |
| 31 | + firstKickoffTeam: firstKickoffTeam |
| 32 | + }) |
| 33 | + } |
14 | 34 | }
|
15 | 35 | </script>
|
16 | 36 |
|
17 | 37 | <template>
|
18 | 38 | <q-btn
|
19 |
| - label="Shuffle sides" |
| 39 | + label="Determine side and kickoff" |
20 | 40 | color="primary"
|
21 |
| - icon="casino" |
22 |
| - @click="update" |
| 41 | + icon="home" |
| 42 | + @click="showDialog = true" |
23 | 43 | />
|
| 44 | + <q-dialog v-model="showDialog"> |
| 45 | + <q-card> |
| 46 | + <q-card-section> |
| 47 | + <div class="text-h6">Determine team to choose side</div> |
| 48 | + </q-card-section> |
| 49 | + |
| 50 | + <q-card-section class="q-pt-none"> |
| 51 | + <q-item-section> |
| 52 | + <TeamInput |
| 53 | + :model-value="team" |
| 54 | + @update:model-value="(v) => team = v" |
| 55 | + /> |
| 56 | + </q-item-section> |
| 57 | + </q-card-section> |
| 58 | + |
| 59 | + <q-card-actions align="right"> |
| 60 | + <q-btn flat label="Randomize" color="primary" @click="randomize(10)"/> |
| 61 | + </q-card-actions> |
| 62 | + |
| 63 | + <q-card-section> |
| 64 | + <div class="text-h6">Let this team choose</div> |
| 65 | + </q-card-section> |
| 66 | + |
| 67 | + <q-card-section class="q-pt-none"> |
| 68 | + <q-item-section> |
| 69 | + <FieldHalfInput :team="team"/> |
| 70 | + </q-item-section> |
| 71 | + <q-item-label header>The other team will have first kick off</q-item-label> |
| 72 | + </q-card-section> |
| 73 | + |
| 74 | + <q-card-actions align="right"> |
| 75 | + <q-btn flat label="Accept" color="primary" @click="accept" v-close-popup/> |
| 76 | + </q-card-actions> |
| 77 | + </q-card> |
| 78 | + </q-dialog> |
24 | 79 | </template>
|
0 commit comments