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.
Files changed (55) hide show
  1. package/README.md +16 -11
  2. package/locales/de.json +1046 -0
  3. package/locales/en.json +1029 -0
  4. package/locales/fr.json +1094 -0
  5. package/locales/pl.json +1117 -0
  6. package/locales/uk.json +1118 -0
  7. package/package.json +2 -2
  8. package/src/alerts.js +3 -1
  9. package/src/backup.js +2 -1
  10. package/src/cardline.js +71 -0
  11. package/src/cli.js +39 -52
  12. package/src/commands.js +14 -12
  13. package/src/demo.js +11 -0
  14. package/src/diff.js +13 -7
  15. package/src/i18n.js +68 -0
  16. package/src/judge.js +24 -6
  17. package/src/library.js +62 -35
  18. package/src/lock.js +2 -1
  19. package/src/manage.js +150 -60
  20. package/src/pause.js +1 -2
  21. package/src/progress.js +76 -59
  22. package/src/quiet.js +3 -2
  23. package/src/scheduler.js +3 -6
  24. package/src/session.js +69 -19
  25. package/src/settings.js +13 -6
  26. package/src/starter.js +36 -27
  27. package/src/store.js +9 -7
  28. package/src/tips.js +12 -3
  29. package/src/ui/AddCard.js +405 -81
  30. package/src/ui/AnswerInput.js +22 -10
  31. package/src/ui/App.js +181 -50
  32. package/src/ui/BadgeUnlock.js +4 -3
  33. package/src/ui/Badges.js +9 -8
  34. package/src/ui/Choice.js +14 -9
  35. package/src/ui/Companion.js +13 -13
  36. package/src/ui/Confetti.js +2 -2
  37. package/src/ui/Decks.js +58 -8
  38. package/src/ui/DieRoll.js +9 -9
  39. package/src/ui/Evolution.js +7 -7
  40. package/src/ui/Hatch.js +7 -6
  41. package/src/ui/Header.js +58 -16
  42. package/src/ui/Help.js +31 -25
  43. package/src/ui/Mascot.js +1 -2
  44. package/src/ui/Missed.js +13 -12
  45. package/src/ui/Preview.js +48 -29
  46. package/src/ui/Reset.js +13 -14
  47. package/src/ui/Settings.js +26 -19
  48. package/src/ui/Stats.js +24 -23
  49. package/src/ui/Summary.js +10 -9
  50. package/src/ui/TheOne.js +7 -6
  51. package/src/ui/icons.js +1 -2
  52. package/src/ui/kit.js +34 -6
  53. package/src/vacation.js +2 -1
  54. package/src/words.js +2 -1
  55. 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
- export const damaged = (file, why) => new Error(`${file} looks damaged (${why}). Run "dracosh restore" to bring back a backup.`);
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(`Can't read ${file}: ${err.message}`);
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, "no progress in it");
63
- if (!Object.values(state.items).every((entry) => isObject(entry) && Number.isFinite(entry.box) && Number.isFinite(entry.due))) throw damaged(STATE_FILE, "a card without its box or date");
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, "the streak and badges are unreadable");
74
- if (state.version > STATE_VERSION) throw new Error(`${STATE_FILE} was saved by a newer version of Dracosh. Please update Dracosh.`);
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.message.includes("looks damaged") ? {} : Promise.reject(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 { readFileSync } from "node:fs";
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
- export const TIPS = JSON.parse(readFileSync(new URL("../data/tips.json", import.meta.url), "utf8"));
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