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
package/src/ui/Preview.js CHANGED
@@ -1,27 +1,34 @@
1
+ import { t } from "../i18n.js";
1
2
  import { Fragment, useEffect, useMemo, useState } from "react";
2
- import { Box, Text, useApp, useInput } from "ink";
3
- import { DEMO_WORDS } from "../demo.js";
3
+ import { Box, useApp, useInput } from "ink";
4
+ import { DEMO_CLOZE, DEMO_SENTENCES, DEMO_WORDS } from "../demo.js";
5
+ import { addCard, createDeck, emptyLibrary } from "../library.js";
6
+ import { libraryActions } from "../manage.js";
7
+ import { AddCard } from "./AddCard.js";
4
8
  import { addDays, dayKey } from "../dates.js";
5
- import { BADGES, ensureProgress, STAGES } from "../progress.js";
9
+ import { BADGES, elementName, ELEMENTS, ensureProgress, rollElement, STAGES } from "../progress.js";
6
10
  import { createSession } from "../session.js";
7
11
  import { DEFAULTS } from "../settings.js";
12
+ import { DieRoll } from "./DieRoll.js";
8
13
  import { App } from "./App.js";
14
+ import { BadgeUnlock, badgeSound } from "./BadgeUnlock.js";
9
15
  import { Badges } from "./Badges.js";
10
16
  import { Confetti } from "./Confetti.js";
11
17
  import { Evolution } from "./Evolution.js";
12
18
  import { Hatch } from "./Hatch.js";
13
- import { Snore, useBlink, useMove } from "./Header.js";
14
- import { html, PANEL_WIDTH, theme } from "./kit.js";
19
+ import { Header, Snore, useBlink, useMove } from "./Header.js";
20
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
15
21
  import { Mascot } from "./Mascot.js";
16
22
  import { Stats } from "./Stats.js";
17
23
  import { Summary } from "./Summary.js";
24
+ import { TheOne } from "./TheOne.js";
18
25
 
19
26
  // Everything here runs on made-up data in memory: nothing is read from or written to ~/.dracosh.
20
27
 
21
28
  const FACES = ["idle", "smile", "happy", "sad", "blink", "sleep"];
22
29
 
