dracosh 0.1.0 → 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 (51) hide show
  1. package/README.md +42 -20
  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/data/tips.json +31 -1361
  7. package/package.json +1 -1
  8. package/src/alerts.js +4 -3
  9. package/src/backup.js +95 -0
  10. package/src/cli.js +97 -16
  11. package/src/commands.js +7 -7
  12. package/src/judge.js +33 -12
  13. package/src/library.js +127 -0
  14. package/src/lock.js +63 -0
  15. package/src/manage.js +75 -0
  16. package/src/pause.js +23 -0
  17. package/src/progress.js +145 -53
  18. package/src/quiet.js +1 -1
  19. package/src/scheduler.js +38 -26
  20. package/src/session.js +128 -30
  21. package/src/settings.js +4 -9
  22. package/src/starter.js +38 -0
  23. package/src/store.js +55 -16
  24. package/src/tips.js +7 -24
  25. package/src/ui/AddCard.js +172 -0
  26. package/src/ui/AnswerInput.js +8 -5
  27. package/src/ui/App.js +211 -71
  28. package/src/ui/BadgeUnlock.js +50 -0
  29. package/src/ui/Badges.js +75 -17
  30. package/src/ui/Choice.js +33 -0
  31. package/src/ui/Companion.js +20 -35
  32. package/src/ui/Decks.js +49 -0
  33. package/src/ui/DieRoll.js +104 -0
  34. package/src/ui/Evolution.js +6 -5
  35. package/src/ui/Hatch.js +5 -4
  36. package/src/ui/Header.js +7 -6
  37. package/src/ui/Help.js +68 -0
  38. package/src/ui/Mascot.js +88 -38
  39. package/src/ui/Missed.js +6 -5
  40. package/src/ui/Preview.js +92 -17
  41. package/src/ui/Reset.js +72 -0
  42. package/src/ui/Settings.js +15 -11
  43. package/src/ui/Stats.js +10 -7
  44. package/src/ui/Summary.js +12 -5
  45. package/src/ui/TheOne.js +121 -0
  46. package/src/ui/icons.js +156 -24
  47. package/src/ui/kit.js +58 -1
  48. package/src/vacation.js +7 -2
  49. package/src/words.js +21 -14
  50. package/assets/sounds/badge.wav +0 -0
  51. package/src/ui/Tip.js +0 -25
package/src/ui/Mascot.js CHANGED
@@ -2,21 +2,21 @@ import React from "react";
2
2
  import { Text } from "ink";
3
3
  import { html } from "./kit.js";
4
4
 
5
- // A tiny flashcard creature, drawn as pixels: every text row stacks two pixel rows using half blocks (▀ ▄ █).
5
+ // A little dragon, drawn as pixels: every text row stacks two pixel rows using half blocks (▀ ▄ █).
6
6
  // Proper pixel art: O = dark outline, L = top highlight, B = body, D = bottom shade.
7
- // Its form (accessories) comes from the evolution stage, its expression from how you are doing.
8
- const WIDTH = 12;
7
+ // Its form (horns, wings, tail…) comes from the evolution stage, its expression from how you are doing.
8
+ const WIDTH = 14;
9
9
  const BASE = [
10
- "............",
11
- "..OOOOOOOO..",
12
- ".OLLLLLLLLO.",
13
- ".OBBEBBEBBO.",
14
- ".OBBEBBEBBO.",
15
- ".OBBBBBBBBO.",
16
- ".ODBBBBBBDO.",
17
- "..OOOOOOOO..",
18
- "...OO..OO...",
19
- "............"
10
+ "..............",
11
+ "...OOOOOOOO...",
12
+ "..OLLLLLLLLO..",
13
+ "..OBBEBBEBBO..",
14
+ "..OBBEBBEBBO..",
15
+ "..OBBBBBBBBO..",
16
+ "..ODBBBBBBDO..",
17
+ "...OOOOOOOO...",
18
+ "....OO..OO....",
19
+ ".............."
20
20
  ];
21
21
 
22
22
  // a little green dragon: scale-green body, cream belly, bone horns, golden spikes
