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/progress.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { dateLocale, t } from "./i18n.js";
|
|
1
2
|
import { addDays, dayKey, daysBetween, weekStart } from "./dates.js";
|
|
2
3
|
import { BOX_INTERVALS_DAYS } from "./scheduler.js";
|
|
3
4
|
|
|
@@ -11,19 +12,27 @@ const FALL_MIN = 30; // a lost streak this long counts as a fall for "Dragon's d
|
|
|
11
12
|
// The die's faces: winning "Dragon's die" rolls one, and the dragon keeps that element for good.
|
|
12
13
|
export const ELEMENTS = ["earth", "wind", "water", "ice", "fire", "cosmos"];
|
|
13
14
|
export const rollElement = (random = Math.random) => ELEMENTS[Math.floor(random() * ELEMENTS.length)];
|
|
14
|
-
export const
|
|
15
|
+
export const elementName = (element) => t(`dragon.elements.${element}.name`);
|
|
16
|
+
export const elementAdjective = (element) => t(`dragon.elements.${element}.adjective`);
|
|
15
17
|
|
|
16
18
|
// what the dragon is called: its form, with its element in front once it has one ("Ice Drake")
|
|
17
|
-
export const dragonName = (stage, element = null) => (element ?
|
|
19
|
+
export const dragonName = (stage, element = null) => (element ? t("dragon.named", { element: elementAdjective(element), stage: STAGES[stage].name }) : STAGES[stage].name);
|
|
18
20
|
|
|
19
21
|
// The companion evolves permanently with your best streak, so a broken streak never takes a form away.
|
|
22
|
+
const stage = (id, from) => ({
|
|
23
|
+
id,
|
|
24
|
+
from,
|
|
25
|
+
get name() {
|
|
26
|
+
return t(`dragon.stages.${id}`);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
20
29
|
export const STAGES = [
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
stage("hatchling", 0),
|
|
31
|
+
stage("imp", 7),
|
|
32
|
+
stage("whelp", 30),
|
|
33
|
+
stage("drake", 90),
|
|
34
|
+
stage("dragon", 180),
|
|
35
|
+
stage("legend", 365)
|
|
27
36
|
];
|
|
28
37
|
|
|
29
38
|
export function stageFor(bestStreak) {
|
|
@@ -159,66 +168,75 @@ function perfectWeek(progress, today) {
|
|
|
159
168
|
|
|
160
169
|
// `s` = stats from collectStats() plus `event`: what this very answer was (correct, hour, days since last activity)
|
|
161
170
|
export const BADGES = [
|
|
162
|
-
{ id: "hello",
|
|
163
|
-
{ id: "first-steps",
|
|
164
|
-
{ id: "century",
|
|
165
|
-
{ id: "thousand",
|
|
166
|
-
{ id: "five-thousand",
|
|
167
|
-
{ id: "ten-thousand",
|
|
168
|
-
{ id: "dragons-hoard",
|
|
169
|
-
|
|
170
|
-
{ id: "on-a-roll",
|
|
171
|
-
{ id: "week",
|
|
172
|
-
{ id: "fortnight",
|
|
173
|
-
{ id: "month",
|
|
174
|
-
{ id: "hundred-days",
|
|
175
|
-
{ id: "dragonheart",
|
|
176
|
-
|
|
177
|
-
{ id: "keeper",
|
|
178
|
-
{ id: "collector",
|
|
179
|
-
{ id: "dictionary",
|
|
180
|
-
{ id: "lexicon",
|
|
181
|
-
{ id: "explorer",
|
|
182
|
-
|
|
183
|
-
{ id: "flawless",
|
|
184
|
-
{ id: "overachiever",
|
|
185
|
-
{ id: "marathon",
|
|
186
|
-
|
|
187
|
-
{ id: "hot-streak",
|
|
188
|
-
{ id: "unstoppable",
|
|
189
|
-
{ id: "combo-master",
|
|
190
|
-
|
|
191
|
-
{ id: "early-bird",
|
|
192
|
-
{ id: "night-owl",
|
|
193
|
-
|
|
194
|
-
{ id: "comeback",
|
|
195
|
-
{ id: "redemption",
|
|
196
|
-
{ id: "frozen",
|
|
197
|
-
{ id: "weekend",
|
|
198
|
-
{ id: "perfect-week",
|
|
199
|
-
{ id: "regular",
|
|
200
|
-
{ id: "machine",
|
|
201
|
-
{ id: "hundred-club",
|
|
171
|
+
{ id: "hello", test: (s) => s.totalCorrect >= 1 },
|
|
172
|
+
{ id: "first-steps", test: (s) => s.totalCorrect >= 10 },
|
|
173
|
+
{ id: "century", test: (s) => s.totalCorrect >= 100 },
|
|
174
|
+
{ id: "thousand", test: (s) => s.totalCorrect >= 1000 },
|
|
175
|
+
{ id: "five-thousand", test: (s) => s.totalCorrect >= 5000 },
|
|
176
|
+
{ id: "ten-thousand", test: (s) => s.totalCorrect >= 10000 },
|
|
177
|
+
{ id: "dragons-hoard", test: (s) => s.totalCorrect >= 20000 },
|
|
178
|
+
|
|
179
|
+
{ id: "on-a-roll", test: (s) => s.bestStreak >= 3 },
|
|
180
|
+
{ id: "week", test: (s) => s.bestStreak >= 7 },
|
|
181
|
+
{ id: "fortnight", test: (s) => s.bestStreak >= 14 },
|
|
182
|
+
{ id: "month", test: (s) => s.bestStreak >= 30 },
|
|
183
|
+
{ id: "hundred-days", test: (s) => s.bestStreak >= 100 },
|
|
184
|
+
{ id: "dragonheart", test: (s) => s.bestStreak >= 180 },
|
|
185
|
+
|
|
186
|
+
{ id: "keeper", test: (s) => s.mastered >= 10 },
|
|
187
|
+
{ id: "collector", test: (s) => s.mastered >= 25 },
|
|
188
|
+
{ id: "dictionary", test: (s) => s.mastered >= 50 },
|
|
189
|
+
{ id: "lexicon", test: (s) => s.mastered >= 150 },
|
|
190
|
+
{ id: "explorer", test: (s) => s.practiced >= 250 },
|
|
191
|
+
|
|
192
|
+
{ id: "flawless", test: (s) => s.today.asked >= 10 && s.today.correct === s.today.asked },
|
|
193
|
+
{ id: "overachiever", test: (s) => s.today.correct >= s.goal * 2 },
|
|
194
|
+
{ id: "marathon", test: (s) => s.today.correct >= 30 },
|
|
195
|
+
|
|
196
|
+
{ id: "hot-streak", test: (s) => s.bestCombo >= 10 },
|
|
197
|
+
{ id: "unstoppable", test: (s) => s.bestCombo >= 25 },
|
|
198
|
+
{ id: "combo-master", test: (s) => s.bestCombo >= 50 },
|
|
199
|
+
|
|
200
|
+
{ id: "early-bird", test: (s) => s.event.correct && s.event.hour < 8 },
|
|
201
|
+
{ id: "night-owl", test: (s) => s.event.correct && s.event.hour >= 23 },
|
|
202
|
+
|
|
203
|
+
{ id: "comeback", test: (s) => s.event.correct && s.event.daysAway >= COMEBACK_AFTER_DAYS },
|
|
204
|
+
{ id: "redemption", test: (s) => s.recoveredToday >= 5 },
|
|
205
|
+
{ id: "frozen", test: (s) => s.freezesUsed >= 1 },
|
|
206
|
+
{ id: "weekend", test: (s) => s.weekendDone },
|
|
207
|
+
{ id: "perfect-week", test: (s) => s.perfectWeek },
|
|
208
|
+
{ id: "regular", test: (s) => s.goalDaysThisMonth >= 20 },
|
|
209
|
+
{ id: "machine", test: (s) => s.goalDaysThisMonth >= 25 },
|
|
210
|
+
{ id: "hundred-club", test: (s) => s.totalGoalDays >= 100 },
|
|
202
211
|
|
|
203
212
|
|
|
204
213
|
// keep this one last: it checks the others, including any unlocked earlier in the same answer
|
|
205
|
-
{ id: "one-ring",
|
|
214
|
+
{ id: "one-ring", test: (s) => BADGES.every((b) => b.id === "one-ring" || b.hidden || s.badges[b.id]) },
|
|
206
215
|
|
|
207
216
|
// hidden: shown as "???" until won, and not needed for The One
|
|
208
217
|
{
|
|
209
218
|
id: "dragons-die",
|
|
210
|
-
name: "Dragon's die",
|
|
211
|
-
desc: "lost a 30+ day streak, then built a longer one",
|
|
212
219
|
hidden: true,
|
|
213
220
|
test: (s) => s.fallenStreak >= FALL_MIN && s.streakCount > s.fallenStreak
|
|
214
221
|
}
|
|
215
222
|
];
|
|
216
223
|
|
|
224
|
+
// a badge's name and description come from the locale (badges.<id>), read each time they're shown
|
|
225
|
+
for (const badge of BADGES) {
|
|
226
|
+
Object.defineProperties(badge, {
|
|
227
|
+
name: { get: () => t(`badges.${badge.id}.name`), enumerable: true },
|
|
228
|
+
desc: { get: () => t(`badges.${badge.id}.desc`), enumerable: true }
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
217
232
|
// progress is kept per card and direction ("id:en-pl"); badges count cards
|
|
218
233
|
const cardOf = (key) => key.slice(0, key.lastIndexOf(":"));
|
|
219
234
|
|
|
220
|
-
// a card is mastered once every direction it's
|
|
221
|
-
|
|
235
|
+
// a card is mastered once every direction it's asked in has reached the last box; a direction its deck
|
|
236
|
+
// no longer asks (`dormant`, kept for when it's turned back on) doesn't hold it back
|
|
237
|
+
function masteredCards(items, dormant = []) {
|
|
238
|
+
const resting = new Set(dormant);
|
|
239
|
+
items = items.filter(([key]) => !resting.has(key));
|
|
222
240
|
const byCard = new Map();
|
|
223
241
|
for (const [key, entry] of items) byCard.set(cardOf(key), (byCard.get(cardOf(key)) ?? true) && entry.box === MAX_BOX);
|
|
224
242
|
return [...byCard.values()].filter(Boolean).length;
|
|
@@ -249,7 +267,7 @@ function collectStats(state, now, goal) {
|
|
|
249
267
|
bestStreak: progress.streak.best,
|
|
250
268
|
bestCombo: progress.bestCombo ?? 0,
|
|
251
269
|
freezesUsed: progress.streak.freezesUsed ?? 0,
|
|
252
|
-
mastered: masteredCards(items),
|
|
270
|
+
mastered: masteredCards(items, state.dormant),
|
|
253
271
|
practiced: new Set(items.map(([key]) => cardOf(key))).size,
|
|
254
272
|
goalDaysThisMonth: goalDaysInMonth(progress, todayKey),
|
|
255
273
|
totalGoalDays: Object.values(progress.days).filter((d) => d.goalMet).length,
|
|
@@ -270,17 +288,17 @@ function award(state, progress, day, today, { correct, goal, rules, now, daysAwa
|
|
|
270
288
|
if (caughtUp) day.caughtUp = true;
|
|
271
289
|
const stageBefore = stageFor(progress.streak.best);
|
|
272
290
|
const streak = completeDay(progress, today, rules);
|
|
273
|
-
cheers.push({ kind: "goal", text:
|
|
291
|
+
cheers.push({ kind: "goal", text: t(caughtUp ? "cheers.allDone" : "cheers.goal", { count: streak }) });
|
|
274
292
|
const stageAfter = stageFor(progress.streak.best);
|
|
275
293
|
if (stageAfter.index > stageBefore.index)
|
|
276
|
-
cheers.push({ kind: "evolve", text:
|
|
294
|
+
cheers.push({ kind: "evolve", text: t("cheers.evolved", { name: stageAfter.name }) });
|
|
277
295
|
}
|
|
278
296
|
|
|
279
297
|
const stats = { ...collectStats(state, now, goal), event: { correct, hour: new Date(now).getHours(), daysAway } };
|
|
280
298
|
for (const badge of BADGES) {
|
|
281
299
|
if (!progress.badges[badge.id] && badge.test(stats)) {
|
|
282
300
|
progress.badges[badge.id] = today;
|
|
283
|
-
cheers.push({ kind: "badge", id: badge.id, name: badge.name, desc: badge.desc, text:
|
|
301
|
+
cheers.push({ kind: "badge", id: badge.id, name: badge.name, desc: badge.desc, text: t("cheers.badge", { name: badge.name, desc: badge.desc }) });
|
|
284
302
|
// rolled and saved right away, before any animation, so quitting mid-roll can't reroll it
|
|
285
303
|
if (badge.id === "dragons-die" && !progress.element && !progress.elementDropped) {
|
|
286
304
|
progress.element = rollElement(random);
|
|
@@ -367,7 +385,6 @@ export function snapshot(state, { goal, rules = NO_RULES, now = Date.now() }) {
|
|
|
367
385
|
};
|
|
368
386
|
}
|
|
369
387
|
|
|
370
|
-
const MONTH_NAMES = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
371
388
|
|
|
372
389
|
// One calendar month, weeks Monday..Sunday: each day has the number of correct answers and whether the goal was met.
|
|
373
390
|
// `offset` moves back (negative) or forward from the current month.
|
|
@@ -391,7 +408,7 @@ export function calendarMonth(state, { offset = 0, rules = NO_RULES, now = Date.
|
|
|
391
408
|
for (let i = 0; i < padded.length; i += 7) weeks.push([...padded.slice(i, i + 7), ...Array(Math.max(0, i + 7 - padded.length)).fill(null)]);
|
|
392
409
|
|
|
393
410
|
return {
|
|
394
|
-
label:
|
|
411
|
+
label: new Intl.DateTimeFormat(dateLocale(), { month: "long", year: "numeric" }).format(first),
|
|
395
412
|
weeks,
|
|
396
413
|
goalDays: cells.filter((c) => c.goalMet).length,
|
|
397
414
|
correct: cells.reduce((sum, c) => sum + c.correct, 0),
|
package/src/quiet.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { dateLocale, t } from "./i18n.js";
|
|
1
2
|
const MINUTE = 60_000;
|
|
2
3
|
const HOUR = 60 * MINUTE;
|
|
3
4
|
|
|
@@ -16,7 +17,7 @@ export function quietEnd(ms, quiet) {
|
|
|
16
17
|
return end.getTime();
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
export const formatQuiet = (quiet) => (quiet ? `${String(quiet.from).padStart(2, "0")}:00–${String(quiet.to).padStart(2, "0")}:00` : "off");
|
|
20
|
+
export const formatQuiet = (quiet) => (quiet ? `${String(quiet.from).padStart(2, "0")}:00–${String(quiet.to).padStart(2, "0")}:00` : t("settings.off"));
|
|
20
21
|
|
|
21
22
|
// /pause durations: "" → 1 h, "30", "30m", "2h", "90s" → milliseconds, "off" → "off", anything else → null
|
|
22
23
|
export function parseSnooze(arg) {
|
|
@@ -29,4 +30,4 @@ export function parseSnooze(arg) {
|
|
|
29
30
|
return amount > 0 ? amount : null;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
export const formatClock = (ms) => new Date(ms).toLocaleTimeString(
|
|
33
|
+
export const formatClock = (ms) => new Date(ms).toLocaleTimeString(dateLocale(), { hour: "2-digit", minute: "2-digit" });
|
package/src/scheduler.js
CHANGED
|
@@ -32,16 +32,13 @@ function pickDue(due, now, random) {
|
|
|
32
32
|
return due[due.length - 1];
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
// Mixes due reviews with new words (up to the daily cap), at random; with nothing to do, practises a soon-due item.
|
|
36
|
-
// Never asks the same note twice in a row when there is any alternative. A `tour` deck is different:
|
|
37
|
-
// each card is asked once, in deck order, and never comes back as a review (null when it's done).
|
|
38
35
|
// What to ask next: a due review or a new card (up to the daily cap), mixed at random; null when there
|
|
39
36
|
// is nothing to do right now. Cards are never asked before they're due: answering early would move them
|
|
40
37
|
// up the boxes without the spacing that makes them stick. Never the same note twice in a row while
|
|
41
38
|
// anything else is waiting. A `tour` deck is different: each card is asked once, in deck order, and
|
|
42
|
-
// never comes back as a review.
|
|
39
|
+
// never comes back as a review. A word's own `directions` (a cloze card's gaps) replace the deck's.
|
|
43
40
|
export function pickNext({ words, state, now = Date.now(), lastNoteId = null, directions = DIRECTIONS, tour = false, random = Math.random }) {
|
|
44
|
-
const candidates = words.flatMap((word) => directions.map((direction) => ({ word, direction, entry: state.items[itemKey(word.noteId, direction)] })));
|
|
41
|
+
const candidates = words.flatMap((word) => (word.directions ?? directions).map((direction) => ({ word, direction, entry: state.items[itemKey(word.noteId, direction)] })));
|
|
45
42
|
if (tour) return candidates.find((c) => !c.entry) ?? null;
|
|
46
43
|
|
|
47
44
|
const canIntroduce = newToday(state, now) < NEW_PER_DAY;
|
|
@@ -60,7 +57,7 @@ export function pickNext({ words, state, now = Date.now(), lastNoteId = null, di
|
|
|
60
57
|
export function nextDueAt({ words, state, now = Date.now(), directions = DIRECTIONS }) {
|
|
61
58
|
let next = null;
|
|
62
59
|
for (const word of words) {
|
|
63
|
-
for (const direction of directions) {
|
|
60
|
+
for (const direction of word.directions ?? directions) {
|
|
64
61
|
const entry = state.items[itemKey(word.noteId, direction)];
|
|
65
62
|
const at = entry ? entry.due : startOfTomorrow(now);
|
|
66
63
|
if (next === null || at < next) next = at;
|
package/src/session.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import { t as say } from "./i18n.js"; // `t` and `text` are taken here (the clock, an answer)
|
|
2
|
+
import { blankGap } from "./cardline.js";
|
|
1
3
|
import { closestCandidate, judge } from "./judge.js";
|
|
2
4
|
import { addVacation, applyAnswer, applyCaughtUp, applyOverrule, calendarMonth, cancelVacations, ensureProgress, markBadgesSeen, missedOn, recordMiss, snapshot, undoMiss, unseenBadges, vacationInfo } from "./progress.js";
|
|
3
5
|
import { describeDue, grade, itemKey, nextDueAt, pickNext, startOfTomorrow } from "./scheduler.js";
|
|
4
6
|
import { recordAnswer, saveState } from "./store.js";
|
|
5
7
|
import { createTipDeck } from "./tips.js";
|
|
6
8
|
import { dayKey } from "./dates.js";
|
|
7
|
-
import {
|
|
9
|
+
import { parsePause } from "./pause.js";
|
|
8
10
|
import { formatRange } from "./vacation.js";
|
|
9
11
|
|
|
10
12
|
const LABELS = { "en-pl": "EN → PL", "pl-en": "PL → EN" };
|
|
11
13
|
|
|
12
14
|
// the tag on the card's border: the language pair for a language deck, the deck's name otherwise
|
|
13
15
|
function labelOf(deck, direction) {
|
|
14
|
-
if (!deck) return LABELS[direction];
|
|
16
|
+
if (!deck) return LABELS[direction] ?? "";
|
|
17
|
+
if (direction.startsWith("c")) return deck.name; // a cloze gap: no direction to show
|
|
15
18
|
if (!deck.languages) return deck.name;
|
|
16
19
|
const { front, back } = deck.languages;
|
|
17
20
|
const [from, to] = direction === "en-pl" ? [front, back] : [back, front];
|
|
@@ -66,34 +69,59 @@ export function createSession({ loadWords, loadAllWords, state, getSettings, sav
|
|
|
66
69
|
empty.cheers = day.cheers;
|
|
67
70
|
empty.dayDone = day.done; // false: this deck is done, but another one still has cards today
|
|
68
71
|
}
|
|
69
|
-
const message = deck?.tour ? "
|
|
72
|
+
const message = deck?.tour ? say("quiz.empty.tourTitle") : words.length ? say("quiz.empty.laterTitle") : say("quiz.empty.noCardsTitle", { deck: deck?.name });
|
|
70
73
|
throw Object.assign(new Error(message), empty);
|
|
71
74
|
}
|
|
72
75
|
lastNoteId = item.word.noteId;
|
|
73
76
|
lastWrong = null;
|
|
74
77
|
|
|
75
78
|
const forward = item.direction === "en-pl";
|
|
79
|
+
const gap = item.direction.startsWith("c") ? Number(item.direction.slice(1)) - 1 : null;
|
|
80
|
+
const [prompt, expected] =
|
|
81
|
+
gap !== null
|
|
82
|
+
? [blankGap(item.word.word, gap), [item.word.cloze[gap]]]
|
|
83
|
+
: forward
|
|
84
|
+
? [item.word.word, item.word.translations]
|
|
85
|
+
: [item.word.translations.join(" / "), [item.word.word]];
|
|
76
86
|
return {
|
|
77
87
|
word: item.word,
|
|
78
88
|
direction: item.direction,
|
|
79
89
|
label: labelOf(deck, item.direction),
|
|
80
|
-
prompt
|
|
81
|
-
expected
|
|
90
|
+
prompt,
|
|
91
|
+
expected,
|
|
92
|
+
// a cloze card's back is a hint under the sentence ("Cieszę się na to")
|
|
93
|
+
context: gap !== null ? item.word.translations.join(" / ") : "",
|
|
82
94
|
wordCount: words.length,
|
|
83
95
|
tour: Boolean(deck?.tour) // the tour marks what to type with `backticks`
|
|
84
96
|
};
|
|
85
97
|
}
|
|
86
98
|
|
|
87
|
-
// Each deck decides which way it's asked (
|
|
88
|
-
// (
|
|
99
|
+
// Each deck decides which way it's asked (picked after its first card): front to back ("2 + 2" → "4"),
|
|
100
|
+
// back to front (a definition shown, its term typed), or both. The front-to-back direction is keyed
|
|
101
|
+
// "en-pl" internally, whatever the languages; a cloze card's gaps ("c1", "c2"…) come with the card.
|
|
89
102
|
function directionsOf(deck) {
|
|
90
|
-
return deck?.directions === "forward" ? ["en-pl"] : ["en-pl", "pl-en"];
|
|
103
|
+
return deck?.directions === "forward" ? ["en-pl"] : deck?.directions === "backward" ? ["pl-en"] : ["en-pl", "pl-en"];
|
|
91
104
|
}
|
|
92
105
|
|
|
106
|
+
// A typed answer, checked. (An empty one is a reveal: see reveal and selfGrade.)
|
|
93
107
|
async function answer(question, text, { hinted = false } = {}) {
|
|
94
108
|
const key = itemKey(question.word.noteId, question.direction);
|
|
95
109
|
// answers you once declared right (/correct) count for this card from now on
|
|
96
110
|
const result = judge(text, [...question.expected, ...(state.accepted?.[key] ?? [])]);
|
|
111
|
+
return record(question, { result, text, hinted });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// An empty Enter shows the answer and nothing is written yet: you say whether you knew it (selfGrade).
|
|
115
|
+
const reveal = (question) => ({ expected: question.expected, example: question.word.example });
|
|
116
|
+
|
|
117
|
+
// After a reveal. "Knew it" counts exactly like a typed right answer: boxes, goal, streak, combo and
|
|
118
|
+
// badges. Long answers can't be typed word for word, and they must be able to earn everything too.
|
|
119
|
+
async function selfGrade(question, knew, { hinted = false } = {}) {
|
|
120
|
+
return { ...(await record(question, { result: knew ? "exact" : "wrong", text: "", hinted })), self: true };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function record(question, { result, text, hinted }) {
|
|
124
|
+
const key = itemKey(question.word.noteId, question.direction);
|
|
97
125
|
const correct = result !== "wrong";
|
|
98
126
|
const t = now();
|
|
99
127
|
const before = state.items[key];
|
|
@@ -106,23 +134,24 @@ export function createSession({ loadWords, loadAllWords, state, getSettings, sav
|
|
|
106
134
|
totals.combo = correct ? totals.combo + 1 : 0;
|
|
107
135
|
lastWrong = correct ? null : { question, text, key, before, comboBefore, hinted, at: t };
|
|
108
136
|
// a blank answer on a tour card just shows it: the tour isn't something to have "missed"
|
|
109
|
-
|
|
137
|
+
const prompt = question.context ? `${question.prompt} (${question.context})` : question.prompt; // a cloze gap keeps its hint
|
|
138
|
+
if (!correct && !(question.tour && !text.trim())) recordMiss(state, { key, label: question.label, prompt, expected: question.expected, answer: text, at: t }, t);
|
|
110
139
|
|
|
111
140
|
const reward = applyAnswer(state, { result, goal: getSettings().dailyGoal, rules: rules(), combo: totals.combo, now: t });
|
|
112
141
|
const cheers = [...reward.cheers];
|
|
113
|
-
if (correct && totals.combo % COMBO_CHEER_EVERY === 0) cheers.push({ kind: "combo", text:
|
|
142
|
+
if (correct && totals.combo % COMBO_CHEER_EVERY === 0) cheers.push({ kind: "combo", text: say("cheers.combo", { count: totals.combo }) });
|
|
114
143
|
|
|
115
144
|
await save(state);
|
|
116
145
|
// the last card of the day settles it right away, so quitting now doesn't lose the goal
|
|
117
146
|
if (!question.tour) cheers.push(...(await settleDay()).cheers);
|
|
118
147
|
// given/closest feed the per-letter diff the UI shows after a miss or a forgiven typo
|
|
119
|
-
const closest = result === "exact" ? null : closestCandidate(text, [...question.expected, ...(state.accepted?.[key] ?? [])]);
|
|
148
|
+
const closest = result === "exact" || !text ? null : closestCandidate(text, [...question.expected, ...(state.accepted?.[key] ?? [])]);
|
|
120
149
|
return { result, hinted: hinted && correct, dueIn: describeDue(entry, t), combo: totals.combo, cheers, given: text, closest, nextDue: upNext() };
|
|
121
150
|
}
|
|
122
151
|
|
|
123
152
|
// Re-grade the last wrong answer as correct and remember the answer for this card.
|
|
124
153
|
async function overrule() {
|
|
125
|
-
if (!lastWrong) throw new Error("
|
|
154
|
+
if (!lastWrong) throw new Error(say("errors.nothingToCorrect"));
|
|
126
155
|
const { question, text, key, before, comboBefore, hinted, at } = lastWrong;
|
|
127
156
|
lastWrong = null;
|
|
128
157
|
|
|
@@ -142,6 +171,7 @@ export function createSession({ loadWords, loadAllWords, state, getSettings, sav
|
|
|
142
171
|
}
|
|
143
172
|
|
|
144
173
|
const canOverrule = () => lastWrong !== null && lastWrong.text.trim() !== ""; // nothing typed, nothing to accept
|
|
174
|
+
const wrongAnswer = () => lastWrong?.text ?? "";
|
|
145
175
|
|
|
146
176
|
const stats = () => snapshot(state, { goal: getSettings().dailyGoal, rules: rules(), now: now() });
|
|
147
177
|
|
|
@@ -153,24 +183,23 @@ export function createSession({ loadWords, loadAllWords, state, getSettings, sav
|
|
|
153
183
|
async function pause(args) {
|
|
154
184
|
const today = dayKey(now());
|
|
155
185
|
const parsed = parsePause(args, today);
|
|
156
|
-
if (!parsed) throw new Error(
|
|
186
|
+
if (!parsed) throw new Error(say("pause.help"));
|
|
157
187
|
if (parsed.action === "snooze") return { snooze: parsed.ms };
|
|
158
188
|
if (parsed.action === "days") {
|
|
159
189
|
// days off start today at the earliest: missed days can't be turned into days off afterwards
|
|
160
190
|
const from = parsed.from < today ? today : parsed.from;
|
|
161
|
-
if (parsed.to < today) throw new Error("
|
|
191
|
+
if (parsed.to < today) throw new Error(say("pause.past"));
|
|
162
192
|
addVacation(state, from, parsed.to, now());
|
|
163
193
|
await save(state);
|
|
164
|
-
|
|
165
|
-
return { message: `${what}: your streak is safe.` };
|
|
194
|
+
return { message: from === parsed.to ? say("pause.dayOff", { day: formatRange(from, from) }) : say("pause.daysOff", { range: formatRange(from, parsed.to) }) };
|
|
166
195
|
}
|
|
167
196
|
if (parsed.action === "off") {
|
|
168
197
|
cancelVacations(state, now());
|
|
169
198
|
await save(state);
|
|
170
|
-
return { snooze: "off", message: "
|
|
199
|
+
return { snooze: "off", message: say("pause.off") };
|
|
171
200
|
}
|
|
172
201
|
const { upcoming } = vacationInfo(ensureProgress(state, now()), today);
|
|
173
|
-
return { list: true, message: upcoming.length ?
|
|
202
|
+
return { list: true, message: upcoming.length ? say("pause.list", { ranges: upcoming.map((v) => formatRange(v.from, v.to)).join(", ") }) : say("pause.none", { help: say("pause.help") }) };
|
|
174
203
|
}
|
|
175
204
|
|
|
176
205
|
// a tip for the wait between questions; remembering which ones were shown is best-effort
|
|
@@ -186,6 +215,27 @@ export function createSession({ loadWords, loadAllWords, state, getSettings, sav
|
|
|
186
215
|
const gone = (key) => ids.has(key.slice(0, key.lastIndexOf(":")));
|
|
187
216
|
for (const key of Object.keys(state.items)) if (gone(key)) delete state.items[key];
|
|
188
217
|
for (const key of Object.keys(state.accepted ?? {})) if (gone(key)) delete state.accepted[key];
|
|
218
|
+
if (state.dormant) state.dormant = state.dormant.filter((key) => !gone(key));
|
|
219
|
+
await save(state);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// A deck is asked another way now (/decks): the directions it no longer asks rest. Their progress stays
|
|
223
|
+
// for when they're back, but doesn't count against mastering the card.
|
|
224
|
+
async function setDirections(cardIds, directions) {
|
|
225
|
+
const asked = new Set(directions === "forward" ? ["en-pl"] : directions === "backward" ? ["pl-en"] : ["en-pl", "pl-en"]);
|
|
226
|
+
const dormant = new Set(state.dormant ?? []);
|
|
227
|
+
for (const id of cardIds) for (const direction of ["en-pl", "pl-en"]) (asked.has(direction) ? dormant.delete : dormant.add).call(dormant, itemKey(id, direction));
|
|
228
|
+
state.dormant = [...dormant];
|
|
229
|
+
await save(state);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// progress of cards that changed shape (a cloze card fixed into a plain one, a gap removed) is dropped
|
|
233
|
+
async function forgetKeys(keys) {
|
|
234
|
+
for (const key of keys) {
|
|
235
|
+
delete state.items[key];
|
|
236
|
+
delete state.accepted?.[key];
|
|
237
|
+
}
|
|
238
|
+
if (state.dormant) state.dormant = state.dormant.filter((key) => !keys.includes(key));
|
|
189
239
|
await save(state);
|
|
190
240
|
}
|
|
191
241
|
|
|
@@ -223,5 +273,5 @@ export function createSession({ loadWords, loadAllWords, state, getSettings, sav
|
|
|
223
273
|
return fresh;
|
|
224
274
|
}
|
|
225
275
|
|
|
226
|
-
return { totals, next, answer, overrule, canOverrule, stats, month, missed, nextTip, pause, isFirstRun, markHatched, openBadges, forget, reset, inTour: () => inTour };
|
|
276
|
+
return { totals, next, answer, reveal, selfGrade, setDirections, forgetKeys, overrule, canOverrule, wrongAnswer, stats, month, missed, nextTip, pause, isFirstRun, markHatched, openBadges, forget, reset, inTour: () => inTour };
|
|
227
277
|
}
|
package/src/settings.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import { LANGUAGES, systemLanguage, t } from "./i18n.js";
|
|
2
|
+
|
|
3
|
+
export const DEFAULTS = { everyMs: 600_000, rhythm: "minutes", sound: true, volume: 0.5, dailyGoal: 20, tips: "sometimes", quiet: null, skipWeekends: true, deck: null };
|
|
2
4
|
|
|
3
5
|
export const INTERVALS = [60_000, 120_000, 300_000, 600_000, 900_000, 1_200_000, 1_800_000, 2_700_000, 3_600_000];
|
|
4
6
|
export const GOALS = [5, 10, 15, 20, 25, 30, 40, 50, 75, 100, 150, 200];
|
|
5
7
|
export const VOLUMES = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1];
|
|
6
8
|
export const TIP_MODES = ["always", "sometimes", "off"];
|
|
7
|
-
|
|
9
|
+
// how cards come: one every few minutes (everyMs), or a session where Enter asks the next one right
|
|
10
|
+
// away, endless or for a set number of cards, after which the minutes take over again
|
|
11
|
+
export const RHYTHMS = ["minutes", "session", "session-10", "session-20"];
|
|
12
|
+
export const sessionLength = (rhythm) => (rhythm.startsWith("session-") ? Number(rhythm.slice("session-".length)) : null);
|
|
8
13
|
// presets for /settings; any { from, to } in settings.json works too
|
|
9
14
|
export const QUIET_PRESETS = [null, { from: 21, to: 7 }, { from: 22, to: 8 }, { from: 23, to: 7 }, { from: 0, to: 8 }];
|
|
10
15
|
|
|
11
16
|
export function formatInterval(ms) {
|
|
12
|
-
if (ms < 60_000) return
|
|
13
|
-
if (ms < 3_600_000) return
|
|
14
|
-
return
|
|
17
|
+
if (ms < 60_000) return t("time.seconds", { n: Math.round(ms / 1000) });
|
|
18
|
+
if (ms < 3_600_000) return t("time.minutes", { n: Math.round(ms / 60_000) });
|
|
19
|
+
return t("time.hours", { n: Math.round(ms / 3_600_000) });
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
// older versions saved tips as a boolean
|
|
@@ -26,13 +31,15 @@ export function normalizeSettings(raw = {}) {
|
|
|
26
31
|
raw = raw && typeof raw === "object" ? raw : {};
|
|
27
32
|
return {
|
|
28
33
|
everyMs: isNumber(raw.everyMs) && raw.everyMs >= 1000 ? raw.everyMs : DEFAULTS.everyMs,
|
|
34
|
+
rhythm: RHYTHMS.includes(raw.rhythm) ? raw.rhythm : DEFAULTS.rhythm,
|
|
29
35
|
sound: typeof raw.sound === "boolean" ? raw.sound : DEFAULTS.sound,
|
|
30
36
|
volume: isNumber(raw.volume) && raw.volume >= 0 && raw.volume <= 1 ? raw.volume : DEFAULTS.volume,
|
|
31
37
|
dailyGoal: isNumber(raw.dailyGoal) && raw.dailyGoal >= 1 ? Math.round(raw.dailyGoal) : DEFAULTS.dailyGoal,
|
|
32
38
|
tips: normalizeTips(raw.tips),
|
|
33
39
|
skipWeekends: typeof raw.skipWeekends === "boolean" ? raw.skipWeekends : DEFAULTS.skipWeekends,
|
|
34
40
|
quiet: raw.quiet && isHour(raw.quiet.from) && isHour(raw.quiet.to) ? { from: raw.quiet.from, to: raw.quiet.to } : null,
|
|
35
|
-
deck: typeof raw.deck === "string" && raw.deck.trim() ? raw.deck : null // picked in /decks; null = your first deck
|
|
41
|
+
deck: typeof raw.deck === "string" && raw.deck.trim() ? raw.deck : null, // picked in /decks; null = your first deck
|
|
42
|
+
language: typeof raw.language === "string" && Object.hasOwn(LANGUAGES, raw.language) ? raw.language : systemLanguage() // until picked in /settings, the system's
|
|
36
43
|
};
|
|
37
44
|
}
|
|
38
45
|
|
package/src/starter.js
CHANGED
|
@@ -1,38 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { entry, language, t } from "./i18n.js";
|
|
2
|
+
import { addCard, cardsOf, createDeck, findDeck } from "./library.js";
|
|
2
3
|
|
|
3
|
-
// The deck a fresh install starts with: a short tour that teaches Dracosh by doing.
|
|
4
|
-
// exactly what to type, and the line shown after the answer
|
|
5
|
-
// deck: every card is asked once, in this order, and never
|
|
6
|
-
// what to type (or a command); the quiz shows them
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const STARTER_CARDS = [
|
|
12
|
-
{ front: "Welcome! Every few minutes a card asks you something. Type the answer and press Enter. Try it and type `hello`", back: ["hello"], example: "Press `Enter` now for the next card, or wait and it will come by itself." },
|
|
13
|
-
{ front: "Small typos still count. Type `dragon`, but miss a letter on purpose (like `dragn`)", back: ["dragon"], example: "A typo counts as right, and Dracosh shows you the correct spelling." },
|
|
14
|
-
{ front: "A card can accept more than one answer. What is 2 + 2? (`4` and `four` both work)", back: ["4", "four"], example: "Every right answer moves a card to a later box, so you see it less and less often." },
|
|
15
|
-
{ front: "Stuck? Type `/hint` and press Enter, and the answer shows up letter by letter. Try it, then type `apple`", back: ["apple"], example: "A hinted answer still counts, but the card stays in its box for now." },
|
|
16
|
-
{ front: "What is your dragon's secret name? Nobody knows, so get this one wrong on purpose and type `dog`", back: ["Asogaras"], example: "In your own decks a missed card comes back sooner. If you were marked wrong by mistake, type `/correct` now." },
|
|
17
|
-
{ front: "Type `/` at any time to see all commands. Try `/badges` after this card. For now, type `ok`", back: ["ok", "okay"], example: "`/stats` shows your calendar, `/companion` your dragon, `/settings` how often cards come." },
|
|
18
|
-
{ front: "Reach your daily goal every day to keep your streak. Your dragon grows with it. Type `every day`", back: ["every day", "everyday", "daily"], example: "Miss a day and a freeze saves your streak, if you have one left." },
|
|
19
|
-
{ front: "Need a break? `/pause 1h` holds the cards for an hour, `/pause 3d` gives you days off. For now, type `later`", back: ["later"], example: "Leave Dracosh alone for a few minutes and the dragon dozes off. Any key wakes it." },
|
|
20
|
-
{ front: "That's the tour! Type `done`", back: ["done"], example: "Now make it yours and type `/add` to start your own deck. The tour makes room for it." }
|
|
21
|
-
];
|
|
4
|
+
// The deck a fresh install starts with: a short tour that teaches Dracosh by doing. Its cards live in
|
|
5
|
+
// the locale (tour.cards): every card says exactly what to type, and the line shown after the answer
|
|
6
|
+
// explains the next thing. It's a `tour` deck: every card is asked once, in this order, and never
|
|
7
|
+
// comes back as a review. `Backticks` mark what to type (or a command); the quiz shows them
|
|
8
|
+
// highlighted, in the tour only. Answers never start with "/", because "/" opens the commands.
|
|
9
|
+
export const STARTER_DECK = "Getting started"; // the tour's English name, which the first versions were found by
|
|
10
|
+
// bump it when the cards change: an older copy of the tour in someone's library gets replaced
|
|
11
|
+
const STARTER_VERSION = 8;
|
|
22
12
|
|
|
23
13
|
// the tour as an earlier version created it (the first one had no version number yet)
|
|
24
14
|
const isStarter = (deck) => deck.starter !== undefined || (deck.name === STARTER_DECK && deck.type === "qa" && !deck.languages);
|
|
25
15
|
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
const tourCards = () => entry("tour.cards");
|
|
17
|
+
|
|
18
|
+
// The app's language changed: the tour's cards say the same in the new one. They keep their ids, so
|
|
19
|
+
// the cards already done stay done. The deck takes the new name unless one of yours has it.
|
|
20
|
+
function translateTour(library, deck, lang) {
|
|
21
|
+
const cards = tourCards();
|
|
22
|
+
cardsOf(library, deck.id).forEach((card, i) => Object.assign(card, { front: cards[i].front, back: [...cards[i].back], example: cards[i].example }));
|
|
23
|
+
const name = t("tour.deck");
|
|
24
|
+
if ((findDeck(library, name) ?? deck) === deck) deck.name = name;
|
|
25
|
+
deck.tourLanguage = lang;
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Adds the tour to an empty library, brings an older copy of it up to date (its progress is dropped
|
|
30
|
+
// with the old cards), or translates it into the app's language. Returns true when the library
|
|
31
|
+
// changed and needs saving.
|
|
28
32
|
export function seedLibrary(library, now = Date.now()) {
|
|
29
33
|
let deck = library.decks.find(isStarter);
|
|
30
34
|
if (library.decks.length && !deck) return false;
|
|
31
|
-
|
|
35
|
+
const lang = language();
|
|
36
|
+
const current = deck && (deck.starter ?? 1) >= STARTER_VERSION && cardsOf(library, deck.id).length === tourCards().length;
|
|
37
|
+
if (current) return (deck.tourLanguage ?? "en") === lang ? false : translateTour(library, deck, lang);
|
|
32
38
|
|
|
33
|
-
if (deck)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
if (deck) {
|
|
40
|
+
library.cards = library.cards.filter((card) => card.deckId !== deck.id);
|
|
41
|
+
const name = t("tour.deck");
|
|
42
|
+
if ((findDeck(library, name) ?? deck) === deck) deck.name = name;
|
|
43
|
+
} else deck = createDeck(library, { name: t("tour.deck"), type: "qa", languages: null, directions: "forward", tour: true, now });
|
|
44
|
+
Object.assign(deck, { tour: true, starter: STARTER_VERSION, tourLanguage: lang });
|
|
45
|
+
for (const card of tourCards()) addCard(library, deck.id, { ...card, now });
|
|
37
46
|
return true;
|
|
38
47
|
}
|