dracosh 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +10 -0
  3. package/README.md +100 -2
  4. package/assets/sounds/ask.wav +0 -0
  5. package/assets/sounds/badge-1.wav +0 -0
  6. package/assets/sounds/badge-2.wav +0 -0
  7. package/assets/sounds/badge-3.wav +0 -0
  8. package/assets/sounds/badge-4.wav +0 -0
  9. package/assets/sounds/close.wav +0 -0
  10. package/assets/sounds/combo.wav +0 -0
  11. package/assets/sounds/correct-0.wav +0 -0
  12. package/assets/sounds/correct-1.wav +0 -0
  13. package/assets/sounds/correct-2.wav +0 -0
  14. package/assets/sounds/correct-3.wav +0 -0
  15. package/assets/sounds/correct-4.wav +0 -0
  16. package/assets/sounds/correct-5.wav +0 -0
  17. package/assets/sounds/evolve.wav +0 -0
  18. package/assets/sounds/goal.wav +0 -0
  19. package/assets/sounds/wrong.wav +0 -0
  20. package/data/tips.json +32 -0
  21. package/package.json +47 -4
  22. package/src/alerts.js +38 -0
  23. package/src/anki.js +36 -0
  24. package/src/backup.js +95 -0
  25. package/src/cli.js +197 -0
  26. package/src/commands.js +28 -0
  27. package/src/dates.js +15 -0
  28. package/src/demo.js +11 -0
  29. package/src/diff.js +46 -0
  30. package/src/hint.js +12 -0
  31. package/src/judge.js +78 -0
  32. package/src/library.js +127 -0
  33. package/src/lock.js +63 -0
  34. package/src/manage.js +75 -0
  35. package/src/parse.js +42 -0
  36. package/src/pause.js +23 -0
  37. package/src/progress.js +455 -0
  38. package/src/quiet.js +32 -0
  39. package/src/scheduler.js +94 -0
  40. package/src/session.js +227 -0
  41. package/src/settings.js +38 -0
  42. package/src/starter.js +38 -0
  43. package/src/store.js +100 -0
  44. package/src/tips.js +30 -0
  45. package/src/ui/AddCard.js +172 -0
  46. package/src/ui/AnswerInput.js +85 -0
  47. package/src/ui/App.js +509 -0
  48. package/src/ui/BadgeUnlock.js +50 -0
  49. package/src/ui/Badges.js +122 -0
  50. package/src/ui/Choice.js +33 -0
  51. package/src/ui/Companion.js +45 -0
  52. package/src/ui/Confetti.js +46 -0
  53. package/src/ui/Decks.js +49 -0
  54. package/src/ui/DieRoll.js +104 -0
  55. package/src/ui/Evolution.js +59 -0
  56. package/src/ui/Hatch.js +100 -0
  57. package/src/ui/Header.js +117 -0
  58. package/src/ui/Help.js +68 -0
  59. package/src/ui/Mascot.js +178 -0
  60. package/src/ui/Missed.js +53 -0
  61. package/src/ui/Preview.js +256 -0
  62. package/src/ui/Reset.js +72 -0
  63. package/src/ui/Settings.js +69 -0
  64. package/src/ui/Stats.js +111 -0
  65. package/src/ui/Summary.js +41 -0
  66. package/src/ui/TheOne.js +121 -0
  67. package/src/ui/icons.js +341 -0
  68. package/src/ui/kit.js +120 -0
  69. package/src/vacation.js +56 -0
  70. package/src/words.js +23 -0
