Skip to content

Commit

Permalink
Fix RTC in online mode
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetenstad committed Jan 30, 2024
1 parent 4283562 commit 95b449e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/components/MainGame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<component
v-if="showInput"
:is="getInputComponent(game.type)"
:game="game"
@hit="emit('hit', $event)"
@miss="emit('miss')"
@undo="emit('undo')"
Expand Down
20 changes: 8 additions & 12 deletions src/components/RtcGameInput.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<template>
<div
v-if="
gameStore.game
? getTypeAttribute < Boolean > (gameStore.game, 'fast', false)
: false
"
div
v-if="game ? getTypeAttribute < Boolean > (game, 'fast', false) : false"
class="row"
style="justify-content: space-between"
>
Expand All @@ -20,23 +15,25 @@
</button>
</div>
<div class="row" style="height: 12em">
<button @click="registerMiss()">&#10008;</button>
<button @click="registerHit()">&#10004;</button>
<button @click="registerMiss">&#10008;</button>
<button @click="registerHit">&#10004;</button>
</div>
<button @click="emit('undo')">&#x232B;</button>
</template>

<script lang="ts" setup>
import { useGameStore } from '@/stores/game'
import {
Game,
Multiplier,
Segment,
getTypeAttribute,
multiplierToString,
} from '@/types/game'
import { ref } from 'vue'
const gameStore = useGameStore()
const props = defineProps<{
game: Game
}>()
const emit = defineEmits<{
hit: [segment: Segment]
Expand All @@ -45,7 +42,7 @@ const emit = defineEmits<{
}>()
const getDefaultMultiplier = () =>
gameStore.game ? getTypeAttribute<Multiplier>(gameStore.game, 'mode', 1) : 1
props.game ? getTypeAttribute<Multiplier>(props.game, 'mode', 1) : 1
const selectedMultiplier = ref(getDefaultMultiplier())
Expand All @@ -55,7 +52,6 @@ const registerMiss = () => {
}
const registerHit = () => {
if (!gameStore.game) throw Error()
emit('hit', { multiplier: selectedMultiplier.value, sector: -1 })
selectedMultiplier.value = getDefaultMultiplier()
}
Expand Down
27 changes: 14 additions & 13 deletions src/stores/online.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ export const useOnlineStore = defineStore('online', {
this.outChannel = supabase
.channel(`game-${userId}`)
.on('broadcast', { event: 'input' }, (args) => {
console.log(args)
const gameStore = useGameStore()
const gameController = gameStore.getController()
const player = gameStore.gameState?.player
if (args.payload.userId == player) {
switch (args.payload.type) {
case 'hit':
gameController.recordHit(args.payload.segment)
break
case 'miss':
gameController.recordMiss()
break
case 'undo':
gameStore.undoScore()
break
}
if (args.payload.userId != player) return

const gameController = gameStore.getController()
switch (args.payload.type) {
case 'hit':
gameController.recordHit(args.payload.segment)
break
case 'miss':
gameController.recordMiss()
break
case 'undo':
gameStore.undoScore()
break
}
})
.on('broadcast', { event: 'refresh' }, () => {
Expand Down

0 comments on commit 95b449e

Please sign in to comment.