Skip to content

Commit

Permalink
Fix Cricket in online mode
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetenstad committed Jan 30, 2024
1 parent 95b449e commit f112a5d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 20 deletions.
26 changes: 18 additions & 8 deletions src/components/CricketGameInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,34 @@
<script lang="ts" setup>
import { stringMaxLength } from '@/functions/string'
import { CricketGameState } from '@/games/cricket'
import { useGameStore } from '@/stores/game'
import { useUsersStore } from '@/stores/users'
import { Segment, multiplierToString } from '@/types/game'
import {
Game,
GameController,
GameState,
Segment,
multiplierToString,
} from '@/types/game'
import { computed, ref } from 'vue'
const selectedMultiplier = ref(1)
const selectedSector = ref<number | null>(null)
const gameState = computed(() => useGameStore().gameState as CricketGameState)
const currentPlayer = computed(() =>
gameState.value.players.find((p) => p.id == gameState.value.player)
)
const props = defineProps<{
game: Game
gameState: CricketGameState
gameController: GameController<GameState>
}>()
const emit = defineEmits<{
hit: [segment: Segment]
miss: []
undo: []
}>()
const selectedMultiplier = ref(1)
const selectedSector = ref<number | null>(null)
const currentPlayer = computed(() =>
props.gameState.players.find((p) => p.id == props.gameState.player)
)
const selectSector = (sector: number) => {
if (sector == 0) {
emit('miss')
Expand Down
22 changes: 12 additions & 10 deletions src/components/KillerGameInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,26 @@

<script lang="ts" setup>
import { KillerController, KillerPlayer } from '@/games/killer'
import { useGameStore } from '@/stores/game'
import { useUsersStore } from '@/stores/users'
import { Segment, multiplierToString } from '@/types/game'
import { Game, GameState, Segment, multiplierToString } from '@/types/game'
import { onMounted, ref } from 'vue'
const selectedMultiplier = ref(1)
const selectedSector = ref<number | null>(null)
const gameStore = useGameStore()
const players = ref<KillerPlayer[]>([])
const props = defineProps<{
game: Game
gameState: GameState
gameController: KillerController
}>()
const emit = defineEmits<{
hit: [segment: Segment]
miss: []
undo: []
}>()
const selectedMultiplier = ref(1)
const selectedSector = ref<number | null>(null)
const players = ref<KillerPlayer[]>([])
const selectSector = (sector: number | null) => {
if (sector == null) throw Error()
if (sector == 0) {
Expand All @@ -112,10 +115,9 @@ const selectSector = (sector: number | null) => {
const updatePlayers = () => {
players.value =
(useGameStore().getController() as KillerController)
props.gameController
.getKillerPlayers()
.filter((player) => !gameStore.gameState?.rank.includes(player.userId)) ??
[]
.filter((player) => !props.gameState?.rank.includes(player.userId)) ?? []
}
onMounted(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/MainGame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
v-if="showInput"
:is="getInputComponent(game.type)"
:game="game"
:game-state="gameState"
:game-controller="gameController"
@hit="emit('hit', $event)"
@miss="emit('miss')"
@undo="emit('undo')"
Expand Down
4 changes: 4 additions & 0 deletions src/components/RtcGameInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<script lang="ts" setup>
import {
Game,
GameController,
GameState,
Multiplier,
Segment,
getTypeAttribute,
Expand All @@ -33,6 +35,8 @@ import { ref } from 'vue'
const props = defineProps<{
game: Game
gameState: GameState
gameController: GameController<GameState>
}>()
const emit = defineEmits<{
Expand Down
14 changes: 13 additions & 1 deletion src/components/X01GameInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,24 @@
</template>

<script lang="ts" setup>
import { Segment, multiplierToString } from '@/types/game'
import {
Game,
GameController,
GameState,
Segment,
multiplierToString,
} from '@/types/game'
import { ref } from 'vue'
const selectedMultiplier = ref(1)
const selectedSector = ref<number | null>(null)
defineProps<{
game: Game
gameState: GameState
gameController: GameController<GameState>
}>()
const emit = defineEmits<{
hit: [segment: Segment]
miss: []
Expand Down
1 change: 0 additions & 1 deletion src/stores/online.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const useOnlineStore = defineStore('online', {
this.outChannel = supabase
.channel(`game-${userId}`)
.on('broadcast', { event: 'input' }, (args) => {
console.log(args)
const gameStore = useGameStore()
const player = gameStore.gameState?.player
if (args.payload.userId != player) return
Expand Down

0 comments on commit f112a5d

Please sign in to comment.