fix: useEvent for clock/place games

This commit is contained in:
2026-09-17 01:37:31 +02:00
parent 6866b45f66
commit 9fc9e19d68
4 changed files with 4 additions and 14 deletions
+1 -3
View File
@@ -3,14 +3,12 @@ import { computed } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useTitle } from "@vueuse/core"; import { useTitle } from "@vueuse/core";
import { useClockSocket } from "@/composables/useClockSocket"; import { useClockSocket } from "@/composables/useClockSocket";
import { provideEventPath } from "@/composables/useEventPath";
interface Props { interface Props {
eventPath: string; eventPath: string;
} }
const props = defineProps<Props>(); const props = defineProps<Props>();
provideEventPath(props.eventPath);
const { t } = useI18n(); const { t } = useI18n();
useTitle(computed(() => t("clock.pageTitle"))); useTitle(computed(() => t("clock.pageTitle")));
@@ -26,7 +24,7 @@ const {
cooldownRemainingMs, cooldownRemainingMs,
cooldownDurationSeconds, cooldownDurationSeconds,
press, press,
} = useClockSocket(); } = useClockSocket(props.eventPath);
const remainingDisplay = computed(() => { const remainingDisplay = computed(() => {
const totalSeconds = Math.floor(remainingMs.value / 1000); const totalSeconds = Math.floor(remainingMs.value / 1000);
+1 -3
View File
@@ -3,7 +3,6 @@ import { computed, onMounted, ref, watch } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useTitle } from "@vueuse/core"; import { useTitle } from "@vueuse/core";
import { usePlaceSocket } from "@/composables/usePlaceSocket"; import { usePlaceSocket } from "@/composables/usePlaceSocket";
import { provideEventPath } from "@/composables/useEventPath";
import { PALETTE } from "@/palette"; import { PALETTE } from "@/palette";
interface Props { interface Props {
@@ -11,7 +10,6 @@ interface Props {
} }
const props = defineProps<Props>(); const props = defineProps<Props>();
provideEventPath(props.eventPath);
const { t } = useI18n(); const { t } = useI18n();
useTitle(computed(() => t("place.pageTitle"))); useTitle(computed(() => t("place.pageTitle")));
@@ -48,7 +46,7 @@ const {
gridWidth, gridWidth,
gridHeight, gridHeight,
place, place,
} = usePlaceSocket(drawPixel); } = usePlaceSocket(props.eventPath, drawPixel);
const overlayWidth = computed(() => gridWidth.value * PX_PER_CELL); const overlayWidth = computed(() => gridWidth.value * PX_PER_CELL);
const overlayHeight = computed(() => gridHeight.value * PX_PER_CELL); const overlayHeight = computed(() => gridHeight.value * PX_PER_CELL);
@@ -1,7 +1,6 @@
import { computed, onBeforeUnmount, onMounted, ref } from 'vue' import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import { useWebSocket } from '@vueuse/core' import { useWebSocket } from '@vueuse/core'
import { clockApiMyStats } from '@/api' import { clockApiMyStats } from '@/api'
import { useEventPath } from './useEventPath'
// Mirrors clock/wire.py: a one-letter type tag then '|'-separated fields, in a // Mirrors clock/wire.py: a one-letter type tag then '|'-separated fields, in a
// fixed order the server always uses. See that file for the message table. // fixed order the server always uses. See that file for the message table.
@@ -10,9 +9,7 @@ import { useEventPath } from './useEventPath'
// "not logged in" branch to handle here. // "not logged in" branch to handle here.
const RECONNECT_DELAY_MS = 1000 const RECONNECT_DELAY_MS = 1000
export function useClockSocket() { export function useClockSocket(eventPath: string) {
const eventPath = useEventPath()
const endTimeMs = ref<number | null>(null) const endTimeMs = ref<number | null>(null)
const offsetMs = ref(0) const offsetMs = ref(0)
const remainingMs = ref(0) const remainingMs = ref(0)
@@ -1,7 +1,6 @@
import { computed, onBeforeUnmount, onMounted, ref } from 'vue' import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import { useWebSocket } from '@vueuse/core' import { useWebSocket } from '@vueuse/core'
import { placeApiCanvas } from '@/api' import { placeApiCanvas } from '@/api'
import { useEventPath } from './useEventPath'
// Mirrors place/wire.py: a one-letter type tag then '|'-separated fields, in // Mirrors place/wire.py: a one-letter type tag then '|'-separated fields, in
// a fixed order the server always uses. See that file for the message table. // a fixed order the server always uses. See that file for the message table.
@@ -27,9 +26,7 @@ let grid = new Uint8Array(DEFAULT_GRID_SIZE * DEFAULT_GRID_SIZE)
const gridWidth = ref(DEFAULT_GRID_SIZE) const gridWidth = ref(DEFAULT_GRID_SIZE)
const gridHeight = ref(DEFAULT_GRID_SIZE) const gridHeight = ref(DEFAULT_GRID_SIZE)
export function usePlaceSocket(onPixel?: OnPixel, onResize?: OnResize) { export function usePlaceSocket(eventPath: string, onPixel?: OnPixel, onResize?: OnResize) {
const eventPath = useEventPath()
const cooldownEndMs = ref<number | null>(null) const cooldownEndMs = ref<number | null>(null)
const cooldownRemainingMs = ref(0) const cooldownRemainingMs = ref(0)