35 lines
2.0 KiB
JavaScript
35 lines
2.0 KiB
JavaScript
const registry = new Map();
|
|
|
|
export function registerGame(definition) {
|
|
if (!definition?.slug) throw new Error('Game definition needs a slug.');
|
|
registry.set(definition.slug, {
|
|
slug: definition.slug,
|
|
name: definition.name ?? definition.slug,
|
|
category: definition.category ?? 'tabletop',
|
|
cardGame: definition.cardGame ?? false,
|
|
minPlayers: definition.minPlayers ?? 2,
|
|
maxPlayers: definition.maxPlayers ?? 2,
|
|
minOpponents: definition.minOpponents ?? 1,
|
|
maxOpponents: definition.maxOpponents ?? 1,
|
|
supportsMultiplayer: definition.supportsMultiplayer ?? true,
|
|
multiplayerOnly: definition.multiplayerOnly ?? false,
|
|
});
|
|
}
|
|
|
|
export function listGames() {
|
|
return [...registry.values()];
|
|
}
|
|
|
|
export function getGame(slug) {
|
|
return registry.get(slug) ?? null;
|
|
}
|
|
|
|
// Built-in placeholders so the menu has something to show.
|
|
registerGame({ slug: 'backgammon', name: 'Backgammon', category: 'tabletop', minPlayers: 2, maxPlayers: 2, minOpponents: 1, maxOpponents: 1, multiplayerOnly: false });
|
|
registerGame({ slug: 'parchisi', name: 'Parchisi', category: 'tabletop', minPlayers: 1, maxPlayers: 4, minOpponents: 3, maxOpponents: 3, multiplayerOnly: false });
|
|
registerGame({ slug: 'blackjack', name: 'Blackjack', category: 'casino', cardGame: true, minPlayers: 1, maxPlayers: 5, minOpponents: 0, maxOpponents: 4, multiplayerOnly: false });
|
|
registerGame({ slug: 'holdem', name: "Texas Hold 'Em", category: 'casino', cardGame: true, minPlayers: 2, maxPlayers: 8, minOpponents: 3, maxOpponents: 3, multiplayerOnly: false });
|
|
registerGame({ slug: 'yatzi', name: 'Yatzi', category: 'tabletop', minPlayers: 1, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, multiplayerOnly: false });
|
|
registerGame({ slug: 'skipbo', name: 'Skip-Bo', category: 'tabletop', cardGame: true, minPlayers: 1, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, multiplayerOnly: false });
|
|
registerGame({ slug: 'phase10', name: 'Phase 10', category: 'tabletop', cardGame: true, minPlayers: 1, maxPlayers: 4, minOpponents: 1, maxOpponents: 3, multiplayerOnly: false });
|