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/store.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t } from "./i18n.js";
|
|
1
2
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
2
3
|
import { homedir } from "node:os";
|
|
3
4
|
import { dirname, join } from "node:path";
|
|
@@ -18,7 +19,8 @@ const emptyState = () => ({ version: STATE_VERSION, items: {}, newToday: { date:
|
|
|
18
19
|
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
19
20
|
|
|
20
21
|
// what to say when a data file can't be used as it is
|
|
21
|
-
|
|
22
|
+
// marked, not only worded: the message is in the app's language
|
|
23
|
+
export const damaged = (file, why) => Object.assign(new Error(t("errors.damaged", { file, why })), { damaged: true });
|
|
22
24
|
|
|
23
25
|
export async function readJson(file, fallback) {
|
|
24
26
|
try {
|
|
@@ -26,7 +28,7 @@ export async function readJson(file, fallback) {
|
|
|
26
28
|
} catch (err) {
|
|
27
29
|
if (err.code === "ENOENT") return fallback;
|
|
28
30
|
if (err instanceof SyntaxError) throw damaged(file, err.message);
|
|
29
|
-
throw new Error(
|
|
31
|
+
throw new Error(t("errors.cantRead", { file, error: err.message }));
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -59,8 +61,8 @@ export const saveLibrary = (library) => writeJson(LIBRARY_FILE, library);
|
|
|
59
61
|
export async function loadState() {
|
|
60
62
|
const state = await readJson(STATE_FILE, undefined);
|
|
61
63
|
if (state === undefined) return emptyState();
|
|
62
|
-
if (!isObject(state) || !isObject(state.items)) throw damaged(STATE_FILE, "
|
|
63
|
-
if (!Object.values(state.items).every((entry) => isObject(entry) && Number.isFinite(entry.box) && Number.isFinite(entry.due))) throw damaged(STATE_FILE, "
|
|
64
|
+
if (!isObject(state) || !isObject(state.items)) throw damaged(STATE_FILE, t("errors.why.noProgress"));
|
|
65
|
+
if (!Object.values(state.items).every((entry) => isObject(entry) && Number.isFinite(entry.box) && Number.isFinite(entry.due))) throw damaged(STATE_FILE, t("errors.why.progressEntry"));
|
|
64
66
|
const { progress } = state;
|
|
65
67
|
const validProgress =
|
|
66
68
|
isObject(progress) &&
|
|
@@ -70,8 +72,8 @@ export async function loadState() {
|
|
|
70
72
|
["count", "best", "freezes"].every((key) => Number.isFinite(progress.streak[key])) &&
|
|
71
73
|
isObject(progress.badges) &&
|
|
72
74
|
(progress.vacations === undefined || Array.isArray(progress.vacations));
|
|
73
|
-
if (progress !== undefined && !validProgress) throw damaged(STATE_FILE, "
|
|
74
|
-
if (state.version > STATE_VERSION) throw new Error(
|
|
75
|
+
if (progress !== undefined && !validProgress) throw damaged(STATE_FILE, t("errors.why.streak"));
|
|
76
|
+
if (state.version > STATE_VERSION) throw new Error(t("errors.newerState", { file: STATE_FILE }));
|
|
75
77
|
if (!isObject(state.newToday)) state.newToday = { date: "", count: 0 };
|
|
76
78
|
return state;
|
|
77
79
|
}
|
|
@@ -89,7 +91,7 @@ export function recordAnswer(state, noteId, direction, entry, now = Date.now(),
|
|
|
89
91
|
|
|
90
92
|
// hand-edited into something odd, even broken JSON: the defaults take over (nothing worth a restore)
|
|
91
93
|
export const loadSettingsRaw = async () => {
|
|
92
|
-
const raw = await readJson(SETTINGS_FILE, {}).catch((err) => (err.
|
|
94
|
+
const raw = await readJson(SETTINGS_FILE, {}).catch((err) => (err.damaged ? {} : Promise.reject(err)));
|
|
93
95
|
return isObject(raw) ? raw : {};
|
|
94
96
|
};
|
|
95
97
|
|
package/src/tips.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { englishMessages, t } from "./i18n.js";
|
|
2
2
|
|
|
3
|
-
// Short tips about Dracosh itself, shown now and then while you wait for the next card.
|
|
4
|
-
|
|
3
|
+
// Short tips about Dracosh itself, shown now and then while you wait for the next card. They live in
|
|
4
|
+
// the locale (tips.<id>); the ids come from English, the text from the language in use.
|
|
5
|
+
export const TIPS = Object.keys(englishMessages().tips).map((id) => ({
|
|
6
|
+
id,
|
|
7
|
+
get cat() {
|
|
8
|
+
return t(`tips.${id}.cat`);
|
|
9
|
+
},
|
|
10
|
+
get text() {
|
|
11
|
+
return t(`tips.${id}.text`);
|
|
12
|
+
}
|
|
13
|
+
}));
|
|
5
14
|
const SOMETIMES_CHANCE = 1 / 3;
|
|
6
15
|
|
|
7
16
|
// "always" shows a tip on every wait, "sometimes" on about one in three
|