23
- // a throwaway session; `progress` fills in a believable last few weeks
24
- function fakeSession({ settings = {}, progress = false } = {}) {
30
+ // a throwaway session; `progress` fills in a believable last few weeks; `words` and `deck` replace the demo words
31
+ function fakeSession({ settings = {}, progress = false, words = DEMO_WORDS, deck } = {}) {
25
32
  const state = { items: {}, newToday: { date: "", count: 0 }, hatched: true };
26
33
  const all = { ...DEFAULTS, dailyGoal: 5, everyMs: 6000, tips: "always", ...settings };
27
34
  if (progress) {
@@ -35,7 +42,15 @@ function fakeSession({ settings = {}, progress = false } = {}) {
35
42
  p.streak = { ...p.streak, count: 12, best: 34, lastGoalDay: addDays(today, -2) };
36
43
  BADGES.slice(0, 13).forEach((b, i) => (p.badges[b.id] = addDays(today, -i * 3)));
37
44
  }
38
- return createSession({ loadWords: async () => ({ words: DEMO_WORDS, cached: false }), state, getSettings: () => all, save: async () => {} });
45
+ return createSession({ loadWords: async () => ({ words, deck }), state, getSettings: () => all, save: async () => {} });
46
+ }
47
+
48
+ // /add on a library that lives in memory: a deck with a few cards, and room for a new one
49
+ function fakeLibrary() {
50
+ let library = emptyLibrary();
51
+ const deck = createDeck(library, { name: "Demo", languages: null, directions: "both" });
52
+ for (const word of DEMO_WORDS.slice(0, 3)) addCard(library, deck.id, { front: word.word, back: word.translations });
53
+ return libraryActions({ load: async () => library, save: async (next) => (library = next), backup: async () => {} });
39
54
  }
40
55
 
41
56
  // a 250 ms tick for the lab's own little animations (the snoring z's)
@@ -50,9 +65,11 @@ function useClock() {
50
65
 
51
66
  // The mascot on its own, to poke at: every form, face, move and the combo glow.
52
67
  function MascotLab({ onBack }) {
68
+ const panel = usePanelWidth();
53
69
  const [stage, setStage] = useState(0);
54
70
  const [face, setFace] = useState(0);
55
71
  const [hot, setHot] = useState(false);
72
+ const [element, setElement] = useState(-1); // -1: the default green dragon
56
73
  const [event, setEvent] = useState(null);
57
74
  const [tick, setTick] = useState(0);
58
75
  const move = useMove(event);
@@ -66,25 +83,81 @@ function MascotLab({ onBack }) {
66
83
  if (input === "j") return setEvent({ kind: "jump", at: Date.now() });
67
84
  if (input === "s") return setEvent({ kind: "shake", at: Date.now() });
68
85
  if (input === "h") return setHot((h) => !h);
86
+ if (input === "e") return setElement((e) => (e + 2) % (ELEMENTS.length + 1) - 1);
69
87
  if (input === " ") return setTick((t) => t + 1); // hand-cranked flicker frame
70
88
  });
71
89
  const shownFace = blinking && FACES[face] === "idle" ? "blink" : FACES[face];
72
90
  return html`
73
91
  <${Fragment}>
74
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${PANEL_WIDTH} alignItems="center">
75
- <${Text} bold color=${theme.accent}>Mascot lab<//>
92
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
93
+ <${Text} bold color=${theme.accent}>${t("preview.mascotLab")}<//>
76
94
  <${Box} marginY=${1} flexDirection="column" alignItems="center">
77
- <${Mascot} stage=${stage} face=${shownFace} hot=${hot} flicker=${hot && tick % 2 === 0} scale=${2} dx=${move.dx ?? 0} dy=${move.dy ?? 0} />
95
+ <${Mascot} stage=${stage} face=${shownFace} hot=${hot} flicker=${hot && tick % 2 === 0} scale=${2} dx=${move.dx ?? 0} dy=${move.dy ?? 0} element=${ELEMENTS[element] ?? null} />
78
96
  <//>
79
97
  ${FACES[face] === "sleep" && html`<${Box}><${Mascot} stage=${stage} face="sleep" /><${Snore} tick=${clock} /><//>`}
80
- <${Text}>${STAGES[stage].name}<${Text} dimColor> · face ${FACES[face]}${hot ? " · combo glow" : ""}<//><//>
98
+ <${Text}>${STAGES[stage].name}<${Text} dimColor>${t("preview.mascotLine", { face: t(`preview.faces.${FACES[face]}`), element: ELEMENTS[element] ? elementName(ELEMENTS[element]) : t("preview.noElement"), glow: hot ? t("preview.glow") : "" })}<//><//>
99
+ <//>
100
+ <${Box} paddingX=${1}><${KeyHints} text=${t("preview.mascotKeys")} /><//>
101
+ <//>
102
+ `;
103
+ }
104
+
105
+ // three badges won with one answer, lighting up one after another, as under the quiz card
106
+ const UNLOCK_SAMPLE = ["thousand", "hot-streak", "dragons-hoard"];
107
+
108
+ function BadgeUnlockLab({ onBack, play }) {
109
+ const panel = usePanelWidth();
110
+ const [run, setRun] = useState(1);
111
+ useInput((input, key) => {
112
+ if (key.escape || input === "q") return onBack();
113
+ if (key.return || input === " ") setRun((r) => r + 1);
114
+ });
115
+ const badges = UNLOCK_SAMPLE.map((id) => BADGES.find((badge) => badge.id === id));
116
+ return html`
117
+ <${Fragment}>
118
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.good} paddingX=${2} width=${panel}>
119
+ <${Text} color=${theme.good} bold>✓ ${t("preview.scenes.unlock.label")}<//>
120
+ ${badges.map((badge, i) => html`<${BadgeUnlock} key=${`${run}-${badge.id}`} id=${badge.id} name=${badge.name} desc=${badge.desc} delay=${i * 700} sound=${badgeSound(i)} play=${play} />`)}
81
121
  <//>
82
- <${Box} paddingX=${1}><${Text} dimColor>←/→ form · ↑/↓ face · j jump · s shake · h glow · space flicker · esc back<//><//>
122
+ <${Box} paddingX=${1}><${KeyHints} text=${t("preview.replay")} /><//>
123
+ <//>
124
+ `;
125
+ }
126
+
127
+ // The quiz screen's header with any form and element, to check how the dragon looks and fits there
128
+ function QuizLookLab({ onBack }) {
129
+ const panel = usePanelWidth();
130
+ const [stage, setStage] = useState(STAGES.length - 1);
131
+ const [element, setElement] = useState(-1);
132
+ const [combo, setCombo] = useState(0);
133
+ useInput((input, key) => {
134
+ if (key.escape || input === "q") return onBack();
135
+ if (key.leftArrow) return setStage((s) => Math.max(0, s - 1));
136
+ if (key.rightArrow) return setStage((s) => Math.min(STAGES.length - 1, s + 1));
137
+ if (input === "e") return setElement((e) => (e + 2) % (ELEMENTS.length + 1) - 1);
138
+ if (input === "c") return setCombo((c) => (c ? 0 : 7));
139
+ });
140
+ const stats = {
141
+ streak: { days: 42, best: 120, freezes: 1, atRisk: false },
142
+ today: { correct: 13, asked: 15, goalMet: false },
143
+ goal: 20,
144
+ vacation: { activeUntil: null },
145
+ companion: { index: stage, name: STAGES[stage].name, element: ELEMENTS[element] ?? null }
146
+ };
147
+ return html`
148
+ <${Fragment}>
149
+ <${Header} deck="Polish" everyMs=${600000} wordCount=${340} stats=${stats} combo=${combo} face="idle" event=${null} tick=${0} />
150
+ <${Box} marginTop=${1} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${panel}>
151
+ <${Text} bold>la mariposa<//>
152
+ <${Box} marginTop=${1}><${Text} color=${theme.accent}>❯ <//><${Text} inverse> <//><//>
153
+ <//>
154
+ <${Box} paddingX=${1}><${KeyHints} text=${t("preview.lookKeys", { stage: STAGES[stage].name, element: ELEMENTS[element] ? elementName(ELEMENTS[element]) : t("preview.noElement") })} /><//>
83
155
  <//>
84
156
  `;
85
157
  }
86
158
 
87
159
  function ConfettiLab({ onBack }) {
160
+ const panel = usePanelWidth();
88
161
  const [run, setRun] = useState(1);
89
162
  useInput((input, key) => {
90
163
  if (key.escape || input === "q") return onBack();
@@ -92,27 +165,33 @@ function ConfettiLab({ onBack }) {
92
165
  });
93
166
  return html`
94
167
  <${Fragment}>
95
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.good} paddingX=${2} width=${PANEL_WIDTH}>
96
- <${Text} color=${theme.good} bold>★ Daily goal reached · 12-day streak<//>
168
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.good} paddingX=${2} width=${panel}>
169
+ <${Text} color=${theme.good} bold>▪ ${t("cheers.goal", { count: 12 })}<//>
97
170
  <//>
