dracosh 0.2.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 +16 -11
- 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 +3 -1
- package/src/backup.js +2 -1
- package/src/cardline.js +71 -0
- package/src/cli.js +39 -52
- package/src/commands.js +14 -12
- package/src/demo.js +11 -0
- package/src/diff.js +13 -7
- package/src/i18n.js +68 -0
- package/src/judge.js +24 -6
- package/src/library.js +62 -35
- package/src/lock.js +2 -1
- package/src/manage.js +150 -60
- package/src/pause.js +1 -2
- package/src/progress.js +76 -59
- package/src/quiet.js +3 -2
- package/src/scheduler.js +3 -6
- package/src/session.js +69 -19
- package/src/settings.js +13 -6
- package/src/starter.js +36 -27
- package/src/store.js +9 -7
- package/src/tips.js +12 -3
- package/src/ui/AddCard.js +405 -81
- package/src/ui/AnswerInput.js +22 -10
- package/src/ui/App.js +181 -50
- package/src/ui/BadgeUnlock.js +4 -3
- package/src/ui/Badges.js +9 -8
- package/src/ui/Choice.js +14 -9
- package/src/ui/Companion.js +13 -13
- package/src/ui/Confetti.js +2 -2
- package/src/ui/Decks.js +58 -8
- package/src/ui/DieRoll.js +9 -9
- package/src/ui/Evolution.js +7 -7
- package/src/ui/Hatch.js +7 -6
- package/src/ui/Header.js +58 -16
- package/src/ui/Help.js +31 -25
- package/src/ui/Mascot.js +1 -2
- package/src/ui/Missed.js +13 -12
- package/src/ui/Preview.js +48 -29
- package/src/ui/Reset.js +13 -14
- package/src/ui/Settings.js +26 -19
- package/src/ui/Stats.js +24 -23
- package/src/ui/Summary.js +10 -9
- package/src/ui/TheOne.js +7 -6
- package/src/ui/icons.js +1 -2
- package/src/ui/kit.js +34 -6
- package/src/vacation.js +2 -1
- package/src/words.js +2 -1
- package/data/tips.json +0 -32
package/src/ui/Choice.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Box,
|
|
2
|
-
import {
|
|
1
|
+
import { Box, useInput } from "ink";
|
|
2
|
+
import { t } from "../i18n.js";
|
|
3
|
+
import { cellWidth, html, Text, theme, usePanelWidth } from "./kit.js";
|
|
3
4
|
|
|
4
|
-
// A question's answers as a list: ↑/↓ and Enter, a number, or an option's own
|
|
5
|
+
// A question's answers as a list: ↑/↓ and Enter, a number, or an option's own keys ("t|y" in Polish).
|
|
5
6
|
// Each option: { label, note?, key?, danger? }; `danger` paints it red while it's chosen.
|
|
6
7
|
export function Choice({ options, selected, onMove, onPick, onCancel }) {
|
|
7
8
|
useInput((input, key) => {
|
|
@@ -9,20 +10,23 @@ export function Choice({ options, selected, onMove, onPick, onCancel }) {
|
|
|
9
10
|
if (key.upArrow) return onMove(Math.max(0, selected - 1));
|
|
10
11
|
if (key.downArrow) return onMove(Math.min(options.length - 1, selected + 1));
|
|
11
12
|
if (key.return) return onPick(selected);
|
|
12
|
-
const index = options.findIndex((o, i) => input === String(i + 1) || (o.key && input.toLowerCase()
|
|
13
|
+
const index = options.findIndex((o, i) => input === String(i + 1) || (o.key && o.key.split("|").includes(input.toLowerCase())));
|
|
13
14
|
if (index >= 0) onPick(index);
|
|
14
15
|
});
|
|
15
16
|
|
|
16
|
-
const
|
|
17
|
+
const panel = usePanelWidth();
|
|
18
|
+
const width = Math.max(...options.map((o) => cellWidth(o.label))) + 2;
|
|
19
|
+
// in a narrow pane the notes go under their labels instead of wrapping into a thin column
|
|
20
|
+
const stacked = options.some((o) => o.note && 5 + width + cellWidth(o.note) > panel - 6);
|
|
17
21
|
return html`
|
|
18
22
|
<${Box} flexDirection="column">
|
|
19
23
|
${options.map((o, i) => {
|
|
20
24
|
const on = i === selected;
|
|
21
25
|
const color = on ? (o.danger ? theme.bad : theme.accent) : undefined;
|
|
22
26
|
return html`
|
|
23
|
-
<${Box} key=${o.label}>
|
|
24
|
-
<${Box} flexShrink=${0}><${Text} color=${color} bold=${on}>${on ? "❯" : " "} ${i + 1}. ${o.label.
|
|
25
|
-
${o.note && html`<${Text} dimColor>${o.note}
|
|
27
|
+
<${Box} key=${o.label} flexDirection=${stacked ? "column" : "row"}>
|
|
28
|
+
<${Box} flexShrink=${0}><${Text} color=${color} bold=${on}>${on ? "❯" : " "} ${i + 1}. ${stacked ? o.label : o.label + " ".repeat(width - cellWidth(o.label))}<//><//>
|
|
29
|
+
${o.note && html`<${Box} marginLeft=${stacked ? 5 : 0}><${Text} dimColor>${o.note}<//><//>`}
|
|
26
30
|
<//>
|
|
27
31
|
`;
|
|
28
32
|
})}
|
|
@@ -30,4 +34,5 @@ export function Choice({ options, selected, onMove, onPick, onCancel }) {
|
|
|
30
34
|
`;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
// the footer under a list of choices; `end` is what Esc does there ("back" or "cancel")
|
|
38
|
+
export const choiceHints = (end = "back") => t(end === "cancel" ? "keyHints.choiceCancel" : "keyHints.choiceBack", { choose: t("choice.keys") });
|
package/src/ui/Companion.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { t } from "../i18n.js";
|
|
1
2
|
import { Fragment } from "react";
|
|
2
|
-
import { Box,
|
|
3
|
-
import {
|
|
4
|
-
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
3
|
+
import { Box, useInput } from "ink";
|
|
4
|
+
import { dragonName, elementName, STAGES } from "../progress.js";
|
|
5
|
+
import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
5
6
|
import { ELEMENT_COLOR, Mascot } from "./Mascot.js";
|
|
6
7
|
|
|
7
|
-
const requirement = (stage, locked) => (stage.from === 0 ? "
|
|
8
|
+
const requirement = (stage, locked) => (stage.from === 0 ? t("companion.fromStart") : t(locked ? "companion.needsDays" : "companion.days", { count: stage.from }));
|
|
8
9
|
|
|
9
10
|
// Every form of the companion. Forms you haven't reached are flat silhouettes named "???".
|
|
10
11
|
// Its moods aren't listed here on purpose: you find them out by playing.
|
|
@@ -17,29 +18,28 @@ export function Companion({ current, best, element = null, roll = null, onClose
|
|
|
17
18
|
return html`
|
|
18
19
|
<${Fragment}>
|
|
19
20
|
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
20
|
-
<${Text} bold color=${theme.accent}
|
|
21
|
+
<${Text} bold color=${theme.accent}>${t("companion.title")}<//>
|
|
21
22
|
<${Box} marginTop=${1}>
|
|
22
|
-
<${Text}
|
|
23
|
-
|
|
24
|
-
<${Text} bold>${STAGES[current].name}<//>
|
|
23
|
+
<${Text}>${t("companion.yourDragon")}<//>
|
|
24
|
+
<${Text} bold color=${element ? ELEMENT_COLOR[element] : undefined}>${dragonName(current, element)}<//>
|
|
25
25
|
<//>
|
|
26
|
-
<${Text} dimColor>${element ?
|
|
27
|
-
<${Box} marginTop=${1}><${Text} dimColor
|
|
26
|
+
<${Text} dimColor>${element ? `${t("companion.element", { element: elementName(element) })}${roll ? t("companion.rolled", { face: roll.face, day: roll.on }) : ""}` : t("companion.noElement")}<//>
|
|
27
|
+
<${Box} marginTop=${1}><${Text} dimColor>${t("companion.evolves", { count: best })}<//><//>
|
|
28
28
|
|
|
29
29
|
<${Box} marginTop=${1} flexWrap="wrap">
|
|
30
30
|
${STAGES.map((stage, i) => {
|
|
31
31
|
const locked = i > current;
|
|
32
32
|
return html`
|
|
33
|
-
<${Box} key=${stage.
|
|
33
|
+
<${Box} key=${stage.id} width=${22} flexDirection="column" marginBottom=${1}>
|
|
34
34
|
<${Box} flexDirection="column"><${Mascot} stage=${i} locked=${locked} face=${locked ? "idle" : "smile"} element=${element} /><//>
|
|
35
|
-
<${Text} bold=${i === current} color=${i === current ? theme.accent : undefined} dimColor=${locked}>${locked ? "
|
|
35
|
+
<${Text} bold=${i === current} color=${i === current ? theme.accent : undefined} dimColor=${locked}>${locked ? t("companion.unknown") : stage.name}${i === current ? t("companion.now") : ""}<//>
|
|
36
36
|
<${Text} dimColor>${requirement(stage, locked)}<//>
|
|
37
37
|
<//>
|
|
38
38
|
`;
|
|
39
39
|
})}
|
|
40
40
|
<//>
|
|
41
41
|
<//>
|
|
42
|
-
<${Box} paddingX=${1}><${KeyHints} text
|
|
42
|
+
<${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.back")} /><//>
|
|
43
43
|
<//>
|
|
44
44
|
`;
|
|
45
45
|
}
|
package/src/ui/Confetti.js
CHANGED
package/src/ui/Decks.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { Fragment, useEffect, useState } from "react";
|
|
2
|
-
import { Box,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { Box, useInput } from "ink";
|
|
3
|
+
import { t } from "../i18n.js";
|
|
4
|
+
import { Choice, choiceHints } from "./Choice.js";
|
|
5
|
+
import { cutToWidth, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
6
|
+
|
|
7
|
+
const DIRECTIONS = ["forward", "backward", "both"];
|
|
5
8
|
|
|
6
9
|
// /decks: your decks with their card counts; Enter quizzes the chosen one from now on, and
|
|
7
|
-
// "+ New deck" starts one (`onNew`).
|
|
8
|
-
|
|
10
|
+
// "+ New deck" starts one (`onNew`). → on a deck of yours: which way it's asked. Renaming and deleting
|
|
11
|
+
// decks come later.
|
|
12
|
+
export function Decks({ current, actions, onPick, onNew, onClose, onDirections }) {
|
|
9
13
|
const panel = usePanelWidth();
|
|
10
14
|
const [decks, setDecks] = useState(null);
|
|
11
15
|
const [picked, setPicked] = useState(0);
|
|
12
16
|
const [error, setError] = useState("");
|
|
17
|
+
const [setting, setSetting] = useState(null); // { deck, selected }: the direction being picked
|
|
18
|
+
const [message, setMessage] = useState("");
|
|
13
19
|
|
|
14
20
|
useEffect(() => {
|
|
15
21
|
actions.allDecks().then(
|
|
@@ -23,17 +29,60 @@ export function Decks({ current, actions, onPick, onNew, onClose }) {
|
|
|
23
29
|
|
|
24
30
|
useInput((input, key) => {
|
|
25
31
|
if (!decks?.length && (key.escape || input === "q")) onClose();
|
|
32
|
+
const deck = decks?.[picked];
|
|
33
|
+
if (key.rightArrow && !setting && deck && !deck.tour) {
|
|
34
|
+
setMessage("");
|
|
35
|
+
setSetting({ deck, selected: Math.max(0, DIRECTIONS.indexOf(deck.directions)) });
|
|
36
|
+
}
|
|
26
37
|
});
|
|
27
38
|
|
|
39
|
+
// progress of a direction turned off stays: turning it back on picks up where it was
|
|
40
|
+
async function setDirections(index) {
|
|
41
|
+
const { deck } = setting;
|
|
42
|
+
setSetting(null);
|
|
43
|
+
try {
|
|
44
|
+
const { cardIds } = await actions.setDirections(deck.name, DIRECTIONS[index]);
|
|
45
|
+
await onDirections?.(cardIds, DIRECTIONS[index]);
|
|
46
|
+
setDecks((all) => all.map((d) => (d.name === deck.name ? { ...d, directions: DIRECTIONS[index] } : d)));
|
|
47
|
+
setMessage(t("decks.directionSaved", { deck: deck.name }));
|
|
48
|
+
} catch (err) {
|
|
49
|
+
setError(err.message);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const short = (text) => cutToWidth(text, Math.max(12, Math.floor(panel / 2) - 8));
|
|
54
|
+
const directionOptions = (deck) => {
|
|
55
|
+
const [front, back] = deck.sample ? [short(deck.sample.front), short(deck.sample.back.join(" / "))] : [t("decks.front"), t("decks.back")];
|
|
56
|
+
return [
|
|
57
|
+
{ label: `${front} → ?`, note: deck.directions === "forward" ? t("decks.now") : "" },
|
|
58
|
+
{ label: `${back} → ?`, note: deck.directions === "backward" ? t("decks.now") : "" },
|
|
59
|
+
{ label: t("add.bothWays"), note: deck.directions === "both" ? t("decks.now") : "" }
|
|
60
|
+
];
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (setting)
|
|
64
|
+
return html`
|
|
65
|
+
<${Fragment}>
|
|
66
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
67
|
+
<${Text} bold color=${theme.accent}>${t("add.directionQuestion", { deck: setting.deck.name })}<//>
|
|
68
|
+
<${Box} marginTop=${1}>
|
|
69
|
+
<${Choice} options=${directionOptions(setting.deck)} selected=${setting.selected} onMove=${(selected) => setSetting((s) => ({ ...s, selected }))} onPick=${setDirections} onCancel=${() => setSetting(null)} />
|
|
70
|
+
<//>
|
|
71
|
+
<${Box} marginTop=${1}><${Text} dimColor>${t("decks.progressKept")}<//><//>
|
|
72
|
+
<//>
|
|
73
|
+
<${Box} paddingX=${1}><${KeyHints} text=${choiceHints()} /><//>
|
|
74
|
+
<//>
|
|
75
|
+
`;
|
|
76
|
+
|
|
28
77
|
return html`
|
|
29
78
|
<${Fragment}>
|
|
30
79
|
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
31
|
-
<${Text} bold color=${theme.accent}
|
|
80
|
+
<${Text} bold color=${theme.accent}>${t("decks.title")}<//>
|
|
32
81
|
${decks?.length > 0 &&
|
|
33
82
|
html`
|
|
34
83
|
<${Box} marginTop=${1}>
|
|
35
84
|
<${Choice}
|
|
36
|
-
options=${[...decks.map((d) => ({ label: d.name, note:
|
|
85
|
+
options=${[...decks.map((d) => ({ label: d.name, note: [t("count.cards", { count: d.cards }), d.tour && t("decks.tour"), d.name === current && t("decks.now")].filter(Boolean).join(" · ") })), { label: t("decks.newDeck") }]}
|
|
37
86
|
selected=${picked}
|
|
38
87
|
onMove=${setPicked}
|
|
39
88
|
onPick=${(i) => (i === decks.length ? onNew() : onPick(decks[i].name))}
|
|
@@ -41,9 +90,10 @@ export function Decks({ current, actions, onPick, onNew, onClose }) {
|
|
|
41
90
|
/>
|
|
42
91
|
<//>
|
|
43
92
|
`}
|
|
93
|
+
${message && html`<${Box} marginTop=${1}><${Text} color=${theme.good}>${message}<//><//>`}
|
|
44
94
|
${error && html`<${Box} marginTop=${1}><${Text} color=${theme.bad}>${error}<//><//>`}
|
|
45
95
|
<//>
|
|
46
|
-
<${Box} paddingX=${1}><${KeyHints} text=${
|
|
96
|
+
<${Box} paddingX=${1}><${KeyHints} text=${decks?.[picked] && !decks[picked].tour ? t("keyHints.decks", { choose: choiceHints() }) : choiceHints()} /><//>
|
|
47
97
|
<//>
|
|
48
98
|
`;
|
|
49
99
|
}
|
package/src/ui/DieRoll.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { t } from "../i18n.js";
|
|
1
2
|
import React, { Fragment, useEffect, useState } from "react";
|
|
2
|
-
import { Box,
|
|
3
|
-
import { ELEMENTS } from "../progress.js";
|
|
4
|
-
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
3
|
+
import { Box, useInput } from "ink";
|
|
4
|
+
import { elementName, ELEMENTS } from "../progress.js";
|
|
5
|
+
import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
5
6
|
import { ELEMENT_COLOR, Mascot } from "./Mascot.js";
|
|
6
7
|
|
|
7
8
|
const FRAME_MS = 80;
|
|
@@ -16,7 +17,6 @@ const FACES = {
|
|
|
16
17
|
5: ["tl", "tr", "c", "bl", "br"],
|
|
17
18
|
6: ["tl", "tr", "ml", "mr", "bl", "br"]
|
|
18
19
|
};
|
|
19
|
-
const ELEMENT_NAME = { earth: "Earth", wind: "Wind", water: "Water", ice: "Ice", fire: "Fire", cosmos: "Cosmos" };
|
|
20
20
|
|
|
21
21
|
// timeline, in frames: tumbling (faces change, slower and slower, bouncing lower) → landed → the dragon changes
|
|
22
22
|
const LAND_AT = 30;
|
|
@@ -78,7 +78,7 @@ export function DieRoll({ element, stage = 0, onClose, play = () => {} }) {
|
|
|
78
78
|
return html`
|
|
79
79
|
<${Fragment}>
|
|
80
80
|
<${Box} flexDirection="column" borderStyle="round" borderColor=${landed ? color : theme.warn} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
|
|
81
|
-
<${Text} bold color=${theme.warn}
|
|
81
|
+
<${Text} bold color=${theme.warn}>${t("die.title")}<//>
|
|
82
82
|
<${Box} marginTop=${1} alignItems="flex-end">
|
|
83
83
|
<${Box} flexDirection="column" marginBottom=${bounce} marginRight=${4}>
|
|
84
84
|
<${BigGrid} grid=${dieGrid(face, landed ? color : "#2a2440")} />
|
|
@@ -91,14 +91,14 @@ export function DieRoll({ element, stage = 0, onClose, play = () => {} }) {
|
|
|
91
91
|
${revealed
|
|
92
92
|
? html`
|
|
93
93
|
<${Fragment}>
|
|
94
|
-
<${Text} bold color=${color}>${result
|
|
95
|
-
<${Text} dimColor
|
|
94
|
+
<${Text} bold color=${color}>${t("die.result", { face: result, element: elementName(element) })}<//>
|
|
95
|
+
<${Text} dimColor>${t("die.awakened", { element: elementName(element) })}<//>
|
|
96
96
|
<//>
|
|
97
97
|
`
|
|
98
|
-
: html`<${Text} dimColor>${landed ?
|
|
98
|
+
: html`<${Text} dimColor>${landed ? t("die.result", { face: result, element: elementName(element) }) : t("die.rolling")}<//>`}
|
|
99
99
|
<//>
|
|
100
100
|
<//>
|
|
101
|
-
<${Box} paddingX=${1}><${KeyHints} text=${revealed ? "
|
|
101
|
+
<${Box} paddingX=${1}><${KeyHints} text=${t(revealed ? "die.keysContinue" : "die.keysSkip")} /><//>
|
|
102
102
|
<//>
|
|
103
103
|
`;
|
|
104
104
|
}
|
package/src/ui/Evolution.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { t } from "../i18n.js";
|
|
1
2
|
import { Fragment, useEffect, useState } from "react";
|
|
2
|
-
import { Box,
|
|
3
|
-
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
3
|
+
import { Box, useInput } from "ink";
|
|
4
|
+
import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
4
5
|
import { Mascot } from "./Mascot.js";
|
|
5
6
|
|
|
6
7
|
const FRAME_MS = 120;
|
|
@@ -8,7 +9,6 @@ const FLASH_FROM = 6; // frames 0..5: the old form, wondering
|
|
|
8
9
|
const REVEAL_AT = 16; // frames 6..15: white-out flashing, then the new form
|
|
9
10
|
const SPARKS = ["✦", "·", "✧", "*"];
|
|
10
11
|
|
|
11
|
-
const article = (name) => (/^[aeiou]/i.test(name) ? "an" : "a");
|
|
12
12
|
|
|
13
13
|
// a loose ring of sparkles around the sprite; which ones show varies per frame
|
|
14
14
|
function sparkleRow(frame, seed, width) {
|
|
@@ -41,7 +41,7 @@ export function Evolution({ from, to, name, element = null, onClose }) {
|
|
|
41
41
|
return html`
|
|
42
42
|
<${Fragment}>
|
|
43
43
|
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.warn} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
|
|
44
|
-
<${Text} bold color=${theme.warn}>✦
|
|
44
|
+
<${Text} bold color=${theme.warn}>✦ ${t("evolution.title")} ✦<//>
|
|
45
45
|
<${Box} flexDirection="column" marginTop=${1} alignItems="center">
|
|
46
46
|
<${Text} color=${theme.warn}>${sparks ? sparkleRow(frame, 1, 30) : " "}<//>
|
|
47
47
|
<${Mascot} stage=${stage} face=${revealed ? "happy" : "idle"} flash=${flashing && frame % 2 === 0} scale=${2} element=${element} />
|
|
@@ -49,11 +49,11 @@ export function Evolution({ from, to, name, element = null, onClose }) {
|
|
|
49
49
|
<//>
|
|
50
50
|
<${Box} marginTop=${1} flexDirection="column" alignItems="center">
|
|
51
51
|
${revealed
|
|
52
|
-
? html`<${Text} bold color=${theme.accent}
|
|
53
|
-
: html`<${Text} dimColor
|
|
52
|
+
? html`<${Text} bold color=${theme.accent}>${t("evolution.evolved", { name })}<//>`
|
|
53
|
+
: html`<${Text} dimColor>${t("evolution.happening")}<//>`}
|
|
54
54
|
<//>
|
|
55
55
|
<//>
|
|
56
|
-
<${Box} paddingX=${1}><${KeyHints} text=${revealed ? "
|
|
56
|
+
<${Box} paddingX=${1}><${KeyHints} text=${t(revealed ? "evolution.keysContinue" : "evolution.keysHurry")} /><//>
|
|
57
57
|
<//>
|
|
58
58
|
`;
|
|
59
59
|
}
|
package/src/ui/Hatch.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { t } from "../i18n.js";
|
|
1
2
|
import React, { Fragment, useEffect, useState } from "react";
|
|
2
|
-
import { Box,
|
|
3
|
-
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
3
|
+
import { Box, useInput } from "ink";
|
|
4
|
+
import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
4
5
|
import { Mascot } from "./Mascot.js";
|
|
5
6
|
|
|
6
7
|
const FRAME_MS = 110;
|
|
@@ -72,7 +73,7 @@ export function Hatch({ onDone, play = () => {} }) {
|
|
|
72
73
|
useInput(() => (revealed ? onDone() : setFrame(REVEAL_AT)));
|
|
73
74
|
|
|
74
75
|
const flashing = frame >= FLASH_AT && !revealed;
|
|
75
|
-
const caption = revealed ? "" : frame >= CRACK_AT[0] ? "
|
|
76
|
+
const caption = revealed ? "" : t(frame >= CRACK_AT[0] ? "hatch.hatching" : "hatch.stirs");
|
|
76
77
|
|
|
77
78
|
return html`
|
|
78
79
|
<${Fragment}>
|
|
@@ -87,14 +88,14 @@ export function Hatch({ onDone, play = () => {} }) {
|
|
|
87
88
|
${revealed
|
|
88
89
|
? html`
|
|
89
90
|
<${Fragment}>
|
|
90
|
-
<${Text} bold color=${theme.good}
|
|
91
|
-
<${Text} dimColor
|
|
91
|
+
<${Text} bold color=${theme.good}>${t("hatch.hatched")}<//>
|
|
92
|
+
<${Text} dimColor>${t("hatch.line")}<//>
|
|
92
93
|
<//>
|
|
93
94
|
`
|
|
94
95
|
: html`<${Text} dimColor>${caption}<//>`}
|
|
95
96
|
<//>
|
|
96
97
|
<//>
|
|
97
|
-
<${Box} paddingX=${1}><${KeyHints} text=${revealed ? "
|
|
98
|
+
<${Box} paddingX=${1}><${KeyHints} text=${t(revealed ? "hatch.keysStart" : "hatch.keysSkip")} /><//>
|
|
98
99
|
<//>
|
|
99
100
|
`;
|
|
100
101
|
}
|
package/src/ui/Header.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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";
|
|
6
7
|
import { Flame } from "./icons.js";
|
|
7
8
|
import { Mascot, MASCOT_WIDTH } from "./Mascot.js";
|
|
8
9
|
|
|
@@ -77,11 +78,52 @@ export function Snore({ tick }) {
|
|
|
77
78
|
`;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
|
|
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;
|
|
81
110
|
const { streak, today, goal, companion } = stats;
|
|
82
111
|
const move = useMove(event);
|
|
83
112
|
const blinking = useBlink();
|
|
84
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);
|
|
85
127
|
const shown = asleep ? "sleep" : blinking && BLINKABLE.has(face) ? "blink" : face;
|
|
86
128
|
return html`
|
|
87
129
|
<${Box} paddingX=${1}>
|
|
@@ -94,22 +136,22 @@ export function Header({ deck, everyMs, wordCount, stats, combo, face, event, ti
|
|
|
94
136
|
<${Box} flexDirection="column" justifyContent="center">
|
|
95
137
|
<${Box}>
|
|
96
138
|
<${Box} flexShrink=${0}><${Text} bold color=${theme.accent}>Dracosh<//><//>
|
|
97
|
-
<${Text} dimColor wrap="truncate-end"
|
|
139
|
+
<${Text} dimColor wrap="truncate-end">${deckLine({ deck, wordCount, pace, room })}<//>
|
|
98
140
|
<//>
|
|
99
|
-
<${Box}>
|
|
141
|
+
<${Box} height=${1} overflow="hidden">
|
|
100
142
|
${streak.days > 0
|
|
101
|
-
? html`<${Box}><${Flame} /><${Text} color=${theme.warn} bold
|
|
102
|
-
: html`<${Text} dimColor
|
|
103
|
-
${
|
|
104
|
-
${
|
|
105
|
-
${
|
|
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 })}<//>`}
|
|
106
148
|
<//>
|
|
107
|
-
<${Box}>
|
|
108
|
-
<${Text} dimColor
|
|
109
|
-
|
|
110
|
-
<${Text} dimColor
|
|
111
|
-
${
|
|
112
|
-
${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 })}<//>`}
|
|
113
155
|
<//>
|
|
114
156
|
<//>
|
|
115
157
|
<//>
|
package/src/ui/Help.js
CHANGED
|
@@ -1,32 +1,38 @@
|
|
|
1
1
|
import { Fragment } from "react";
|
|
2
|
-
import { Box,
|
|
2
|
+
import { Box, useInput } from "ink";
|
|
3
|
+
import { t } from "../i18n.js";
|
|
3
4
|
import { MAX_FREEZES } from "../progress.js";
|
|
4
5
|
import { BOX_INTERVALS_DAYS } from "../scheduler.js";
|
|
5
|
-
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
6
|
+
import { cellWidth, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
["
|
|
10
|
-
["
|
|
11
|
-
["
|
|
12
|
-
["
|
|
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")]
|
|
13
16
|
];
|
|
14
17
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
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 })
|
|
20
24
|
];
|
|
21
25
|
|
|
22
|
-
const
|
|
23
|
-
[
|
|
24
|
-
["dracosh --data", "
|
|
25
|
-
["dracosh restore", "
|
|
26
|
-
["dracosh --help", "
|
|
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")]
|
|
27
31
|
];
|
|
28
32
|
|
|
29
|
-
|
|
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;
|
|
30
36
|
return rows.map(
|
|
31
37
|
([left, right]) => html`
|
|
32
38
|
<${Box} key=${left}>
|
|
@@ -55,14 +61,14 @@ export function Help({ onClose }) {
|
|
|
55
61
|
return html`
|
|
56
62
|
<${Fragment}>
|
|
57
63
|
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
58
|
-
<${Text} bold color=${theme.accent}
|
|
59
|
-
<${Section} title
|
|
60
|
-
<${Section} title
|
|
61
|
-
${
|
|
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}<//><//>`)}
|
|
62
68
|
<//>
|
|
63
|
-
<${Section} title
|
|
69
|
+
<${Section} title=${t("help.outsideTitle")}><${Rows} rows=${outside()} /><//>
|
|
64
70
|
<//>
|
|
65
|
-
<${Box} paddingX=${1}><${KeyHints} text
|
|
71
|
+
<${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.back")} /><//>
|
|
66
72
|
<//>
|
|
67
73
|
`;
|
|
68
74
|
}
|
package/src/ui/Mascot.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
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
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.
|
package/src/ui/Missed.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { t } from "../i18n.js";
|
|
1
2
|
import { Fragment, useState } from "react";
|
|
2
|
-
import { Box,
|
|
3
|
-
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
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 }) {
|
|
@@ -23,11 +24,11 @@ export function Missed({ getMissed, onClose }) {
|
|
|
23
24
|
<${Fragment}>
|
|
24
25
|
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
25
26
|
<${Box}>
|
|
26
|
-
<${Text} bold color=${theme.accent}
|
|
27
|
-
<${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 })}<//>
|
|
28
29
|
<//>
|
|
29
30
|
${items.length === 0
|
|
30
|
-
? html`<${Box} marginTop=${1}><${Text} dimColor>${offset === 0 ? "
|
|
31
|
+
? html`<${Box} marginTop=${1}><${Text} dimColor>${t(offset === 0 ? "missed.nothingToday" : "missed.nothingThatDay")}<//><//>`
|
|
31
32
|
: html`
|
|
32
33
|
<${Box} flexDirection="column" marginTop=${1}>
|
|
33
34
|
${shown.map(
|
|
@@ -35,19 +36,19 @@ export function Missed({ getMissed, onClose }) {
|
|
|
35
36
|
<${Box} key=${item.key} flexDirection="column" marginBottom=${1}>
|
|
36
37
|
<${Text}>
|
|
37
38
|
<${Text} color=${item.recovered ? theme.good : theme.bad} bold>${item.recovered ? "✓" : "✗"}<//>
|
|
38
|
-
<${Text} bold> ${item.prompt}<//>
|
|
39
|
-
<${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 }) : ""}<//>
|
|
40
41
|
<//>
|
|
41
|
-
<${Text}> ${item.expected.join("
|
|
42
|
-
<${Text} dimColor> ${item.answer ?
|
|
42
|
+
<${Text}> ${item.expected.join(" / ")}<//>
|
|
43
|
+
<${Text} dimColor> ${item.answer ? t("missed.youWrote", { answer: item.answer }) : t("missed.noAnswer")}${item.recovered ? t("missed.recovered") : ""}<//>
|
|
43
44
|
<//>
|
|
44
45
|
`
|
|
45
46
|
)}
|
|
46
|
-
${items.length > MAX_ROWS && html`<${Text} dimColor
|
|
47
|
+
${items.length > MAX_ROWS && html`<${Text} dimColor>${t("missed.more", { count: items.length - MAX_ROWS })}<//>`}
|
|
47
48
|
<//>
|
|
48
49
|
`}
|
|
49
50
|
<//>
|
|
50
|
-
<${Box} paddingX=${1}><${KeyHints} text
|
|
51
|
+
<${Box} paddingX=${1}><${KeyHints} text=${t("missed.keys")} /><//>
|
|
51
52
|
<//>
|
|
52
53
|
`;
|
|
53
54
|
}
|