@@ -31,37 +31,83 @@ const PALETTES = {
31
31
  const ACCESSORY_COLORS = { H: "#e8dcc8", W: "#2f6b45", P: "#e6d79a", S: "#d9a441", G: "#fcd34d" };
32
32
  const FLASH_ACCESSORIES = { H: "#ffffff", W: "#cfe6d4", P: "#ffffff", S: "#ffffff", G: "#ffffff" };
33
33
 
34
- // What each evolution stage adds on top of the previous one: [row, col, pixel]
34
+ // The dragon's element, rolled once with "Dragon's die": its own body and accessory colors, plus a few
35
+ // details (X, Y) drawn before the evolution accessories, so horns, wings and the crown always show.
36
+ const ELEMENT_LOOKS = {
37
+ earth: {
38
+ body: { B: "#8b6d47", L: "#b8955f", D: "#5e4630", O: "#2e2216" },
39
+ accents: { H: "#d9cbb0", W: "#6b4f2e", P: "#c9b48a", S: "#a07c4f" },
40
+ colors: { X: "#7fb045", Y: "#6b5a44" },
41
+ details: [[2, 4, "X"], [2, 5, "X"], [2, 9, "X"], [6, 3, "Y"], [6, 10, "Y"]] // moss on the head, pebbles below
42
+ },
43
+ wind: {
44
+ body: { B: "#b4bfbc", L: "#e3e8e6", D: "#8a9592", O: "#4a5452" },
45
+ accents: { H: "#f0f3f2", W: "#9aa5a2", P: "#d5dcda", S: "#e3e8e6" },
46
+ colors: { X: "#eef2f1" },
47
+ details: [[3, 0, "X"], [4, 0, "X"], [4, 13, "X"], [8, 1, "X"]] // wisps of air around it
48
+ },
49
+ water: {
50
+ body: { B: "#3b82c4", L: "#7cb8e8", D: "#245d94", O: "#13304d" },
51
+ accents: { H: "#cfe8ff", W: "#1e5a8f", P: "#a5d3f5", S: "#7cb8e8" },
52
+ colors: { X: "#5fb3f0", Y: "#bfe3ff" },
53
+ details: [[1, 6, "X"], [1, 7, "X"], [3, 13, "Y"]] // a fin on the head, a drop of water
54
+ },
55
+ ice: {
56
+ body: { B: "#bfe6f5", L: "#ffffff", D: "#86c0d8", O: "#3d6f86" },
57
+ accents: { H: "#e0f7ff", W: "#86c0d8", P: "#ffffff", S: "#e0f7ff" },
58
+ colors: { X: "#e0f7ff", Y: "#ffffff" },
59
+ details: [[0, 3, "X"], [0, 10, "X"], [6, 4, "Y"], [6, 9, "Y"]] // crystal spikes, frost
60
+ },
61
+ fire: {
62
+ body: { B: "#e4572e", L: "#f59e5b", D: "#a8341c", O: "#4a140a" },
63
+ accents: { H: "#fde68a", W: "#a8341c", P: "#fbbf24", S: "#fbbf24" },
64
+ colors: { X: "#fbbf24", Y: "#fde68a" },
65
+ details: [[0, 5, "X"], [0, 8, "X"], [3, 0, "Y"], [3, 13, "Y"]] // flame tips, embers
66
+ },
67
+ cosmos: {
68
+ body: { B: "#3b2f7a", L: "#5b4bb0", D: "#30266a", O: "#2a2163", E: "#05030f", C: "#c084fc" },
69
+ accents: { H: "#c4b5fd", W: "#261d55", P: "#5b4bb0", S: "#c4b5fd" },
70
+ colors: { X: "#fef3c7" },
71
+ details: [[2, 3, "X"], [2, 10, "X"], [5, 10, "X"], [6, 3, "X"]] // stars on its body
72
+ }
73
+ };
74
+
75
+ // one color that stands for each element in text (names, the die's pips)
76
+ export const ELEMENT_COLOR = { earth: "#a07c4f", wind: "#b4bfbc", water: "#3b82c4", ice: "#bfe6f5", fire: "#e4572e", cosmos: "#8b7cf6" };
77
+
78
+ // What each evolution stage adds on top of the previous one: [row, col, pixel]. The wings rise over
79
+ // the shoulders and never frame the face, so the later forms read as a dragon, not a maned lion.
35
80
  const STAGE_EDITS = [
36
81
  [], // 0 Hatchling
37
- [[0, 3, "H"], [1, 3, "H"], [0, 8, "H"], [1, 8, "H"]], // 1 Imp: horns
38
- [[3, 0, "W"], [4, 0, "W"], [3, 11, "W"], [4, 11, "W"]], // 2 Whelp: little wings
39
- [[5, 4, "P"], [5, 5, "P"], [5, 6, "P"], [5, 7, "P"], [6, 4, "P"], [6, 5, "P"], [6, 6, "P"], [6, 7, "P"], [6, 11, "W"], [7, 10, "W"]], // 3 Drake: belly and tail
40
- [[0, 5, "S"], [0, 6, "S"], [2, 0, "W"], [2, 11, "W"], [5, 0, "W"], [5, 11, "W"]], // 4 Dragon: head spikes, bigger wings
41
- [[0, 4, "G"], [0, 5, "G"], [0, 6, "G"], [0, 7, "G"]] // 5 Legend: halo (and golden horns, see below)
82
+ [[0, 4, "H"], [1, 4, "H"], [0, 9, "H"], [1, 9, "H"]], // 1 Imp: upright horns
83
+ [[0, 0, "W"], [1, 0, "W"], [1, 1, "W"], [2, 1, "W"], [0, 13, "W"], [1, 13, "W"], [1, 12, "W"], [2, 12, "W"]], // 2 Whelp: little bat wings
84
+ [[5, 5, "P"], [5, 6, "P"], [5, 7, "P"], [5, 8, "P"], [6, 5, "P"], [6, 6, "P"], [6, 7, "P"], [6, 8, "P"], [6, 12, "W"], [7, 13, "W"], [8, 12, "S"], [8, 13, "S"]], // 3 Drake: belly, curled tail with a spade
85
+ [[0, 1, "W"], [0, 12, "W"], [7, 12, "W"], [0, 6, "S"], [0, 7, "S"]], // 4 Dragon: wider wings, a thicker tail, a crest
86
+ [[0, 5, "G"], [0, 6, "G"], [0, 7, "G"], [0, 8, "G"]] // 5 Legend: a crown (and golden horns, see below)
42
87
  ];
43
88
  const LEGEND = STAGE_EDITS.length - 1;
44
89
 
45
90
  const OPEN_EYES = []; // the base already has them
46
- const SHUT_EYES = [[3, 4, "B"], [3, 7, "B"]]; // only the lower eye pixel stays: half-closed
47
- const SMILE = [[5, 4, "E"], [6, 5, "E"], [6, 6, "E"], [5, 7, "E"]];
48
- const GRIN = [[5, 4, "E"], [5, 7, "E"], [6, 4, "E"], [6, 5, "E"], [6, 6, "E"], [6, 7, "E"]];
49
- const FROWN = [[6, 4, "E"], [5, 5, "E"], [5, 6, "E"], [6, 7, "E"]];
91
+ const SHUT_EYES = [[3, 5, "B"], [3, 8, "B"]]; // only the lower eye pixel stays: half-closed
92
+ const SMILE = [[5, 5, "E"], [6, 6, "E"], [6, 7, "E"], [5, 8, "E"]];
93
+ const GRIN = [[5, 5, "E"], [5, 8, "E"], [6, 5, "E"], [6, 6, "E"], [6, 7, "E"], [6, 8, "E"]];
94
+ const FROWN = [[6, 5, "E"], [5, 6, "E"], [5, 7, "E"], [6, 8, "E"]];
50
95
 
51
96
  // [row, col, pixel] edits for each expression, applied last
52
97
  const FACES = {
53
- idle: [...OPEN_EYES, [5, 5, "E"], [5, 6, "E"]], // straight little mouth
54
- blink: [...SHUT_EYES, [5, 5, "E"], [5, 6, "E"]],
98
+ idle: [...OPEN_EYES, [5, 6, "E"], [5, 7, "E"]], // straight little mouth
99
+ blink: [...SHUT_EYES, [5, 6, "E"], [5, 7, "E"]],
55
100
  smile: SMILE, // content: today's goal is done
56
- happy: [...SHUT_EYES, ...GRIN, [4, 2, "C"], [4, 9, "C"]], // beaming, with blushing cheeks
57
- sad: [...FROWN, [5, 8, "T"]], // a tear under the right eye
101
+ happy: [...SHUT_EYES, ...GRIN, [4, 3, "C"], [4, 10, "C"]], // beaming, with blushing cheeks
102
+ sad: [...FROWN, [5, 9, "T"]], // a tear under the right eye
58
103
  sleep: [...SHUT_EYES] // eyes shut, mouth relaxed away
59
104
  };
60
105
 
61
- // `shift` nudges the whole grid by dx columns / dy pixel rows (half a text row) for jump and shake frames
62
- export function drawSprite(face, stage = 0, { dx = 0, dy = 0 } = {}) {
106
+ // `dx`/`dy` nudge the whole grid by columns / pixel rows (half a text row) for jump and shake frames
107
+ export function drawSprite(face, stage = 0, { dx = 0, dy = 0, element = null } = {}) {
63
108
  const grid = BASE.map((row) => [...row]);
64
109
  const apply = (edits) => edits.forEach(([r, c, pixel]) => (grid[r][c] = pixel));
110
+ if (ELEMENT_LOOKS[element]) apply(ELEMENT_LOOKS[element].details);
65
111
  STAGE_EDITS.slice(0, stage + 1).forEach(apply);
66
112
  apply(FACES[face] ?? FACES.idle);
67
113
  if (!dx && !dy) return grid;
@@ -90,22 +136,26 @@ export function PixelGrid({ grid, palette }) {
90
136
  return html`<${React.Fragment}>${rows}<//>`;
91
137
  }
92
138
 
93
- const LOCKED = { B: "#3a3f47", L: "#454b54", D: "#31363d", O: "#23272d", E: "#1f2328", C: "#3a3f47", T: "#3a3f47", H: "#4a5058", W: "#4a5058", P: "#4a5058", S: "#4a5058", G: "#4a5058" };
139
+ // A form you haven't reached: one flat color, no eyes or shading, so only the outline gives it away
140
+ const SILHOUETTE = "#2c3038";
141
+ const LOCKED = Object.fromEntries([..."BLDOECTHWPSGXY"].map((key) => [key, SILHOUETTE]));
94
142
 
95
- function paletteFor({ locked, flash, hot, flicker, stage }) {
143
+ function paletteFor({ locked, flash, hot, flicker, stage, element }) {
96
144
  if (locked) return LOCKED;
97
- if (flash) return { ...FLASH_ACCESSORIES, ...PALETTES.flash };
98
- const body = hot ? (flicker ? PALETTES.hot2 : PALETTES.hot) : PALETTES.normal;
99
- const palette = { ...ACCESSORY_COLORS, ...body };
145
+ if (flash) return { ...FLASH_ACCESSORIES, ...PALETTES.flash, X: "#ffffff", Y: "#ffffff" };
146
+ const look = ELEMENT_LOOKS[element];
147
+ const body = hot ? (flicker ? PALETTES.hot2 : PALETTES.hot) : { ...PALETTES.normal, ...look?.body };
148
+ const palette = { ...ACCESSORY_COLORS, ...look?.accents, ...look?.colors, ...body };
100
149
  if (stage >= LEGEND) palette.H = ACCESSORY_COLORS.G; // Legend: golden horns under the halo
101
150
  return palette;
102
151
  }
103
152
 
104
153
  // `locked` draws a dark silhouette (a form you haven't reached yet); `flash` whites it out (evolution);
105
154
  // `flicker` alternates the hot palette; `scale: 2` draws one text row per pixel row, two chars per pixel.
106
- export function Mascot({ face = "idle", hot = false, stage = 0, locked = false, flash = false, flicker = false, scale = 1, dx = 0, dy = 0 }) {
107
- const palette = paletteFor({ locked, flash, hot, flicker, stage });
108
- const grid = drawSprite(face, stage, { dx, dy });
155
+ // `element` is the dragon's rolled element ("earth" … "cosmos"), or null for the default green dragon
156
+ export function Mascot({ face = "idle", hot = false, stage = 0, locked = false, flash = false, flicker = false, scale = 1, dx = 0, dy = 0, element = null }) {
157
+ const palette = paletteFor({ locked, flash, hot, flicker, stage, element });
158
+ const grid = drawSprite(face, stage, { dx, dy, element });
109
159
  const rows = [];
110
160
  if (scale === 2) {
111
161
  for (let r = 0; r < grid.length; r++) {
@@ -118,7 +168,7 @@ export function Mascot({ face = "idle", hot = false, stage = 0, locked = false,
118
168
  } else {
119
169
  for (let r = 0; r < grid.length; r += 2) {
120
170
  const cells = [];
121
- for (let c = 0; c < WIDTH; c++) cells.push(cell(grid[r][c], grid[r + 1][c], palette, c));
171
+ for (let c = 0; c < grid[r].length; c++) cells.push(cell(grid[r][c], grid[r + 1][c], palette, c));
122
172
  rows.push(html`<${Text} key=${r}>${cells}<//>`);
123
173
  }
124
174
  }
package/src/ui/Missed.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Fragment, useState } from "react";
2
2
  import { Box, Text, useInput } from "ink";
3
- import { html, PANEL_WIDTH, theme } from "./kit.js";
3
+ import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
4
4
 
5
5
  const MAX_ROWS = 10;
6
6
 
@@ -8,6 +8,7 @@ const dayLabel = (offset, date) => (offset === 0 ? "today" : offset === -1 ? `ye
8
8
 
9
9
  // Words you got wrong on a day, with what you typed and whether you got them right afterwards.
10
10
  export function Missed({ getMissed, onClose }) {
11
+ const panel = usePanelWidth();
11
12
  const [offset, setOffset] = useState(0);
12
13
  useInput((input, key) => {
13
14
  if (key.escape || key.return || input === "q") return onClose();
@@ -20,10 +21,10 @@ export function Missed({ getMissed, onClose }) {
20
21
 
21
22
  return html`
22
23
  <${Fragment}>
23
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
24
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
24
25
  <${Box}>
25
26
  <${Text} bold color=${theme.accent}>Missed<//>
26
- <${Text} dimColor> ${dayLabel(offset, date)} · ${items.length} word${items.length === 1 ? "" : "s"}<//>
27
+ <${Text} dimColor> ${dayLabel(offset, date)} · ${items.length} card${items.length === 1 ? "" : "s"}<//>
27
28
  <//>
28
29
  ${items.length === 0
29
30
  ? html`<${Box} marginTop=${1}><${Text} dimColor>${offset === 0 ? "Nothing missed so far today." : "Nothing missed that day."}<//><//>`
@@ -38,7 +39,7 @@ export function Missed({ getMissed, onClose }) {
38
39
  <${Text} dimColor> ${item.label}${item.times > 1 ? ` · missed ${item.times}×` : ""}<//>
39
40
  <//>
40
41
  <${Text}> ${item.expected.join(", ")}<//>
41
- <${Text} dimColor> you wrote: ${item.answer}${item.recovered ? " · got it right since" : ""}<//>
42
+ <${Text} dimColor> ${item.answer ? `you wrote: ${item.answer}` : "no answer"}${item.recovered ? " · got it right since" : ""}<//>
42
43
  <//>
43
44
  `
44
45
  )}
@@ -46,7 +47,7 @@ export function Missed({ getMissed, onClose }) {
46
47
  <//>
47
48
  `}
48
49
  <//>
49
- <${Box} paddingX=${1}><${Text} dimColor>←/→ day · esc back<//><//>
50
+ <${Box} paddingX=${1}><${KeyHints} text="←/→ day · esc back" /><//>
50
51
  <//>
51
52
  `;
52
53
  }
package/src/ui/Preview.js CHANGED
@@ -2,19 +2,22 @@ import { Fragment, useEffect, useMemo, useState } from "react";
2
2
  import { Box, Text, useApp, useInput } from "ink";
3
3
  import { DEMO_WORDS } from "../demo.js";
4
4
  import { addDays, dayKey } from "../dates.js";
5
- import { BADGES, ensureProgress, STAGES } from "../progress.js";
5
+ import { BADGES, ELEMENTS, ensureProgress, rollElement, STAGES } from "../progress.js";
6
6
  import { createSession } from "../session.js";
7
7
  import { DEFAULTS } from "../settings.js";
8
+ import { DieRoll } from "./DieRoll.js";
8
9
  import { App } from "./App.js";
10
+ import { BadgeUnlock, badgeSound } from "./BadgeUnlock.js";
9
11
  import { Badges } from "./Badges.js";
10
12
  import { Confetti } from "./Confetti.js";
11
13
  import { Evolution } from "./Evolution.js";
12
14
  import { Hatch } from "./Hatch.js";
13
- import { Snore, useBlink, useMove } from "./Header.js";
14
- import { html, PANEL_WIDTH, theme } from "./kit.js";
15
+ import { Header, Snore, useBlink, useMove } from "./Header.js";
16
+ import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
15
17
  import { Mascot } from "./Mascot.js";
16
18
  import { Stats } from "./Stats.js";
17
19
  import { Summary } from "./Summary.js";
20
+ import { TheOne } from "./TheOne.js";
18
21
 
19
22
  // Everything here runs on made-up data in memory: nothing is read from or written to ~/.dracosh.
20
23
 
@@ -35,7 +38,7 @@ function fakeSession({ settings = {}, progress = false } = {}) {
35
38
  p.streak = { ...p.streak, count: 12, best: 34, lastGoalDay: addDays(today, -2) };
36
39
  BADGES.slice(0, 13).forEach((b, i) => (p.badges[b.id] = addDays(today, -i * 3)));
37
40
  }
38
- return createSession({ loadWords: async () => ({ words: DEMO_WORDS, cached: false }), state, getSettings: () => all, save: async () => {} });
41
+ return createSession({ loadWords: async () => ({ words: DEMO_WORDS }), state, getSettings: () => all, save: async () => {} });
39
42
  }
40
43
 
41
44
  // a 250 ms tick for the lab's own little animations (the snoring z's)
@@ -50,9 +53,11 @@ function useClock() {
50
53
 
51
54
  // The mascot on its own, to poke at: every form, face, move and the combo glow.
52
55
  function MascotLab({ onBack }) {
56
+ const panel = usePanelWidth();
53
57
  const [stage, setStage] = useState(0);
54
58
  const [face, setFace] = useState(0);
55
59
  const [hot, setHot] = useState(false);
60
+ const [element, setElement] = useState(-1); // -1: the default green dragon
56
61
  const [event, setEvent] = useState(null);
57
62
  const [tick, setTick] = useState(0);
58
63
  const move = useMove(event);
@@ -66,25 +71,81 @@ function MascotLab({ onBack }) {
66
71
  if (input === "j") return setEvent({ kind: "jump", at: Date.now() });
67
72
  if (input === "s") return setEvent({ kind: "shake", at: Date.now() });
68
73
  if (input === "h") return setHot((h) => !h);
74
+ if (input === "e") return setElement((e) => (e + 2) % (ELEMENTS.length + 1) - 1);
69
75
  if (input === " ") return setTick((t) => t + 1); // hand-cranked flicker frame
70
76
  });
71
77
  const shownFace = blinking && FACES[face] === "idle" ? "blink" : FACES[face];
72
78
  return html`
73
79
  <${Fragment}>
74
- <${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">
75
81
  <${Text} bold color=${theme.accent}>Mascot lab<//>
76
82
  <${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} />
83
+ <${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
84
  <//>
79
85
  ${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" : ""}<//><//>
86
+ <${Text}>${STAGES[stage].name}<${Text} dimColor> · face ${FACES[face]} · ${ELEMENTS[element] ?? "no element"}${hot ? " · combo glow" : ""}<//><//>
81
87
  <//>
82
- <${Box} paddingX=${1}><${Text} dimColor>←/→ form · ↑/↓ face · j jump · s shake · h glow · space flicker · esc back<//><//>
88
+ <${Box} paddingX=${1}><${KeyHints} text="←/→ form · ↑/↓ face · e element · j jump · s shake · h glow · esc back" /><//>
89
+ <//>
90
+ `;
91
+ }
92
+
93
+ // three badges won with one answer, lighting up one after another, as under the quiz card
94
+ const UNLOCK_SAMPLE = ["thousand", "hot-streak", "dragons-hoard"];
95
+
96
+ function BadgeUnlockLab({ onBack, play }) {
97
+ const panel = usePanelWidth();
98
+ const [run, setRun] = useState(1);
99
+ useInput((input, key) => {
100
+ if (key.escape || input === "q") return onBack();
101
+ if (key.return || input === " ") setRun((r) => r + 1);
102
+ });
103
+ const badges = UNLOCK_SAMPLE.map((id) => BADGES.find((badge) => badge.id === id));
104
+ return html`
105
+ <${Fragment}>
106
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.good} paddingX=${2} width=${panel}>
107
+ <${Text} color=${theme.good} bold>✓ dragon<//>
108
+ ${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} />`)}
109
+ <//>
110
+ <${Box} paddingX=${1}><${KeyHints} text="enter replay · esc back" /><//>
111
+ <//>
112
+ `;
113
+ }
114
+
115
+ // The quiz screen's header with any form and element, to check how the dragon looks and fits there
116
+ function QuizLookLab({ onBack }) {
117
+ const panel = usePanelWidth();
118
+ const [stage, setStage] = useState(STAGES.length - 1);
119
+ const [element, setElement] = useState(-1);
120
+ const [combo, setCombo] = useState(0);
121
+ useInput((input, key) => {
122
+ if (key.escape || input === "q") return onBack();
123
+ if (key.leftArrow) return setStage((s) => Math.max(0, s - 1));
124
+ if (key.rightArrow) return setStage((s) => Math.min(STAGES.length - 1, s + 1));
125
+ if (input === "e") return setElement((e) => (e + 2) % (ELEMENTS.length + 1) - 1);
126
+ if (input === "c") return setCombo((c) => (c ? 0 : 7));
127
+ });
128
+ const stats = {
129
+ streak: { days: 42, best: 120, freezes: 1, atRisk: false },
130
+ today: { correct: 13, asked: 15, goalMet: false },
131
+ goal: 20,
132
+ vacation: { activeUntil: null },
133
+ companion: { index: stage, name: STAGES[stage].name, element: ELEMENTS[element] ?? null }
134
+ };
135
+ return html`
136
+ <${Fragment}>
137
+ <${Header} deck="Polish" everyMs=${600000} wordCount=${340} stats=${stats} combo=${combo} face="idle" event=${null} tick=${0} />
138
+ <${Box} marginTop=${1} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${panel}>
139
+ <${Text} bold>la mariposa<//>
140
+ <${Box} marginTop=${1}><${Text} color=${theme.accent}>❯ <//><${Text} inverse> <//><//>
141
+ <//>
142
+ <${Box} paddingX=${1}><${Text} dimColor>${STAGES[stage].name} · ${ELEMENTS[element] ?? "no element"} · ←/→ form · e element · c combo · esc back<//><//>
83
143
  <//>
84
144
  `;
85
145
  }
86
146
 
87
147
  function ConfettiLab({ onBack }) {
148
+ const panel = usePanelWidth();
88
149
  const [run, setRun] = useState(1);
89
150
  useInput((input, key) => {
90
151
  if (key.escape || input === "q") return onBack();
@@ -92,11 +153,11 @@ function ConfettiLab({ onBack }) {
92
153
  });
93
154
  return html`
94
155
  <${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<//>
156
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.good} paddingX=${2} width=${panel}>
157
+ <${Text} color=${theme.good} bold>▪ Daily goal reached · 12-day streak<//>
97
158
  <//>
98
- <${Box} height=${5}><${Confetti} key=${run} width=${PANEL_WIDTH} onDone=${() => {}} /><//>
99
- <${Box} paddingX=${1}><${Text} dimColor>enter replay · esc back<//><//>
159
+ <${Box} height=${5}><${Confetti} key=${run} width=${panel} onDone=${() => {}} /><//>
160
+ <${Box} paddingX=${1}><${KeyHints} text="enter replay · esc back" /><//>
100
161
  <//>
101
162
  `;
102
163
  }
@@ -104,15 +165,20 @@ function ConfettiLab({ onBack }) {
104
165
  const SCENES = [
105
166
  { id: "hatch", label: "Hatching", hint: "the first-launch intro" },
106
167
  ...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" },
168
+ { id: "mascot", label: "Mascot lab", hint: "forms, faces, elements, moves, glow" },
108
169
  { id: "quiz", label: "Quiz", hint: "a live round on demo words, goal at 5" },
170
+ { id: "quiz-look", label: "Quiz screen", hint: "the header with any form and element" },
171
+ { id: "unlock", label: "Badge unlocked", hint: "three badges won at once" },
172
+ { id: "the-one", label: "The One...", hint: "the ring rises from the lava" },
173
+ { id: "die", label: "Dragon's die", hint: "the secret badge: a roll for an element" },
109
174
  { id: "confetti", label: "Confetti", hint: "the daily-goal burst" },
110
175
  { id: "stats", label: "Stats", hint: "calendar tiles, weeks of fake history" },
111
- { id: "badges", label: "Badges", hint: "the badge browser with pixel icons" },
176
+ { id: "badges", label: "Badges", hint: "all unlocked, three of them new" },
112
177
  { id: "summary", label: "Session summary", hint: "what you see when quitting" }
113
178
  ];
114
179
 
115
180
  function Menu({ selected, onMove, onPick, onQuit }) {
181
+ const panel = usePanelWidth();
116
182
  useInput((input, key) => {
117
183
  if (key.escape || input === "q") return onQuit();
118
184
  if (key.upArrow) return onMove(-1);
@@ -121,7 +187,7 @@ function Menu({ selected, onMove, onPick, onQuit }) {
121
187
  });
122
188
  return html`
123
189
  <${Fragment}>
124
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
190
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
125
191
  <${Box}><${Text} bold color=${theme.accent}>Preview<//><${Text} dimColor> made-up data · nothing is saved<//><//>
126
192
  <${Box} flexDirection="column" marginTop=${1}>
127
193
  ${SCENES.map(
@@ -136,7 +202,7 @@ function Menu({ selected, onMove, onPick, onQuit }) {
136
202
  )}
137
203
  <//>
138
204
  <//>
139
- <${Box} paddingX=${1}><${Text} dimColor>↑/↓ choose · enter play · esc quit<//><//>
205
+ <${Box} paddingX=${1}><${KeyHints} text="↑/↓ choose · enter play · esc quit" /><//>
140
206
  <//>
141
207
  `;
142
208
  }
@@ -150,6 +216,7 @@ export function Preview({ alerts }) {
150
216
  const back = () => setScene(null);
151
217
  const history = useMemo(() => fakeSession({ progress: true }), []);
152
218
  const quizSession = useMemo(() => fakeSession(), [run]); // every quiz run starts from zero
219
+ const dieElement = useMemo(() => rollElement(), [run]); // a fresh roll every time the scene plays
153
220
 
154
221
  const wrap = (content) => html`<${Box} flexDirection="column" marginY=${1}>${content}<//>`;
155
222
 
@@ -169,9 +236,17 @@ export function Preview({ alerts }) {
169
236
  return wrap(html`<${Evolution} key=${run} from=${to - 1} to=${to} name=${STAGES[to].name} onClose=${back} />`);
170
237
  }
171
238
  if (scene === "mascot") return wrap(html`<${MascotLab} onBack=${back} />`);
239
+ if (scene === "quiz-look") return wrap(html`<${QuizLookLab} onBack=${back} />`);
172
240
  if (scene === "confetti") return wrap(html`<${ConfettiLab} onBack=${back} />`);
241
+ if (scene === "unlock") return wrap(html`<${BadgeUnlockLab} onBack=${back} play=${alerts.play} />`);
242
+ if (scene === "die") return wrap(html`<${DieRoll} key=${run} element=${dieElement} stage=${2} play=${alerts.play} onClose=${back} />`);
243
+ if (scene === "the-one") return wrap(html`<${TheOne} key=${run} play=${alerts.play} onClose=${back} />`);
173
244
  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} />`);
245
+ if (scene === "badges") {
246
+ // every badge unlocked, so each icon and rank color can be seen
247
+ const all = history.stats().badges.map((badge) => ({ ...badge, unlockedOn: badge.unlockedOn ?? dayKey(Date.now()) }));
248
+ return wrap(html`<${Badges} key=${run} badges=${all} fresh=${["thousand", "hot-streak", "dragonheart"]} onClose=${back} />`);
249
+ }
175
250
  if (scene === "summary")
176
251
  return wrap(html`<${Summary} stats=${history.stats()} totals=${{ asked: 23, correct: 20 }} bestCombo=${9} onDone=${back} />`);
177
252
  if (scene === "quiz") {
@@ -0,0 +1,72 @@
1
+ import { Fragment, useEffect, useState } from "react";
2
+ import { Box, Text } from "ink";
3
+ import { Choice, CHOICE_KEYS } from "./Choice.js";
4
+ import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
5
+
6
+ const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
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 = [plural(badges, "badge"), stats.streak.best > 0 && `a ${stats.streak.best}-day best streak`, `your ${stats.companion.name}`].filter(Boolean).join(" · ");
26
+ const SCOPES = [
27
+ { scope: "progress", label: "Progress", note: "badges, streak and the dragon start over; your cards stay", question: "Reset your progress?", goes: progress, stays: "Your decks, cards and how well you know them stay." },
28
+ { scope: "everything", label: "Everything", note: "a fresh start with the tour; settings stay", question: "Reset everything?", goes: `${plural(own.length, "deck")} · ${plural(cards, "card")} · ${progress}`, stays: "Dracosh starts over like a fresh install, with the tour. Settings stay." }
29
+ ];
30
+ const chosen = SCOPES[scope];
31
+
32
+ async function confirm(index) {
33
+ if (index === 0) return setStep("choose");
34
+ setStep("working");
35
+ try {
36
+ await onConfirm(chosen.scope);
37
+ } catch (err) {
38
+ setError(err.message);
39
+ setStep("confirm");
40
+ }
41
+ }
42
+
43
+ return html`
44
+ <${Fragment}>
45
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${step === "choose" ? theme.accent : theme.bad} paddingX=${2} width=${panel}>
46
+ <${Text} bold color=${step === "choose" ? theme.accent : theme.bad}>${step === "choose" ? "Reset: what should start over?" : chosen.question}<//>
47
+ ${step === "choose" &&
48
+ html`<${Box} marginTop=${1}><${Choice} options=${SCOPES} selected=${scope} onMove=${setScope} onPick=${(i) => decks && (setScope(i), setAnswer(0), setStep("confirm"))} onCancel=${onClose} /><//>`}
49
+ ${step !== "choose" &&
50
+ html`
51
+ <${Box} flexDirection="column">
52
+ <${Box} flexDirection="column" marginTop=${1}>
53
+ <${Text}>This clears <${Text} bold>${chosen.goes}<//>.<//>
54
+ <${Text} dimColor>${chosen.stays} A backup is made first, so dracosh restore can undo it.<//>
55
+ <//>
56
+ <${Box} marginTop=${1}>
57
+ <${Choice}
58
+ options=${[{ label: "No, keep it all", key: "n" }, { label: `Yes, reset ${chosen.label.toLowerCase()}`, key: "y", danger: true }]}
59
+ selected=${answer}
60
+ onMove=${setAnswer}
61
+ onPick=${(i) => step === "confirm" && confirm(i)}
62
+ onCancel=${() => setStep("choose")}
63
+ />
64
+ <//>
65
+ <//>
66
+ `}
67
+ ${error && html`<${Box} marginTop=${1}><${Text} color=${theme.bad}>${error}<//><//>`}
68
+ <//>
69
+ <${Box} paddingX=${1}><${KeyHints} text=${step === "working" ? "resetting…" : `${CHOICE_KEYS} · esc back`} /><//>
70
+ <//>
71
+ `;
72
+ }
@@ -1,22 +1,22 @@
1
1
  import { Fragment, useState } from "react";
2
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";
3
+ import { GOALS, INTERVALS, QUIET_PRESETS, TIP_LABELS, TIP_MODES, VOLUMES, formatInterval } from "../settings.js";
4
4
  import { formatQuiet } from "../quiet.js";
5
- import { Bar, html, PANEL_WIDTH, theme } from "./kit.js";
5
+ import { Bar, html, KeyHints, theme, usePanelWidth } from "./kit.js";
6
6
 
7
7
  function VolumeValue({ value }) {
8
8
  return html`<${Text}><${Bar} value=${value} max=${1} width=${10} /> ${Math.round(value * 100)}%<//>`;
9
9
  }
10
10
 
11
- const ROWS = [
11
+ const ALL_ROWS = [
12
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 },
13
+ { key: "sound", label: "Sound", options: [true, false], format: (v) => (v ? "on" : "off"), hint: "answer and new-card sounds", toggle: true },
14
14
  { key: "volume", label: "Volume", options: VOLUMES, format: (v) => html`<${VolumeValue} value=${v} />`, hint: "plays a preview when changed" },
15
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)" },
16
+ { key: "tips", label: "Tips", options: TIP_MODES, format: (v) => TIP_LABELS[v], hint: "a short tip about Dracosh while you wait" },
17
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
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" }
19
+ { key: "reset", label: "Reset", action: true, format: () => "press enter", hint: "start over: your progress only, or everything (a backup is made first)" }
20
20
  ];
21
21
 
22
22
  const nearestIndex = (options, value) => {
@@ -25,9 +25,12 @@ const nearestIndex = (options, value) => {
25
25
  return options.reduce((best, option, i) => (Math.abs(option - value) < Math.abs(options[best] - value) ? i : best), 0);
26
26
  };
27
27
 
28
- // Changes apply and persist immediately; there is no save step.
29
- export function Settings({ settings, onChange, onClose }) {
28
+ // Changes apply and persist immediately; there is no save step. Action rows (Reset) open their own
29
+ // screen through `onAction`; without it (the preview) they are left out.
30
+ export function Settings({ settings, onChange, onClose, onAction }) {
31
+ const panel = usePanelWidth();
30
32
  const [row, setRow] = useState(0);
33
+ const ROWS = onAction ? ALL_ROWS : ALL_ROWS.filter((item) => !item.action);
31
34
 
32
35
  useInput((input, key) => {
33
36
  if (key.escape || input === "q") return onClose();
@@ -35,6 +38,7 @@ export function Settings({ settings, onChange, onClose }) {
35
38
  if (key.downArrow) return setRow((r) => Math.min(ROWS.length - 1, r + 1));
36
39
 
37
40
  const current = ROWS[row];
41
+ if (current.action) return key.return ? onAction(current.key) : undefined;
38
42
  const direction = key.leftArrow ? -1 : key.rightArrow ? 1 : 0;
39
43
  if (current.toggle && (direction || key.return || input === " ")) return onChange({ [current.key]: !settings[current.key] });
40
44
  if (!direction) return;
@@ -45,21 +49,21 @@ export function Settings({ settings, onChange, onClose }) {
45
49
 
46
50
  return html`
47
51
  <${Fragment}>
48
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
52
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
49
53
  <${Text} bold color=${theme.accent}>Settings<//>
50
54
  <${Box} flexDirection="column" marginTop=${1}>
51
55
  ${ROWS.map(
52
56
  (item, i) => html`
53
57
  <${Box} key=${item.key}>
54
58
  <${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 ? " ❯" : ""}<//>
59
+ <${Text} color=${i === row ? theme.accent : undefined}>${i === row && !item.action ? "❮ " : " "}${item.format(settings[item.key])}${i === row && !item.action ? " ❯" : ""}<//>
56
60
  <//>
57
61
  `
58
62
  )}
59
63
  <//>
60
64
  <${Box} marginTop=${1}><${Text} dimColor>${ROWS[row].hint}<//><//>
61
65
  <//>
62
- <${Box} paddingX=${1}><${Text} dimColor>↑/↓ select · ←/→ change · esc back<//><//>
66
+ <${Box} paddingX=${1}><${KeyHints} text="↑/↓ select · ←/→ change · esc back" /><//>
63
67
  <//>
64
68
  `;
65
69
  }