38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import type { GameName } from '#lib/content';
|
|
import { line, span } from '../output';
|
|
import type { Command } from './types';
|
|
|
|
const gameDescriptions: Record<GameName, string> = {
|
|
snake: 'Eat the food and avoid your own tail',
|
|
breakout: 'Bounce the ball and clear every brick'
|
|
};
|
|
|
|
const gameNames = Object.keys(gameDescriptions) as GameName[];
|
|
|
|
const launchCommands: Command[] = gameNames.map((game) => ({
|
|
name: game,
|
|
description: gameDescriptions[game],
|
|
hidden: true,
|
|
run: (_args, context) => context.openApp(game)
|
|
}));
|
|
|
|
const gamesCommand: Command = {
|
|
name: 'games',
|
|
description: 'List or launch the games',
|
|
usage: 'games [name]',
|
|
argumentOptions: () => gameNames,
|
|
run: (args, context) => {
|
|
const requestedGame = gameNames.find((game) => game === args[0]?.toLowerCase());
|
|
if (requestedGame) {
|
|
context.openApp(requestedGame);
|
|
return;
|
|
}
|
|
gameNames.forEach((game) =>
|
|
context.print(line(span(game.padEnd(12), 'accent', { bold: true }), gameDescriptions[game]))
|
|
);
|
|
context.print(line(span('Run ', 'muted'), span('games <name>', 'accent'), span(' to play', 'muted')));
|
|
}
|
|
};
|
|
|
|
export const gameCommands: Command[] = [gamesCommand, ...launchCommands];
|