dracosh 0.1.0 → 0.3.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 (61) hide show
  1. package/README.md +49 -22
  2. package/assets/sounds/badge-1.wav +0 -0
  3. package/assets/sounds/badge-2.wav +0 -0
  4. package/assets/sounds/badge-3.wav +0 -0
  5. package/assets/sounds/badge-4.wav +0 -0
  6. package/locales/de.json +1046 -0
  7. package/locales/en.json +1029 -0
  8. package/locales/fr.json +1094 -0
  9. package/locales/pl.json +1117 -0
  10. package/locales/uk.json +1118 -0
  11. package/package.json +2 -2
  12. package/src/alerts.js +7 -4
  13. package/src/backup.js +96 -0
  14. package/src/cardline.js +71 -0
  15. package/src/cli.js +106 -38
  16. package/src/commands.js +15 -13
  17. package/src/demo.js +11 -0
  18. package/src/diff.js +13 -7
  19. package/src/i18n.js +68 -0
  20. package/src/judge.js +51 -12
  21. package/src/library.js +154 -0
  22. package/src/lock.js +64 -0
  23. package/src/manage.js +165 -0
  24. package/src/pause.js +22 -0
  25. package/src/progress.js +202 -93
  26. package/src/quiet.js +4 -3
  27. package/src/scheduler.js +39 -30
  28. package/src/session.js +181 -33
  29. package/src/settings.js +15 -13
  30. package/src/starter.js +47 -0
  31. package/src/store.js +58 -17
  32. package/src/tips.js +17 -25
  33. package/src/ui/AddCard.js +496 -0
  34. package/src/ui/AnswerInput.js +28 -13
  35. package/src/ui/App.js +360 -89
  36. package/src/ui/BadgeUnlock.js +51 -0
  37. package/src/ui/Badges.js +79 -20
  38. package/src/ui/Choice.js +38 -0
  39. package/src/ui/Companion.js +24 -39
  40. package/src/ui/Confetti.js +2 -2
  41. package/src/ui/Decks.js +99 -0
  42. package/src/ui/DieRoll.js +104 -0
  43. package/src/ui/Evolution.js +11 -10
  44. package/src/ui/Hatch.js +9 -7
  45. package/src/ui/Header.js +62 -19
  46. package/src/ui/Help.js +74 -0
  47. package/src/ui/Mascot.js +89 -40
  48. package/src/ui/Missed.js +15 -13
  49. package/src/ui/Preview.js +123 -29
  50. package/src/ui/Reset.js +71 -0
  51. package/src/ui/Settings.js +34 -23
  52. package/src/ui/Stats.js +28 -24
  53. package/src/ui/Summary.js +18 -10
  54. package/src/ui/TheOne.js +122 -0
  55. package/src/ui/icons.js +156 -25
  56. package/src/ui/kit.js +87 -2
  57. package/src/vacation.js +9 -3
  58. package/src/words.js +22 -14
  59. package/assets/sounds/badge.wav +0 -0
  60. package/data/tips.json +0 -1362
  61. package/src/ui/Tip.js +0 -25