@@ -0,0 +1,122 @@
1
+ import { Fragment, useEffect, useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
4
+ import { badgeColor, BadgeIcon, ICON_WIDTH } from "./icons.js";
5
+
6
+ const COLUMNS = 3;
7
+ const COLUMN_WIDTH = 22; // fits "❯ ● " plus the longest badge name
8
+
9
+ // badges won since the last visit light up one after another
10
+ const FRAME_MS = 90;
11
+ const STAGGER = 7; // frames between two badges
12
+ const FLASH_FRAMES = [2, 4];
13
+ const LIT_FROM = 5;
14
+ const GREY = "#4a5058";
15
+
16
+ // a hidden badge reveals nothing until it's won
17
+ const SECRET = { name: "???", desc: "a secret, keep playing" };
18
+ const display = (badge) => (badge.hidden && !badge.unlockedOn ? { ...badge, ...SECRET } : badge);
19
+ const WHITE = "#ffffff";
20
+
21
+ // where a fresh badge is in its little animation: "waiting" (still looks locked), "flash", or "lit"
22
+ function phaseOf(freshIndex, frame) {
23
+ if (freshIndex < 0) return "lit";
24
+ const local = frame - freshIndex * STAGGER;
25
+ if (FLASH_FRAMES.includes(local)) return "flash";
26
+ return local >= LIT_FROM ? "lit" : "waiting";
27
+ }
28
+
29
+ // Three columns of badges with a pixel-icon preview of the selected one. Badges in `fresh`
30
+ // (won since /badges was last opened) light up in order, and the preview follows them until
31
+ // a key is pressed. ↑/↓ walk a column, ←/→ jump between columns, esc closes.
32
+ export function Badges({ badges, fresh = [], onClose }) {
33
+ const panel = usePanelWidth();
34
+ const firstFresh = badges.findIndex((b) => b.id === fresh[0]);
35
+ const [selected, setSelected] = useState(firstFresh >= 0 ? firstFresh : 0);
36
+ const [following, setFollowing] = useState(fresh.length > 0);
37
+ const [frame, setFrame] = useState(0);
38
+ const rows = Math.ceil(badges.length / COLUMNS);
39
+ const animationEnd = (fresh.length - 1) * STAGGER + LIT_FROM;
40
+
41
+ useEffect(() => {
42
+ if (!fresh.length) return undefined;
43
+ const timer = setInterval(() => {
44
+ setFrame((f) => {
45
+ if (f >= animationEnd) clearInterval(timer);
46
+ return f + 1;
47
+ });
48
+ }, FRAME_MS);
49
+ return () => clearInterval(timer);
50
+ }, []);
51
+
52
+ // the preview jumps to each fresh badge as it starts to light up
53
+ useEffect(() => {
54
+ if (!following || frame % STAGGER !== 0) return;
55
+ const index = badges.findIndex((b) => b.id === fresh[frame / STAGGER]);
56
+ if (index >= 0) setSelected(index);
57
+ }, [frame, following]);
58
+
59
+ useInput((input, key) => {
60
+ if (key.escape || input === "q") return onClose();
61
+ setFollowing(false);
62
+ if (key.upArrow) return setSelected((s) => Math.max(0, s - 1));
63
+ if (key.downArrow) return setSelected((s) => Math.min(badges.length - 1, s + 1));
64
+ if (key.leftArrow) return setSelected((s) => Math.max(0, s - rows));
65
+ if (key.rightArrow) return setSelected((s) => Math.min(badges.length - 1, s + rows));
66
+ });
67
+
68
+ const unlocked = badges.filter((b) => b.unlockedOn).length;
69
+ const badge = display(badges[selected]);
70
+ const phase = phaseOf(fresh.indexOf(badge.id), frame);
71
+ const shownUnlocked = badge.unlockedOn && phase === "lit";
72
+
73
+ return html`
74
+ <${Fragment}>
75
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
76
+ <${Box}>
77
+ <${Text} bold color=${theme.accent}>Badges<//>
78
+ <${Text} dimColor> ${unlocked}/${badges.length}<//>
79
+ ${fresh.length > 0 && html`<${Text} color=${theme.warn}> ${fresh.length} new<//>`}
80
+ <//>
81
+
82
+ <${Box} marginTop=${1}>
83
+ <${Box} flexDirection="column" width=${ICON_WIDTH + 3}>
84
+ <${BadgeIcon} id=${badge.id} locked=${!badge.unlockedOn || phase === "waiting"} flash=${phase === "flash"} secret=${badge.hidden && !badge.unlockedOn} />
85
+ <//>
86
+ <${Box} flexDirection="column" justifyContent="center">
87
+ <${Box}><${Text} bold color=${shownUnlocked ? badgeColor(badge.id) : undefined} dimColor=${!shownUnlocked}>${badge.name}<//><//>
88
+ <${Box}><${Text}>${badge.desc}<//><//>
89
+ <${Box}><${Text} dimColor>${badge.unlockedOn ? `unlocked ${badge.unlockedOn}` : "still locked"}<//><//>
90
+ <//>
91
+ <//>
92
+
93
+ <${Box} marginTop=${1}>
94
+ ${Array.from({ length: COLUMNS }, (_, column) => column).map(
95
+ (column) => html`
96
+ <${Box} key=${column} flexDirection="column" width=${COLUMN_WIDTH}>
97
+ ${badges.slice(column * rows, column * rows + rows).map((b, r) => {
98
+ const index = column * rows + r;
99
+ const current = index === selected;
100
+ const rowPhase = phaseOf(fresh.indexOf(b.id), frame);
101
+ const shown = b.unlockedOn && rowPhase !== "waiting";
102
+ const dotColor = !shown ? undefined : rowPhase === "flash" ? WHITE : badgeColor(b.id);
103
+ const nameColor = current ? theme.accent : rowPhase === "flash" ? WHITE : shown ? theme.text : undefined;
104
+ return html`
105
+ <${Box} key=${b.id}>
106
+ <${Text} bold=${current} dimColor=${!current && !shown} wrap="truncate">
107
+ <${Text} color=${current ? theme.accent : undefined}>${current ? "❯" : " "} <//>
108
+ <${Text} color=${dotColor ?? (b.unlockedOn ? GREY : undefined)}>${shown ? "●" : "○"} <//>
109
+ <${Text} color=${nameColor}>${display(b).name}<//>
110
+ <//>
111
+ <//>
112
+ `;
113
+ })}
114
+ <//>
115
+ `
116
+ )}
117
+ <//>
118
+ <//>
119
+ <${Box} paddingX=${1}><${KeyHints} text="↑/↓ browse · ←/→ column · esc back" /><//>
120
+ <//>
121
+ `;
122
+ }
@@ -0,0 +1,33 @@
1
+ import { Box, Text, useInput } from "ink";
2
+ import { html, theme } from "./kit.js";
3
+
4
+ // A question's answers as a list: ↑/↓ and Enter, a number, or an option's own key ("y", "n").
5
+ // Each option: { label, note?, key?, danger? }; `danger` paints it red while it's chosen.
6
+ export function Choice({ options, selected, onMove, onPick, onCancel }) {
7
+ useInput((input, key) => {
8
+ if (key.escape) return onCancel?.();
9
+ if (key.upArrow) return onMove(Math.max(0, selected - 1));
10
+ if (key.downArrow) return onMove(Math.min(options.length - 1, selected + 1));
11
+ if (key.return) return onPick(selected);
12
+ const index = options.findIndex((o, i) => input === String(i + 1) || (o.key && input.toLowerCase() === o.key));
13
+ if (index >= 0) onPick(index);
14
+ });
15
+
16
+ const width = Math.max(...options.map((o) => o.label.length)) + 2;
17
+ return html`
18
+ <${Box} flexDirection="column">
19
+ ${options.map((o, i) => {
20
+ const on = i === selected;
21
+ const color = on ? (o.danger ? theme.bad : theme.accent) : undefined;
22
+ return html`
23
+ <${Box} key=${o.label}>
24
+ <${Box} flexShrink=${0}><${Text} color=${color} bold=${on}>${on ? "❯" : " "} ${i + 1}. ${o.label.padEnd(width)}<//><//>
25
+ ${o.note && html`<${Text} dimColor>${o.note}<//>`}
26
+ <//>
27
+ `;
28
+ })}
29
+ <//>
30
+ `;
31
+ }
32
+
33
+ export const CHOICE_KEYS = "↑/↓ choose · enter confirm";
@@ -0,0 +1,45 @@
1
+ import { Fragment } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { ELEMENT_ADJECTIVE, STAGES } from "../progress.js";
4
+ import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
5
+ import { ELEMENT_COLOR, Mascot } from "./Mascot.js";
6
+
7
+ const requirement = (stage, locked) => (stage.from === 0 ? "from the start" : `${locked ? "needs " : ""}${stage.from} days`);
8
+
9
+ // Every form of the companion. Forms you haven't reached are flat silhouettes named "???".
10
+ // Its moods aren't listed here on purpose: you find them out by playing.
11
+ export function Companion({ current, best, element = null, roll = null, onClose }) {
12
+ const panel = usePanelWidth();
13
+ useInput((input, key) => {
14
+ if (key.escape || key.return || input === "q") onClose();
15
+ });
16
+
17
+ return html`
18
+ <${Fragment}>
19
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
20
+ <${Text} bold color=${theme.accent}>Companion<//>
21
+ <${Box} marginTop=${1}>
22
+ <${Text}>Your dragon: <//>
23
+ ${element && html`<${Text} bold color=${ELEMENT_COLOR[element]}>${ELEMENT_ADJECTIVE[element]} <//>`}
24
+ <${Text} bold>${STAGES[current].name}<//>
25
+ <//>
26
+ <${Text} dimColor>${element ? `Element: ${element}${roll ? ` · rolled a ${roll.face} on Dragon's die, ${roll.on}` : ""}` : "No element yet. Some say a die decides it…"}<//>
27
+ <${Box} marginTop=${1}><${Text} dimColor>Evolves with your best streak (${best} days) and never loses a form.<//><//>
28
+
29
+ <${Box} marginTop=${1} flexWrap="wrap">
30
+ ${STAGES.map((stage, i) => {
31
+ const locked = i > current;
32
+ return html`
33
+ <${Box} key=${stage.name} width=${22} flexDirection="column" marginBottom=${1}>
34
+ <${Box} flexDirection="column"><${Mascot} stage=${i} locked=${locked} face=${locked ? "idle" : "smile"} element=${element} /><//>
35
+ <${Text} bold=${i === current} color=${i === current ? theme.accent : undefined} dimColor=${locked}>${locked ? "???" : stage.name}${i === current ? " ← now" : ""}<//>
36
+ <${Text} dimColor>${requirement(stage, locked)}<//>
37
+ <//>
38
+ `;
39
+ })}
40
+ <//>
41
+ <//>
42
+ <${Box} paddingX=${1}><${KeyHints} text="esc back" /><//>
43
+ <//>
44
+ `;
45
+ }
@@ -0,0 +1,46 @@
1
+ import { useEffect, useMemo, useState } from "react";
2
+ import { Box, Text } from "ink";
3
+ import { html, theme } from "./kit.js";
4
+
5
+ const ROWS = 4;
6
+ const FRAME_MS = 100;
7
+ const COLORS = [theme.accent, theme.good, theme.warn, "#7dd3fc", "#f0abfc"];
8
+ const GLYPHS = ["▪", "▘", "▝", "▖", "▗", "•"];
9
+
10
+ // A short burst of falling pixels over the card, played once when the daily goal lands.
11
+ export function Confetti({ width, onDone }) {
12
+ const particles = useMemo(
13
+ () =>
14
+ Array.from({ length: Math.floor(width / 2.5) }, () => ({
15
+ col: Math.floor(Math.random() * width),
16
+ delay: Math.floor(Math.random() * 7),
17
+ color: COLORS[Math.floor(Math.random() * COLORS.length)],
18
+ glyph: GLYPHS[Math.floor(Math.random() * GLYPHS.length)]
19
+ })),
20
+ [width]
21
+ );
22
+ const total = ROWS + 7 + 1;
23
+ const [frame, setFrame] = useState(0);
24
+ useEffect(() => {
25
+ const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
26
+ return () => clearInterval(id);
27
+ }, []);
28
+ useEffect(() => {
29
+ if (frame > total) onDone();
30
+ }, [frame, total, onDone]);
31
+
32
+ const rows = Array.from({ length: ROWS }, (_, r) => {
33
+ const here = particles.filter((p) => frame - p.delay === r).sort((a, b) => a.col - b.col);
34
+ const cells = [];
35
+ let at = 0;
36
+ for (const p of here) {
37
+ if (p.col < at) continue; // two particles on one cell: draw the first
38
+ cells.push(html`<${Text} key=${`g${p.col}`}>${" ".repeat(p.col - at)}<//>`);
39
+ cells.push(html`<${Text} key=${`p${p.col}`} color=${p.color}>${p.glyph}<//>`);
40
+ at = p.col + 1;
41
+ }
42
+ return html`<${Text} key=${r}>${cells.length ? cells : " "}<//>`;
43
+ });
44
+
45
+ return html`<${Box} flexDirection="column" paddingX=${1}>${rows}<//>`;
46
+ }
@@ -0,0 +1,49 @@
1
+ import { Fragment, useEffect, useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { Choice, CHOICE_KEYS } from "./Choice.js";
4
+ import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
5
+
6
+ // /decks: your decks with their card counts; Enter quizzes the chosen one from now on, and
7
+ // "+ New deck" starts one (`onNew`). Renaming and deleting decks come later.
8
+ export function Decks({ current, actions, onPick, onNew, onClose }) {
9
+ const panel = usePanelWidth();
10
+ const [decks, setDecks] = useState(null);
11
+ const [picked, setPicked] = useState(0);
12
+ const [error, setError] = useState("");
13
+
14
+ useEffect(() => {
15
+ actions.allDecks().then(
16
+ (all) => {
17
+ setDecks(all);
18
+ setPicked(Math.max(0, all.findIndex((d) => d.name === current)));
19
+ },
20
+ (err) => setError(err.message)
21
+ );
22
+ }, []);
23
+
24
+ useInput((input, key) => {
25
+ if (!decks?.length && (key.escape || input === "q")) onClose();
26
+ });
27
+
28
+ return html`
29
+ <${Fragment}>
30
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
31
+ <${Text} bold color=${theme.accent}>Decks<//>
32
+ ${decks?.length > 0 &&
33
+ html`
34
+ <${Box} marginTop=${1}>
35
+ <${Choice}
36
+ options=${[...decks.map((d) => ({ label: d.name, note: `${d.cards} card${d.cards === 1 ? "" : "s"}${d.tour ? " · the tour" : ""}${d.name === current ? " · now" : ""}` })), { label: "+ New deck" }]}
37
+ selected=${picked}
38
+ onMove=${setPicked}
39
+ onPick=${(i) => (i === decks.length ? onNew() : onPick(decks[i].name))}
40
+ onCancel=${onClose}
41
+ />
42
+ <//>
43
+ `}
44
+ ${error && html`<${Box} marginTop=${1}><${Text} color=${theme.bad}>${error}<//><//>`}
45
+ <//>
46
+ <${Box} paddingX=${1}><${KeyHints} text=${`${CHOICE_KEYS} · esc back`} /><//>
47
+ <//>
48
+ `;
49
+ }
@@ -0,0 +1,104 @@
1
+ import React, { Fragment, useEffect, useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { ELEMENTS } from "../progress.js";
4
+ import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
5
+ import { ELEMENT_COLOR, Mascot } from "./Mascot.js";
6
+
7
+ const FRAME_MS = 80;
8
+ // single-pixel pips on a 9×9 die, with a pixel of space between any two, so six reads as six
9
+ const SIZE = 9;
10
+ const PIPS = { tl: [2, 2], tr: [2, 6], ml: [4, 2], c: [4, 4], mr: [4, 6], bl: [6, 2], br: [6, 6] };
11
+ const FACES = {
12
+ 1: ["c"],
13
+ 2: ["tl", "br"],
14
+ 3: ["tl", "c", "br"],
15
+ 4: ["tl", "tr", "bl", "br"],
16
+ 5: ["tl", "tr", "c", "bl", "br"],
17
+ 6: ["tl", "tr", "ml", "mr", "bl", "br"]
18
+ };
19
+ const ELEMENT_NAME = { earth: "Earth", wind: "Wind", water: "Water", ice: "Ice", fire: "Fire", cosmos: "Cosmos" };
20
+
21
+ // timeline, in frames: tumbling (faces change, slower and slower, bouncing lower) → landed → the dragon changes
22
+ const LAND_AT = 30;
23
+ const FLASH_FRAMES = [36, 38];
24
+ const REVEAL_AT = 40;
25
+ const BOUNCE = [2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0];
26
+
27
+ function dieGrid(face, pipColor) {
28
+ const last = SIZE - 1;
29
+ const grid = Array.from({ length: SIZE }, (_, r) => Array.from({ length: SIZE }, (_, c) => ((r === 0 || r === last) && (c === 0 || c === last) ? null : "#f4f4f5")));
30
+ for (let r = 1; r < last; r++) grid[r][last] = "#c7c9d1"; // a shaded edge
31
+ for (let c = 1; c < last; c++) grid[last][c] = "#c7c9d1";
32
+ for (const pip of FACES[face]) {
33
+ const [r, c] = PIPS[pip];
34
+ grid[r][c] = pipColor;
35
+ }
36
+ return grid;
37
+ }
38
+
39
+ // while tumbling the shown face changes every frame at first, then every 2, then every 3
40
+ function tumblingFace(frame, result) {
41
+ if (frame >= LAND_AT) return result;
42
+ const step = frame < 12 ? frame : frame < 22 ? 12 + Math.floor((frame - 12) / 2) : 17 + Math.floor((frame - 22) / 3);
43
+ const face = ((step * 5 + 2) % 6) + 1;
44
+ return face === result && frame > LAND_AT - 4 ? (face % 6) + 1 : face; // don't give it away just before landing
45
+ }
46
+
47
+ function BigGrid({ grid }) {
48
+ return html`
49
+ <${Fragment}>
50
+ ${grid.map((row, r) => html`<${Text} key=${r}>${row.map((color, c) => React.createElement(Text, { key: c, color }, color ? "██" : " "))}<//>`)}
51
+ <//>
52
+ `;
53
+ }
54
+
55
+ // The roll for "Dragon's die". The element was already rolled and saved; this only shows it.
56
+ // Any key skips to the end; after the reveal, any key closes it.
57
+ export function DieRoll({ element, stage = 0, onClose, play = () => {} }) {
58
+ const panel = usePanelWidth();
59
+ const result = ELEMENTS.indexOf(element) + 1;
60
+ const [frame, setFrame] = useState(0);
61
+ useEffect(() => {
62
+ const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
63
+ return () => clearInterval(id);
64
+ }, []);
65
+ useEffect(() => {
66
+ if (frame === LAND_AT) play("close");
67
+ if (frame === REVEAL_AT) play("evolve");
68
+ }, [frame]);
69
+
70
+ const revealed = frame >= REVEAL_AT;
71
+ useInput(() => (revealed ? onClose() : setFrame(REVEAL_AT)));
72
+
73
+ const landed = frame >= LAND_AT;
74
+ const color = ELEMENT_COLOR[element];
75
+ const face = tumblingFace(frame, result);
76
+ const bounce = landed ? 0 : BOUNCE[Math.min(Math.floor(frame / 1.5), BOUNCE.length - 1)];
77
+
78
+ return html`
79
+ <${Fragment}>
80
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${landed ? color : theme.warn} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
81
+ <${Text} bold color=${theme.warn}>Dragon's die<//>
82
+ <${Box} marginTop=${1} alignItems="flex-end">
83
+ <${Box} flexDirection="column" marginBottom=${bounce} marginRight=${4}>
84
+ <${BigGrid} grid=${dieGrid(face, landed ? color : "#2a2440")} />
85
+ <//>
86
+ <${Box} flexDirection="column">
87
+ <${Mascot} stage=${stage} face=${revealed ? "happy" : "idle"} flash=${FLASH_FRAMES.includes(frame)} element=${revealed ? element : null} scale=${2} />
88
+ <//>
89
+ <//>
90
+ <${Box} marginTop=${1} flexDirection="column" alignItems="center">
91
+ ${revealed
92
+ ? html`
93
+ <${Fragment}>
94
+ <${Text} bold color=${color}>${result} · ${ELEMENT_NAME[element]}<//>
95
+ <${Text} dimColor>Your dragon awakened the power of ${element}. It's yours for good.<//>
96
+ <//>
97
+ `
98
+ : html`<${Text} dimColor>${landed ? `${result} · ${ELEMENT_NAME[element]}` : "the die is rolling…"}<//>`}
99
+ <//>
100
+ <//>
101
+ <${Box} paddingX=${1}><${KeyHints} text=${revealed ? "any key to continue" : "any key to skip"} /><//>
102
+ <//>
103
+ `;
104
+ }
@@ -0,0 +1,59 @@
1
+ import { Fragment, useEffect, useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
4
+ import { Mascot } from "./Mascot.js";
5
+
6
+ const FRAME_MS = 120;
7
+ const FLASH_FROM = 6; // frames 0..5: the old form, wondering
8
+ const REVEAL_AT = 16; // frames 6..15: white-out flashing, then the new form
9
+ const SPARKS = ["✦", "·", "✧", "*"];
10
+
11
+ const article = (name) => (/^[aeiou]/i.test(name) ? "an" : "a");
12
+
13
+ // a loose ring of sparkles around the sprite; which ones show varies per frame
14
+ function sparkleRow(frame, seed, width) {
15
+ const chars = [];
16
+ for (let i = 0; i < width; i++) {
17
+ chars.push((i * 7 + seed * 13 + frame * 3) % 11 === 0 ? SPARKS[(i + frame) % SPARKS.length] : " ");
18
+ }
19
+ return chars.join("");
20
+ }
21
+
22
+ // The full-screen moment when the companion evolves: old form → white flashes → new form.
23
+ // Any key fast-forwards to the reveal; Enter/Esc then closes it.
24
+ export function Evolution({ from, to, name, element = null, onClose }) {
25
+ const panel = usePanelWidth();
26
+ const [frame, setFrame] = useState(0);
27
+ useEffect(() => {
28
+ const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
29
+ return () => clearInterval(id);
30
+ }, []);
31
+ const revealed = frame >= REVEAL_AT;
32
+ useInput(() => {
33
+ if (!revealed) return setFrame(REVEAL_AT);
34
+ onClose();
35
+ });
36
+
37
+ const flashing = frame >= FLASH_FROM && !revealed;
38
+ const stage = revealed ? to : from;
39
+ const sparks = flashing || (revealed && frame < REVEAL_AT + 8);
40
+
41
+ return html`
42
+ <${Fragment}>
43
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.warn} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
44
+ <${Text} bold color=${theme.warn}>✦ Evolution ✦<//>
45
+ <${Box} flexDirection="column" marginTop=${1} alignItems="center">
46
+ <${Text} color=${theme.warn}>${sparks ? sparkleRow(frame, 1, 30) : " "}<//>
47
+ <${Mascot} stage=${stage} face=${revealed ? "happy" : "idle"} flash=${flashing && frame % 2 === 0} scale=${2} element=${element} />
48
+ <${Text} color=${theme.warn}>${sparks ? sparkleRow(frame, 2, 30) : " "}<//>
49
+ <//>
50
+ <${Box} marginTop=${1} flexDirection="column" alignItems="center">
51
+ ${revealed
52
+ ? html`<${Text} bold color=${theme.accent}>Your companion evolved into ${article(name)} ${name}!<//>`
53
+ : html`<${Text} dimColor>Something is happening…<//>`}
54
+ <//>
55
+ <//>
56
+ <${Box} paddingX=${1}><${KeyHints} text=${revealed ? "enter continue" : "any key to hurry it up"} /><//>
57
+ <//>
58
+ `;
59
+ }
@@ -0,0 +1,100 @@
1
+ import React, { Fragment, useEffect, useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
4
+ import { Mascot } from "./Mascot.js";
5
+
6
+ const FRAME_MS = 110;
7
+ // a cream egg with green dragon spots: O outline, L shell, D shade, S spot, K crack
8
+ const EGG = [
9
+ "............",
10
+ "....OOOO....",
11
+ "...OLLLLO...",
12
+ "..OLLSSLLO..",
13
+ "..OLLLLLLO..",
14
+ ".OLSLLLLSLO.",
15
+ ".OLLLLLLLLO.",
16
+ ".OLLLLSLLLO.",
17
+ "..ODDDDDDO..",
18
+ "...OOOOOO..."
19
+ ];
20
+ const EGG_COLORS = { O: "#5a5040", L: "#f3ead7", D: "#cdbf9f", S: "#58a66d", K: "#2a241c" };
21
+ const FLASH_COLORS = { O: "#d8e8dc", L: "#ffffff", D: "#eef6f0", S: "#ffffff", K: "#ffffff" };
22
+ const CRACKS = [
23
+ [[4, 5, "K"], [5, 6, "K"], [4, 7, "K"]],
24
+ [[6, 3, "K"], [5, 4, "K"], [6, 5, "K"], [5, 8, "K"], [6, 8, "K"], [3, 4, "K"]]
25
+ ];
26
+
27
+ // the timeline, in frames: rest → wobble → crack → wobble → crack → shake → flash → dragon
28
+ const CRACK_AT = [16, 26];
29
+ const FLASH_AT = 36;
30
+ const REVEAL_AT = 41;
31
+
32
+ const wobble = (frame) => {
33
+ if (frame < 8) return 0;
34
+ const speed = frame < CRACK_AT[1] ? 2 : 1; // the egg shakes faster once it's badly cracked
35
+ return Math.floor(frame / speed) % 2 === 0 ? 1 : -1;
36
+ };
37
+
38
+ function eggGrid(frame) {
39
+ const grid = EGG.map((row) => [...row]);
40
+ CRACKS.forEach((edits, i) => {
41
+ if (frame >= CRACK_AT[i]) edits.forEach(([r, c, p]) => (grid[r][c] = p));
42
+ });
43
+ const dx = wobble(frame);
44
+ return dx ? grid.map((row) => row.map((_, c) => row[c - dx] ?? ".")) : grid;
45
+ }
46
+
47
+ // one text row per pixel row, two characters per pixel: the same 2× scale as the evolution ceremony
48
+ function BigPixels({ grid, colors }) {
49
+ return html`
50
+ <${Fragment}>
51
+ ${grid.map(
52
+ (row, r) => html`<${Text} key=${r}>${row.map((p, c) => React.createElement(Text, { key: c, color: colors[p] }, colors[p] ? "██" : " "))}<//>`
53
+ )}
54
+ <//>
55
+ `;
56
+ }
57
+
58
+ // First launch ever: the dragon hatches. Any key skips ahead; after the reveal, any key starts the quiz.
59
+ export function Hatch({ onDone, play = () => {} }) {
60
+ const panel = usePanelWidth();
61
+ const [frame, setFrame] = useState(0);
62
+ useEffect(() => {
63
+ const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
64
+ return () => clearInterval(id);
65
+ }, []);
66
+ useEffect(() => {
67
+ if (CRACK_AT.includes(frame)) play("close");
68
+ if (frame === REVEAL_AT) play("evolve");
69
+ }, [frame]);
70
+
71
+ const revealed = frame >= REVEAL_AT;
72
+ useInput(() => (revealed ? onDone() : setFrame(REVEAL_AT)));
73
+
74
+ const flashing = frame >= FLASH_AT && !revealed;
75
+ const caption = revealed ? "" : frame >= CRACK_AT[0] ? "it's hatching…" : "something stirs inside…";
76
+
77
+ return html`
78
+ <${Fragment}>
79
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
80
+ <${Text} bold color=${theme.accent}>Dracosh<//>
81
+ <${Box} flexDirection="column" marginTop=${1} alignItems="center">
82
+ ${revealed
83
+ ? html`<${Mascot} stage=${0} face="happy" scale=${2} />`
84
+ : html`<${BigPixels} grid=${eggGrid(frame)} colors=${flashing && frame % 2 === 0 ? FLASH_COLORS : EGG_COLORS} />`}
85
+ <//>
86
+ <${Box} marginTop=${1} flexDirection="column" alignItems="center">
87
+ ${revealed
88
+ ? html`
89
+ <${Fragment}>
90
+ <${Text} bold color=${theme.good}>Your dragon has hatched!<//>
91
+ <${Text} dimColor>Answer cards to keep it happy. It grows with your streak.<//>
92
+ <//>
93
+ `
94
+ : html`<${Text} dimColor>${caption}<//>`}
95
+ <//>
96
+ <//>
97
+ <${Box} paddingX=${1}><${KeyHints} text=${revealed ? "any key to start" : "any key to skip"} /><//>
98
+ <//>
99
+ `;
100
+ }