Bring games 9-18 in line with GAMES-NEW.md: - Library sorts easiest first, filters by category and difficulty; difficulty 5 shows a Nightmare chip, and a no-hint finish earns Nightmare Survivors. - Time limits end on "Out of time" (no rank); Deep Lab Nereid's countdown is a rising water gauge behind the header. - Evidence Locker search, chapter filter and starred clues (partner sees a count). - One-shot accusations ask "One shot. Are you both sure?" first. - Symbol font fallback, tight monospace blocks for grids/keypads/SQL. - Rank rounds reorder by drag or up/down buttons; reveal highlights #1 and #4. - Telepathy capped at 30 characters; maze:move accepts forward/left/right/back; gate buttons read "Gate (won't open from this side)". - Overtime solver tables checked against Appendix A; keypad generator re-rolls. - More content checks (rank items, password fixtures, glyphs/gates on traps) and sanitize tests for all ten new games. - GAMES.md carries the full spoiler guide for 9-18. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import { useEffect } from 'react';
|
|
import type { CSSProperties } from 'react';
|
|
import type { Category, Role, Theme } from '@two-keys/shared';
|
|
|
|
/** "#7b1e3a" → "123 30 58", the form Tailwind's rgb(var(--x) / alpha) wants. */
|
|
export function hexToRgb(hex: string): string {
|
|
const n = parseInt(hex.slice(1), 16);
|
|
return `${(n >> 16) & 255} ${(n >> 8) & 255} ${n & 255}`;
|
|
}
|
|
|
|
export function themeVars(theme: Theme): CSSProperties {
|
|
return {
|
|
'--primary': hexToRgb(theme.primary),
|
|
'--accent': hexToRgb(theme.accent),
|
|
'--bg': hexToRgb(theme.background),
|
|
'--heading-font': `'${theme.headingFont}'`,
|
|
} as CSSProperties;
|
|
}
|
|
|
|
/** Applies a game's theme to the whole page while a room is open. */
|
|
export function useTheme(theme: Theme | undefined) {
|
|
const key = theme ? JSON.stringify(theme) : '';
|
|
useEffect(() => {
|
|
if (!key) return;
|
|
const root = document.documentElement;
|
|
const vars = themeVars(JSON.parse(key)) as Record<string, string>;
|
|
for (const [name, value] of Object.entries(vars)) root.style.setProperty(name, value);
|
|
return () => {
|
|
for (const name of Object.keys(vars)) root.style.removeProperty(name);
|
|
};
|
|
}, [key]);
|
|
}
|
|
|
|
export const CATEGORY_LABEL: Record<Category, string> = {
|
|
'murder-mystery': 'Murder Mystery',
|
|
'escape-room': 'Escape Room',
|
|
'co-op': 'Co-op',
|
|
};
|
|
|
|
/** A is warm (amber), B is cool (teal). */
|
|
export const ROLE_TEXT: Record<Role, string> = { A: 'text-roleA', B: 'text-roleB' };
|
|
export const ROLE_BORDER: Record<Role, string> = { A: 'border-roleA/60', B: 'border-roleB/60' };
|
|
export const ROLE_BG: Record<Role, string> = { A: 'bg-roleA/15', B: 'bg-roleB/15' };
|
|
|
|
export const MAX_DIFFICULTY = 5;
|
|
export const DIFFICULTY_LABEL: Record<number, string> = { 1: 'Easy', 2: 'Medium', 3: 'Hard', 4: 'Expert', 5: 'Nightmare' };
|
|
export const difficultyKeys = (n: number) => '🔑'.repeat(Math.max(0, n));
|