Skip to content

Commit

Permalink
fix: letters adding to queue
Browse files Browse the repository at this point in the history
  • Loading branch information
lmaosoggypancakes committed Jun 19, 2023
1 parent 4a3de9d commit 1bccbc3
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 34 deletions.
5 changes: 2 additions & 3 deletions components/app/play/LetterBlock.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<li
:id="String(letter.id)"
class="text-center text-2xl relative inline-block h-14 w-16 p-2 border-2 border-secondary rounded-md bg-raisin transition-all cursor-pointer"
class="text-center text-2xl relative inline-block h-14 w-16 p-2 border-2 bg-base-100 rounded-md transition-all cursor-pointer"
:class="{
'grayscale blur-sm': letter.active && !queue,
'hover:shadow-[inset_0_0_10px_rgba(169,255,203,1)] ': !letter.active,
'bg-blue-400 bg-opacity-30 text-seasalt border-blue-400': letter,
// 'bg-blue-400 bg-opacity-30 text-seasalt border-blue-400': letter,
}"
@click="$emit('toggle', letter)"
>
Expand All @@ -21,7 +21,6 @@ const props = defineProps<{
disabled: boolean;
queue?: boolean;
}>();
console.log(props.letter.active, props.queue);
const emits = defineEmits<{
toggle: Letter;
}>();
Expand Down
10 changes: 10 additions & 0 deletions components/app/play/PlayModePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@ import AdventureCard from "./cards/AdventureCard.vue";
import MasterCard from "./cards/MasterCard.vue";
import ComputerCard from "./cards/ComputerCard.vue";
import { Difficulty } from "~/types";
const router = useRouter();
const matchmaker = useMatchmaker();
const props = defineProps<{
primary?: boolean; // takes up 3 cols instead of 1
disabled?: boolean;
}>();
const modes = [CasualCard, AdventureCard, MasterCard, ComputerCard];
matchmaker.$subscribe((_, val) => {
if (val.type === Difficulty.COMPUTER) {
router.push("/app/play/computer");
} else {
emits("matchmake", val.type);
}
});
const emits = defineEmits(["matchmake"]);
</script>
5 changes: 2 additions & 3 deletions components/app/play/cards/AdventureCard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<BaseCard>
<BaseCard @click="matchmaker.type = Difficulty.ADVENTURE">
<figure class="h-full p-2">
<svg
xmlns="http://www.w3.org/2000/svg"
Expand All @@ -24,6 +24,5 @@
</template>
<script setup lang="ts">
import { Difficulty } from "~/types";
const emits = defineEmits(["play"]);
const matchmaker = useMatchmaker();
</script>
5 changes: 2 additions & 3 deletions components/app/play/cards/CasualCard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<BaseCard>
<BaseCard @click="matchmaker.type = Difficulty.CASUAL">
<figure class="w-24 h-24 p-2">
<svg
xmlns="http://www.w3.org/2000/svg"
Expand All @@ -22,6 +22,5 @@

<script setup lang="ts">
import { Difficulty } from "~/types";
// define play emit
const emits = defineEmits(["play"]);
const matchmaker = useMatchmaker();
</script>
6 changes: 2 additions & 4 deletions components/app/play/cards/ComputerCard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<BaseCard class="bg-green-200">
<BaseCard class="bg-green-200" @click="matchmaker.type = Difficulty.COMPUTER">
<figure class="w-24 h-24 p-2">
<svg
xmlns="http://www.w3.org/2000/svg"
Expand All @@ -21,7 +21,5 @@
</template>
<script setup lang="ts">
import { Difficulty } from "~/types";
// define play emit
const emits = defineEmits(["play"]);
const matchmaker = useMatchmaker();
</script>
5 changes: 2 additions & 3 deletions components/app/play/cards/MasterCard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<BaseCard class="bg-secondary">
<BaseCard class="bg-secondary" @click="matchmaker.type = Difficulty.MASTER">
<figure class="w-24 h-24 p-2">
<svg
xmlns="http://www.w3.org/2000/svg"
Expand All @@ -21,6 +21,5 @@
</template>
<script setup lang="ts">
import { Difficulty } from "~/types";
// define play emit
const emits = defineEmits(["play"]);
const matchmaker = useMatchmaker;
</script>
17 changes: 8 additions & 9 deletions composables/useMatchmaker.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { defineStore, acceptHMRUpdate } from "pinia";
import { defineStore } from "pinia";
import { Difficulty, GameConnectionStatus } from "~/types";

export const useMatchmakerStore = defineStore({
id: "matchmaker",
state: () => ({
type: null as Difficulty | null,
status: null as GameConnectionStatus.CONNECTING | null,
}),
export default defineStore("matchmaker", {
state: () => {
return {
type: null as Difficulty | null,
status: null as GameConnectionStatus | null,
};
},
});
if (import.meta.hot)
import.meta.hot.accept(acceptHMRUpdate(useMatchmakerStore, import.meta.hot));
16 changes: 7 additions & 9 deletions pages/app/play/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
gameStatus == GameStatus.PLAYER_SUDDEN_DEATH,
}"
>
<span class="text-4xl block text-seasalt">{{
userStore.username
}}</span>
<span class="text-4xl block">{{ userStore.username }}</span>
<Avatar :src="userStore.picture" />
<ul class="space-x-4 my-4">
<LetterBlock
Expand All @@ -35,7 +33,7 @@
/>
</ul>
<div
class="absolute bottom-4 right-4 bg-apricot p-4 rounded-md text-2xl text-primary"
class="absolute bottom-4 right-4 bg-apricot p-4 rounded-md text-2xl"
>
+{{ points }} Points
</div>
Expand Down Expand Up @@ -64,7 +62,7 @@
}}</span>
<Avatar :src="opponent?.picture || ''" />
<div
class="absolute bottom-4 left-4 bg-apricot p-4 rounded-md text-2xl text-primary"
class="absolute bottom-4 left-4 bg-apricot p-4 rounded-md text-2xl"
>
+{{ opponentPoints }} Points
</div>
Expand All @@ -82,8 +80,8 @@
</ul>
</div>
</div>
<WaitingToast v-if="status == GameConnectionStatus.WAITING" />
<ConnectingToast v-if="status == GameConnectionStatus.CONNECTING" />
<Waiting v-if="status == GameConnectionStatus.WAITING" />
<Connecting v-if="status == GameConnectionStatus.CONNECTING" />
<TransitionRoot
appear
:show="
Expand Down Expand Up @@ -274,7 +272,7 @@ useKeydownEvent((event) => {
!letter.active && letter.value.toLowerCase() == event.key.toLowerCase()
);
if (possibleLetter) {
toggleLetter(possibleLetter, true);
toggleLetter(possibleLetter, false);
}
}
});
Expand All @@ -298,7 +296,7 @@ const toggleLetter = (letter: Letter, active = false) => {
};
const popFromQueue = () => {
const lastLetter = queue.pop();
const lastLetter = queue[queue.length - 1];
// assumes lastLetter.active is true
if (!lastLetter) return;
toggleLetter(lastLetter);
Expand Down

0 comments on commit 1bccbc3

Please sign in to comment.