vibe coding is the best
This commit is contained in:
39
src/rooms.ts
39
src/rooms.ts
@@ -4,10 +4,10 @@ export interface RoomSettings {
|
||||
mode: "individual" | "teams";
|
||||
numTeams: number;
|
||||
teamNames: string[];
|
||||
playerPickTeam: boolean; // players can self-assign teams
|
||||
showBuzzOrder: boolean; // show full order vs first only
|
||||
buzzerLockout: boolean; // lock after first buzz
|
||||
timerSeconds: number; // 0 = no timer
|
||||
playerPickTeam: boolean;
|
||||
showBuzzOrder: boolean;
|
||||
buzzerLockout: boolean;
|
||||
timerSeconds: number;
|
||||
}
|
||||
|
||||
export interface Player {
|
||||
@@ -31,13 +31,28 @@ export interface Room {
|
||||
settings: RoomSettings;
|
||||
players: Map<string, Player>;
|
||||
buzzerState: BuzzerState;
|
||||
locked: boolean; // room locked to new joins
|
||||
teamLocked: boolean; // team selection locked
|
||||
locked: boolean;
|
||||
teamLocked: boolean;
|
||||
}
|
||||
|
||||
export const rooms = new Map<string, Room>();
|
||||
export const rooms = new Map<string, Room>();
|
||||
export const wsToPlayer = new Map<ServerWebSocket<unknown>, { roomId: string; playerId: string }>();
|
||||
|
||||
// Infinite Greek alphabet: Alpha, Beta, ... Omega, Alpha II, Beta II, ...
|
||||
const GREEK = ["Alpha","Beta","Gamma","Delta","Epsilon","Zeta","Eta","Theta","Iota","Kappa","Lambda","Mu","Nu","Xi","Omicron","Pi","Rho","Sigma","Tau","Upsilon","Phi","Chi","Psi","Omega"];
|
||||
export function greekName(i: number): string {
|
||||
const cycle = Math.floor(i / GREEK.length);
|
||||
const name = GREEK[i % GREEK.length];
|
||||
return cycle === 0 ? name : `${name} ${toRoman(cycle + 1)}`;
|
||||
}
|
||||
function toRoman(n: number): string {
|
||||
const vals = [1000,900,500,400,100,90,50,40,10,9,5,4,1];
|
||||
const syms = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"];
|
||||
let out = "";
|
||||
for (let i = 0; i < vals.length; i++) while (n >= vals[i]) { out += syms[i]; n -= vals[i]; }
|
||||
return out;
|
||||
}
|
||||
|
||||
export function genId(len = 8): string {
|
||||
const c = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
||||
let s = "";
|
||||
@@ -55,11 +70,11 @@ export function freshBuzzer(): BuzzerState {
|
||||
|
||||
export function publicRoom(room: Room) {
|
||||
return {
|
||||
id: room.id,
|
||||
settings: room.settings,
|
||||
locked: room.locked,
|
||||
teamLocked: room.teamLocked,
|
||||
modOnline: room.modWs !== null,
|
||||
id: room.id,
|
||||
settings: room.settings,
|
||||
locked: room.locked,
|
||||
teamLocked: room.teamLocked,
|
||||
modOnline: room.modWs !== null,
|
||||
buzzerState: {
|
||||
roundOpen: room.buzzerState.roundOpen,
|
||||
buzzOrder: room.buzzerState.buzzOrder,
|
||||
|
||||
Reference in New Issue
Block a user