Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function parseArgs(argv: string[]): { command: string | undefined; flags: CliFla
flags.peak = args[++i];
} else if (arg === '--dump' && next !== undefined) {
flags.dump = args[++i];
} else if (arg === '--all') {
flags.all = true;
} else if (arg === '--silent') {
flags.silent = true;
} else if (arg === '--no-hook') {
Expand Down Expand Up @@ -137,13 +139,15 @@ Usage:
Fully non-interactive
any-buddy --preset "Arcane Dragon" Use a curated preset build
any-buddy preview Browse pets without applying
any-buddy preview --all Show all preset builds at once
any-buddy current Show your current pet
any-buddy apply [--silent] Re-apply saved pet after update
any-buddy restore Restore original pet
any-buddy buddies Browse and switch between your buddies
any-buddy rehatch Delete companion to re-hatch via /buddy

Options:
--all (preview only) Dump all preset builds with sprites to stdout
--preset <name> Use a curated preset (e.g., "Arcane Dragon", "Royal Capybara")
-s, --species <name> Species (duck, goose, blob, cat, dragon, octopus, owl,
penguin, turtle, snail, ghost, axolotl, capybara,
Expand Down
52 changes: 51 additions & 1 deletion src/tui/commands/preview.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
import chalk from 'chalk';
import type { CliFlags } from '@/types.js';
import { SPECIES, EYES, RARITIES, HATS } from '@/constants.js';
import { SPECIES, EYES, RARITIES, HATS, RARITY_STARS } from '@/constants.js';
import { runPreflight } from '@/patcher/preflight.js';
import { banner, showPet } from '../display.ts';
import { validateFlag, selectSpecies, selectEyes, selectRarity, selectHat } from '../prompts.ts';
import { allTraitsFlagged } from '../builder/state.ts';
import { PRESETS } from '@/presets.js';
import { renderSprite } from '@/sprites/index.js';
import { RARITY_CHALK } from '../format.ts';

function runPreviewAll(): void {
const cols = process.stdout.columns ?? 80;
const rule = chalk.dim(' ' + '─'.repeat(Math.min(cols - 4, 60)));

console.log(chalk.bold(`\n Preset gallery `) + chalk.dim(`(${PRESETS.length} presets)\n`));

for (let i = 0; i < PRESETS.length; i++) {
const p = PRESETS[i];
const color = RARITY_CHALK[p.rarity] ?? chalk.white;
const stars = RARITY_STARS[p.rarity] ?? '';
const bones = {
species: p.species,
eye: p.eye,
hat: p.hat,
rarity: p.rarity,
shiny: false,
stats: {},
};
const spriteLines = renderSprite(bones, 0);

console.log(color(` ${p.name} · ${p.rarity} ${p.species} ${stars}`));
console.log(chalk.dim(` eyes: ${p.eye} hat: ${p.hat} "${p.description}"`));
console.log();
for (const line of spriteLines) {
console.log(color(' ' + line));
}
console.log();

if (i < PRESETS.length - 1) {
console.log(rule);
console.log();
}
}

console.log(
chalk.dim(
` ${PRESETS.length} presets total. Run 'any-buddy --preset "<name>"' to apply one.\n`,
),
);
}

async function runSequentialPreview(flags: CliFlags): Promise<void> {
const species = validateFlag('species', flags.species, SPECIES) ?? (await selectSpecies());
Expand All @@ -23,6 +67,12 @@ async function runSequentialPreview(flags: CliFlags): Promise<void> {

export async function runPreview(flags: CliFlags = {}): Promise<void> {
banner();

if (flags.all) {
runPreviewAll();
return;
}

const preflight = runPreflight({ requireBinary: false });
if (!preflight.ok) process.exit(1);

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export interface CliFlags {
silent?: boolean;
noHook?: boolean;
yes?: boolean;
all?: boolean;
}

export type RngFunction = () => number;
Expand Down
Loading