98
- <${Box} height=${5}><${Confetti} key=${run} width=${PANEL_WIDTH} onDone=${() => {}} /><//>
99
- <${Box} paddingX=${1}><${Text} dimColor>enter replay · esc back<//><//>
171
+ <${Box} height=${5}><${Confetti} key=${run} width=${panel} onDone=${() => {}} /><//>
172
+ <${Box} paddingX=${1}><${KeyHints} text=${t("preview.replay")} /><//>
100
173
  <//>
101
174
  `;
102
175
  }
103
176
 
177
+ // labels and hints come from the locale, read each time the menu is drawn
178
+ const scene = (id, text = () => [t(`preview.scenes.${id}.label`), t(`preview.scenes.${id}.hint`)]) => ({
179
+ id,
180
+ get label() {
181
+ return text()[0];
182
+ },
183
+ get hint() {
184
+ return text()[1];
185
+ }
186
+ });
104
187
  const SCENES = [
105
- { id: "hatch", label: "Hatching", hint: "the first-launch intro" },
106
- ...STAGES.slice(1).map((stage, i) => ({ id: `evolve-${i + 1}`, label: `Evolution → ${stage.name}`, hint: `reached at a ${stage.from}-day best streak` })),
107
- { id: "mascot", label: "Mascot lab", hint: "forms, faces, sleep, hop, shake, glow" },
108
- { id: "quiz", label: "Quiz", hint: "a live round on demo words, goal at 5" },
109
- { id: "confetti", label: "Confetti", hint: "the daily-goal burst" },
110
- { id: "stats", label: "Stats", hint: "calendar tiles, weeks of fake history" },
111
- { id: "badges", label: "Badges", hint: "the badge browser with pixel icons" },
112
- { id: "summary", label: "Session summary", hint: "what you see when quitting" }
188
+ scene("hatch"),
189
+ ...STAGES.slice(1).map((stage, i) => scene(`evolve-${i + 1}`, () => [t("preview.evolution", { name: stage.name }), t("preview.evolutionHint", { count: stage.from })])),
190
+ ...["mascot", "quiz", "add", "reveal", "cloze", "quiz-look", "unlock", "the-one", "die", "confetti", "stats", "badges", "summary"].map((id) => scene(id))
113
191
  ];
114
192
 
115
193
  function Menu({ selected, onMove, onPick, onQuit }) {
194
+ const panel = usePanelWidth();
116
195
  useInput((input, key) => {
117
196
  if (key.escape || input === "q") return onQuit();
118
197
  if (key.upArrow) return onMove(-1);
@@ -121,8 +200,8 @@ function Menu({ selected, onMove, onPick, onQuit }) {
121
200
  });
122
201
  return html`
123
202
  <${Fragment}>
124
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
125
- <${Box}><${Text} bold color=${theme.accent}>Preview<//><${Text} dimColor> made-up data · nothing is saved<//><//>
203
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
204
+ <${Box}><${Text} bold color=${theme.accent}>${t("preview.title")}<//><${Text} dimColor>${t("preview.subtitle")}<//><//>
126
205
  <${Box} flexDirection="column" marginTop=${1}>
