Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
import type { PokerSnapshot, PokerTableSummary } from "@/app/(frontend)/minigames/poker/actions";
|
|
|
|
export const GAME_TICK_EVENT = "ptf:game-tick";
|
|
export const PROFILE_UPDATE_EVENT = "ptf:profile-update";
|
|
export const GAME_EVENT_EVENT = "ptf:game-event";
|
|
export const NOTIFICATION_EVENT = "ptf:notification";
|
|
export const SESSION_EXPIRED_EVENT = "ptf:session-expired";
|
|
export const POKER_STATE_EVENT = "ptf:poker-state";
|
|
export const POKER_TABLES_EVENT = "ptf:poker-tables";
|
|
export const POKER_TERMINATED_EVENT = "ptf:poker-terminated";
|
|
|
|
export interface GameTickDetail {
|
|
processedAt?: string;
|
|
}
|
|
|
|
export interface ProfileUpdateDetail {
|
|
reason?: string;
|
|
xpGained?: number;
|
|
}
|
|
|
|
export interface PokerStateDetail {
|
|
tableId?: string;
|
|
snapshot?: PokerSnapshot;
|
|
}
|
|
|
|
export interface PokerTablesDetail {
|
|
tables?: PokerTableSummary[];
|
|
}
|
|
|
|
export interface PokerTerminatedDetail {
|
|
tableId?: string;
|
|
reason?: string;
|
|
}
|
|
|
|
export function useGameTick(onTick?: () => void): number {
|
|
const [count, setCount] = useState(0);
|
|
const callbackRef = useRef(onTick);
|
|
callbackRef.current = onTick;
|
|
|
|
useEffect(() => {
|
|
const handler = () => {
|
|
setCount((c) => c + 1);
|
|
callbackRef.current?.();
|
|
};
|
|
window.addEventListener(GAME_TICK_EVENT, handler);
|
|
return () => window.removeEventListener(GAME_TICK_EVENT, handler);
|
|
}, []);
|
|
|
|
return count;
|
|
}
|