Skip to content

Commit 2f5b17c

Browse files
committed
Improve random color and side choosing
1 parent a40bafe commit 2f5b17c

File tree

2 files changed

+66
-11
lines changed

2 files changed

+66
-11
lines changed

frontend/src/components/start/SwitchColorRandomButton.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const update = () => {
1818

1919
<template>
2020
<q-btn
21-
label="Shuffle color"
21+
label="Random color"
2222
color="primary"
2323
icon="casino"
2424
@click="update"
Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,79 @@
11
<script setup lang="ts">
2-
import {inject} from "vue";
2+
import {inject, ref} from "vue";
33
import {Team} from "@/proto/ssl_gc_common";
44
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";
59
610
const control = inject<ControlApi>('control-api')
11+
const matchStore = useMatchStateStore()
712
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+
}
1434
}
1535
</script>
1636

1737
<template>
1838
<q-btn
19-
label="Shuffle sides"
39+
label="Determine side and kickoff"
2040
color="primary"
21-
icon="casino"
22-
@click="update"
41+
icon="home"
42+
@click="showDialog = true"
2343
/>
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>
2479
</template>

0 commit comments

Comments
 (0)