127
206
  ${SCENES.map(
128
207
  (scene, i) => html`
@@ -136,7 +215,7 @@ function Menu({ selected, onMove, onPick, onQuit }) {
136
215
  )}
137
216
  <//>
138
217
  <//>
139
- <${Box} paddingX=${1}><${Text} dimColor>↑/↓ choose · enter play · esc quit<//><//>
218
+ <${Box} paddingX=${1}><${KeyHints} text=${t("preview.keys")} /><//>
140
219
  <//>
141
220
  `;
142
221
  }
@@ -150,6 +229,7 @@ export function Preview({ alerts }) {
150
229
  const back = () => setScene(null);
151
230
  const history = useMemo(() => fakeSession({ progress: true }), []);
152
231
  const quizSession = useMemo(() => fakeSession(), [run]); // every quiz run starts from zero
232
+ const dieElement = useMemo(() => rollElement(), [run]); // a fresh roll every time the scene plays
153
233
 
154
234
  const wrap = (content) => html`<${Box} flexDirection="column" marginY=${1}>${content}<//>`;
155
235
 
@@ -169,11 +249,25 @@ export function Preview({ alerts }) {
169
249
  return wrap(html`<${Evolution} key=${run} from=${to - 1} to=${to} name=${STAGES[to].name} onClose=${back} />`);
170
250
  }
171
251
  if (scene === "mascot") return wrap(html`<${MascotLab} onBack=${back} />`);
252
+ if (scene === "quiz-look") return wrap(html`<${QuizLookLab} onBack=${back} />`);
172
253
  if (scene === "confetti") return wrap(html`<${ConfettiLab} onBack=${back} />`);
254
+ if (scene === "unlock") return wrap(html`<${BadgeUnlockLab} onBack=${back} play=${alerts.play} />`);
255
+ if (scene === "die") return wrap(html`<${DieRoll} key=${run} element=${dieElement} stage=${2} play=${alerts.play} onClose=${back} />`);
256
+ if (scene === "the-one") return wrap(html`<${TheOne} key=${run} play=${alerts.play} onClose=${back} />`);
173
257
  if (scene === "stats") return wrap(html`<${Stats} stats=${history.stats()} getMonth=${history.month} onClose=${back} />`);
174
- if (scene === "badges") return wrap(html`<${Badges} badges=${history.stats().badges} onClose=${back} />`);
258
+ if (scene === "badges") {
259
+ // every badge unlocked, so each icon and rank color can be seen
260
+ const all = history.stats().badges.map((badge) => ({ ...badge, unlockedOn: badge.unlockedOn ?? dayKey(Date.now()) }));
261
+ return wrap(html`<${Badges} key=${run} badges=${all} fresh=${["thousand", "hot-streak", "dragonheart"]} onClose=${back} />`);
262
+ }
175
263
  if (scene === "summary")
176
264
  return wrap(html`<${Summary} stats=${history.stats()} totals=${{ asked: 23, correct: 20 }} bestCombo=${9} onDone=${back} />`);
265
+ if (scene === "add") return wrap(html`<${AddCard} key=${run} current="Demo" actions=${fakeLibrary()} onDone=${back} />`);
266
+ if (scene === "reveal" || scene === "cloze") {
267
+ const words = scene === "reveal" ? DEMO_SENTENCES : DEMO_CLOZE;
268
+ const session = fakeSession({ words, deck: { name: "Demo", directions: "forward" } });
269
+ return html`<${App} key=${run} session=${session} deck="Demo" initialSettings=${{ ...DEFAULTS, dailyGoal: 5, everyMs: 6000, tips: "off", rhythm: "session" }} alerts=${alerts} persistSettings=${async () => {}} onExit=${back} />`;
270
+ }
177
271
  if (scene === "quiz") {
178
272
  return html`<${App} key=${run} session=${quizSession} deck="Demo" initialSettings=${{ ...DEFAULTS, dailyGoal: 5, everyMs: 6000, tips: "always" }} alerts=${alerts} persistSettings=${async () => {}} onExit=${back} />`;
179
273
  }
@@ -0,0 +1,71 @@
1
+ import { Fragment, useEffect, useState } from "react";
2
+ import { Box } from "ink";
3
+ import { t } from "../i18n.js";
4
+ import { Choice, choiceHints } from "./Choice.js";
5
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
6
+
7
+
8
+ // Reset from /settings: pick what to clear, see exactly what goes, then confirm (No is the default).
9
+ // A backup is made first, so `dracosh restore` can undo it.
10
+ export function Reset({ stats, actions, onConfirm, onClose }) {
11
+ const panel = usePanelWidth();
12
+ const [decks, setDecks] = useState(null);
13
+ const [scope, setScope] = useState(0);
14
+ const [answer, setAnswer] = useState(0);
15
+ const [step, setStep] = useState("choose"); // choose | confirm | working
16
+ const [error, setError] = useState("");
17
+
18
+ useEffect(() => {
19
+ actions.allDecks().then(setDecks, (err) => setError(err.message));
20
+ }, []);
21
+
22
+ const own = (decks ?? []).filter((d) => !d.tour);
23
+ const cards = own.reduce((sum, d) => sum + d.cards, 0);
24
+ const badges = stats.badges.filter((b) => b.unlockedOn).length;
25
+ const progress = [t("count.badges", { count: badges }), stats.streak.best > 0 && t("reset.bestStreak", { count: stats.streak.best }), t("reset.yourDragon", { name: stats.companion.name })].filter(Boolean).join(" · ");
26
+ const everything = [t("count.decks", { count: own.length }), t("count.cards", { count: cards }), progress].join(" · ");
27
+ const option = (name, goes) => ({ scope: name, goes, ...Object.fromEntries(["label", "note", "question", "stays", "yes"].map((key) => [key, t(`reset.${name}.${key}`)])) });
28
+ const SCOPES = [option("progress", progress), option("everything", everything)];
29
+ const chosen = SCOPES[scope];
30
+
31
+ async function confirm(index) {
32
+ if (index === 0) return setStep("choose");
33
+ setStep("working");
34
+ try {
35
+ await onConfirm(chosen.scope);
36
+ } catch (err) {
37
+ setError(err.message);
38
+ setStep("confirm");
39
+ }
40
+ }
41
+
42
+ return html`
43
+ <${Fragment}>
44
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${step === "choose" ? theme.accent : theme.bad} paddingX=${2} width=${panel}>
45
+ <${Text} bold color=${step === "choose" ? theme.accent : theme.bad}>${step === "choose" ? t("reset.pickTitle") : chosen.question}<//>
46
+ ${step === "choose" &&
47
+ html`<${Box} marginTop=${1}><${Choice} options=${SCOPES} selected=${scope} onMove=${setScope} onPick=${(i) => decks && (setScope(i), setAnswer(0), setStep("confirm"))} onCancel=${onClose} /><//>`}
48
+ ${step !== "choose" &&
49
+ html`
50
+ <${Box} flexDirection="column">
51
+ <${Box} flexDirection="column" marginTop=${1}>
52
+ <${Text}>${t("reset.clears", { what: chosen.goes })}<//>
53
+ <${Text} dimColor>${chosen.stays} ${t("reset.backupFirst")}<//>
54
+ <//>
55
+ <${Box} marginTop=${1}>
56
+ <${Choice}
57
+ options=${[{ label: t("reset.no"), key: t("choice.noKey") }, { label: chosen.yes, key: t("choice.yesKey"), danger: true }]}
58
+ selected=${answer}
59
+ onMove=${setAnswer}
60
+ onPick=${(i) => step === "confirm" && confirm(i)}
61
+ onCancel=${() => setStep("choose")}
62
+ />
63
+ <//>
64
+ <//>
65
+ `}
66
+ ${error && html`<${Box} marginTop=${1}><${Text} color=${theme.bad}>${error}<//><//>`}
67
+ <//>
68
+ <${Box} paddingX=${1}><${KeyHints} text=${step === "working" ? t("keyHints.resetting") : choiceHints()} /><//>
69
+ <//>
70
+ `;
71
+ }
@@ -1,23 +1,28 @@
1
1
  import { Fragment, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { DIRECTION_LABELS, DIRECTION_OPTIONS, GOALS, INTERVALS, QUIET_PRESETS, TIP_LABELS, TIP_MODES, VOLUMES, formatInterval } from "../settings.js";
2
+ import { Box, useInput } from "ink";
3
+ import { language, LANGUAGES, t } from "../i18n.js";
4
+ import { GOALS, INTERVALS, QUIET_PRESETS, RHYTHMS, TIP_MODES, VOLUMES, formatInterval } from "../settings.js";
4
5
  import { formatQuiet } from "../quiet.js";
5
- import { Bar, html, PANEL_WIDTH, theme } from "./kit.js";
6
+ import { Bar, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
6
7
 
7
8
  function VolumeValue({ value }) {
8
9
  return html`<${Text}><${Bar} value=${value} max=${1} width=${10} /> ${Math.round(value * 100)}%<//>`;
9
10
  }
10
11
 
11
- const ROWS = [
12
- { key: "everyMs", label: "Interval", options: INTERVALS, format: formatInterval, hint: "time between questions" },
13
- { key: "sound", label: "Sound", options: [true, false], format: (v) => (v ? "on" : "off"), hint: "answer and new-word sounds", toggle: true },
14
- { key: "volume", label: "Volume", options: VOLUMES, format: (v) => html`<${VolumeValue} value=${v} />`, hint: "plays a preview when changed" },
15
- { key: "dailyGoal", label: "Daily goal", options: GOALS, format: (n) => `${n} correct`, hint: "keeps your streak alive" },
16
- { key: "tips", label: "Tips", options: TIP_MODES, format: (v) => TIP_LABELS[v], hint: "a short grammar tip while you wait (or /tip any time)" },
17
- { key: "skipWeekends", label: "Weekends", options: [true, false], format: (v) => (v ? "rest days" : "count like other days"), hint: "rest days never break your streak (doing them still counts)", toggle: true },
18
- { key: "quiet", label: "Quiet hours", options: QUIET_PRESETS, format: formatQuiet, hint: "no questions, sounds or banners during these hours" },
19
- { key: "directions", label: "Direction", options: DIRECTION_OPTIONS, format: (v) => DIRECTION_LABELS[v], hint: "which way to ask" }
12
+ // label and hint come from settings.rows.<key> in the locale
13
+ const ALL_ROWS = [
14
+ { key: "language", options: Object.keys(LANGUAGES), format: (code) => LANGUAGES[code] },
15
+ { key: "rhythm", options: RHYTHMS, format: (v) => t(`settings.rhythms.${v}`) },
16
+ { key: "everyMs", options: INTERVALS, format: formatInterval },
17
+ { key: "sound", options: [true, false], format: (v) => t(v ? "settings.on" : "settings.off"), toggle: true },
18
+ { key: "volume", options: VOLUMES, format: (v) => html`<${VolumeValue} value=${v} />` },
19
+ { key: "dailyGoal", options: GOALS, format: (n) => t("settings.goal", { n }) },
20
+ { key: "tips", options: TIP_MODES, format: (v) => t(`settings.tipModes.${v}`) },
21
+ { key: "skipWeekends", options: [true, false], format: (v) => t(v ? "settings.weekendsRest" : "settings.weekendsCount"), toggle: true },
22
+ { key: "quiet", options: QUIET_PRESETS, format: formatQuiet },
23
+ { key: "reset", action: true, format: () => t("settings.pressEnter") }
20
24
  ];
25
+ const label = (row) => t(`settings.rows.${row.key}.label`);
21
26
 
22
27
  const nearestIndex = (options, value) => {
23
28
  const exact = options.findIndex((option) => JSON.stringify(option) === JSON.stringify(value));
@@ -25,9 +30,14 @@ const nearestIndex = (options, value) => {
25
30
  return options.reduce((best, option, i) => (Math.abs(option - value) < Math.abs(options[best] - value) ? i : best), 0);
26
31
  };
27
32
 
28
- // Changes apply and persist immediately; there is no save step.
29
- export function Settings({ settings, onChange, onClose }) {
33
+ // Changes apply and persist immediately; there is no save step. Action rows (Reset) open their own
34
+ // screen through `onAction`; without it (the preview) they are left out.
35
+ export function Settings({ settings, onChange, onClose, onAction }) {
36
+ const panel = usePanelWidth();
30
37
  const [row, setRow] = useState(0);
38
+ const ROWS = onAction ? ALL_ROWS : ALL_ROWS.filter((item) => !item.action);
39
+ const values = { ...settings, language: settings.language ?? language() };
40
+ const labelWidth = Math.max(...ROWS.map((item) => label(item).length)) + 2;
31
41
 
32
42
  useInput((input, key) => {
33
43
  if (key.escape || input === "q") return onClose();
@@ -35,31 +45,32 @@ export function Settings({ settings, onChange, onClose }) {
35
45
  if (key.downArrow) return setRow((r) => Math.min(ROWS.length - 1, r + 1));
36
46
 
37
47
  const current = ROWS[row];
48
+ if (current.action) return key.return ? onAction(current.key) : undefined;
38
49
  const direction = key.leftArrow ? -1 : key.rightArrow ? 1 : 0;
39
- if (current.toggle && (direction || key.return || input === " ")) return onChange({ [current.key]: !settings[current.key] });
50
+ if (current.toggle && (direction || key.return || input === " ")) return onChange({ [current.key]: !values[current.key] });
40
51
  if (!direction) return;
41
- const index = nearestIndex(current.options, settings[current.key]);
52
+ const index = nearestIndex(current.options, values[current.key]);
42
53
  const next = current.options[Math.min(current.options.length - 1, Math.max(0, index + direction))];
43
- if (JSON.stringify(next) !== JSON.stringify(settings[current.key])) onChange({ [current.key]: next });
54
+ if (JSON.stringify(next) !== JSON.stringify(values[current.key])) onChange({ [current.key]: next });
44
55
  });
45
56
 
46
57
  return html`
47
58
  <${Fragment}>
48
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
49
- <${Text} bold color=${theme.accent}>Settings<//>
59
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
60
+ <${Text} bold color=${theme.accent}>${t("settings.title")}<//>
50
61
  <${Box} flexDirection="column" marginTop=${1}>
51
62
  ${ROWS.map(
52
63
  (item, i) => html`
53
64
  <${Box} key=${item.key}>
54
- <${Text} color=${i === row ? theme.accent : undefined} bold=${i === row}>${i === row ? "❯" : " "} ${item.label.padEnd(13)}<//>
55
- <${Text} color=${i === row ? theme.accent : undefined}>${i === row ? "❮ " : " "}${item.format(settings[item.key])}${i === row ? " ❯" : ""}<//>
65
+ <${Box} flexShrink=${0}><${Text} color=${i === row ? theme.accent : undefined} bold=${i === row}>${i === row ? "❯" : " "} ${label(item).padEnd(labelWidth)}<//><//>
66
+ <${Text} color=${i === row ? theme.accent : undefined}>${i === row && !item.action ? "❮ " : " "}${item.format(values[item.key])}${i === row && !item.action ? " ❯" : ""}<//>
56
67
  <//>
57
68
  `
58
69
  )}
59
70
  <//>
60
- <${Box} marginTop=${1}><${Text} dimColor>${ROWS[row].hint}<//><//>
71
+ <${Box} marginTop=${1}><${Text} dimColor>${t(`settings.rows.${ROWS[row].key}.hint`)}<//><//>
61
72
  <//>
62
- <${Box} paddingX=${1}><${Text} dimColor>↑/↓ select · ←/→ change · esc back<//><//>
73
+ <${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.settings")} /><//>
63
74
  <//>
64
75
  `;
65
76
  }
package/src/ui/Stats.js CHANGED
@@ -1,9 +1,10 @@
1
+ import { t } from "../i18n.js";
1
2
  import { Fragment, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
+ import { Box, useInput } from "ink";
4
+ import { dragonName } from "../progress.js";
3
5
  import { formatRange } from "../vacation.js";
4
- import { html, PANEL_WIDTH, theme } from "./kit.js";
6
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
5
7
 
6
- const DAY_LETTERS = ["M", "T", "W", "T", "F", "S", "S"];
7
8
  // One shape for every day; only the color tells them apart, GitHub-contribution style.
8
9
  const TILE = {
9
10
  goal: theme.good,
@@ -30,7 +31,7 @@ function Calendar({ month, goal }) {
30
31
  return html`
31
32
  <${Box} flexDirection="column">
32
33
  <${Box}>
33
- ${DAY_LETTERS.map((letter, i) =>
34
+ ${t("stats.weekdays").split(" ").map((letter, i) =>
34
35
  i === todayColumn ? html`<${Text} key=${i} color=${theme.accent} bold>${letter} <//>` : html`<${Text} key=${i} dimColor>${letter} <//>`
35
36
  )}
36
37
  <//>
@@ -47,21 +48,23 @@ function Calendar({ month, goal }) {
47
48
 
48
49
  function Legend({ goal }) {
49
50
  const items = [
50
- [TILE.goal, `goal (${goal})`],
51
- [TILE.halfway, "halfway"],
52
- [TILE.some, "some"],
53
- [TILE.none, "none"],
54
- [TILE.rest, "rest"],
55
- [TILE.today, "today"]
51
+ [TILE.goal, t("stats.legend.goal", { goal })],
52
+ [TILE.halfway, t("stats.legend.halfway")],
53
+ [TILE.some, t("stats.legend.some")],
54
+ [TILE.none, t("stats.legend.none")],
55
+ [TILE.rest, t("stats.legend.rest")],
56
+ [TILE.today, t("stats.legend.today")]
56
57
  ];
58
+ // a box per item, so a longer language wraps whole items instead of splitting one
57
59
  return html`
58
- <${Text}>
59
- ${items.map(([color, label]) => html`<${Text} key=${label}><${Text} color=${color}>■<//><${Text} dimColor> ${label} <//><//>`)}
60
+ <${Box} flexWrap="wrap" columnGap=${2}>
61
+ ${items.map(([color, label]) => html`<${Text} key=${label}><${Text} color=${color}>■<//><${Text} dimColor> ${label}<//><//>`)}
60
62
  <//>
61
63
  `;
62
64
  }
63
65
 
64
66
  export function Stats({ stats, getMonth, onClose }) {
67
+ const panel = usePanelWidth();
65
68
  const [offset, setOffset] = useState(0);
66
69
  useInput((input, key) => {
67
70
  if (key.escape || key.return || input === "q") return onClose();
@@ -73,36 +76,37 @@ export function Stats({ stats, getMonth, onClose }) {
73
76
  const accuracy = today.asked ? Math.round((today.correct / today.asked) * 100) : null;
74
77
  const unlocked = stats.badges.filter((b) => b.unlockedOn).length;
75
78
  const month = getMonth(offset);
76
- const next = companion.nextAt ? ` · ${companion.nextName} at a ${companion.nextAt}-day streak` : " · fully evolved";
79
+ const next = companion.nextAt ? t("stats.nextForm", { count: companion.nextAt }) : t("stats.fullyEvolved");
80
+ const title = dragonName(companion.index, companion.element);
77
81
 
78
82
  return html`
79
83
  <${Fragment}>
80
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
81
- <${Text} bold color=${theme.accent}>Stats<//>
84
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
85
+ <${Text} bold color=${theme.accent}>${t("stats.title")}<//>
82
86
 
83
87
  <${Box} marginTop=${1} flexDirection="column">
84
88
  <${Text}>
85
- ${streak.days > 0 ? html`<${Text} color=${theme.warn} bold>${streak.days}-day streak<//>` : html`<${Text} dimColor>no streak yet<//>`}
86
- <${Text} dimColor> · best ${streak.best} · ${streak.freezes} freeze${streak.freezes === 1 ? "" : "s"} in stock<//>
89
+ ${streak.days > 0 ? html`<${Text} color=${theme.warn} bold>${t("stats.streak", { count: streak.days })}<//>` : html`<${Text} dimColor>${t("stats.noStreak")}<//>`}
90
+ <${Text} dimColor>${t("stats.bestAndFreezes", { best: streak.best, count: streak.freezes })}<//>
87
91
  <//>
88
- <${Text} dimColor>today ${today.correct}/${goal} correct${accuracy === null ? "" : ` · ${accuracy}% accuracy`}<//>
89
- <${Text} dimColor>cards ${stats.mastered} mastered · ${stats.practiced} practiced · ${stats.totalCorrect} correct in total<//>
90
- <${Text} dimColor>companion ${companion.name} (${companion.index + 1}/6)${next}<//>
91
- <${Text} dimColor>rest days ${stats.skipWeekends ? "weekends" : "no weekends"}${stats.vacation.upcoming.length ? ` · vacation ${stats.vacation.upcoming.map((v) => formatRange(v.from, v.to)).join(", ")}` : ""}<//>
92
+ <${Text} dimColor>${t("stats.today", { correct: today.correct, goal, accuracy: accuracy === null ? "" : t("stats.accuracy", { percent: accuracy }) })}<//>
93
+ <${Text} dimColor>${t("stats.cards", { mastered: stats.mastered, practised: stats.practiced, total: stats.totalCorrect })}<//>
94
+ <${Text} dimColor>${t("stats.companion", { name: title, stage: companion.index + 1, next })}<//>
95
+ <${Text} dimColor>${t("stats.restDays", { weekends: t(stats.skipWeekends ? "stats.weekends" : "stats.noWeekends"), daysOff: stats.vacation.upcoming.length ? t("stats.daysOff", { ranges: stats.vacation.upcoming.map((v) => formatRange(v.from, v.to)).join(", ") }) : "" })}<//>
92
96
  <//>
93
97
 
94
98
  <${Box} marginTop=${1} flexDirection="column">
95
99
  <${Text} bold>${month.label}<//>
96
100
  <${Box} marginTop=${1}><${Calendar} month=${month} goal=${goal} /><//>
97
101
  <${Box} marginTop=${1} flexDirection="column">
98
- <${Text} dimColor>Goal reached on ${month.goalDays} of ${month.daysSoFar} days · ${month.correct} correct answers<//>
102
+ <${Text} dimColor>${t("stats.month", { goalDays: month.goalDays, days: month.daysSoFar, correct: month.correct })}<//>
99
103
  <${Legend} goal=${goal} />
100
104
  <//>
101
105
  <//>
102
106
 
103
- <${Box} marginTop=${1}><${Text} dimColor>${unlocked}/${stats.badges.length} badges · /badges lists them all<//><//>
107
+ <${Box} marginTop=${1}><${Text} dimColor>${t("stats.badgesLine", { unlocked, total: stats.badges.length })}<//><//>
104
108
  <//>
105
- <${Box} paddingX=${1}><${Text} dimColor>←/→ month · esc back<//><//>
109
+ <${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.stats")} /><//>
106
110
  <//>
107
111
  `;
108
112
  }
package/src/ui/Summary.js CHANGED
@@ -1,10 +1,14 @@
1
+ import { t } from "../i18n.js";
1
2
  import { Fragment } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { Bar, html, PANEL_WIDTH, theme } from "./kit.js";
3
+ import { Box, useInput } from "ink";
4
+ import { Bar, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
5
+ import { dragonName } from "../progress.js";
6
+ import { Flame } from "./icons.js";
4
7
  import { Mascot, MASCOT_WIDTH } from "./Mascot.js";
5
8
 
6
9
  // The end-of-session screen: how this run went, shown on quit. Any key leaves for real.
7
10
  export function Summary({ stats, totals, bestCombo, onDone }) {
11
+ const panel = usePanelWidth();
8
12
  useInput(() => onDone());
9
13
  const { streak, today, goal, companion } = stats;
10
14
  const accuracy = totals.asked ? Math.round((totals.correct / totals.asked) * 100) : 0;
@@ -12,23 +16,27 @@ export function Summary({ stats, totals, bestCombo, onDone }) {
12
16
 
13
17
  return html`
14
18
  <${Fragment}>
15
- <${Box} borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${PANEL_WIDTH}>
19
+ <${Box} borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${panel}>
16
20
  <${Box} flexDirection="column" width=${MASCOT_WIDTH + 3}>
17
- <${Mascot} face=${face} stage=${companion.index} />
21
+ <${Mascot} face=${face} stage=${companion.index} element=${companion.element} />
18
22
  <//>
19
23
  <${Box} flexDirection="column" justifyContent="center">
20
- <${Box}><${Text} bold color=${theme.accent}>Session over<//><//>
21
- <${Box}><${Text}>${totals.correct}/${totals.asked} correct · ${accuracy}%${bestCombo >= 2 ? ` · best combo ×${bestCombo}` : ""}<//><//>
24
+ <${Box}><${Text} bold color=${theme.accent}>${t("summary.title")}<//><//>
25
+ <${Box}><${Text}>${t("summary.result", { correct: totals.correct, asked: totals.asked, percent: accuracy })}${bestCombo >= 2 ? t("summary.bestCombo", { count: bestCombo }) : ""}<//><//>
22
26
  <${Box}>
23
- <${Text} dimColor>today <//>
27
+ <${Text} dimColor>${t("summary.today")}<//>
24
28
  <${Bar} value=${today.correct} max=${goal} width=${12} color=${today.goalMet ? theme.good : theme.accent} />
25
29
  <${Text} dimColor> ${Math.min(today.correct, goal)}/${goal}<//>
26
- ${today.goalMet && html`<${Text} color=${theme.good}> goal reached<//>`}
30
+ ${today.goalMet && html`<${Text} color=${theme.good}>${t("summary.goalReached")}<//>`}
27
31
  <//>
28
- <${Box}><${Text} dimColor>${streak.days > 0 ? `🔥 ${streak.days}-day streak` : "no streak yet"}${streak.atRisk ? " · still at risk today" : ""}<//><//>
32
+ <${Box}>
33
+ ${streak.days > 0 && html`<${Box}><${Flame} /><${Text}> <//><//>`}
34
+ <${Text} dimColor>${streak.days > 0 ? t("summary.streak", { count: streak.days }) : t("summary.noStreak")}${streak.atRisk ? t("summary.atRisk") : ""}<//>
35
+ <//>
36
+ <${Box}><${Text} dimColor>${t("summary.waiting", { name: dragonName(companion.index, companion.element) })}<//><//>
29
37
  <//>
30
38
  <//>
31
- <${Box} paddingX=${1}><${Text} dimColor>see you later · any key to leave<//><//>
39
+ <${Box} paddingX=${1}><${KeyHints} text=${t("summary.keys")} /><//>
32
40
  <//>
33
41
  `;
34
42
  }