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.
- package/README.md +49 -22
- package/assets/sounds/badge-1.wav +0 -0
- package/assets/sounds/badge-2.wav +0 -0
- package/assets/sounds/badge-3.wav +0 -0
- package/assets/sounds/badge-4.wav +0 -0
- package/locales/de.json +1046 -0
- package/locales/en.json +1029 -0
- package/locales/fr.json +1094 -0
- package/locales/pl.json +1117 -0
- package/locales/uk.json +1118 -0
- package/package.json +2 -2
- package/src/alerts.js +7 -4
- package/src/backup.js +96 -0
- package/src/cardline.js +71 -0
- package/src/cli.js +106 -38
- package/src/commands.js +15 -13
- package/src/demo.js +11 -0
- package/src/diff.js +13 -7
- package/src/i18n.js +68 -0
- package/src/judge.js +51 -12
- package/src/library.js +154 -0
- package/src/lock.js +64 -0
- package/src/manage.js +165 -0
- package/src/pause.js +22 -0
- package/src/progress.js +202 -93
- package/src/quiet.js +4 -3
- package/src/scheduler.js +39 -30
- package/src/session.js +181 -33
- package/src/settings.js +15 -13
- package/src/starter.js +47 -0
- package/src/store.js +58 -17
- package/src/tips.js +17 -25
- package/src/ui/AddCard.js +496 -0
- package/src/ui/AnswerInput.js +28 -13
- package/src/ui/App.js +360 -89
- package/src/ui/BadgeUnlock.js +51 -0
- package/src/ui/Badges.js +79 -20
- package/src/ui/Choice.js +38 -0
- package/src/ui/Companion.js +24 -39
- package/src/ui/Confetti.js +2 -2
- package/src/ui/Decks.js +99 -0
- package/src/ui/DieRoll.js +104 -0
- package/src/ui/Evolution.js +11 -10
- package/src/ui/Hatch.js +9 -7
- package/src/ui/Header.js +62 -19
- package/src/ui/Help.js +74 -0
- package/src/ui/Mascot.js +89 -40
- package/src/ui/Missed.js +15 -13
- package/src/ui/Preview.js +123 -29
- package/src/ui/Reset.js +71 -0
- package/src/ui/Settings.js +34 -23
- package/src/ui/Stats.js +28 -24
- package/src/ui/Summary.js +18 -10
- package/src/ui/TheOne.js +122 -0
- package/src/ui/icons.js +156 -25
- package/src/ui/kit.js +87 -2
- package/src/vacation.js +9 -3
- package/src/words.js +22 -14
- package/assets/sounds/badge.wav +0 -0
- package/data/tips.json +0 -1362
- package/src/ui/Tip.js +0 -25
package/src/ui/Header.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { t } from "../i18n.js";
|
|
3
|
+
import { Box, useStdout } from "ink";
|
|
3
4
|
import { formatInterval } from "../settings.js";
|
|
4
5
|
import { formatDay } from "../vacation.js";
|
|
5
|
-
import { AnimatedBar, html, theme } from "./kit.js";
|
|
6
|
+
import { AnimatedBar, cellWidth, cutToWidth, html, Text, theme } from "./kit.js";
|
|
7
|
+
import { Flame } from "./icons.js";
|
|
6
8
|
import { Mascot, MASCOT_WIDTH } from "./Mascot.js";
|
|
7
9
|
|
|
8
10
|
const FRAME_MS = 90;
|
|
@@ -76,39 +78,80 @@ export function Snore({ tick }) {
|
|
|
76
78
|
`;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
// "Polish · 50 cards · every 10 min", shortened from the end in a narrow pane: the interval goes
|
|
82
|
+
// first, then the card count, and only then is the deck's name cut. A study session has no interval.
|
|
83
|
+
function deckLine({ deck, wordCount, pace, room }) {
|
|
84
|
+
const cards = wordCount ? t("header.cards", { cards: t("count.cards", { count: wordCount }) }) : "";
|
|
85
|
+
const tries = [pace && t("header.deckLine", { deck, cards, interval: pace }), ` ${deck}${cards}`, ` ${deck}`].filter(Boolean);
|
|
86
|
+
return tries.find((line) => cellWidth(line) <= room) ?? ` ${cutToWidth(deck, Math.max(4, room - 2))}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// The extras that fit beside what a row always shows, most important first: `[[name, text], …]` → Set of names
|
|
90
|
+
function fitting(base, extras, room) {
|
|
91
|
+
let used = base;
|
|
92
|
+
const shown = new Set();
|
|
93
|
+
for (const [name, text] of extras) {
|
|
94
|
+
if (!text) continue;
|
|
95
|
+
if (used + cellWidth(text) > room) break; // a smaller extra never jumps the queue
|
|
96
|
+
used += cellWidth(text);
|
|
97
|
+
shown.add(name);
|
|
98
|
+
}
|
|
99
|
+
return shown;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const BAR_WIDTH = 12;
|
|
103
|
+
const MIN_BAR_WIDTH = 4;
|
|
104
|
+
|
|
105
|
+
export function Header({ deck, everyMs, rhythm = "minutes", wordCount, stats, combo, face, event, tick = 0, asleep = false }) {
|
|
106
|
+
const { stdout } = useStdout();
|
|
107
|
+
const rowRoom = (stdout?.columns || 80) - MASCOT_WIDTH - 3 - 2;
|
|
108
|
+
const room = rowRoom - "Dracosh".length;
|
|
109
|
+
const pace = rhythm === "minutes" ? formatInterval(everyMs) : null;
|
|
80
110
|
const { streak, today, goal, companion } = stats;
|
|
81
111
|
const move = useMove(event);
|
|
82
112
|
const blinking = useBlink();
|
|
83
113
|
const hot = combo >= 3 && !asleep;
|
|
114
|
+
// a narrow pane keeps the streak and today's count; the extras beside them go when they don't fit
|
|
115
|
+
const streakText = streak.days > 0 ? t("header.streak", { count: streak.days }) : t("header.noStreak");
|
|
116
|
+
const second = fitting(cellWidth(streakText) + (streak.days > 0 ? 1 : 0), [
|
|
117
|
+
["atRisk", streak.atRisk && t("header.atRisk")],
|
|
118
|
+
["daysOff", stats.vacation.activeUntil && t("header.daysOffUntil", { day: formatDay(stats.vacation.activeUntil) })],
|
|
119
|
+
["freezes", streak.freezes > 0 && t("header.freezes", { count: streak.freezes })]
|
|
120
|
+
], rowRoom);
|
|
121
|
+
const count = ` ${Math.min(today.correct, goal)}/${goal}`;
|
|
122
|
+
const barWidth = Math.min(BAR_WIDTH, rowRoom - cellWidth(t("header.today")) - cellWidth(count));
|
|
123
|
+
const third = fitting(cellWidth(t("header.today")) + Math.max(0, barWidth) + cellWidth(count), [
|
|
124
|
+
["combo", combo >= 2 && t("header.combo", { count: combo })],
|
|
125
|
+
["goal", today.goalMet && t("header.goalReached")]
|
|
126
|
+
], rowRoom);
|
|
84
127
|
const shown = asleep ? "sleep" : blinking && BLINKABLE.has(face) ? "blink" : face;
|
|
85
128
|
return html`
|
|
86
129
|
<${Box} paddingX=${1}>
|
|
87
|
-
<${Box} width=${MASCOT_WIDTH + 3}>
|
|
130
|
+
<${Box} width=${MASCOT_WIDTH + 3} flexShrink=${0}>
|
|
88
131
|
<${Box} flexDirection="column" width=${MASCOT_WIDTH}>
|
|
89
|
-
<${Mascot} face=${shown} hot=${hot} flicker=${hot && tick % 2 === 0} stage=${companion.index} dx=${move.dx ?? 0} dy=${move.dy ?? 0} />
|
|
132
|
+
<${Mascot} face=${shown} hot=${hot} flicker=${hot && tick % 2 === 0} stage=${companion.index} element=${companion.element} dx=${move.dx ?? 0} dy=${move.dy ?? 0} />
|
|
90
133
|
<//>
|
|
91
134
|
${asleep && html`<${Snore} tick=${tick} />`}
|
|
92
135
|
<//>
|
|
93
136
|
<${Box} flexDirection="column" justifyContent="center">
|
|
94
137
|
<${Box}>
|
|
95
|
-
<${Text} bold color=${theme.accent}>Dracosh
|
|
96
|
-
<${Text} dimColor
|
|
138
|
+
<${Box} flexShrink=${0}><${Text} bold color=${theme.accent}>Dracosh<//><//>
|
|
139
|
+
<${Text} dimColor wrap="truncate-end">${deckLine({ deck, wordCount, pace, room })}<//>
|
|
97
140
|
<//>
|
|
98
|
-
<${Box}>
|
|
141
|
+
<${Box} height=${1} overflow="hidden">
|
|
99
142
|
${streak.days > 0
|
|
100
|
-
? html`<${Text} color=${theme.warn} bold
|
|
101
|
-
: html`<${Text} dimColor
|
|
102
|
-
${
|
|
103
|
-
${
|
|
104
|
-
${
|
|
143
|
+
? html`<${Box}><${Flame} /><${Text} color=${theme.warn} bold wrap="truncate-end">${streakText}<//><//>`
|
|
144
|
+
: html`<${Text} dimColor wrap="truncate-end">${streakText}<//>`}
|
|
145
|
+
${second.has("atRisk") && html`<${Text} color=${theme.warn}>${t("header.atRisk")}<//>`}
|
|
146
|
+
${second.has("daysOff") && html`<${Text} color=${theme.accent}>${t("header.daysOffUntil", { day: formatDay(stats.vacation.activeUntil) })}<//>`}
|
|
147
|
+
${second.has("freezes") && html`<${Text} dimColor>${t("header.freezes", { count: streak.freezes })}<//>`}
|
|
105
148
|
<//>
|
|
106
|
-
<${Box}>
|
|
107
|
-
<${Text} dimColor
|
|
108
|
-
|
|
109
|
-
<${Text} dimColor
|
|
110
|
-
${
|
|
111
|
-
${combo
|
|
149
|
+
<${Box} height=${1} overflow="hidden">
|
|
150
|
+
<${Text} dimColor>${t("header.today")}<//>
|
|
151
|
+
${barWidth >= MIN_BAR_WIDTH && html`<${AnimatedBar} value=${today.correct} max=${goal} width=${barWidth} color=${today.goalMet ? theme.good : theme.accent} />`}
|
|
152
|
+
<${Text} dimColor>${count}<//>
|
|
153
|
+
${third.has("goal") && html`<${Text} color=${theme.good}>${t("header.goalReached")}<//>`}
|
|
154
|
+
${third.has("combo") && html`<${Text} color=${theme.warn} bold>${t("header.combo", { count: combo })}<//>`}
|
|
112
155
|
<//>
|
|
113
156
|
<//>
|
|
114
157
|
<//>
|
package/src/ui/Help.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Fragment } from "react";
|
|
2
|
+
import { Box, useInput } from "ink";
|
|
3
|
+
import { t } from "../i18n.js";
|
|
4
|
+
import { MAX_FREEZES } from "../progress.js";
|
|
5
|
+
import { BOX_INTERVALS_DAYS } from "../scheduler.js";
|
|
6
|
+
import { cellWidth, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
7
|
+
|
|
8
|
+
// built at render time, so the texts follow the app language
|
|
9
|
+
const keys = () => [
|
|
10
|
+
[t("help.keys.enter"), t("help.keys.enterWhat")],
|
|
11
|
+
[t("help.keys.grade"), t("help.keys.gradeWhat")],
|
|
12
|
+
["/", t("help.keys.slashWhat")],
|
|
13
|
+
[t("help.keys.esc"), t("help.keys.escWhat")],
|
|
14
|
+
["q", t("help.keys.qWhat")],
|
|
15
|
+
[t("help.keys.anyKey"), t("help.keys.anyKeyWhat")]
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const how = () => [
|
|
19
|
+
t("help.how.boxes", { first: BOX_INTERVALS_DAYS.slice(0, -1).join(", "), last: BOX_INTERVALS_DAYS.at(-1) }),
|
|
20
|
+
t("help.how.typos"),
|
|
21
|
+
t("help.how.cards"),
|
|
22
|
+
t("help.how.streak"),
|
|
23
|
+
t("help.how.freezes", { max: MAX_FREEZES })
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const outside = () => [
|
|
27
|
+
[`dracosh --deck "${t("help.outside.deckExample")}"`, t("help.outside.deck")],
|
|
28
|
+
["dracosh --data", t("help.outside.data")],
|
|
29
|
+
["dracosh restore", t("help.outside.restore")],
|
|
30
|
+
["dracosh --help", t("help.outside.help")]
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
// the left column fits its longest entry, whatever the language
|
|
34
|
+
function Rows({ rows }) {
|
|
35
|
+
const width = Math.max(...rows.map(([left]) => cellWidth(left))) + 2;
|
|
36
|
+
return rows.map(
|
|
37
|
+
([left, right]) => html`
|
|
38
|
+
<${Box} key=${left}>
|
|
39
|
+
<${Box} width=${width} flexShrink=${0}><${Text} color=${theme.accent}>${left}<//><//>
|
|
40
|
+
<${Text}>${right}<//>
|
|
41
|
+
<//>
|
|
42
|
+
`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const Section = ({ title, children }) => html`
|
|
47
|
+
<${Box} flexDirection="column" marginTop=${1}>
|
|
48
|
+
<${Text} bold>${title}<//>
|
|
49
|
+
${children}
|
|
50
|
+
<//>
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
// How Dracosh works, on one screen: the keys, the rules behind the boxes and the streak,
|
|
54
|
+
// and what you can do from the shell.
|
|
55
|
+
export function Help({ onClose }) {
|
|
56
|
+
const panel = usePanelWidth();
|
|
57
|
+
useInput((input, key) => {
|
|
58
|
+
if (key.escape || key.return || input === "q") onClose();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return html`
|
|
62
|
+
<${Fragment}>
|
|
63
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
64
|
+
<${Text} bold color=${theme.accent}>${t("help.title")}<//>
|
|
65
|
+
<${Section} title=${t("help.keysTitle")}><${Rows} rows=${keys()} /><//>
|
|
66
|
+
<${Section} title=${t("help.howTitle")}>
|
|
67
|
+
${how().map((line) => html`<${Box} key=${line}><${Box} width=${2} flexShrink=${0}><${Text} dimColor>·<//><//><${Text}>${line}<//><//>`)}
|
|
68
|
+
<//>
|
|
69
|
+
<${Section} title=${t("help.outsideTitle")}><${Rows} rows=${outside()} /><//>
|
|
70
|
+
<//>
|
|
71
|
+
<${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.back")} /><//>
|
|
72
|
+
<//>
|
|
73
|
+
`;
|
|
74
|
+
}
|
package/src/ui/Mascot.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Text } from "
|
|
3
|
-
import { html } from "./kit.js";
|
|
2
|
+
import { html, Text } from "./kit.js";
|
|
4
3
|
|
|
5
|
-
// A
|
|
4
|
+
// A little dragon, drawn as pixels: every text row stacks two pixel rows using half blocks (▀ ▄ █).
|
|
6
5
|
// Proper pixel art: O = dark outline, L = top highlight, B = body, D = bottom shade.
|
|
7
|
-
// Its form (
|
|
8
|
-
const WIDTH =
|
|
6
|
+
// Its form (horns, wings, tail…) comes from the evolution stage, its expression from how you are doing.
|
|
7
|
+
const WIDTH = 14;
|
|
9
8
|
const BASE = [
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
9
|
+
"..............",
|
|
10
|
+
"...OOOOOOOO...",
|
|
11
|
+
"..OLLLLLLLLO..",
|
|
12
|
+
"..OBBEBBEBBO..",
|
|
13
|
+
"..OBBEBBEBBO..",
|
|
14
|
+
"..OBBBBBBBBO..",
|
|
15
|
+
"..ODBBBBBBDO..",
|
|
16
|
+
"...OOOOOOOO...",
|
|
17
|
+
"....OO..OO....",
|
|
18
|
+
".............."
|
|
20
19
|
];
|
|
21
20
|
|
|
22
21
|
// a little green dragon: scale-green body, cream belly, bone horns, golden spikes
|
|
@@ -31,37 +30,83 @@ const PALETTES = {
|
|
|
31
30
|
const ACCESSORY_COLORS = { H: "#e8dcc8", W: "#2f6b45", P: "#e6d79a", S: "#d9a441", G: "#fcd34d" };
|
|
32
31
|
const FLASH_ACCESSORIES = { H: "#ffffff", W: "#cfe6d4", P: "#ffffff", S: "#ffffff", G: "#ffffff" };
|
|
33
32
|
|
|
34
|
-
//
|
|
33
|
+
// The dragon's element, rolled once with "Dragon's die": its own body and accessory colors, plus a few
|
|
34
|
+
// details (X, Y) drawn before the evolution accessories, so horns, wings and the crown always show.
|
|
35
|
+
const ELEMENT_LOOKS = {
|
|
36
|
+
earth: {
|
|
37
|
+
body: { B: "#8b6d47", L: "#b8955f", D: "#5e4630", O: "#2e2216" },
|
|
38
|
+
accents: { H: "#d9cbb0", W: "#6b4f2e", P: "#c9b48a", S: "#a07c4f" },
|
|
39
|
+
colors: { X: "#7fb045", Y: "#6b5a44" },
|
|
40
|
+
details: [[2, 4, "X"], [2, 5, "X"], [2, 9, "X"], [6, 3, "Y"], [6, 10, "Y"]] // moss on the head, pebbles below
|
|
41
|
+
},
|
|
42
|
+
wind: {
|
|
43
|
+
body: { B: "#b4bfbc", L: "#e3e8e6", D: "#8a9592", O: "#4a5452" },
|
|
44
|
+
accents: { H: "#f0f3f2", W: "#9aa5a2", P: "#d5dcda", S: "#e3e8e6" },
|
|
45
|
+
colors: { X: "#eef2f1" },
|
|
46
|
+
details: [[3, 0, "X"], [4, 0, "X"], [4, 13, "X"], [8, 1, "X"]] // wisps of air around it
|
|
47
|
+
},
|
|
48
|
+
water: {
|
|
49
|
+
body: { B: "#3b82c4", L: "#7cb8e8", D: "#245d94", O: "#13304d" },
|
|
50
|
+
accents: { H: "#cfe8ff", W: "#1e5a8f", P: "#a5d3f5", S: "#7cb8e8" },
|
|
51
|
+
colors: { X: "#5fb3f0", Y: "#bfe3ff" },
|
|
52
|
+
details: [[1, 6, "X"], [1, 7, "X"], [3, 13, "Y"]] // a fin on the head, a drop of water
|
|
53
|
+
},
|
|
54
|
+
ice: {
|
|
55
|
+
body: { B: "#bfe6f5", L: "#ffffff", D: "#86c0d8", O: "#3d6f86" },
|
|
56
|
+
accents: { H: "#e0f7ff", W: "#86c0d8", P: "#ffffff", S: "#e0f7ff" },
|
|
57
|
+
colors: { X: "#e0f7ff", Y: "#ffffff" },
|
|
58
|
+
details: [[0, 3, "X"], [0, 10, "X"], [6, 4, "Y"], [6, 9, "Y"]] // crystal spikes, frost
|
|
59
|
+
},
|
|
60
|
+
fire: {
|
|
61
|
+
body: { B: "#e4572e", L: "#f59e5b", D: "#a8341c", O: "#4a140a" },
|
|
62
|
+
accents: { H: "#fde68a", W: "#a8341c", P: "#fbbf24", S: "#fbbf24" },
|
|
63
|
+
colors: { X: "#fbbf24", Y: "#fde68a" },
|
|
64
|
+
details: [[0, 5, "X"], [0, 8, "X"], [3, 0, "Y"], [3, 13, "Y"]] // flame tips, embers
|
|
65
|
+
},
|
|
66
|
+
cosmos: {
|
|
67
|
+
body: { B: "#3b2f7a", L: "#5b4bb0", D: "#30266a", O: "#2a2163", E: "#05030f", C: "#c084fc" },
|
|
68
|
+
accents: { H: "#c4b5fd", W: "#261d55", P: "#5b4bb0", S: "#c4b5fd" },
|
|
69
|
+
colors: { X: "#fef3c7" },
|
|
70
|
+
details: [[2, 3, "X"], [2, 10, "X"], [5, 10, "X"], [6, 3, "X"]] // stars on its body
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// one color that stands for each element in text (names, the die's pips)
|
|
75
|
+
export const ELEMENT_COLOR = { earth: "#a07c4f", wind: "#b4bfbc", water: "#3b82c4", ice: "#bfe6f5", fire: "#e4572e", cosmos: "#8b7cf6" };
|
|
76
|
+
|
|
77
|
+
// What each evolution stage adds on top of the previous one: [row, col, pixel]. The wings rise over
|
|
78
|
+
// the shoulders and never frame the face, so the later forms read as a dragon, not a maned lion.
|
|
35
79
|
const STAGE_EDITS = [
|
|
36
80
|
[], // 0 Hatchling
|
|
37
|
-
[[0,
|
|
38
|
-
[[
|
|
39
|
-
[[5,
|
|
40
|
-
[[0,
|
|
41
|
-
[[0,
|
|
81
|
+
[[0, 4, "H"], [1, 4, "H"], [0, 9, "H"], [1, 9, "H"]], // 1 Imp: upright horns
|
|
82
|
+
[[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
|
|
83
|
+
[[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
|
|
84
|
+
[[0, 1, "W"], [0, 12, "W"], [7, 12, "W"], [0, 6, "S"], [0, 7, "S"]], // 4 Dragon: wider wings, a thicker tail, a crest
|
|
85
|
+
[[0, 5, "G"], [0, 6, "G"], [0, 7, "G"], [0, 8, "G"]] // 5 Legend: a crown (and golden horns, see below)
|
|
42
86
|
];
|
|
43
87
|
const LEGEND = STAGE_EDITS.length - 1;
|
|
44
88
|
|
|
45
89
|
const OPEN_EYES = []; // the base already has them
|
|
46
|
-
const SHUT_EYES = [[3,
|
|
47
|
-
const SMILE = [[5,
|
|
48
|
-
const GRIN = [[5,
|
|
49
|
-
const FROWN = [[6,
|
|
90
|
+
const SHUT_EYES = [[3, 5, "B"], [3, 8, "B"]]; // only the lower eye pixel stays: half-closed
|
|
91
|
+
const SMILE = [[5, 5, "E"], [6, 6, "E"], [6, 7, "E"], [5, 8, "E"]];
|
|
92
|
+
const GRIN = [[5, 5, "E"], [5, 8, "E"], [6, 5, "E"], [6, 6, "E"], [6, 7, "E"], [6, 8, "E"]];
|
|
93
|
+
const FROWN = [[6, 5, "E"], [5, 6, "E"], [5, 7, "E"], [6, 8, "E"]];
|
|
50
94
|
|
|
51
95
|
// [row, col, pixel] edits for each expression, applied last
|
|
52
96
|
const FACES = {
|
|
53
|
-
idle: [...OPEN_EYES, [5,
|
|
54
|
-
blink: [...SHUT_EYES, [5,
|
|
97
|
+
idle: [...OPEN_EYES, [5, 6, "E"], [5, 7, "E"]], // straight little mouth
|
|
98
|
+
blink: [...SHUT_EYES, [5, 6, "E"], [5, 7, "E"]],
|
|
55
99
|
smile: SMILE, // content: today's goal is done
|
|
56
|
-
happy: [...SHUT_EYES, ...GRIN, [4,
|
|
57
|
-
sad: [...FROWN, [5,
|
|
100
|
+
happy: [...SHUT_EYES, ...GRIN, [4, 3, "C"], [4, 10, "C"]], // beaming, with blushing cheeks
|
|
101
|
+
sad: [...FROWN, [5, 9, "T"]], // a tear under the right eye
|
|
58
102
|
sleep: [...SHUT_EYES] // eyes shut, mouth relaxed away
|
|
59
103
|
};
|
|
60
104
|
|
|
61
|
-
// `
|
|
62
|
-
export function drawSprite(face, stage = 0, { dx = 0, dy = 0 } = {}) {
|
|
105
|
+
// `dx`/`dy` nudge the whole grid by columns / pixel rows (half a text row) for jump and shake frames
|
|
106
|
+
export function drawSprite(face, stage = 0, { dx = 0, dy = 0, element = null } = {}) {
|
|
63
107
|
const grid = BASE.map((row) => [...row]);
|
|
64
108
|
const apply = (edits) => edits.forEach(([r, c, pixel]) => (grid[r][c] = pixel));
|
|
109
|
+
if (ELEMENT_LOOKS[element]) apply(ELEMENT_LOOKS[element].details);
|
|
65
110
|
STAGE_EDITS.slice(0, stage + 1).forEach(apply);
|
|
66
111
|
apply(FACES[face] ?? FACES.idle);
|
|
67
112
|
if (!dx && !dy) return grid;
|
|
@@ -90,22 +135,26 @@ export function PixelGrid({ grid, palette }) {
|
|
|
90
135
|
return html`<${React.Fragment}>${rows}<//>`;
|
|
91
136
|
}
|
|
92
137
|
|
|
93
|
-
|
|
138
|
+
// A form you haven't reached: one flat color, no eyes or shading, so only the outline gives it away
|
|
139
|
+
const SILHOUETTE = "#2c3038";
|
|
140
|
+
const LOCKED = Object.fromEntries([..."BLDOECTHWPSGXY"].map((key) => [key, SILHOUETTE]));
|
|
94
141
|
|
|
95
|
-
function paletteFor({ locked, flash, hot, flicker, stage }) {
|
|
142
|
+
function paletteFor({ locked, flash, hot, flicker, stage, element }) {
|
|
96
143
|
if (locked) return LOCKED;
|
|
97
|
-
if (flash) return { ...FLASH_ACCESSORIES, ...PALETTES.flash };
|
|
98
|
-
const
|
|
99
|
-
const
|
|
144
|
+
if (flash) return { ...FLASH_ACCESSORIES, ...PALETTES.flash, X: "#ffffff", Y: "#ffffff" };
|
|
145
|
+
const look = ELEMENT_LOOKS[element];
|
|
146
|
+
const body = hot ? (flicker ? PALETTES.hot2 : PALETTES.hot) : { ...PALETTES.normal, ...look?.body };
|
|
147
|
+
const palette = { ...ACCESSORY_COLORS, ...look?.accents, ...look?.colors, ...body };
|
|
100
148
|
if (stage >= LEGEND) palette.H = ACCESSORY_COLORS.G; // Legend: golden horns under the halo
|
|
101
149
|
return palette;
|
|
102
150
|
}
|
|
103
151
|
|
|
104
152
|
// `locked` draws a dark silhouette (a form you haven't reached yet); `flash` whites it out (evolution);
|
|
105
153
|
// `flicker` alternates the hot palette; `scale: 2` draws one text row per pixel row, two chars per pixel.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
154
|
+
// `element` is the dragon's rolled element ("earth" … "cosmos"), or null for the default green dragon
|
|
155
|
+
export function Mascot({ face = "idle", hot = false, stage = 0, locked = false, flash = false, flicker = false, scale = 1, dx = 0, dy = 0, element = null }) {
|
|
156
|
+
const palette = paletteFor({ locked, flash, hot, flicker, stage, element });
|
|
157
|
+
const grid = drawSprite(face, stage, { dx, dy, element });
|
|
109
158
|
const rows = [];
|
|
110
159
|
if (scale === 2) {
|
|
111
160
|
for (let r = 0; r < grid.length; r++) {
|
|
@@ -118,7 +167,7 @@ export function Mascot({ face = "idle", hot = false, stage = 0, locked = false,
|
|
|
118
167
|
} else {
|
|
119
168
|
for (let r = 0; r < grid.length; r += 2) {
|
|
120
169
|
const cells = [];
|
|
121
|
-
for (let c = 0; c <
|
|
170
|
+
for (let c = 0; c < grid[r].length; c++) cells.push(cell(grid[r][c], grid[r + 1][c], palette, c));
|
|
122
171
|
rows.push(html`<${Text} key=${r}>${cells}<//>`);
|
|
123
172
|
}
|
|
124
173
|
}
|
package/src/ui/Missed.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { t } from "../i18n.js";
|
|
1
2
|
import { Fragment, useState } from "react";
|
|
2
|
-
import { Box,
|
|
3
|
-
import { html,
|
|
3
|
+
import { Box, useInput } from "ink";
|
|
4
|
+
import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
4
5
|
|
|
5
6
|
const MAX_ROWS = 10;
|
|
6
7
|
|
|
7
|
-
const dayLabel = (offset, date) => (offset === 0 ? "today" : offset === -1 ?
|
|
8
|
+
const dayLabel = (offset, date) => (offset === 0 ? t("missed.today") : offset === -1 ? t("missed.yesterday", { date }) : date);
|
|
8
9
|
|
|
9
10
|
// Words you got wrong on a day, with what you typed and whether you got them right afterwards.
|
|
10
11
|
export function Missed({ getMissed, onClose }) {
|
|
12
|
+
const panel = usePanelWidth();
|
|
11
13
|
const [offset, setOffset] = useState(0);
|
|
12
14
|
useInput((input, key) => {
|
|
13
15
|
if (key.escape || key.return || input === "q") return onClose();
|
|
@@ -20,13 +22,13 @@ export function Missed({ getMissed, onClose }) {
|
|
|
20
22
|
|
|
21
23
|
return html`
|
|
22
24
|
<${Fragment}>
|
|
23
|
-
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${
|
|
25
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
24
26
|
<${Box}>
|
|
25
|
-
<${Text} bold color=${theme.accent}
|
|
26
|
-
<${Text} dimColor> ${dayLabel(offset, date)} · ${
|
|
27
|
+
<${Text} bold color=${theme.accent}>${t("missed.title")}<//>
|
|
28
|
+
<${Text} dimColor> ${dayLabel(offset, date)} · ${t("count.cards", { count: items.length })}<//>
|
|
27
29
|
<//>
|
|
28
30
|
${items.length === 0
|
|
29
|
-
? html`<${Box} marginTop=${1}><${Text} dimColor>${offset === 0 ? "
|
|
31
|
+
? html`<${Box} marginTop=${1}><${Text} dimColor>${t(offset === 0 ? "missed.nothingToday" : "missed.nothingThatDay")}<//><//>`
|
|
30
32
|
: html`
|
|
31
33
|
<${Box} flexDirection="column" marginTop=${1}>
|
|
32
34
|
${shown.map(
|
|
@@ -34,19 +36,19 @@ export function Missed({ getMissed, onClose }) {
|
|
|
34
36
|
<${Box} key=${item.key} flexDirection="column" marginBottom=${1}>
|
|
35
37
|
<${Text}>
|
|
36
38
|
<${Text} color=${item.recovered ? theme.good : theme.bad} bold>${item.recovered ? "✓" : "✗"}<//>
|
|
37
|
-
<${Text} bold> ${item.prompt}<//>
|
|
38
|
-
<${Text} dimColor> ${item.label}${item.times > 1 ?
|
|
39
|
+
<${Text} bold> ${item.prompt.replaceAll("`", "")}<//>
|
|
40
|
+
<${Text} dimColor> ${item.label}${item.times > 1 ? t("missed.times", { count: item.times }) : ""}<//>
|
|
39
41
|
<//>
|
|
40
|
-
<${Text}> ${item.expected.join("
|
|
41
|
-
<${Text} dimColor>
|
|
42
|
+
<${Text}> ${item.expected.join(" / ")}<//>
|
|
43
|
+
<${Text} dimColor> ${item.answer ? t("missed.youWrote", { answer: item.answer }) : t("missed.noAnswer")}${item.recovered ? t("missed.recovered") : ""}<//>
|
|
42
44
|
<//>
|
|
43
45
|
`
|
|
44
46
|
)}
|
|
45
|
-
${items.length > MAX_ROWS && html`<${Text} dimColor
|
|
47
|
+
${items.length > MAX_ROWS && html`<${Text} dimColor>${t("missed.more", { count: items.length - MAX_ROWS })}<//>`}
|
|
46
48
|
<//>
|
|
47
49
|
`}
|
|
48
50
|
<//>
|
|
49
|
-
<${Box} paddingX=${1}><${
|
|
51
|
+
<${Box} paddingX=${1}><${KeyHints} text=${t("missed.keys")} /><//>
|
|
50
52
|
<//>
|
|
51
53
|
`;
|
|
52
54
|
}
|