Skip to content

Commit a40bafe

Browse files
committed
Show game event details as tree
1 parent 75803cd commit a40bafe

File tree

4 files changed

+63
-38
lines changed

4 files changed

+63
-38
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<script setup lang="ts">
2+
import {computed} from "vue";
3+
import type {GameEvent} from "@/proto/ssl_gc_game_event";
4+
import {gameEventDetails} from "@/helpers";
5+
6+
const props = defineProps<{
7+
gameEvent: GameEvent,
8+
}>()
9+
10+
const details = computed(() => {
11+
return gameEventDetails(props.gameEvent)
12+
})
13+
14+
interface QTreeNode {
15+
label: string,
16+
children?: QTreeNode[]
17+
}
18+
19+
function treeChildren(object: { [key: string]: any }): QTreeNode[] {
20+
const nodes = []
21+
const keys = Object.keys(object)
22+
for (const key of keys) {
23+
const detail = object[key];
24+
if (detail !== undefined) {
25+
if (typeof detail === 'object') {
26+
nodes.push({
27+
label: key,
28+
children: treeChildren(detail)
29+
})
30+
} else {
31+
nodes.push({
32+
label: `${key}: ${detail}`
33+
})
34+
}
35+
}
36+
}
37+
return nodes
38+
}
39+
40+
const nodes = treeChildren(details.value)
41+
42+
</script>
43+
44+
<template>
45+
<q-card v-if="nodes.length > 0">
46+
<q-card-section>
47+
<q-tree
48+
:nodes="nodes"
49+
node-key="label"
50+
no-connectors
51+
default-expand-all
52+
dense
53+
/>
54+
</q-card-section>
55+
</q-card>
56+
</template>

frontend/src/components/match/GameEventItem.vue

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {computed} from "vue";
33
import TeamBadge from "@/components/common/TeamBadge.vue";
44
import {gameEventNames} from "@/helpers/texts";
55
import type {GameEvent} from "@/proto/ssl_gc_game_event";
6-
import {gameEventDetails, gameEventForTeam, originIcon} from "@/helpers";
6+
import {gameEventForTeam, originIcon} from "@/helpers";
7+
import GameEventDetailsTree from "@/components/match/GameEventDetailsTree.vue";
78
89
const props = defineProps<{
910
gameEvent: GameEvent,
@@ -14,10 +15,6 @@ const label = computed(() => {
1415
return gameEventNames.get(props.gameEvent.type!)
1516
})
1617
17-
const details = computed(() => {
18-
return gameEventDetails(props.gameEvent)
19-
})
20-
2118
const team = computed(() => {
2219
return gameEventForTeam(props.gameEvent)
2320
})
@@ -48,10 +45,6 @@ const origins = computed(() => {
4845
</div>
4946
</q-item-section>
5047
</template>
51-
<q-card>
52-
<q-card-section>
53-
{{ details }}
54-
</q-card-section>
55-
</q-card>
48+
<GameEventDetailsTree :game-event="props.gameEvent"/>
5649
</q-expansion-item>
5750
</template>

frontend/src/components/protocol/ProtocolItem.vue

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {computed, inject} from "vue";
33
import TeamBadge from "@/components/common/TeamBadge.vue";
44
import type {ProtocolEntry} from "@/proto/ssl_gc_api";
55
import formatDuration from "format-duration";
6-
import {gameEventDetails, gameEventDetailsKeys} from "@/helpers";
76
import {changeDetails} from "@/helpers/ChangeDetails";
87
import type {ControlApi} from "@/providers/controlApi/ControlApi";
98
import OriginIcon from "@/components/common/OriginIcon.vue";
9+
import GameEventDetailsTree from "@/components/match/GameEventDetailsTree.vue";
1010

1111
const props = defineProps<{
1212
protocolEntry: ProtocolEntry,
@@ -29,18 +29,6 @@ const revertible = computed(() => {
2929
const change = computed(() => {
3030
return changeDetails(props.protocolEntry.change!)
3131
})
32-
const details = computed(() => {
33-
if (change.value.gameEvent) {
34-
return gameEventDetails(change.value.gameEvent)
35-
}
36-
return undefined
37-
})
38-
const detailsKeys = computed(() => {
39-
if (details.value) {
40-
return gameEventDetailsKeys(details.value)
41-
}
42-
return []
43-
})
4432
const gameEventOrigins = computed(() => {
4533
if (change.value.gameEvent) {
4634
return change.value.gameEvent.origin!.filter(o => o !== origin.value)
@@ -90,13 +78,7 @@ function revert() {
9078
</q-item-section>
9179
</template>
9280

93-
<q-card v-if="detailsKeys.length > 0">
94-
<q-card-section>
95-
<q-item-label v-for="key in detailsKeys" :key="key">
96-
{{ key }}: {{ details[key] }}
97-
</q-item-label>
98-
</q-card-section>
99-
</q-card>
81+
<GameEventDetailsTree :game-event="change.gameEvent" v-if="change.gameEvent"/>
10082
</q-expansion-item>
10183
</q-item-section>
10284

frontend/src/helpers/index.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,8 @@ export function gameEventForTeam(gameEvent: GameEvent): Team {
2929
}
3030

3131
export function gameEventDetails(gameEvent: GameEvent) {
32-
const event = gameEvent.event!
33-
return (event as { [key: string]: any })[event.$case]
34-
}
35-
36-
export function gameEventDetailsKeys(details: any) {
37-
return Object.keys(details)
38-
.filter(k => details[k] !== undefined)
39-
.filter(k => k !== "byTeam")
32+
const event = gameEvent.event! as { [key: string]: any }
33+
return event[event.$case] as { [key: string]: any }
4034
}
4135

4236
export const originIcon = (origin: string) => {

0 commit comments

Comments
 (0)