@@ -0,0 +1,51 @@
1
+ import { t } from "../i18n.js";
2
+ import { useEffect, useState } from "react";
3
+ import { Box } from "ink";
4
+ import { badgeColor } from "./icons.js";
5
+ import { html, Text, theme } from "./kit.js";
6
+
7
+ const FRAME_MS = 90;
8
+ const FLASH_FRAMES = [5, 7]; // white-out frames before the name lights up in its rank color
9
+ const COLOR_FROM = 8;
10
+ const SPARKS_UNTIL = 22;
11
+ const SPARKS = ["✦", "·", "✧", "·"];
12
+ const GREY = "#4a5058";
13
+ const WHITE = "#ffffff";
14
+ const STEPS = 4; // badge-1 … badge-4 (scripts/make-sounds.js)
15
+
16
+ // Badges won with the same answer ring one after another, each a step higher. The climb starts
17
+ // over with every answer: a badge won later, on its own, plays the first step again.
18
+ export const badgeSound = (i) => `badge-${Math.min(i + 1, STEPS)}`;
19
+
20
+ // A badge just won, as one line under the card: the name comes out of grey, flashes white and
21
+ // lights up in its rank color while a few sparks fly. The badge art lives in /badges.
22
+ // `delay` staggers several badges won at once; `sound` rings as the line appears.
23
+ export function BadgeUnlock({ id, name, desc, delay = 0, sound = badgeSound(0), play }) {
24
+ const [frame, setFrame] = useState(-Math.round(delay / FRAME_MS));
25
+ useEffect(() => {
26
+ if (frame === 0) play?.(sound);
27
+ }, [frame === 0]);
28
+ useEffect(() => {
29
+ const timer = setInterval(() => {
30
+ setFrame((f) => {
31
+ if (f >= SPARKS_UNTIL) clearInterval(timer);
32
+ return f + 1;
33
+ });
34
+ }, FRAME_MS);
35
+ return () => clearInterval(timer);
36
+ }, []);
37
+
38
+ if (frame < 0) return null;
39
+ const color = FLASH_FRAMES.includes(frame) ? WHITE : frame >= COLOR_FROM ? badgeColor(id) : GREY;
40
+ const sparks = frame < SPARKS_UNTIL ? ` ${Array.from({ length: 3 }, (_, i) => SPARKS[(frame + i) % SPARKS.length]).join(" ")}` : "";
41
+
42
+ return html`
43
+ <${Box}>
44
+ <${Text} color=${color}>✦ <//>
45
+ <${Text} color=${theme.warn}>${t("badgeUnlock.label")}<//>
46
+ <${Text} bold color=${color}>${name}<//>
47
+ <${Text} dimColor> · ${desc}<//>
48
+ <${Text} color=${theme.warn}>${sparks}<//>
49
+ <//>
50
+ `;
51
+ }
package/src/ui/Badges.js CHANGED
@@ -1,15 +1,65 @@
1
- import { Fragment, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { html, PANEL_WIDTH, theme } from "./kit.js";
4
- import { BadgeIcon, ICON_WIDTH } from "./icons.js";
1
+ import { t } from "../i18n.js";
2
+ import { Fragment, useEffect, useState } from "react";
3
+ import { Box, useInput } from "ink";
4
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
5
+ import { badgeColor, BadgeIcon, ICON_WIDTH } from "./icons.js";
6
+
7
+ const COLUMNS = 3;
8
+ const COLUMN_WIDTH = 22; // fits "❯ ● " plus the longest badge name
9
+
10
+ // badges won since the last visit light up one after another
11
+ const FRAME_MS = 90;
12
+ const STAGGER = 7; // frames between two badges
13
+ const FLASH_FRAMES = [2, 4];
14
+ const LIT_FROM = 5;
15
+ const GREY = "#4a5058";
16
+
17
+ // a hidden badge reveals nothing until it's won
18
+ const secret = () => ({ name: t("badgesScreen.secretName"), desc: t("badgesScreen.secretDesc") });
19
+ const display = (badge) => (badge.hidden && !badge.unlockedOn ? { ...badge, ...secret() } : badge);
20
+ const WHITE = "#ffffff";
21
+
22
+ // where a fresh badge is in its little animation: "waiting" (still looks locked), "flash", or "lit"
23
+ function phaseOf(freshIndex, frame) {
24
+ if (freshIndex < 0) return "lit";
25
+ const local = frame - freshIndex * STAGGER;
26
+ if (FLASH_FRAMES.includes(local)) return "flash";
27
+ return local >= LIT_FROM ? "lit" : "waiting";
28
+ }
29
+
30
+ // Three columns of badges with a pixel-icon preview of the selected one. Badges in `fresh`
31
+ // (won since /badges was last opened) light up in order, and the preview follows them until
32
+ // a key is pressed. ↑/↓ walk a column, ←/→ jump between columns, esc closes.
33
+ export function Badges({ badges, fresh = [], onClose }) {
34
+ const panel = usePanelWidth();
35
+ const firstFresh = badges.findIndex((b) => b.id === fresh[0]);
36
+ const [selected, setSelected] = useState(firstFresh >= 0 ? firstFresh : 0);
37
+ const [following, setFollowing] = useState(fresh.length > 0);
38
+ const [frame, setFrame] = useState(0);
39
+ const rows = Math.ceil(badges.length / COLUMNS);
40
+ const animationEnd = (fresh.length - 1) * STAGGER + LIT_FROM;
41
+
42
+ useEffect(() => {
43
+ if (!fresh.length) return undefined;
44
+ const timer = setInterval(() => {
45
+ setFrame((f) => {
46
+ if (f >= animationEnd) clearInterval(timer);
47
+ return f + 1;
48
+ });
49
+ }, FRAME_MS);
50
+ return () => clearInterval(timer);
51
+ }, []);
52
+
53
+ // the preview jumps to each fresh badge as it starts to light up
54
+ useEffect(() => {
55
+ if (!following || frame % STAGGER !== 0) return;
56
+ const index = badges.findIndex((b) => b.id === fresh[frame / STAGGER]);
57
+ if (index >= 0) setSelected(index);
58
+ }, [frame, following]);
5
59
 
6
- // Two columns of badges with a pixel-icon preview of the selected one.
7
- // ↑/↓ walk a column, ←/→ jump between columns, esc closes.
8
- export function Badges({ badges, onClose }) {
9
- const [selected, setSelected] = useState(0);
10
- const rows = Math.ceil(badges.length / 2);
11
60
  useInput((input, key) => {
12
61
  if (key.escape || input === "q") return onClose();
62
+ setFollowing(false);
13
63
  if (key.upArrow) return setSelected((s) => Math.max(0, s - 1));
14
64
  if (key.downArrow) return setSelected((s) => Math.min(badges.length - 1, s + 1));
15
65
  if (key.leftArrow) return setSelected((s) => Math.max(0, s - rows));
@@ -17,38 +67,47 @@ export function Badges({ badges, onClose }) {
17
67
  });
18
68
 
19
69
  const unlocked = badges.filter((b) => b.unlockedOn).length;
20
- const badge = badges[selected];
70
+ const badge = display(badges[selected]);
71
+ const phase = phaseOf(fresh.indexOf(badge.id), frame);
72
+ const shownUnlocked = badge.unlockedOn && phase === "lit";
21
73
 
22
74
  return html`
23
75
  <${Fragment}>
24
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
76
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
25
77
  <${Box}>
26
- <${Text} bold color=${theme.accent}>Badges<//>
78
+ <${Text} bold color=${theme.accent}>${t("badgesScreen.title")}<//>
27
79
  <${Text} dimColor> ${unlocked}/${badges.length}<//>
80
+ ${fresh.length > 0 && html`<${Text} color=${theme.warn}>${t("badgesScreen.new", { count: fresh.length })}<//>`}
28
81
  <//>
29
82
 
30
83
  <${Box} marginTop=${1}>
31
84
  <${Box} flexDirection="column" width=${ICON_WIDTH + 3}>
32
- <${BadgeIcon} id=${badge.id} locked=${!badge.unlockedOn} />
85
+ <${BadgeIcon} id=${badge.id} locked=${!badge.unlockedOn || phase === "waiting"} flash=${phase === "flash"} secret=${badge.hidden && !badge.unlockedOn} />
33
86
  <//>
34
87
  <${Box} flexDirection="column" justifyContent="center">
35
- <${Box}><${Text} bold color=${badge.unlockedOn ? theme.warn : undefined} dimColor=${!badge.unlockedOn}>${badge.name}<//><//>
88
+ <${Box}><${Text} bold color=${shownUnlocked ? badgeColor(badge.id) : undefined} dimColor=${!shownUnlocked}>${badge.name}<//><//>
36
89
  <${Box}><${Text}>${badge.desc}<//><//>
37
- <${Box}><${Text} dimColor>${badge.unlockedOn ? `unlocked ${badge.unlockedOn}` : "still locked"}<//><//>
90
+ <${Box}><${Text} dimColor>${badge.unlockedOn ? t("badgesScreen.unlocked", { day: badge.unlockedOn }) : t("badgesScreen.locked")}<//><//>
38
91
  <//>
39
92
  <//>
40
93
 
41
94
  <${Box} marginTop=${1}>
42
- ${[0, 1].map(
95
+ ${Array.from({ length: COLUMNS }, (_, column) => column).map(
43
96
  (column) => html`
44
- <${Box} key=${column} flexDirection="column" width=${column === 0 ? 34 : undefined}>
97
+ <${Box} key=${column} flexDirection="column" width=${COLUMN_WIDTH}>
45
98
  ${badges.slice(column * rows, column * rows + rows).map((b, r) => {
46
99
  const index = column * rows + r;
47
100
  const current = index === selected;
101
+ const rowPhase = phaseOf(fresh.indexOf(b.id), frame);
102
+ const shown = b.unlockedOn && rowPhase !== "waiting";
103
+ const dotColor = !shown ? undefined : rowPhase === "flash" ? WHITE : badgeColor(b.id);
104
+ const nameColor = current ? theme.accent : rowPhase === "flash" ? WHITE : shown ? theme.text : undefined;
48
105
  return html`
49
106
  <${Box} key=${b.id}>
50
- <${Text} color=${current ? theme.accent : b.unlockedOn ? theme.warn : undefined} bold=${current} dimColor=${!current && !b.unlockedOn}>
51
- ${current ? "❯" : " "} ${b.unlockedOn ? "●" : "○"} ${b.name}
107
+ <${Text} bold=${current} dimColor=${!current && !shown} wrap="truncate">
108
+ <${Text} color=${current ? theme.accent : undefined}>${current ? "❯" : " "} <//>
109
+ <${Text} color=${dotColor ?? (b.unlockedOn ? GREY : undefined)}>${shown ? "●" : "○"} <//>
110
+ <${Text} color=${nameColor}>${display(b).name}<//>
52
111
  <//>
53
112
  <//>
54
113
  `;
@@ -58,7 +117,7 @@ export function Badges({ badges, onClose }) {
58
117
  )}
59
118
  <//>
60
119
  <//>
61
- <${Box} paddingX=${1}><${Text} dimColor>↑/↓ browse · ←/→ column · esc back<//><//>
120
+ <${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.badges")} /><//>
62
121
  <//>
63
122
  `;
64
123
  }
@@ -0,0 +1,38 @@
1
+ import { Box, useInput } from "ink";
2
+ import { t } from "../i18n.js";
3
+ import { cellWidth, html, Text, theme, usePanelWidth } from "./kit.js";
4
+
5
+ // A question's answers as a list: ↑/↓ and Enter, a number, or an option's own keys ("t|y" in Polish).
6
+ // Each option: { label, note?, key?, danger? }; `danger` paints it red while it's chosen.
7
+ export function Choice({ options, selected, onMove, onPick, onCancel }) {
8
+ useInput((input, key) => {
9
+ if (key.escape) return onCancel?.();
10
+ if (key.upArrow) return onMove(Math.max(0, selected - 1));
11
+ if (key.downArrow) return onMove(Math.min(options.length - 1, selected + 1));
12
+ if (key.return) return onPick(selected);
13
+ const index = options.findIndex((o, i) => input === String(i + 1) || (o.key && o.key.split("|").includes(input.toLowerCase())));
14
+ if (index >= 0) onPick(index);
15
+ });
16
+
17
+ const panel = usePanelWidth();
18
+ const width = Math.max(...options.map((o) => cellWidth(o.label))) + 2;
19
+ // in a narrow pane the notes go under their labels instead of wrapping into a thin column
20
+ const stacked = options.some((o) => o.note && 5 + width + cellWidth(o.note) > panel - 6);
21
+ return html`
22
+ <${Box} flexDirection="column">
23
+ ${options.map((o, i) => {
24
+ const on = i === selected;
25
+ const color = on ? (o.danger ? theme.bad : theme.accent) : undefined;
26
+ return html`
27
+ <${Box} key=${o.label} flexDirection=${stacked ? "column" : "row"}>
28
+ <${Box} flexShrink=${0}><${Text} color=${color} bold=${on}>${on ? "❯" : " "} ${i + 1}. ${stacked ? o.label : o.label + " ".repeat(width - cellWidth(o.label))}<//><//>
29
+ ${o.note && html`<${Box} marginLeft=${stacked ? 5 : 0}><${Text} dimColor>${o.note}<//><//>`}
30
+ <//>
31
+ `;
32
+ })}
33
+ <//>
34
+ `;
35
+ }
36
+
37
+ // the footer under a list of choices; `end` is what Esc does there ("back" or "cancel")
38
+ export const choiceHints = (end = "back") => t(end === "cancel" ? "keyHints.choiceCancel" : "keyHints.choiceBack", { choose: t("choice.keys") });
@@ -1,60 +1,45 @@
1
- import { Fragment, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { STAGES } from "../progress.js";
4
- import { html, PANEL_WIDTH, theme } from "./kit.js";
5
- import { Mascot, MASCOT_WIDTH } from "./Mascot.js";
1
+ import { t } from "../i18n.js";
2
+ import { Fragment } from "react";
3
+ import { Box, useInput } from "ink";
4
+ import { dragonName, elementName, STAGES } from "../progress.js";
5
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
6
+ import { ELEMENT_COLOR, Mascot } from "./Mascot.js";
6
7
 
7
- const MOODS = [
8
- { face: "idle", label: "calm" },
9
- { face: "smile", label: "content" },
10
- { face: "happy", label: "right!" },
11
- { face: "sad", label: "wrong" },
12
- { face: "happy", label: "combo", hot: true }
13
- ];
8
+ const requirement = (stage, locked) => (stage.from === 0 ? t("companion.fromStart") : t(locked ? "companion.needsDays" : "companion.days", { count: stage.from }));
14
9
 
15
- const requirement = (stage, locked) => (stage.from === 0 ? "from the start" : `${locked ? "needs " : ""}${stage.from} days`);
16
-
17
- // Every form of the companion (dark silhouettes for the ones you haven't reached) and its moods.
18
- export function Companion({ current, best, onClose }) {
19
- const [shown, setShown] = useState(current);
10
+ // Every form of the companion. Forms you haven't reached are flat silhouettes named "???".
11
+ // Its moods aren't listed here on purpose: you find them out by playing.
12
+ export function Companion({ current, best, element = null, roll = null, onClose }) {
13
+ const panel = usePanelWidth();
20
14
  useInput((input, key) => {
21
- if (key.escape || input === "q") return onClose();
22
- if (key.leftArrow) return setShown((s) => Math.max(0, s - 1));
23
- if (key.rightArrow) return setShown((s) => Math.min(STAGES.length - 1, s + 1));
15
+ if (key.escape || key.return || input === "q") onClose();
24
16
  });
25
17
 
26
18
  return html`
27
19
  <${Fragment}>
28
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
29
- <${Text} bold color=${theme.accent}>Companion<//>
30
- <${Text} dimColor>It evolves with your best streak (best: ${best} days) and never loses a form.<//>
20
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
21
+ <${Text} bold color=${theme.accent}>${t("companion.title")}<//>
22
+ <${Box} marginTop=${1}>
23
+ <${Text}>${t("companion.yourDragon")}<//>
24
+ <${Text} bold color=${element ? ELEMENT_COLOR[element] : undefined}>${dragonName(current, element)}<//>
25
+ <//>
26
+ <${Text} dimColor>${element ? `${t("companion.element", { element: elementName(element) })}${roll ? t("companion.rolled", { face: roll.face, day: roll.on }) : ""}` : t("companion.noElement")}<//>
27
+ <${Box} marginTop=${1}><${Text} dimColor>${t("companion.evolves", { count: best })}<//><//>
31
28
 
32
29
  <${Box} marginTop=${1} flexWrap="wrap">
33
30
  ${STAGES.map((stage, i) => {
34
31
  const locked = i > current;
35
32
  return html`
36
- <${Box} key=${stage.name} width=${22} flexDirection="column" marginBottom=${1}>
37
- <${Box} flexDirection="column"><${Mascot} stage=${i} locked=${locked} face=${locked ? "idle" : "smile"} /><//>
38
- <${Text} bold=${i === current} color=${i === current ? theme.accent : undefined} dimColor=${locked}>${stage.name}${i === current ? " ← now" : ""}<//>
33
+ <${Box} key=${stage.id} 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 ? t("companion.unknown") : stage.name}${i === current ? t("companion.now") : ""}<//>
39
36
  <${Text} dimColor>${requirement(stage, locked)}<//>
40
37
  <//>
41
38
  `;
42
39
  })}
43
40
  <//>
44
-
45
- <${Text} bold>Moods <${Text} dimColor>of ${STAGES[shown].name} · ←/→ to switch form<//><//>
46
- <${Box} marginTop=${1}>
47
- ${MOODS.map(
48
- (mood) => html`
49
- <${Box} key=${mood.label} width=${MASCOT_WIDTH + 1} flexDirection="column">
50
- <${Mascot} stage=${shown} face=${mood.face} hot=${Boolean(mood.hot)} locked=${shown > current} />
51
- <${Text} dimColor>${mood.label}<//>
52
- <//>
53
- `
54
- )}
55
- <//>
56
41
  <//>
57
- <${Box} paddingX=${1}><${Text} dimColor>←/→ form · esc back<//><//>
42
+ <${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.back")} /><//>
58
43
  <//>
59
44
  `;
60
45
  }
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useMemo, useState } from "react";
2
- import { Box, Text } from "ink";
3
- import { html, theme } from "./kit.js";
2
+ import { Box } from "ink";
3
+ import { html, Text, theme } from "./kit.js";
4
4
 
5
5
  const ROWS = 4;
6
6
  const FRAME_MS = 100;
@@ -0,0 +1,99 @@
1
+ import { Fragment, useEffect, useState } from "react";
2
+ import { Box, useInput } from "ink";
3
+ import { t } from "../i18n.js";
4
+ import { Choice, choiceHints } from "./Choice.js";
5
+ import { cutToWidth, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
6
+
7
+ const DIRECTIONS = ["forward", "backward", "both"];
8
+
9
+ // /decks: your decks with their card counts; Enter quizzes the chosen one from now on, and
10
+ // "+ New deck" starts one (`onNew`). → on a deck of yours: which way it's asked. Renaming and deleting
11
+ // decks come later.
12
+ export function Decks({ current, actions, onPick, onNew, onClose, onDirections }) {
13
+ const panel = usePanelWidth();
14
+ const [decks, setDecks] = useState(null);
15
+ const [picked, setPicked] = useState(0);
16
+ const [error, setError] = useState("");
17
+ const [setting, setSetting] = useState(null); // { deck, selected }: the direction being picked
18
+ const [message, setMessage] = useState("");
19
+
20
+ useEffect(() => {
21
+ actions.allDecks().then(
22
+ (all) => {
23
+ setDecks(all);
24
+ setPicked(Math.max(0, all.findIndex((d) => d.name === current)));
25
+ },
26
+ (err) => setError(err.message)
27
+ );
28
+ }, []);
29
+
30
+ useInput((input, key) => {
31
+ if (!decks?.length && (key.escape || input === "q")) onClose();
32
+ const deck = decks?.[picked];
33
+ if (key.rightArrow && !setting && deck && !deck.tour) {
34
+ setMessage("");
35
+ setSetting({ deck, selected: Math.max(0, DIRECTIONS.indexOf(deck.directions)) });
36
+ }
37
+ });
38
+
39
+ // progress of a direction turned off stays: turning it back on picks up where it was
40
+ async function setDirections(index) {
41
+ const { deck } = setting;
42
+ setSetting(null);
43
+ try {
44
+ const { cardIds } = await actions.setDirections(deck.name, DIRECTIONS[index]);
45
+ await onDirections?.(cardIds, DIRECTIONS[index]);
46
+ setDecks((all) => all.map((d) => (d.name === deck.name ? { ...d, directions: DIRECTIONS[index] } : d)));
47
+ setMessage(t("decks.directionSaved", { deck: deck.name }));
48
+ } catch (err) {
49
+ setError(err.message);
50
+ }
51
+ }
52
+
53
+ const short = (text) => cutToWidth(text, Math.max(12, Math.floor(panel / 2) - 8));
54
+ const directionOptions = (deck) => {
55
+ const [front, back] = deck.sample ? [short(deck.sample.front), short(deck.sample.back.join(" / "))] : [t("decks.front"), t("decks.back")];
56
+ return [
57
+ { label: `${front} → ?`, note: deck.directions === "forward" ? t("decks.now") : "" },
58
+ { label: `${back} → ?`, note: deck.directions === "backward" ? t("decks.now") : "" },
59
+ { label: t("add.bothWays"), note: deck.directions === "both" ? t("decks.now") : "" }
60
+ ];
61
+ };
62
+
63
+ if (setting)
64
+ return html`
65
+ <${Fragment}>
66
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
67
+ <${Text} bold color=${theme.accent}>${t("add.directionQuestion", { deck: setting.deck.name })}<//>
68
+ <${Box} marginTop=${1}>
69
+ <${Choice} options=${directionOptions(setting.deck)} selected=${setting.selected} onMove=${(selected) => setSetting((s) => ({ ...s, selected }))} onPick=${setDirections} onCancel=${() => setSetting(null)} />
70
+ <//>
71
+ <${Box} marginTop=${1}><${Text} dimColor>${t("decks.progressKept")}<//><//>
72
+ <//>
73
+ <${Box} paddingX=${1}><${KeyHints} text=${choiceHints()} /><//>
74
+ <//>
75
+ `;
76
+
77
+ return html`
78
+ <${Fragment}>
79
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
80
+ <${Text} bold color=${theme.accent}>${t("decks.title")}<//>
81
+ ${decks?.length > 0 &&
82
+ html`
83
+ <${Box} marginTop=${1}>
84
+ <${Choice}
85
+ options=${[...decks.map((d) => ({ label: d.name, note: [t("count.cards", { count: d.cards }), d.tour && t("decks.tour"), d.name === current && t("decks.now")].filter(Boolean).join(" · ") })), { label: t("decks.newDeck") }]}
86
+ selected=${picked}
87
+ onMove=${setPicked}
88
+ onPick=${(i) => (i === decks.length ? onNew() : onPick(decks[i].name))}
89
+ onCancel=${onClose}
90
+ />
91
+ <//>
92
+ `}
93
+ ${message && html`<${Box} marginTop=${1}><${Text} color=${theme.good}>${message}<//><//>`}
94
+ ${error && html`<${Box} marginTop=${1}><${Text} color=${theme.bad}>${error}<//><//>`}
95
+ <//>
96
+ <${Box} paddingX=${1}><${KeyHints} text=${decks?.[picked] && !decks[picked].tour ? t("keyHints.decks", { choose: choiceHints() }) : choiceHints()} /><//>
97
+ <//>
98
+ `;
99
+ }
@@ -0,0 +1,104 @@
1
+ import { t } from "../i18n.js";
2
+ import React, { Fragment, useEffect, useState } from "react";
3
+ import { Box, useInput } from "ink";
4
+ import { elementName, ELEMENTS } from "../progress.js";
5
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
6
+ import { ELEMENT_COLOR, Mascot } from "./Mascot.js";
7
+
8
+ const FRAME_MS = 80;
9
+ // single-pixel pips on a 9×9 die, with a pixel of space between any two, so six reads as six
10
+ const SIZE = 9;
11
+ const PIPS = { tl: [2, 2], tr: [2, 6], ml: [4, 2], c: [4, 4], mr: [4, 6], bl: [6, 2], br: [6, 6] };
12
+ const FACES = {
13
+ 1: ["c"],
14
+ 2: ["tl", "br"],
15
+ 3: ["tl", "c", "br"],
16
+ 4: ["tl", "tr", "bl", "br"],
17
+ 5: ["tl", "tr", "c", "bl", "br"],
18
+ 6: ["tl", "tr", "ml", "mr", "bl", "br"]
19
+ };
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}>${t("die.title")}<//>
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}>${t("die.result", { face: result, element: elementName(element) })}<//>
95
+ <${Text} dimColor>${t("die.awakened", { element: elementName(element) })}<//>
96
+ <//>
97
+ `
98
+ : html`<${Text} dimColor>${landed ? t("die.result", { face: result, element: elementName(element) }) : t("die.rolling")}<//>`}
99
+ <//>
100
+ <//>
101
+ <${Box} paddingX=${1}><${KeyHints} text=${t(revealed ? "die.keysContinue" : "die.keysSkip")} /><//>
102
+ <//>
103
+ `;
104
+ }
@@ -1,6 +1,7 @@
1
+ import { t } from "../i18n.js";
1
2
  import { Fragment, useEffect, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { html, PANEL_WIDTH, theme } from "./kit.js";
3
+ import { Box, useInput } from "ink";
4
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
4
5
  import { Mascot } from "./Mascot.js";
5
6
 
6
7
  const FRAME_MS = 120;
@@ -8,7 +9,6 @@ const FLASH_FROM = 6; // frames 0..5: the old form, wondering
8
9
  const REVEAL_AT = 16; // frames 6..15: white-out flashing, then the new form
9
10
  const SPARKS = ["✦", "·", "✧", "*"];
10
11
 
11
- const article = (name) => (/^[aeiou]/i.test(name) ? "an" : "a");
12
12
 
13
13
  // a loose ring of sparkles around the sprite; which ones show varies per frame
14
14
  function sparkleRow(frame, seed, width) {
@@ -21,7 +21,8 @@ function sparkleRow(frame, seed, width) {
21
21
 
22
22
  // The full-screen moment when the companion evolves: old form → white flashes → new form.
23
23
  // Any key fast-forwards to the reveal; Enter/Esc then closes it.
24
- export function Evolution({ from, to, name, onClose }) {
24
+ export function Evolution({ from, to, name, element = null, onClose }) {
25
+ const panel = usePanelWidth();
25
26
  const [frame, setFrame] = useState(0);
26
27
  useEffect(() => {
27
28
  const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
@@ -39,20 +40,20 @@ export function Evolution({ from, to, name, onClose }) {
39
40
 
40
41
  return html`
41
42
  <${Fragment}>
42
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.warn} paddingX=${2} paddingY=${1} width=${PANEL_WIDTH} alignItems="center">
43
- <${Text} bold color=${theme.warn}>✦ Evolution ✦<//>
43
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.warn} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
44
+ <${Text} bold color=${theme.warn}>✦ ${t("evolution.title")} ✦<//>
44
45
  <${Box} flexDirection="column" marginTop=${1} alignItems="center">
45
46
  <${Text} color=${theme.warn}>${sparks ? sparkleRow(frame, 1, 30) : " "}<//>
46
- <${Mascot} stage=${stage} face=${revealed ? "happy" : "idle"} flash=${flashing && frame % 2 === 0} scale=${2} />
47
+ <${Mascot} stage=${stage} face=${revealed ? "happy" : "idle"} flash=${flashing && frame % 2 === 0} scale=${2} element=${element} />
47
48
  <${Text} color=${theme.warn}>${sparks ? sparkleRow(frame, 2, 30) : " "}<//>
48
49
  <//>
49
50
  <${Box} marginTop=${1} flexDirection="column" alignItems="center">
50
51
  ${revealed
51
- ? html`<${Text} bold color=${theme.accent}>Your companion evolved into ${article(name)} ${name}!<//>`
52
- : html`<${Text} dimColor>Something is happening…<//>`}
52
+ ? html`<${Text} bold color=${theme.accent}>${t("evolution.evolved", { name })}<//>`
53
+ : html`<${Text} dimColor>${t("evolution.happening")}<//>`}
53
54
  <//>
54
55
  <//>
55
- <${Box} paddingX=${1}><${Text} dimColor>${revealed ? "enter continue" : "any key to hurry it up"}<//><//>
56
+ <${Box} paddingX=${1}><${KeyHints} text=${t(revealed ? "evolution.keysContinue" : "evolution.keysHurry")} /><//>
56
57
  <//>
57
58
  `;
58
59
  }
package/src/ui/Hatch.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { t } from "../i18n.js";
1
2
  import React, { Fragment, useEffect, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { html, PANEL_WIDTH, theme } from "./kit.js";
3
+ import { Box, useInput } from "ink";
4
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
4
5
  import { Mascot } from "./Mascot.js";
5
6
 
6
7
  const FRAME_MS = 110;
@@ -57,6 +58,7 @@ function BigPixels({ grid, colors }) {
57
58
 
58
59
  // First launch ever: the dragon hatches. Any key skips ahead; after the reveal, any key starts the quiz.
59
60
  export function Hatch({ onDone, play = () => {} }) {
61
+ const panel = usePanelWidth();
60
62
  const [frame, setFrame] = useState(0);
61
63
  useEffect(() => {
62
64
  const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
@@ -71,11 +73,11 @@ export function Hatch({ onDone, play = () => {} }) {
71
73
  useInput(() => (revealed ? onDone() : setFrame(REVEAL_AT)));
72
74
 
73
75
  const flashing = frame >= FLASH_AT && !revealed;
74
- const caption = revealed ? "" : frame >= CRACK_AT[0] ? "it's hatching…" : "something stirs inside…";
76
+ const caption = revealed ? "" : t(frame >= CRACK_AT[0] ? "hatch.hatching" : "hatch.stirs");
75
77
 
76
78
  return html`
77
79
  <${Fragment}>
78
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${PANEL_WIDTH} alignItems="center">
80
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
79
81
  <${Text} bold color=${theme.accent}>Dracosh<//>
80
82
  <${Box} flexDirection="column" marginTop=${1} alignItems="center">
81
83
  ${revealed
@@ -86,14 +88,14 @@ export function Hatch({ onDone, play = () => {} }) {
86
88
  ${revealed
87
89
  ? html`
88
90
  <${Fragment}>
89
- <${Text} bold color=${theme.good}>Your dragon has hatched!<//>
90
- <${Text} dimColor>Answer words to keep it happy. It grows with your streak.<//>
91
+ <${Text} bold color=${theme.good}>${t("hatch.hatched")}<//>
92
+ <${Text} dimColor>${t("hatch.line")}<//>
91
93
  <//>
92
94
  `
93
95
  : html`<${Text} dimColor>${caption}<//>`}
94
96
  <//>
95
97
  <//>
96
- <${Box} paddingX=${1}><${Text} dimColor>${revealed ? "any key to start" : "any key to skip"}<//><//>
98
+ <${Box} paddingX=${1}><${KeyHints} text=${t(revealed ? "hatch.keysStart" : "hatch.keysSkip")} /><//>
97
99
  <//>
98
100
  `;
99
101
  }