From 7c18b6f257c9f5799af0dec0dc810eab120ac3d2 Mon Sep 17 00:00:00 2001 From: legonzaur Date: Wed, 1 May 2024 11:49:44 +0200 Subject: [PATCH] Fix market not showing for spectators --- app.vue | 4 ++-- netcode/index.ts | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app.vue b/app.vue index bd15972..7baa09e 100644 --- a/app.vue +++ b/app.vue @@ -2,7 +2,7 @@ import { ref } from 'vue'; -import goStore, { GameObjectRegister, register, setReady } from '@/netcode'; +import goStore, { register, setReady } from '@/netcode'; let username = ref('legonzaur') @@ -15,6 +15,6 @@ let username = ref('legonzaur') type="checkbox" id="ready">
- +
diff --git a/netcode/index.ts b/netcode/index.ts index c6e34dd..aaedf26 100644 --- a/netcode/index.ts +++ b/netcode/index.ts @@ -6,6 +6,8 @@ import { type Player, create_player, type PlayerNetcode } from "./Player" import { type Team, create_team, type TeamNetcode } from "./Team" import { type Turn, create_turn } from "./Turn" +import { type Ref } from "vue" + export const socket = new WebSocket("ws://127.0.0.1:8765") export class GameObjectRegister { @@ -18,8 +20,8 @@ export class GameObjectRegister { context: 'login' | 'pregame' | 'game' = "login" private readonly objects: Map - game?: Game - self?: Player + game: Ref + self: Ref constructor() { this.effects = reactive(new Map()) this.cards = reactive(new Map()) @@ -28,6 +30,9 @@ export class GameObjectRegister { this.turns = reactive(new Map()) this.objects = reactive(new Map()) + + this.game = ref(null) + this.self = ref(null) } update_object(obj: GameObjectNetcode) { @@ -57,8 +62,8 @@ export class GameObjectRegister { this.objects.set(data.uuid, team) }, "game": (data: GameNetcode) => { - this.game = create_game(data, this) - this.objects.set(data.uuid, this.game) + this.game.value = create_game(data, this) + this.objects.set(data.uuid, this.game.value) }, "turn": (data: any) => { const turn = create_turn(data, this) @@ -68,7 +73,7 @@ export class GameObjectRegister { } as { [id: string]: (data: any) => any } set_self(uuid: string) { - this.self = this.players.get(uuid) + this.self.value = this.players.get(uuid) ?? null } }