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.
- package/README.md +42 -20
- 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/data/tips.json +31 -1361
- package/package.json +1 -1
- package/src/alerts.js +4 -3
- package/src/backup.js +95 -0
- package/src/cli.js +97 -16
- package/src/commands.js +7 -7
- package/src/judge.js +33 -12
- package/src/library.js +127 -0
- package/src/lock.js +63 -0
- package/src/manage.js +75 -0
- package/src/pause.js +23 -0
- package/src/progress.js +145 -53
- package/src/quiet.js +1 -1
- package/src/scheduler.js +38 -26
- package/src/session.js +128 -30
- package/src/settings.js +4 -9
- package/src/starter.js +38 -0
- package/src/store.js +55 -16
- package/src/tips.js +7 -24
- package/src/ui/AddCard.js +172 -0
- package/src/ui/AnswerInput.js +8 -5
- package/src/ui/App.js +211 -71
- package/src/ui/BadgeUnlock.js +50 -0
- package/src/ui/Badges.js +75 -17
- package/src/ui/Choice.js +33 -0
- package/src/ui/Companion.js +20 -35
- package/src/ui/Decks.js +49 -0
- package/src/ui/DieRoll.js +104 -0
- package/src/ui/Evolution.js +6 -5
- package/src/ui/Hatch.js +5 -4
- package/src/ui/Header.js +7 -6
- package/src/ui/Help.js +68 -0
- package/src/ui/Mascot.js +88 -38
- package/src/ui/Missed.js +6 -5
- package/src/ui/Preview.js +92 -17
- package/src/ui/Reset.js +72 -0
- package/src/ui/Settings.js +15 -11
- package/src/ui/Stats.js +10 -7
- package/src/ui/Summary.js +12 -5
- package/src/ui/TheOne.js +121 -0
- package/src/ui/icons.js +156 -24
- package/src/ui/kit.js +58 -1
- package/src/vacation.js +7 -2
- package/src/words.js +21 -14
- package/assets/sounds/badge.wav +0 -0
- package/src/ui/Tip.js +0 -25
package/src/ui/Badges.js
CHANGED
|
@@ -1,15 +1,64 @@
|
|
|
1
|
-
import { Fragment, useState } from "react";
|
|
1
|
+
import { Fragment, useEffect, useState } from "react";
|
|
2
2
|
import { Box, Text, useInput } from "ink";
|
|
3
|
-
import { html,
|
|
4
|
-
import { BadgeIcon, ICON_WIDTH } from "./icons.js";
|
|
3
|
+
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
4
|
+
import { badgeColor, BadgeIcon, ICON_WIDTH } from "./icons.js";
|
|
5
|
+
|
|
6
|
+
const COLUMNS = 3;
|
|
7
|
+
const COLUMN_WIDTH = 22; // fits "❯ ● " plus the longest badge name
|
|
8
|
+
|
|
9
|
+
// badges won since the last visit light up one after another
|
|
10
|
+
const FRAME_MS = 90;
|
|
11
|
+
const STAGGER = 7; // frames between two badges
|
|
12
|
+
const FLASH_FRAMES = [2, 4];
|
|
13
|
+
const LIT_FROM = 5;
|
|
14
|
+
const GREY = "#4a5058";
|
|
15
|
+
|
|
16
|
+
// a hidden badge reveals nothing until it's won
|
|
17
|
+
const SECRET = { name: "???", desc: "a secret, keep playing" };
|
|
18
|
+
const display = (badge) => (badge.hidden && !badge.unlockedOn ? { ...badge, ...SECRET } : badge);
|
|
19
|
+
const WHITE = "#ffffff";
|
|
20
|
+
|
|
21
|
+
// where a fresh badge is in its little animation: "waiting" (still looks locked), "flash", or "lit"
|
|
22
|
+
function phaseOf(freshIndex, frame) {
|
|
23
|
+
if (freshIndex < 0) return "lit";
|
|
24
|
+
const local = frame - freshIndex * STAGGER;
|
|
25
|
+
if (FLASH_FRAMES.includes(local)) return "flash";
|
|
26
|
+
return local >= LIT_FROM ? "lit" : "waiting";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Three columns of badges with a pixel-icon preview of the selected one. Badges in `fresh`
|
|
30
|
+
// (won since /badges was last opened) light up in order, and the preview follows them until
|
|
31
|
+
// a key is pressed. ↑/↓ walk a column, ←/→ jump between columns, esc closes.
|
|
32
|
+
export function Badges({ badges, fresh = [], onClose }) {
|
|
33
|
+
const panel = usePanelWidth();
|
|
34
|
+
const firstFresh = badges.findIndex((b) => b.id === fresh[0]);
|
|
35
|
+
const [selected, setSelected] = useState(firstFresh >= 0 ? firstFresh : 0);
|
|
36
|
+
const [following, setFollowing] = useState(fresh.length > 0);
|
|
37
|
+
const [frame, setFrame] = useState(0);
|
|
38
|
+
const rows = Math.ceil(badges.length / COLUMNS);
|
|
39
|
+
const animationEnd = (fresh.length - 1) * STAGGER + LIT_FROM;
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (!fresh.length) return undefined;
|
|
43
|
+
const timer = setInterval(() => {
|
|
44
|
+
setFrame((f) => {
|
|
45
|
+
if (f >= animationEnd) clearInterval(timer);
|
|
46
|
+
return f + 1;
|
|
47
|
+
});
|
|
48
|
+
}, FRAME_MS);
|
|
49
|
+
return () => clearInterval(timer);
|
|
50
|
+
}, []);
|
|
51
|
+
|
|
52
|
+
// the preview jumps to each fresh badge as it starts to light up
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (!following || frame % STAGGER !== 0) return;
|
|
55
|
+
const index = badges.findIndex((b) => b.id === fresh[frame / STAGGER]);
|
|
56
|
+
if (index >= 0) setSelected(index);
|
|
57
|
+
}, [frame, following]);
|
|
5
58
|
|
|
6
|
-
// Two columns of badges with a pixel-icon preview of the selected one.
|
|
7
|
-
// ↑/↓ walk a column, ←/→ jump between columns, esc closes.
|
|
8
|
-
export function Badges({ badges, onClose }) {
|
|
9
|
-
const [selected, setSelected] = useState(0);
|
|
10
|
-
const rows = Math.ceil(badges.length / 2);
|
|
11
59
|
useInput((input, key) => {
|
|
12
60
|
if (key.escape || input === "q") return onClose();
|
|
61
|
+
setFollowing(false);
|
|
13
62
|
if (key.upArrow) return setSelected((s) => Math.max(0, s - 1));
|
|
14
63
|
if (key.downArrow) return setSelected((s) => Math.min(badges.length - 1, s + 1));
|
|
15
64
|
if (key.leftArrow) return setSelected((s) => Math.max(0, s - rows));
|
|
@@ -17,38 +66,47 @@ export function Badges({ badges, onClose }) {
|
|
|
17
66
|
});
|
|
18
67
|
|
|
19
68
|
const unlocked = badges.filter((b) => b.unlockedOn).length;
|
|
20
|
-
const badge = badges[selected];
|
|
69
|
+
const badge = display(badges[selected]);
|
|
70
|
+
const phase = phaseOf(fresh.indexOf(badge.id), frame);
|
|
71
|
+
const shownUnlocked = badge.unlockedOn && phase === "lit";
|
|
21
72
|
|
|
22
73
|
return html`
|
|
23
74
|
<${Fragment}>
|
|
24
|
-
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${
|
|
75
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
25
76
|
<${Box}>
|
|
26
77
|
<${Text} bold color=${theme.accent}>Badges<//>
|
|
27
78
|
<${Text} dimColor> ${unlocked}/${badges.length}<//>
|
|
79
|
+
${fresh.length > 0 && html`<${Text} color=${theme.warn}> ${fresh.length} new<//>`}
|
|
28
80
|
<//>
|
|
29
81
|
|
|
30
82
|
<${Box} marginTop=${1}>
|
|
31
83
|
<${Box} flexDirection="column" width=${ICON_WIDTH + 3}>
|
|
32
|
-
<${BadgeIcon} id=${badge.id} locked=${!badge.unlockedOn} />
|
|
84
|
+
<${BadgeIcon} id=${badge.id} locked=${!badge.unlockedOn || phase === "waiting"} flash=${phase === "flash"} secret=${badge.hidden && !badge.unlockedOn} />
|
|
33
85
|
<//>
|
|
34
86
|
<${Box} flexDirection="column" justifyContent="center">
|
|
35
|
-
<${Box}><${Text} bold color=${
|
|
87
|
+
<${Box}><${Text} bold color=${shownUnlocked ? badgeColor(badge.id) : undefined} dimColor=${!shownUnlocked}>${badge.name}<//><//>
|
|
36
88
|
<${Box}><${Text}>${badge.desc}<//><//>
|
|
37
89
|
<${Box}><${Text} dimColor>${badge.unlockedOn ? `unlocked ${badge.unlockedOn}` : "still locked"}<//><//>
|
|
38
90
|
<//>
|
|
39
91
|
<//>
|
|
40
92
|
|
|
41
93
|
<${Box} marginTop=${1}>
|
|
42
|
-
${
|
|
94
|
+
${Array.from({ length: COLUMNS }, (_, column) => column).map(
|
|
43
95
|
(column) => html`
|
|
44
|
-
<${Box} key=${column} flexDirection="column" width=${
|
|
96
|
+
<${Box} key=${column} flexDirection="column" width=${COLUMN_WIDTH}>
|
|
45
97
|
${badges.slice(column * rows, column * rows + rows).map((b, r) => {
|
|
46
98
|
const index = column * rows + r;
|
|
47
99
|
const current = index === selected;
|
|
100
|
+
const rowPhase = phaseOf(fresh.indexOf(b.id), frame);
|
|
101
|
+
const shown = b.unlockedOn && rowPhase !== "waiting";
|
|
102
|
+
const dotColor = !shown ? undefined : rowPhase === "flash" ? WHITE : badgeColor(b.id);
|
|
103
|
+
const nameColor = current ? theme.accent : rowPhase === "flash" ? WHITE : shown ? theme.text : undefined;
|
|
48
104
|
return html`
|
|
49
105
|
<${Box} key=${b.id}>
|
|
50
|
-
<${Text}
|
|
51
|
-
|
|
106
|
+
<${Text} bold=${current} dimColor=${!current && !shown} wrap="truncate">
|
|
107
|
+
<${Text} color=${current ? theme.accent : undefined}>${current ? "❯" : " "} <//>
|
|
108
|
+
<${Text} color=${dotColor ?? (b.unlockedOn ? GREY : undefined)}>${shown ? "●" : "○"} <//>
|
|
109
|
+
<${Text} color=${nameColor}>${display(b).name}<//>
|
|
52
110
|
<//>
|
|
53
111
|
<//>
|
|
54
112
|
`;
|
|
@@ -58,7 +116,7 @@ export function Badges({ badges, onClose }) {
|
|
|
58
116
|
)}
|
|
59
117
|
<//>
|
|
60
118
|
<//>
|
|
61
|
-
<${Box} paddingX=${1}><${
|
|
119
|
+
<${Box} paddingX=${1}><${KeyHints} text="↑/↓ browse · ←/→ column · esc back" /><//>
|
|
62
120
|
<//>
|
|
63
121
|
`;
|
|
64
122
|
}
|
package/src/ui/Choice.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Box, Text, useInput } from "ink";
|
|
2
|
+
import { html, theme } from "./kit.js";
|
|
3
|
+
|
|
4
|
+
// A question's answers as a list: ↑/↓ and Enter, a number, or an option's own key ("y", "n").
|
|
5
|
+
// Each option: { label, note?, key?, danger? }; `danger` paints it red while it's chosen.
|
|
6
|
+
export function Choice({ options, selected, onMove, onPick, onCancel }) {
|
|
7
|
+
useInput((input, key) => {
|
|
8
|
+
if (key.escape) return onCancel?.();
|
|
9
|
+
if (key.upArrow) return onMove(Math.max(0, selected - 1));
|
|
10
|
+
if (key.downArrow) return onMove(Math.min(options.length - 1, selected + 1));
|
|
11
|
+
if (key.return) return onPick(selected);
|
|
12
|
+
const index = options.findIndex((o, i) => input === String(i + 1) || (o.key && input.toLowerCase() === o.key));
|
|
13
|
+
if (index >= 0) onPick(index);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const width = Math.max(...options.map((o) => o.label.length)) + 2;
|
|
17
|
+
return html`
|
|
18
|
+
<${Box} flexDirection="column">
|
|
19
|
+
${options.map((o, i) => {
|
|
20
|
+
const on = i === selected;
|
|
21
|
+
const color = on ? (o.danger ? theme.bad : theme.accent) : undefined;
|
|
22
|
+
return html`
|
|
23
|
+
<${Box} key=${o.label}>
|
|
24
|
+
<${Box} flexShrink=${0}><${Text} color=${color} bold=${on}>${on ? "❯" : " "} ${i + 1}. ${o.label.padEnd(width)}<//><//>
|
|
25
|
+
${o.note && html`<${Text} dimColor>${o.note}<//>`}
|
|
26
|
+
<//>
|
|
27
|
+
`;
|
|
28
|
+
})}
|
|
29
|
+
<//>
|
|
30
|
+
`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const CHOICE_KEYS = "↑/↓ choose · enter confirm";
|
package/src/ui/Companion.js
CHANGED
|
@@ -1,60 +1,45 @@
|
|
|
1
|
-
import { Fragment
|
|
1
|
+
import { Fragment } from "react";
|
|
2
2
|
import { Box, Text, useInput } from "ink";
|
|
3
|
-
import { STAGES } from "../progress.js";
|
|
4
|
-
import { html,
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
const MOODS = [
|
|
8
|
-
{ face: "idle", label: "calm" },
|
|
9
|
-
{ face: "smile", label: "content" },
|
|
10
|
-
{ face: "happy", label: "right!" },
|
|
11
|
-
{ face: "sad", label: "wrong" },
|
|
12
|
-
{ face: "happy", label: "combo", hot: true }
|
|
13
|
-
];
|
|
3
|
+
import { ELEMENT_ADJECTIVE, STAGES } from "../progress.js";
|
|
4
|
+
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
5
|
+
import { ELEMENT_COLOR, Mascot } from "./Mascot.js";
|
|
14
6
|
|
|
15
7
|
const requirement = (stage, locked) => (stage.from === 0 ? "from the start" : `${locked ? "needs " : ""}${stage.from} days`);
|
|
16
8
|
|
|
17
|
-
// Every form of the companion
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
// Every form of the companion. Forms you haven't reached are flat silhouettes named "???".
|
|
10
|
+
// Its moods aren't listed here on purpose: you find them out by playing.
|
|
11
|
+
export function Companion({ current, best, element = null, roll = null, onClose }) {
|
|
12
|
+
const panel = usePanelWidth();
|
|
20
13
|
useInput((input, key) => {
|
|
21
|
-
if (key.escape || input === "q")
|
|
22
|
-
if (key.leftArrow) return setShown((s) => Math.max(0, s - 1));
|
|
23
|
-
if (key.rightArrow) return setShown((s) => Math.min(STAGES.length - 1, s + 1));
|
|
14
|
+
if (key.escape || key.return || input === "q") onClose();
|
|
24
15
|
});
|
|
25
16
|
|
|
26
17
|
return html`
|
|
27
18
|
<${Fragment}>
|
|
28
|
-
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${
|
|
19
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
29
20
|
<${Text} bold color=${theme.accent}>Companion<//>
|
|
30
|
-
<${
|
|
21
|
+
<${Box} marginTop=${1}>
|
|
22
|
+
<${Text}>Your dragon: <//>
|
|
23
|
+
${element && html`<${Text} bold color=${ELEMENT_COLOR[element]}>${ELEMENT_ADJECTIVE[element]} <//>`}
|
|
24
|
+
<${Text} bold>${STAGES[current].name}<//>
|
|
25
|
+
<//>
|
|
26
|
+
<${Text} dimColor>${element ? `Element: ${element}${roll ? ` · rolled a ${roll.face} on Dragon's die, ${roll.on}` : ""}` : "No element yet. Some say a die decides it…"}<//>
|
|
27
|
+
<${Box} marginTop=${1}><${Text} dimColor>Evolves with your best streak (${best} days) and never loses a form.<//><//>
|
|
31
28
|
|
|
32
29
|
<${Box} marginTop=${1} flexWrap="wrap">
|
|
33
30
|
${STAGES.map((stage, i) => {
|
|
34
31
|
const locked = i > current;
|
|
35
32
|
return html`
|
|
36
33
|
<${Box} key=${stage.name} width=${22} flexDirection="column" marginBottom=${1}>
|
|
37
|
-
<${Box} flexDirection="column"><${Mascot} stage=${i} locked=${locked} face=${locked ? "idle" : "smile"} /><//>
|
|
38
|
-
<${Text} bold=${i === current} color=${i === current ? theme.accent : undefined} dimColor=${locked}>${stage.name}${i === current ? " ← now" : ""}<//>
|
|
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 ? "???" : stage.name}${i === current ? " ← now" : ""}<//>
|
|
39
36
|
<${Text} dimColor>${requirement(stage, locked)}<//>
|
|
40
37
|
<//>
|
|
41
38
|
`;
|
|
42
39
|
})}
|
|
43
40
|
<//>
|
|
44
|
-
|
|
45
|
-
<${Text} bold>Moods <${Text} dimColor>of ${STAGES[shown].name} · ←/→ to switch form<//><//>
|
|
46
|
-
<${Box} marginTop=${1}>
|
|
47
|
-
${MOODS.map(
|
|
48
|
-
(mood) => html`
|
|
49
|
-
<${Box} key=${mood.label} width=${MASCOT_WIDTH + 1} flexDirection="column">
|
|
50
|
-
<${Mascot} stage=${shown} face=${mood.face} hot=${Boolean(mood.hot)} locked=${shown > current} />
|
|
51
|
-
<${Text} dimColor>${mood.label}<//>
|
|
52
|
-
<//>
|
|
53
|
-
`
|
|
54
|
-
)}
|
|
55
|
-
<//>
|
|
56
41
|
<//>
|
|
57
|
-
<${Box} paddingX=${1}><${
|
|
42
|
+
<${Box} paddingX=${1}><${KeyHints} text="esc back" /><//>
|
|
58
43
|
<//>
|
|
59
44
|
`;
|
|
60
45
|
}
|
package/src/ui/Decks.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Fragment, useEffect, useState } from "react";
|
|
2
|
+
import { Box, Text, useInput } from "ink";
|
|
3
|
+
import { Choice, CHOICE_KEYS } from "./Choice.js";
|
|
4
|
+
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
5
|
+
|
|
6
|
+
// /decks: your decks with their card counts; Enter quizzes the chosen one from now on, and
|
|
7
|
+
// "+ New deck" starts one (`onNew`). Renaming and deleting decks come later.
|
|
8
|
+
export function Decks({ current, actions, onPick, onNew, onClose }) {
|
|
9
|
+
const panel = usePanelWidth();
|
|
10
|
+
const [decks, setDecks] = useState(null);
|
|
11
|
+
const [picked, setPicked] = useState(0);
|
|
12
|
+
const [error, setError] = useState("");
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
actions.allDecks().then(
|
|
16
|
+
(all) => {
|
|
17
|
+
setDecks(all);
|
|
18
|
+
setPicked(Math.max(0, all.findIndex((d) => d.name === current)));
|
|
19
|
+
},
|
|
20
|
+
(err) => setError(err.message)
|
|
21
|
+
);
|
|
22
|
+
}, []);
|
|
23
|
+
|
|
24
|
+
useInput((input, key) => {
|
|
25
|
+
if (!decks?.length && (key.escape || input === "q")) onClose();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return html`
|
|
29
|
+
<${Fragment}>
|
|
30
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
31
|
+
<${Text} bold color=${theme.accent}>Decks<//>
|
|
32
|
+
${decks?.length > 0 &&
|
|
33
|
+
html`
|
|
34
|
+
<${Box} marginTop=${1}>
|
|
35
|
+
<${Choice}
|
|
36
|
+
options=${[...decks.map((d) => ({ label: d.name, note: `${d.cards} card${d.cards === 1 ? "" : "s"}${d.tour ? " · the tour" : ""}${d.name === current ? " · now" : ""}` })), { label: "+ New deck" }]}
|
|
37
|
+
selected=${picked}
|
|
38
|
+
onMove=${setPicked}
|
|
39
|
+
onPick=${(i) => (i === decks.length ? onNew() : onPick(decks[i].name))}
|
|
40
|
+
onCancel=${onClose}
|
|
41
|
+
/>
|
|
42
|
+
<//>
|
|
43
|
+
`}
|
|
44
|
+
${error && html`<${Box} marginTop=${1}><${Text} color=${theme.bad}>${error}<//><//>`}
|
|
45
|
+
<//>
|
|
46
|
+
<${Box} paddingX=${1}><${KeyHints} text=${`${CHOICE_KEYS} · esc back`} /><//>
|
|
47
|
+
<//>
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import React, { Fragment, useEffect, useState } from "react";
|
|
2
|
+
import { Box, Text, useInput } from "ink";
|
|
3
|
+
import { ELEMENTS } from "../progress.js";
|
|
4
|
+
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
5
|
+
import { ELEMENT_COLOR, Mascot } from "./Mascot.js";
|
|
6
|
+
|
|
7
|
+
const FRAME_MS = 80;
|
|
8
|
+
// single-pixel pips on a 9×9 die, with a pixel of space between any two, so six reads as six
|
|
9
|
+
const SIZE = 9;
|
|
10
|
+
const PIPS = { tl: [2, 2], tr: [2, 6], ml: [4, 2], c: [4, 4], mr: [4, 6], bl: [6, 2], br: [6, 6] };
|
|
11
|
+
const FACES = {
|
|
12
|
+
1: ["c"],
|
|
13
|
+
2: ["tl", "br"],
|
|
14
|
+
3: ["tl", "c", "br"],
|
|
15
|
+
4: ["tl", "tr", "bl", "br"],
|
|
16
|
+
5: ["tl", "tr", "c", "bl", "br"],
|
|
17
|
+
6: ["tl", "tr", "ml", "mr", "bl", "br"]
|
|
18
|
+
};
|
|
19
|
+
const ELEMENT_NAME = { earth: "Earth", wind: "Wind", water: "Water", ice: "Ice", fire: "Fire", cosmos: "Cosmos" };
|
|
20
|
+
|
|
21
|
+
// timeline, in frames: tumbling (faces change, slower and slower, bouncing lower) → landed → the dragon changes
|
|
22
|
+
const LAND_AT = 30;
|
|
23
|
+
const FLASH_FRAMES = [36, 38];
|
|
24
|
+
const REVEAL_AT = 40;
|
|
25
|
+
const BOUNCE = [2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0];
|
|
26
|
+
|
|
27
|
+
function dieGrid(face, pipColor) {
|
|
28
|
+
const last = SIZE - 1;
|
|
29
|
+
const grid = Array.from({ length: SIZE }, (_, r) => Array.from({ length: SIZE }, (_, c) => ((r === 0 || r === last) && (c === 0 || c === last) ? null : "#f4f4f5")));
|
|
30
|
+
for (let r = 1; r < last; r++) grid[r][last] = "#c7c9d1"; // a shaded edge
|
|
31
|
+
for (let c = 1; c < last; c++) grid[last][c] = "#c7c9d1";
|
|
32
|
+
for (const pip of FACES[face]) {
|
|
33
|
+
const [r, c] = PIPS[pip];
|
|
34
|
+
grid[r][c] = pipColor;
|
|
35
|
+
}
|
|
36
|
+
return grid;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// while tumbling the shown face changes every frame at first, then every 2, then every 3
|
|
40
|
+
function tumblingFace(frame, result) {
|
|
41
|
+
if (frame >= LAND_AT) return result;
|
|
42
|
+
const step = frame < 12 ? frame : frame < 22 ? 12 + Math.floor((frame - 12) / 2) : 17 + Math.floor((frame - 22) / 3);
|
|
43
|
+
const face = ((step * 5 + 2) % 6) + 1;
|
|
44
|
+
return face === result && frame > LAND_AT - 4 ? (face % 6) + 1 : face; // don't give it away just before landing
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function BigGrid({ grid }) {
|
|
48
|
+
return html`
|
|
49
|
+
<${Fragment}>
|
|
50
|
+
${grid.map((row, r) => html`<${Text} key=${r}>${row.map((color, c) => React.createElement(Text, { key: c, color }, color ? "██" : " "))}<//>`)}
|
|
51
|
+
<//>
|
|
52
|
+
`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The roll for "Dragon's die". The element was already rolled and saved; this only shows it.
|
|
56
|
+
// Any key skips to the end; after the reveal, any key closes it.
|
|
57
|
+
export function DieRoll({ element, stage = 0, onClose, play = () => {} }) {
|
|
58
|
+
const panel = usePanelWidth();
|
|
59
|
+
const result = ELEMENTS.indexOf(element) + 1;
|
|
60
|
+
const [frame, setFrame] = useState(0);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
|
|
63
|
+
return () => clearInterval(id);
|
|
64
|
+
}, []);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (frame === LAND_AT) play("close");
|
|
67
|
+
if (frame === REVEAL_AT) play("evolve");
|
|
68
|
+
}, [frame]);
|
|
69
|
+
|
|
70
|
+
const revealed = frame >= REVEAL_AT;
|
|
71
|
+
useInput(() => (revealed ? onClose() : setFrame(REVEAL_AT)));
|
|
72
|
+
|
|
73
|
+
const landed = frame >= LAND_AT;
|
|
74
|
+
const color = ELEMENT_COLOR[element];
|
|
75
|
+
const face = tumblingFace(frame, result);
|
|
76
|
+
const bounce = landed ? 0 : BOUNCE[Math.min(Math.floor(frame / 1.5), BOUNCE.length - 1)];
|
|
77
|
+
|
|
78
|
+
return html`
|
|
79
|
+
<${Fragment}>
|
|
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}>Dragon's die<//>
|
|
82
|
+
<${Box} marginTop=${1} alignItems="flex-end">
|
|
83
|
+
<${Box} flexDirection="column" marginBottom=${bounce} marginRight=${4}>
|
|
84
|
+
<${BigGrid} grid=${dieGrid(face, landed ? color : "#2a2440")} />
|
|
85
|
+
<//>
|
|
86
|
+
<${Box} flexDirection="column">
|
|
87
|
+
<${Mascot} stage=${stage} face=${revealed ? "happy" : "idle"} flash=${FLASH_FRAMES.includes(frame)} element=${revealed ? element : null} scale=${2} />
|
|
88
|
+
<//>
|
|
89
|
+
<//>
|
|
90
|
+
<${Box} marginTop=${1} flexDirection="column" alignItems="center">
|
|
91
|
+
${revealed
|
|
92
|
+
? html`
|
|
93
|
+
<${Fragment}>
|
|
94
|
+
<${Text} bold color=${color}>${result} · ${ELEMENT_NAME[element]}<//>
|
|
95
|
+
<${Text} dimColor>Your dragon awakened the power of ${element}. It's yours for good.<//>
|
|
96
|
+
<//>
|
|
97
|
+
`
|
|
98
|
+
: html`<${Text} dimColor>${landed ? `${result} · ${ELEMENT_NAME[element]}` : "the die is rolling…"}<//>`}
|
|
99
|
+
<//>
|
|
100
|
+
<//>
|
|
101
|
+
<${Box} paddingX=${1}><${KeyHints} text=${revealed ? "any key to continue" : "any key to skip"} /><//>
|
|
102
|
+
<//>
|
|
103
|
+
`;
|
|
104
|
+
}
|
package/src/ui/Evolution.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment, useEffect, useState } from "react";
|
|
2
2
|
import { Box, Text, useInput } from "ink";
|
|
3
|
-
import { html,
|
|
3
|
+
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
4
4
|
import { Mascot } from "./Mascot.js";
|
|
5
5
|
|
|
6
6
|
const FRAME_MS = 120;
|
|
@@ -21,7 +21,8 @@ function sparkleRow(frame, seed, width) {
|
|
|
21
21
|
|
|
22
22
|
// The full-screen moment when the companion evolves: old form → white flashes → new form.
|
|
23
23
|
// Any key fast-forwards to the reveal; Enter/Esc then closes it.
|
|
24
|
-
export function Evolution({ from, to, name, onClose }) {
|
|
24
|
+
export function Evolution({ from, to, name, element = null, onClose }) {
|
|
25
|
+
const panel = usePanelWidth();
|
|
25
26
|
const [frame, setFrame] = useState(0);
|
|
26
27
|
useEffect(() => {
|
|
27
28
|
const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
|
|
@@ -39,11 +40,11 @@ export function Evolution({ from, to, name, onClose }) {
|
|
|
39
40
|
|
|
40
41
|
return html`
|
|
41
42
|
<${Fragment}>
|
|
42
|
-
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.warn} paddingX=${2} paddingY=${1} width=${
|
|
43
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.warn} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
|
|
43
44
|
<${Text} bold color=${theme.warn}>✦ Evolution ✦<//>
|
|
44
45
|
<${Box} flexDirection="column" marginTop=${1} alignItems="center">
|
|
45
46
|
<${Text} color=${theme.warn}>${sparks ? sparkleRow(frame, 1, 30) : " "}<//>
|
|
46
|
-
<${Mascot} stage=${stage} face=${revealed ? "happy" : "idle"} flash=${flashing && frame % 2 === 0} scale=${2} />
|
|
47
|
+
<${Mascot} stage=${stage} face=${revealed ? "happy" : "idle"} flash=${flashing && frame % 2 === 0} scale=${2} element=${element} />
|
|
47
48
|
<${Text} color=${theme.warn}>${sparks ? sparkleRow(frame, 2, 30) : " "}<//>
|
|
48
49
|
<//>
|
|
49
50
|
<${Box} marginTop=${1} flexDirection="column" alignItems="center">
|
|
@@ -52,7 +53,7 @@ export function Evolution({ from, to, name, onClose }) {
|
|
|
52
53
|
: html`<${Text} dimColor>Something is happening…<//>`}
|
|
53
54
|
<//>
|
|
54
55
|
<//>
|
|
55
|
-
<${Box} paddingX=${1}><${
|
|
56
|
+
<${Box} paddingX=${1}><${KeyHints} text=${revealed ? "enter continue" : "any key to hurry it up"} /><//>
|
|
56
57
|
<//>
|
|
57
58
|
`;
|
|
58
59
|
}
|
package/src/ui/Hatch.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { Fragment, useEffect, useState } from "react";
|
|
2
2
|
import { Box, Text, useInput } from "ink";
|
|
3
|
-
import { html,
|
|
3
|
+
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
4
4
|
import { Mascot } from "./Mascot.js";
|
|
5
5
|
|
|
6
6
|
const FRAME_MS = 110;
|
|
@@ -57,6 +57,7 @@ function BigPixels({ grid, colors }) {
|
|
|
57
57
|
|
|
58
58
|
// First launch ever: the dragon hatches. Any key skips ahead; after the reveal, any key starts the quiz.
|
|
59
59
|
export function Hatch({ onDone, play = () => {} }) {
|
|
60
|
+
const panel = usePanelWidth();
|
|
60
61
|
const [frame, setFrame] = useState(0);
|
|
61
62
|
useEffect(() => {
|
|
62
63
|
const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
|
|
@@ -75,7 +76,7 @@ export function Hatch({ onDone, play = () => {} }) {
|
|
|
75
76
|
|
|
76
77
|
return html`
|
|
77
78
|
<${Fragment}>
|
|
78
|
-
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${
|
|
79
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
|
|
79
80
|
<${Text} bold color=${theme.accent}>Dracosh<//>
|
|
80
81
|
<${Box} flexDirection="column" marginTop=${1} alignItems="center">
|
|
81
82
|
${revealed
|
|
@@ -87,13 +88,13 @@ export function Hatch({ onDone, play = () => {} }) {
|
|
|
87
88
|
? html`
|
|
88
89
|
<${Fragment}>
|
|
89
90
|
<${Text} bold color=${theme.good}>Your dragon has hatched!<//>
|
|
90
|
-
<${Text} dimColor>Answer
|
|
91
|
+
<${Text} dimColor>Answer cards to keep it happy. It grows with your streak.<//>
|
|
91
92
|
<//>
|
|
92
93
|
`
|
|
93
94
|
: html`<${Text} dimColor>${caption}<//>`}
|
|
94
95
|
<//>
|
|
95
96
|
<//>
|
|
96
|
-
<${Box} paddingX=${1}><${
|
|
97
|
+
<${Box} paddingX=${1}><${KeyHints} text=${revealed ? "any key to start" : "any key to skip"} /><//>
|
|
97
98
|
<//>
|
|
98
99
|
`;
|
|
99
100
|
}
|
package/src/ui/Header.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Box, Text } from "ink";
|
|
|
3
3
|
import { formatInterval } from "../settings.js";
|
|
4
4
|
import { formatDay } from "../vacation.js";
|
|
5
5
|
import { AnimatedBar, html, theme } from "./kit.js";
|
|
6
|
+
import { Flame } from "./icons.js";
|
|
6
7
|
import { Mascot, MASCOT_WIDTH } from "./Mascot.js";
|
|
7
8
|
|
|
8
9
|
const FRAME_MS = 90;
|
|
@@ -84,23 +85,23 @@ export function Header({ deck, everyMs, wordCount, stats, combo, face, event, ti
|
|
|
84
85
|
const shown = asleep ? "sleep" : blinking && BLINKABLE.has(face) ? "blink" : face;
|
|
85
86
|
return html`
|
|
86
87
|
<${Box} paddingX=${1}>
|
|
87
|
-
<${Box} width=${MASCOT_WIDTH + 3}>
|
|
88
|
+
<${Box} width=${MASCOT_WIDTH + 3} flexShrink=${0}>
|
|
88
89
|
<${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} />
|
|
90
|
+
<${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
91
|
<//>
|
|
91
92
|
${asleep && html`<${Snore} tick=${tick} />`}
|
|
92
93
|
<//>
|
|
93
94
|
<${Box} flexDirection="column" justifyContent="center">
|
|
94
95
|
<${Box}>
|
|
95
|
-
<${Text} bold color=${theme.accent}>Dracosh
|
|
96
|
-
<${Text} dimColor> ${deck}${wordCount ? ` · ${wordCount}
|
|
96
|
+
<${Box} flexShrink=${0}><${Text} bold color=${theme.accent}>Dracosh<//><//>
|
|
97
|
+
<${Text} dimColor wrap="truncate-end"> ${deck}${wordCount ? ` · ${wordCount} card${wordCount === 1 ? "" : "s"}` : ""} · every ${formatInterval(everyMs)}<//>
|
|
97
98
|
<//>
|
|
98
99
|
<${Box}>
|
|
99
100
|
${streak.days > 0
|
|
100
|
-
? html`<${Text} color=${theme.warn} bold
|
|
101
|
+
? html`<${Box}><${Flame} /><${Text} color=${theme.warn} bold> ${streak.days}-day streak<//><//>`
|
|
101
102
|
: html`<${Text} dimColor>no streak yet<//>`}
|
|
102
103
|
${streak.atRisk && html`<${Text} color=${theme.warn}> · at risk today<//>`}
|
|
103
|
-
${stats.vacation.activeUntil && html`<${Text} color=${theme.accent}> ·
|
|
104
|
+
${stats.vacation.activeUntil && html`<${Text} color=${theme.accent}> · days off until ${formatDay(stats.vacation.activeUntil)}<//>`}
|
|
104
105
|
${streak.freezes > 0 && html`<${Text} dimColor> · ${streak.freezes} freeze${streak.freezes > 1 ? "s" : ""}<//>`}
|
|
105
106
|
<//>
|
|
106
107
|
<${Box}>
|
package/src/ui/Help.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Fragment } from "react";
|
|
2
|
+
import { Box, Text, useInput } from "ink";
|
|
3
|
+
import { MAX_FREEZES } from "../progress.js";
|
|
4
|
+
import { BOX_INTERVALS_DAYS } from "../scheduler.js";
|
|
5
|
+
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
6
|
+
|
|
7
|
+
const KEYS = [
|
|
8
|
+
["Enter", "submit your answer (empty shows the answer); between cards, ask the next one"],
|
|
9
|
+
["/", "open the commands"],
|
|
10
|
+
["Esc", "clear what you typed, or quit"],
|
|
11
|
+
["q", "quit, between cards"],
|
|
12
|
+
["any key", "wakes a sleeping dragon"]
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
const HOW = [
|
|
16
|
+
`A right answer moves a card to a later box: it comes back in ${BOX_INTERVALS_DAYS.slice(0, -1).join(", ")}, then ${BOX_INTERVALS_DAYS.at(-1)} days. A miss sends it back to the first box.`,
|
|
17
|
+
"One wrong letter in a longer word still counts, and you see the right spelling.",
|
|
18
|
+
"Reach your daily goal to keep your streak going; a day where you did every card there was counts too. Your dragon grows with your best streak.",
|
|
19
|
+
`A freeze covers a day you missed. You start with ${MAX_FREEZES} and get one back each week, ${MAX_FREEZES} at most.`
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const OUTSIDE = [
|
|
23
|
+
['dracosh --deck "Polish"', "quiz another deck"],
|
|
24
|
+
["dracosh --data", "where your cards and backups are"],
|
|
25
|
+
["dracosh restore", "bring back a backup"],
|
|
26
|
+
["dracosh --help", "every option"]
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
function Rows({ rows, width }) {
|
|
30
|
+
return rows.map(
|
|
31
|
+
([left, right]) => html`
|
|
32
|
+
<${Box} key=${left}>
|
|
33
|
+
<${Box} width=${width} flexShrink=${0}><${Text} color=${theme.accent}>${left}<//><//>
|
|
34
|
+
<${Text}>${right}<//>
|
|
35
|
+
<//>
|
|
36
|
+
`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const Section = ({ title, children }) => html`
|
|
41
|
+
<${Box} flexDirection="column" marginTop=${1}>
|
|
42
|
+
<${Text} bold>${title}<//>
|
|
43
|
+
${children}
|
|
44
|
+
<//>
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
// How Dracosh works, on one screen: the keys, the rules behind the boxes and the streak,
|
|
48
|
+
// and what you can do from the shell.
|
|
49
|
+
export function Help({ onClose }) {
|
|
50
|
+
const panel = usePanelWidth();
|
|
51
|
+
useInput((input, key) => {
|
|
52
|
+
if (key.escape || key.return || input === "q") onClose();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return html`
|
|
56
|
+
<${Fragment}>
|
|
57
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
58
|
+
<${Text} bold color=${theme.accent}>Help<//>
|
|
59
|
+
<${Section} title="Keys"><${Rows} rows=${KEYS} width=${10} /><//>
|
|
60
|
+
<${Section} title="How it works">
|
|
61
|
+
${HOW.map((line) => html`<${Box} key=${line}><${Box} width=${2} flexShrink=${0}><${Text} dimColor>·<//><//><${Text}>${line}<//><//>`)}
|
|
62
|
+
<//>
|
|
63
|
+
<${Section} title="Outside the quiz"><${Rows} rows=${OUTSIDE} width=${26} /><//>
|
|
64
|
+
<//>
|
|
65
|
+
<${Box} paddingX=${1}><${KeyHints} text="esc back" /><//>
|
|
66
|
+
<//>
|
|
67
|
+
`;
|
|
68
|
+
}
|