dracosh 0.0.0-stage → 0.1.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.
- package/LICENSE +202 -0
- package/NOTICE +10 -0
- package/README.md +78 -2
- package/assets/sounds/ask.wav +0 -0
- package/assets/sounds/badge.wav +0 -0
- package/assets/sounds/close.wav +0 -0
- package/assets/sounds/combo.wav +0 -0
- package/assets/sounds/correct-0.wav +0 -0
- package/assets/sounds/correct-1.wav +0 -0
- package/assets/sounds/correct-2.wav +0 -0
- package/assets/sounds/correct-3.wav +0 -0
- package/assets/sounds/correct-4.wav +0 -0
- package/assets/sounds/correct-5.wav +0 -0
- package/assets/sounds/evolve.wav +0 -0
- package/assets/sounds/goal.wav +0 -0
- package/assets/sounds/wrong.wav +0 -0
- package/data/tips.json +1362 -0
- package/package.json +47 -4
- package/src/alerts.js +37 -0
- package/src/anki.js +36 -0
- package/src/cli.js +116 -0
- package/src/commands.js +28 -0
- package/src/dates.js +15 -0
- package/src/demo.js +11 -0
- package/src/diff.js +46 -0
- package/src/hint.js +12 -0
- package/src/judge.js +57 -0
- package/src/parse.js +42 -0
- package/src/progress.js +363 -0
- package/src/quiet.js +32 -0
- package/src/scheduler.js +82 -0
- package/src/session.js +129 -0
- package/src/settings.js +43 -0
- package/src/store.js +61 -0
- package/src/tips.js +47 -0
- package/src/ui/AnswerInput.js +82 -0
- package/src/ui/App.js +369 -0
- package/src/ui/Badges.js +64 -0
- package/src/ui/Companion.js +60 -0
- package/src/ui/Confetti.js +46 -0
- package/src/ui/Evolution.js +58 -0
- package/src/ui/Hatch.js +99 -0
- package/src/ui/Header.js +116 -0
- package/src/ui/Mascot.js +128 -0
- package/src/ui/Missed.js +52 -0
- package/src/ui/Preview.js +181 -0
- package/src/ui/Settings.js +65 -0
- package/src/ui/Stats.js +108 -0
- package/src/ui/Summary.js +34 -0
- package/src/ui/Tip.js +25 -0
- package/src/ui/icons.js +209 -0
- package/src/ui/kit.js +63 -0
- package/src/vacation.js +51 -0
- package/src/words.js +16 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { Fragment, useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { Box, Text, useApp, useInput } from "ink";
|
|
3
|
+
import { DEMO_WORDS } from "../demo.js";
|
|
4
|
+
import { addDays, dayKey } from "../dates.js";
|
|
5
|
+
import { BADGES, ensureProgress, STAGES } from "../progress.js";
|
|
6
|
+
import { createSession } from "../session.js";
|
|
7
|
+
import { DEFAULTS } from "../settings.js";
|
|
8
|
+
import { App } from "./App.js";
|
|
9
|
+
import { Badges } from "./Badges.js";
|
|
10
|
+
import { Confetti } from "./Confetti.js";
|
|
11
|
+
import { Evolution } from "./Evolution.js";
|
|
12
|
+
import { Hatch } from "./Hatch.js";
|
|
13
|
+
import { Snore, useBlink, useMove } from "./Header.js";
|
|
14
|
+
import { html, PANEL_WIDTH, theme } from "./kit.js";
|
|
15
|
+
import { Mascot } from "./Mascot.js";
|
|
16
|
+
import { Stats } from "./Stats.js";
|
|
17
|
+
import { Summary } from "./Summary.js";
|
|
18
|
+
|
|
19
|
+
// Everything here runs on made-up data in memory: nothing is read from or written to ~/.dracosh.
|
|
20
|
+
|
|
21
|
+
const FACES = ["idle", "smile", "happy", "sad", "blink", "sleep"];
|
|
22
|
+
|
|
23
|
+
// a throwaway session; `progress` fills in a believable last few weeks
|
|
24
|
+
function fakeSession({ settings = {}, progress = false } = {}) {
|
|
25
|
+
const state = { items: {}, newToday: { date: "", count: 0 }, hatched: true };
|
|
26
|
+
const all = { ...DEFAULTS, dailyGoal: 5, everyMs: 6000, tips: "always", ...settings };
|
|
27
|
+
if (progress) {
|
|
28
|
+
const p = ensureProgress(state);
|
|
29
|
+
const today = dayKey(Date.now());
|
|
30
|
+
const counts = [9, 20, 0, 12, 25, 20, 3, 0, 20, 22, 8, 20, 0, 20, 14, 20, 20, 5];
|
|
31
|
+
counts.forEach((correct, i) => {
|
|
32
|
+
if (correct) p.days[addDays(today, -(i + 1))] = { asked: correct + 2, correct, goalMet: correct >= 20 };
|
|
33
|
+
});
|
|
34
|
+
p.days[today] = { asked: 7, correct: 6 };
|
|
35
|
+
p.streak = { ...p.streak, count: 12, best: 34, lastGoalDay: addDays(today, -2) };
|
|
36
|
+
BADGES.slice(0, 13).forEach((b, i) => (p.badges[b.id] = addDays(today, -i * 3)));
|
|
37
|
+
}
|
|
38
|
+
return createSession({ loadWords: async () => ({ words: DEMO_WORDS, cached: false }), state, getSettings: () => all, save: async () => {} });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// a 250 ms tick for the lab's own little animations (the snoring z's)
|
|
42
|
+
function useClock() {
|
|
43
|
+
const [tick, setTick] = useState(0);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
const id = setInterval(() => setTick((t) => t + 1), 250);
|
|
46
|
+
return () => clearInterval(id);
|
|
47
|
+
}, []);
|
|
48
|
+
return tick;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// The mascot on its own, to poke at: every form, face, move and the combo glow.
|
|
52
|
+
function MascotLab({ onBack }) {
|
|
53
|
+
const [stage, setStage] = useState(0);
|
|
54
|
+
const [face, setFace] = useState(0);
|
|
55
|
+
const [hot, setHot] = useState(false);
|
|
56
|
+
const [event, setEvent] = useState(null);
|
|
57
|
+
const [tick, setTick] = useState(0);
|
|
58
|
+
const move = useMove(event);
|
|
59
|
+
const blinking = useBlink();
|
|
60
|
+
const clock = useClock();
|
|
61
|
+
useInput((input, key) => {
|
|
62
|
+
if (key.escape || input === "q") return onBack();
|
|
63
|
+
if (key.leftArrow) return setStage((s) => Math.max(0, s - 1));
|
|
64
|
+
if (key.rightArrow) return setStage((s) => Math.min(STAGES.length - 1, s + 1));
|
|
65
|
+
if (key.upArrow || key.downArrow) return setFace((f) => (f + (key.upArrow ? FACES.length - 1 : 1)) % FACES.length);
|
|
66
|
+
if (input === "j") return setEvent({ kind: "jump", at: Date.now() });
|
|
67
|
+
if (input === "s") return setEvent({ kind: "shake", at: Date.now() });
|
|
68
|
+
if (input === "h") return setHot((h) => !h);
|
|
69
|
+
if (input === " ") return setTick((t) => t + 1); // hand-cranked flicker frame
|
|
70
|
+
});
|
|
71
|
+
const shownFace = blinking && FACES[face] === "idle" ? "blink" : FACES[face];
|
|
72
|
+
return html`
|
|
73
|
+
<${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<//>
|
|
76
|
+
<${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} />
|
|
78
|
+
<//>
|
|
79
|
+
${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" : ""}<//><//>
|
|
81
|
+
<//>
|
|
82
|
+
<${Box} paddingX=${1}><${Text} dimColor>←/→ form · ↑/↓ face · j jump · s shake · h glow · space flicker · esc back<//><//>
|
|
83
|
+
<//>
|
|
84
|
+
`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function ConfettiLab({ onBack }) {
|
|
88
|
+
const [run, setRun] = useState(1);
|
|
89
|
+
useInput((input, key) => {
|
|
90
|
+
if (key.escape || input === "q") return onBack();
|
|
91
|
+
if (key.return || input === " ") setRun((r) => r + 1);
|
|
92
|
+
});
|
|
93
|
+
return html`
|
|
94
|
+
<${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<//>
|
|
97
|
+
<//>
|
|
98
|
+
<${Box} height=${5}><${Confetti} key=${run} width=${PANEL_WIDTH} onDone=${() => {}} /><//>
|
|
99
|
+
<${Box} paddingX=${1}><${Text} dimColor>enter replay · esc back<//><//>
|
|
100
|
+
<//>
|
|
101
|
+
`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
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" }
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
function Menu({ selected, onMove, onPick, onQuit }) {
|
|
116
|
+
useInput((input, key) => {
|
|
117
|
+
if (key.escape || input === "q") return onQuit();
|
|
118
|
+
if (key.upArrow) return onMove(-1);
|
|
119
|
+
if (key.downArrow) return onMove(1);
|
|
120
|
+
if (key.return) onPick();
|
|
121
|
+
});
|
|
122
|
+
return html`
|
|
123
|
+
<${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<//><//>
|
|
126
|
+
<${Box} flexDirection="column" marginTop=${1}>
|
|
127
|
+
${SCENES.map(
|
|
128
|
+
(scene, i) => html`
|
|
129
|
+
<${Box} key=${scene.id}>
|
|
130
|
+
<${Box} width=${25} flexShrink=${0}>
|
|
131
|
+
<${Text} color=${i === selected ? theme.accent : undefined} bold=${i === selected}>${i === selected ? "❯" : " "} ${scene.label}<//>
|
|
132
|
+
<//>
|
|
133
|
+
<${Text} dimColor wrap="truncate-end">${scene.hint}<//>
|
|
134
|
+
<//>
|
|
135
|
+
`
|
|
136
|
+
)}
|
|
137
|
+
<//>
|
|
138
|
+
<//>
|
|
139
|
+
<${Box} paddingX=${1}><${Text} dimColor>↑/↓ choose · enter play · esc quit<//><//>
|
|
140
|
+
<//>
|
|
141
|
+
`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// `dracosh --preview`: a gallery of every scene and animation, to look at without playing for weeks.
|
|
145
|
+
export function Preview({ alerts }) {
|
|
146
|
+
const { exit } = useApp();
|
|
147
|
+
const [selected, setSelected] = useState(0);
|
|
148
|
+
const [scene, setScene] = useState(null);
|
|
149
|
+
const [run, setRun] = useState(0); // a fresh key per play, so every scene starts from its first frame
|
|
150
|
+
const back = () => setScene(null);
|
|
151
|
+
const history = useMemo(() => fakeSession({ progress: true }), []);
|
|
152
|
+
const quizSession = useMemo(() => fakeSession(), [run]); // every quiz run starts from zero
|
|
153
|
+
|
|
154
|
+
const wrap = (content) => html`<${Box} flexDirection="column" marginY=${1}>${content}<//>`;
|
|
155
|
+
|
|
156
|
+
function pick() {
|
|
157
|
+
const id = SCENES[selected].id;
|
|
158
|
+
if (id.startsWith("evolve-")) alerts.play("evolve"); // in the app the answer that triggers it plays this
|
|
159
|
+
setRun((r) => r + 1);
|
|
160
|
+
setScene(id);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (!scene) {
|
|
164
|
+
return wrap(html`<${Menu} selected=${selected} onMove=${(d) => setSelected((s) => (s + d + SCENES.length) % SCENES.length)} onPick=${pick} onQuit=${exit} />`);
|
|
165
|
+
}
|
|
166
|
+
if (scene === "hatch") return wrap(html`<${Hatch} key=${run} play=${alerts.play} onDone=${back} />`);
|
|
167
|
+
if (scene.startsWith("evolve-")) {
|
|
168
|
+
const to = Number(scene.slice("evolve-".length));
|
|
169
|
+
return wrap(html`<${Evolution} key=${run} from=${to - 1} to=${to} name=${STAGES[to].name} onClose=${back} />`);
|
|
170
|
+
}
|
|
171
|
+
if (scene === "mascot") return wrap(html`<${MascotLab} onBack=${back} />`);
|
|
172
|
+
if (scene === "confetti") return wrap(html`<${ConfettiLab} onBack=${back} />`);
|
|
173
|
+
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} />`);
|
|
175
|
+
if (scene === "summary")
|
|
176
|
+
return wrap(html`<${Summary} stats=${history.stats()} totals=${{ asked: 23, correct: 20 }} bestCombo=${9} onDone=${back} />`);
|
|
177
|
+
if (scene === "quiz") {
|
|
178
|
+
return html`<${App} key=${run} session=${quizSession} deck="Demo" initialSettings=${{ ...DEFAULTS, dailyGoal: 5, everyMs: 6000, tips: "always" }} alerts=${alerts} persistSettings=${async () => {}} onExit=${back} />`;
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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";
|
|
4
|
+
import { formatQuiet } from "../quiet.js";
|
|
5
|
+
import { Bar, html, PANEL_WIDTH, theme } from "./kit.js";
|
|
6
|
+
|
|
7
|
+
function VolumeValue({ value }) {
|
|
8
|
+
return html`<${Text}><${Bar} value=${value} max=${1} width=${10} /> ${Math.round(value * 100)}%<//>`;
|
|
9
|
+
}
|
|
10
|
+
|
|
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" }
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const nearestIndex = (options, value) => {
|
|
23
|
+
const exact = options.findIndex((option) => JSON.stringify(option) === JSON.stringify(value));
|
|
24
|
+
if (exact >= 0) return exact;
|
|
25
|
+
return options.reduce((best, option, i) => (Math.abs(option - value) < Math.abs(options[best] - value) ? i : best), 0);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Changes apply and persist immediately; there is no save step.
|
|
29
|
+
export function Settings({ settings, onChange, onClose }) {
|
|
30
|
+
const [row, setRow] = useState(0);
|
|
31
|
+
|
|
32
|
+
useInput((input, key) => {
|
|
33
|
+
if (key.escape || input === "q") return onClose();
|
|
34
|
+
if (key.upArrow) return setRow((r) => Math.max(0, r - 1));
|
|
35
|
+
if (key.downArrow) return setRow((r) => Math.min(ROWS.length - 1, r + 1));
|
|
36
|
+
|
|
37
|
+
const current = ROWS[row];
|
|
38
|
+
const direction = key.leftArrow ? -1 : key.rightArrow ? 1 : 0;
|
|
39
|
+
if (current.toggle && (direction || key.return || input === " ")) return onChange({ [current.key]: !settings[current.key] });
|
|
40
|
+
if (!direction) return;
|
|
41
|
+
const index = nearestIndex(current.options, settings[current.key]);
|
|
42
|
+
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 });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return html`
|
|
47
|
+
<${Fragment}>
|
|
48
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
|
|
49
|
+
<${Text} bold color=${theme.accent}>Settings<//>
|
|
50
|
+
<${Box} flexDirection="column" marginTop=${1}>
|
|
51
|
+
${ROWS.map(
|
|
52
|
+
(item, i) => html`
|
|
53
|
+
<${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 ? " ❯" : ""}<//>
|
|
56
|
+
<//>
|
|
57
|
+
`
|
|
58
|
+
)}
|
|
59
|
+
<//>
|
|
60
|
+
<${Box} marginTop=${1}><${Text} dimColor>${ROWS[row].hint}<//><//>
|
|
61
|
+
<//>
|
|
62
|
+
<${Box} paddingX=${1}><${Text} dimColor>↑/↓ select · ←/→ change · esc back<//><//>
|
|
63
|
+
<//>
|
|
64
|
+
`;
|
|
65
|
+
}
|
package/src/ui/Stats.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Fragment, useState } from "react";
|
|
2
|
+
import { Box, Text, useInput } from "ink";
|
|
3
|
+
import { formatRange } from "../vacation.js";
|
|
4
|
+
import { html, PANEL_WIDTH, theme } from "./kit.js";
|
|
5
|
+
|
|
6
|
+
const DAY_LETTERS = ["M", "T", "W", "T", "F", "S", "S"];
|
|
7
|
+
// One shape for every day; only the color tells them apart, GitHub-contribution style.
|
|
8
|
+
const TILE = {
|
|
9
|
+
goal: theme.good,
|
|
10
|
+
halfway: "#3f9d5e",
|
|
11
|
+
some: "#2f6b45",
|
|
12
|
+
none: "#3a3f47",
|
|
13
|
+
rest: "#2a2e35",
|
|
14
|
+
future: "#1c1f25",
|
|
15
|
+
today: theme.accent // today with nothing done yet
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function tileColor(cell, goal) {
|
|
19
|
+
if (cell.goalMet) return TILE.goal;
|
|
20
|
+
if (cell.correct > 0) return cell.correct >= goal / 2 ? TILE.halfway : TILE.some;
|
|
21
|
+
if (cell.today) return TILE.today;
|
|
22
|
+
if (cell.future) return TILE.future;
|
|
23
|
+
return cell.rest ? TILE.rest : TILE.none;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// A plain full-month grid: weeks as rows under one-letter day headers.
|
|
27
|
+
// Today: its weekday letter lights up, and its tile is violet until the first correct answer.
|
|
28
|
+
function Calendar({ month, goal }) {
|
|
29
|
+
const todayColumn = month.weeks.flat().findIndex((cell) => cell?.today) % 7;
|
|
30
|
+
return html`
|
|
31
|
+
<${Box} flexDirection="column">
|
|
32
|
+
<${Box}>
|
|
33
|
+
${DAY_LETTERS.map((letter, i) =>
|
|
34
|
+
i === todayColumn ? html`<${Text} key=${i} color=${theme.accent} bold>${letter} <//>` : html`<${Text} key=${i} dimColor>${letter} <//>`
|
|
35
|
+
)}
|
|
36
|
+
<//>
|
|
37
|
+
${month.weeks.map(
|
|
38
|
+
(week, w) => html`
|
|
39
|
+
<${Box} key=${w}>
|
|
40
|
+
${week.map((cell, d) => (cell ? html`<${Text} key=${d}><${Text} color=${tileColor(cell, goal)}>■<//> <//>` : html`<${Text} key=${d}> <//>`))}
|
|
41
|
+
<//>
|
|
42
|
+
`
|
|
43
|
+
)}
|
|
44
|
+
<//>
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function Legend({ goal }) {
|
|
49
|
+
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"]
|
|
56
|
+
];
|
|
57
|
+
return html`
|
|
58
|
+
<${Text}>
|
|
59
|
+
${items.map(([color, label]) => html`<${Text} key=${label}><${Text} color=${color}>■<//><${Text} dimColor> ${label} <//><//>`)}
|
|
60
|
+
<//>
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function Stats({ stats, getMonth, onClose }) {
|
|
65
|
+
const [offset, setOffset] = useState(0);
|
|
66
|
+
useInput((input, key) => {
|
|
67
|
+
if (key.escape || key.return || input === "q") return onClose();
|
|
68
|
+
if (key.leftArrow) return setOffset((o) => o - 1);
|
|
69
|
+
if (key.rightArrow) return setOffset((o) => Math.min(0, o + 1));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const { streak, today, goal, companion } = stats;
|
|
73
|
+
const accuracy = today.asked ? Math.round((today.correct / today.asked) * 100) : null;
|
|
74
|
+
const unlocked = stats.badges.filter((b) => b.unlockedOn).length;
|
|
75
|
+
const month = getMonth(offset);
|
|
76
|
+
const next = companion.nextAt ? ` · ${companion.nextName} at a ${companion.nextAt}-day streak` : " · fully evolved";
|
|
77
|
+
|
|
78
|
+
return html`
|
|
79
|
+
<${Fragment}>
|
|
80
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
|
|
81
|
+
<${Text} bold color=${theme.accent}>Stats<//>
|
|
82
|
+
|
|
83
|
+
<${Box} marginTop=${1} flexDirection="column">
|
|
84
|
+
<${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<//>
|
|
87
|
+
<//>
|
|
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
|
+
<//>
|
|
93
|
+
|
|
94
|
+
<${Box} marginTop=${1} flexDirection="column">
|
|
95
|
+
<${Text} bold>${month.label}<//>
|
|
96
|
+
<${Box} marginTop=${1}><${Calendar} month=${month} goal=${goal} /><//>
|
|
97
|
+
<${Box} marginTop=${1} flexDirection="column">
|
|
98
|
+
<${Text} dimColor>Goal reached on ${month.goalDays} of ${month.daysSoFar} days · ${month.correct} correct answers<//>
|
|
99
|
+
<${Legend} goal=${goal} />
|
|
100
|
+
<//>
|
|
101
|
+
<//>
|
|
102
|
+
|
|
103
|
+
<${Box} marginTop=${1}><${Text} dimColor>${unlocked}/${stats.badges.length} badges · /badges lists them all<//><//>
|
|
104
|
+
<//>
|
|
105
|
+
<${Box} paddingX=${1}><${Text} dimColor>←/→ month · esc back<//><//>
|
|
106
|
+
<//>
|
|
107
|
+
`;
|
|
108
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Fragment } from "react";
|
|
2
|
+
import { Box, Text, useInput } from "ink";
|
|
3
|
+
import { Bar, html, PANEL_WIDTH, theme } from "./kit.js";
|
|
4
|
+
import { Mascot, MASCOT_WIDTH } from "./Mascot.js";
|
|
5
|
+
|
|
6
|
+
// The end-of-session screen: how this run went, shown on quit. Any key leaves for real.
|
|
7
|
+
export function Summary({ stats, totals, bestCombo, onDone }) {
|
|
8
|
+
useInput(() => onDone());
|
|
9
|
+
const { streak, today, goal, companion } = stats;
|
|
10
|
+
const accuracy = totals.asked ? Math.round((totals.correct / totals.asked) * 100) : 0;
|
|
11
|
+
const face = today.goalMet ? "happy" : totals.correct > 0 ? "smile" : "idle";
|
|
12
|
+
|
|
13
|
+
return html`
|
|
14
|
+
<${Fragment}>
|
|
15
|
+
<${Box} borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${PANEL_WIDTH}>
|
|
16
|
+
<${Box} flexDirection="column" width=${MASCOT_WIDTH + 3}>
|
|
17
|
+
<${Mascot} face=${face} stage=${companion.index} />
|
|
18
|
+
<//>
|
|
19
|
+
<${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}` : ""}<//><//>
|
|
22
|
+
<${Box}>
|
|
23
|
+
<${Text} dimColor>today <//>
|
|
24
|
+
<${Bar} value=${today.correct} max=${goal} width=${12} color=${today.goalMet ? theme.good : theme.accent} />
|
|
25
|
+
<${Text} dimColor> ${Math.min(today.correct, goal)}/${goal}<//>
|
|
26
|
+
${today.goalMet && html`<${Text} color=${theme.good}> goal reached<//>`}
|
|
27
|
+
<//>
|
|
28
|
+
<${Box}><${Text} dimColor>${streak.days > 0 ? `🔥 ${streak.days}-day streak` : "no streak yet"}${streak.atRisk ? " · still at risk today" : ""}<//><//>
|
|
29
|
+
<//>
|
|
30
|
+
<//>
|
|
31
|
+
<${Box} paddingX=${1}><${Text} dimColor>see you later · any key to leave<//><//>
|
|
32
|
+
<//>
|
|
33
|
+
`;
|
|
34
|
+
}
|
package/src/ui/Tip.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Fragment, useState } from "react";
|
|
2
|
+
import { Box, Text, useInput } from "ink";
|
|
3
|
+
import { html, PANEL_WIDTH, theme } from "./kit.js";
|
|
4
|
+
|
|
5
|
+
// A full-screen grammar tip; Enter or → shows another one.
|
|
6
|
+
export function Tip({ nextTip, onClose }) {
|
|
7
|
+
const [tip, setTip] = useState(() => nextTip());
|
|
8
|
+
useInput((input, key) => {
|
|
9
|
+
if (key.escape || input === "q") return onClose();
|
|
10
|
+
if (key.return || key.rightArrow || input === " ") setTip(nextTip());
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return html`
|
|
14
|
+
<${Fragment}>
|
|
15
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
|
|
16
|
+
<${Box}>
|
|
17
|
+
<${Text} bold color=${theme.accent}>Grammar tip<//>
|
|
18
|
+
<${Text} dimColor> ${tip.cat}<//>
|
|
19
|
+
<//>
|
|
20
|
+
<${Box} marginTop=${1}><${Text}>${tip.text}<//><//>
|
|
21
|
+
<//>
|
|
22
|
+
<${Box} paddingX=${1}><${Text} dimColor>enter or → another tip · esc back<//><//>
|
|
23
|
+
<//>
|
|
24
|
+
`;
|
|
25
|
+
}
|
package/src/ui/icons.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { html } from "./kit.js";
|
|
2
|
+
import { PixelGrid } from "./Mascot.js";
|
|
3
|
+
|
|
4
|
+
// 8×8 pixel icons for the badge groups, drawn with the same half-block technique as the mascot.
|
|
5
|
+
// Letters are per-icon palette keys; "." is transparent.
|
|
6
|
+
const ICONS = {
|
|
7
|
+
trophy: {
|
|
8
|
+
palette: { G: "#fcd34d", D: "#b45309", W: "#fef3c7" },
|
|
9
|
+
grid: [
|
|
10
|
+
".GGGGGG.",
|
|
11
|
+
"GDGWGGDG",
|
|
12
|
+
"GDGGGGDG",
|
|
13
|
+
".DGGGGD.",
|
|
14
|
+
"..DGGD..",
|
|
15
|
+
"...GG...",
|
|
16
|
+
"..DGGD..",
|
|
17
|
+
".GGGGGG."
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
flame: {
|
|
21
|
+
palette: { R: "#f97316", Y: "#fbbf24", W: "#fef3c7" },
|
|
22
|
+
grid: [
|
|
23
|
+
"...R....",
|
|
24
|
+
"...RR.R.",
|
|
25
|
+
"..RRRR..",
|
|
26
|
+
".RRYYRR.",
|
|
27
|
+
".RYYYYR.",
|
|
28
|
+
".RYWWYR.",
|
|
29
|
+
"..YWWY..",
|
|
30
|
+
"...YY..."
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
book: {
|
|
34
|
+
palette: { B: "#9d7cd8", D: "#6b4fa0", W: "#efe6f7", L: "#cbb8e8" },
|
|
35
|
+
grid: [
|
|
36
|
+
"........",
|
|
37
|
+
".BBBBBB.",
|
|
38
|
+
"DBWWWWB.",
|
|
39
|
+
"DBWLLWB.",
|
|
40
|
+
"DBWWWWB.",
|
|
41
|
+
"DBWLLWB.",
|
|
42
|
+
".BBBBBB.",
|
|
43
|
+
"........"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
star: {
|
|
47
|
+
palette: { S: "#fbbf24", W: "#fef3c7" },
|
|
48
|
+
grid: [
|
|
49
|
+
"...S....",
|
|
50
|
+
"..SSS...",
|
|
51
|
+
"SSSWSSS.",
|
|
52
|
+
".SSWSS..",
|
|
53
|
+
"..SSS...",
|
|
54
|
+
".SS.SS..",
|
|
55
|
+
"SS...SS.",
|
|
56
|
+
"........"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
bolt: {
|
|
60
|
+
palette: { Y: "#fbbf24", W: "#fef3c7" },
|
|
61
|
+
grid: [
|
|
62
|
+
"...YYY..",
|
|
63
|
+
"..YYY...",
|
|
64
|
+
".YYYYY..",
|
|
65
|
+
"...YWY..",
|
|
66
|
+
"..YYY...",
|
|
67
|
+
".YYY....",
|
|
68
|
+
".YY.....",
|
|
69
|
+
"Y......."
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
sun: {
|
|
73
|
+
palette: { Y: "#fbbf24", O: "#f97316" },
|
|
74
|
+
grid: [
|
|
75
|
+
"Y..YY..Y",
|
|
76
|
+
"..YYYY..",
|
|
77
|
+
".YYOOYY.",
|
|
78
|
+
"YYOOOOYY",
|
|
79
|
+
"YYOOOOYY",
|
|
80
|
+
".YYOOYY.",
|
|
81
|
+
"..YYYY..",
|
|
82
|
+
"Y..YY..Y"
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
moon: {
|
|
86
|
+
palette: { M: "#7dd3fc", W: "#fef3c7" },
|
|
87
|
+
grid: [
|
|
88
|
+
"...MMM..",
|
|
89
|
+
"..MM..W.",
|
|
90
|
+
".MM.....",
|
|
91
|
+
".MM.....",
|
|
92
|
+
".MM...W.",
|
|
93
|
+
"..MM....",
|
|
94
|
+
"...MMM..",
|
|
95
|
+
"........"
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
calendar: {
|
|
99
|
+
palette: { C: "#9aa4b2", R: "#f87171", W: "#f4f4f5", G: "#4ade80" },
|
|
100
|
+
grid: [
|
|
101
|
+
".C.CC.C.",
|
|
102
|
+
"RRRRRRRR",
|
|
103
|
+
"CWWWWWWC",
|
|
104
|
+
"CWGWGWWC",
|
|
105
|
+
"CWWWWWWC",
|
|
106
|
+
"CWGWWGWC",
|
|
107
|
+
"CCCCCCCC",
|
|
108
|
+
"........"
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
snowflake: {
|
|
112
|
+
palette: { I: "#7dd3fc", W: "#e0f2fe" },
|
|
113
|
+
grid: [
|
|
114
|
+
"...I....",
|
|
115
|
+
".I.I.I..",
|
|
116
|
+
"..IWI...",
|
|
117
|
+
"IIIWIII.",
|
|
118
|
+
"..IWI...",
|
|
119
|
+
".I.I.I..",
|
|
120
|
+
"...I....",
|
|
121
|
+
"........"
|
|
122
|
+
]
|
|
123
|
+
},
|
|
124
|
+
arrows: {
|
|
125
|
+
palette: { A: "#4ade80", B: "#9d7cd8" },
|
|
126
|
+
grid: [
|
|
127
|
+
"..A.....",
|
|
128
|
+
".AA.....",
|
|
129
|
+
"AAAAAAA.",
|
|
130
|
+
".AA.....",
|
|
131
|
+
".....BB.",
|
|
132
|
+
".BBBBBBB",
|
|
133
|
+
".....BB.",
|
|
134
|
+
"....B..."
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
heart: {
|
|
138
|
+
palette: { H: "#f87171", W: "#fecaca" },
|
|
139
|
+
grid: [
|
|
140
|
+
"........",
|
|
141
|
+
".HH..HH.",
|
|
142
|
+
"HWHHHHHH",
|
|
143
|
+
"HWHHHHHH",
|
|
144
|
+
".HHHHHH.",
|
|
145
|
+
"..HHHH..",
|
|
146
|
+
"...HH...",
|
|
147
|
+
"........"
|
|
148
|
+
]
|
|
149
|
+
},
|
|
150
|
+
compass: {
|
|
151
|
+
palette: { C: "#9aa4b2", W: "#f4f4f5", R: "#f87171", B: "#64748b" },
|
|
152
|
+
grid: [
|
|
153
|
+
"..CCCC..",
|
|
154
|
+
".CWWWWC.",
|
|
155
|
+
"CWWWRWWC",
|
|
156
|
+
"CWWRRWWC",
|
|
157
|
+
"CWWBBWWC",
|
|
158
|
+
".CWBWWC.",
|
|
159
|
+
"..CCCC..",
|
|
160
|
+
"........"
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// which icon each badge gets, by badge id
|
|
166
|
+
const ICON_FOR = {
|
|
167
|
+
hello: "trophy",
|
|
168
|
+
"first-steps": "trophy",
|
|
169
|
+
century: "trophy",
|
|
170
|
+
"five-hundred": "trophy",
|
|
171
|
+
thousand: "trophy",
|
|
172
|
+
"two-thousand": "trophy",
|
|
173
|
+
"on-a-roll": "flame",
|
|
174
|
+
week: "flame",
|
|
175
|
+
fortnight: "flame",
|
|
176
|
+
month: "flame",
|
|
177
|
+
"hundred-days": "flame",
|
|
178
|
+
keeper: "book",
|
|
179
|
+
collector: "book",
|
|
180
|
+
dictionary: "book",
|
|
181
|
+
explorer: "compass",
|
|
182
|
+
flawless: "star",
|
|
183
|
+
overachiever: "star",
|
|
184
|
+
marathon: "star",
|
|
185
|
+
"hot-streak": "bolt",
|
|
186
|
+
unstoppable: "bolt",
|
|
187
|
+
"combo-master": "bolt",
|
|
188
|
+
"early-bird": "sun",
|
|
189
|
+
"night-owl": "moon",
|
|
190
|
+
comeback: "heart",
|
|
191
|
+
redemption: "heart",
|
|
192
|
+
frozen: "snowflake",
|
|
193
|
+
weekend: "calendar",
|
|
194
|
+
"perfect-week": "calendar",
|
|
195
|
+
regular: "calendar",
|
|
196
|
+
machine: "calendar",
|
|
197
|
+
"hundred-club": "calendar",
|
|
198
|
+
"both-ways": "arrows"
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const LOCKED_COLOR = "#4a5058";
|
|
202
|
+
|
|
203
|
+
export function BadgeIcon({ id, locked = false }) {
|
|
204
|
+
const icon = ICONS[ICON_FOR[id]] ?? ICONS.star;
|
|
205
|
+
const palette = locked ? Object.fromEntries(Object.keys(icon.palette).map((k) => [k, LOCKED_COLOR])) : icon.palette;
|
|
206
|
+
return html`<${PixelGrid} grid=${icon.grid.map((row) => [...row])} palette=${palette} />`;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export const ICON_WIDTH = 8;
|