@openbooknetwork/hesap 0.2.3 → 0.3.1
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/package.json +2 -2
- package/src/client.css +254 -1
- package/src/families/counters/add-figures.js +85 -0
- package/src/families/counters/add-goals.js +82 -0
- package/src/families/counters/add-model.js +82 -0
- package/src/families/counters/add.js +442 -0
- package/src/families/counters/add.mjs +102 -0
- package/src/families/counters/bonds.js +5 -5
- package/src/families/counters/client.css +126 -1
- package/src/families/counters/client.js +10 -12
- package/src/families/counters/count-figures.js +23 -3
- package/src/families/counters/count-model.js +5 -0
- package/src/families/counters/count.js +31 -9
- package/src/families/counters/count.mjs +5 -3
- package/src/families/counters/counter.js +25 -0
- package/src/families/counters/goals.js +1 -9
- package/src/families/counters/i18n/en.yaml +142 -30
- package/src/families/counters/i18n/tr.yaml +116 -4
- package/src/families/counters/index.mjs +11 -6
- package/src/families/counters/match-figures.js +60 -0
- package/src/families/counters/match-goals.js +63 -0
- package/src/families/counters/match-model.js +93 -0
- package/src/families/counters/match.js +399 -0
- package/src/families/counters/match.mjs +102 -0
- package/src/families/counters/order-figures.js +46 -0
- package/src/families/counters/order-model.js +69 -0
- package/src/families/counters/order.js +199 -0
- package/src/families/counters/order.mjs +62 -0
- package/src/families/counters/reading.js +66 -0
- package/src/families/counters/scenes.js +18 -0
- package/src/families/line/client.css +118 -0
- package/src/families/line/client.js +12 -0
- package/src/families/line/figures.js +143 -0
- package/src/families/line/goals.js +168 -0
- package/src/families/line/i18n/en.yaml +61 -0
- package/src/families/line/i18n/tr.yaml +61 -0
- package/src/families/line/index.mjs +227 -0
- package/src/families/line/lens.js +49 -0
- package/src/families/line/line.js +624 -0
- package/src/families/line/model.js +219 -0
- package/src/families.mjs +2 -1
- package/src/i18n/en.yaml +211 -31
- package/src/i18n/tr.yaml +184 -4
- package/src/kit/i18n/en.yaml +8 -1
- package/src/kit/i18n/tr.yaml +7 -0
- package/src/kit/kit.css +9 -0
- package/src/kit/panel.js +9 -4
- package/src/kit/random.js +9 -0
- package/src/kit/written.js +70 -0
- package/src/node.mjs +13 -1
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// The goals a challenge page of the line scene can name. The page declares ranges, and the goal draws a target from
|
|
2
|
+
// them each time the page opens and each time the reader asks for another one. Every goal answers Check the same way:
|
|
3
|
+
// the point is on the target, or to its left, or to its right, and its goal line and notes are those of place. The
|
|
4
|
+
// build and the browser both use this file.
|
|
5
|
+
import { gapsOf, numberAt, labelled } from './model.js';
|
|
6
|
+
import { PLUS, MINUS } from '../../kit/written.js';
|
|
7
|
+
|
|
8
|
+
const range = r => Array.isArray(r) && r.length === 2 && r.every(Number.isInteger) && r[0] <= r[1];
|
|
9
|
+
const span = (lo, hi) => Array.from({ length: Math.max(0, hi - lo + 1) }, (_, i) => lo + i);
|
|
10
|
+
// judge compares the number at the point with the target once the reader has pressed Check.
|
|
11
|
+
const judge = (state, target) => !state.checked ? { done: false } : state.point === target ? { done: true } : { done: false, note: state.point < target ? 'left' : 'right' };
|
|
12
|
+
// The line of place-unmarked is at least UNMARKED_APART long, and its length is one of UNMARKED_LENGTHS, so its
|
|
13
|
+
// middle is a ten.
|
|
14
|
+
export const UNMARKED_APART = 40, UNMARKED_LENGTHS = [20, 40, 60, 80, 100];
|
|
15
|
+
const lengths = () => UNMARKED_LENGTHS.filter(n => n >= UNMARKED_APART);
|
|
16
|
+
export const TWO_GAPS = 10, TWO_TOP = 100, TWO_STEPS = [2, 5, 10], TWO_APART = 3; // The line of place-two-labels.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
// The words of a goal's hint and of its notes, as a string key and the numbers in it. The place goals share their
|
|
20
|
+
// notes: the side the point is on, and the number to move it to.
|
|
21
|
+
const sideNote = (t, note) => ({ key: `note-place-${note}`, vars: { target: t.target } });
|
|
22
|
+
|
|
23
|
+
export const GOALS = {
|
|
24
|
+
// The reader puts the point on a number of a marked line that carries no label, and presses Check. The target is
|
|
25
|
+
// a mark of the line in the page's range, with no label and away from the point's start.
|
|
26
|
+
place: {
|
|
27
|
+
fields: ['target'],
|
|
28
|
+
problem(c, spec) {
|
|
29
|
+
if (!range(c.target)) return `target is ${JSON.stringify(c.target ?? null)}, write the range of numbers to place as [low, high], such as [11, 99]`;
|
|
30
|
+
if (c.target[0] < spec.from || c.target[1] > spec.to) return `target is [${c.target}], write a range inside the line from ${spec.from} to ${spec.to}`;
|
|
31
|
+
return null;
|
|
32
|
+
},
|
|
33
|
+
targets(c, spec) {
|
|
34
|
+
const start = spec.point ?? spec.from;
|
|
35
|
+
return span(0, gapsOf(spec)).map(k => numberAt(spec, k)).filter(n => n >= c.target[0] && n <= c.target[1] && !labelled(spec, n) && n !== start);
|
|
36
|
+
},
|
|
37
|
+
draw(c, spec, dice) { const all = GOALS.place.targets(c, spec); return all.length ? { target: dice.pick(all) } : null; },
|
|
38
|
+
holds: (state, spec, c, t) => judge(state, t.target),
|
|
39
|
+
// Every mark of a marked line is in reach of the drag and of the jumps.
|
|
40
|
+
reach: () => null,
|
|
41
|
+
// The hint names the long marks either side of the number and counts from the nearer one.
|
|
42
|
+
hint(t, spec) {
|
|
43
|
+
const marks = span(0, gapsOf(spec)).map(k => numberAt(spec, k)).filter(n => labelled(spec, n));
|
|
44
|
+
const before = Math.max(...marks.filter(n => n < t.target)), after = Math.min(...marks.filter(n => n > t.target));
|
|
45
|
+
return { key: t.target - before <= after - t.target ? 'hint-place-on' : 'hint-place-back', vars: { target: t.target, before, after } };
|
|
46
|
+
},
|
|
47
|
+
note: sideNote,
|
|
48
|
+
},
|
|
49
|
+
// The goal draws the line: a step, a left end that is a multiple of it, and 10 gaps that end at 100 or below. Two
|
|
50
|
+
// marks next to each other carry labels, and the point starts on one of them. The target is a mark at least three
|
|
51
|
+
// steps from both, so the reader reads the step and counts jumps. Once the goal holds every mark shows its label.
|
|
52
|
+
'place-two-labels': {
|
|
53
|
+
fields: ['step', 'from'],
|
|
54
|
+
draws: true,
|
|
55
|
+
problem(c) {
|
|
56
|
+
if (!Array.isArray(c.step) || !c.step.length || !c.step.every(v => TWO_STEPS.includes(v))) return `step is ${JSON.stringify(c.step ?? null)}, write a list of steps from ${TWO_STEPS.join(', ')}, such as [2, 5, 10]`;
|
|
57
|
+
if (!range(c.from) || c.from[0] < 0) return `from is ${JSON.stringify(c.from ?? null)}, write the range of the left end as [low, high] from 0, such as [0, 50]`;
|
|
58
|
+
return null;
|
|
59
|
+
},
|
|
60
|
+
// lines gives every line the page's ranges allow: each step with each left end that is a multiple of it.
|
|
61
|
+
noLine: c => `step [${c.step}] and from [${c.from}] give no line of 10 gaps that ends at 100 or below`,
|
|
62
|
+
lines: c => c.step.flatMap(step => span(c.from[0], c.from[1]).filter(from => from % step === 0 && from + TWO_GAPS * step <= TWO_TOP).map(from => ({ step, from }))),
|
|
63
|
+
draw(c, spec, dice) {
|
|
64
|
+
// The step comes first, each step that has a line as likely as the others, and then a left end of that step, so
|
|
65
|
+
// the steps with many left ends do not crowd out the others.
|
|
66
|
+
const lines = GOALS['place-two-labels'].lines(c), steps = [...new Set(lines.map(l => l.step))];
|
|
67
|
+
if (!lines.length) return null;
|
|
68
|
+
const pickStep = dice.pick(steps), { step, from } = dice.pick(lines.filter(l => l.step === pickStep)), k = dice.int(0, TWO_GAPS - 1), at = k2 => from + k2 * step;
|
|
69
|
+
const marks = span(0, TWO_GAPS).filter(j => Math.abs(j - k) >= TWO_APART && Math.abs(j - k - 1) >= TWO_APART);
|
|
70
|
+
return { step, from, to: at(TWO_GAPS), labels: [at(k), at(k + 1)], start: at(dice.pick([k, k + 1])), target: at(dice.pick(marks)) };
|
|
71
|
+
},
|
|
72
|
+
// The page's line as the goal drew it. Its ends are marks like the others, and reveal shows every label once the
|
|
73
|
+
// goal holds.
|
|
74
|
+
page: t => ({ from: t.from, to: t.to, step: t.step, labels: t.labels, point: t.start, reveal: true }),
|
|
75
|
+
holds: (state, spec, c, t) => judge(state, t.target),
|
|
76
|
+
// The hint reads the step from the two labels and counts on from the right one, or back from the left one.
|
|
77
|
+
hint: t => ({ key: t.target > t.labels[1] ? 'hint-place-two-labels-on' : 'hint-place-two-labels-back', vars: { a: t.labels[0], b: t.labels[1], target: t.target } }),
|
|
78
|
+
note: sideNote,
|
|
79
|
+
reach: (spec, c, t) => t.target < t.from || t.target > t.to || (t.target - t.from) % t.step ? `the target ${t.target} is no mark of the line from ${t.from} to ${t.to} in steps of ${t.step}` : null,
|
|
80
|
+
},
|
|
81
|
+
// The goal draws an unmarked line between two tens whose length is one of UNMARKED_LENGTHS, and a whole number more
|
|
82
|
+
// than a tenth of the line from each end and from its middle, so neither the start nor the Middle button holds the
|
|
83
|
+
// goal. The point starts at the left end and moves freely. Check holds within a tenth of the line either side of
|
|
84
|
+
// the number. Once the goal holds, a flag shows where the number is.
|
|
85
|
+
'place-unmarked': {
|
|
86
|
+
fields: ['from', 'to'],
|
|
87
|
+
draws: true,
|
|
88
|
+
takes: ['middle'],
|
|
89
|
+
flags: true,
|
|
90
|
+
problem(c) {
|
|
91
|
+
for (const f of ['from', 'to']) if (!range(c[f]) || c[f][0] < 0 || c[f][1] > 100) return `${f} is ${JSON.stringify(c[f] ?? null)}, write the range of the ${f === 'from' ? 'left' : 'right'} end as [low, high] from 0 to 100, such as ${f === 'from' ? '[0, 30]' : '[40, 100]'}`;
|
|
92
|
+
return null;
|
|
93
|
+
},
|
|
94
|
+
noLine: c => `from [${c.from}] and to [${c.to}] give no two tens ${lengths().slice(0, -1).join(', ')} or ${lengths().at(-1)} apart`,
|
|
95
|
+
lines: c => span(c.from[0], c.from[1]).filter(a => a % 10 === 0).flatMap(a => span(c.to[0], c.to[1]).filter(b => b % 10 === 0 && lengths().includes(b - a)).map(b => ({ from: a, to: b }))),
|
|
96
|
+
// targets gives the whole numbers of a line more than a tenth of it from its ends and its middle.
|
|
97
|
+
targets: (from, to) => { const far = (to - from) / 10, mid = (from + to) / 2; return span(from, to).filter(n => n - from > far && to - n > far && Math.abs(n - mid) > far); },
|
|
98
|
+
draw(c, spec, dice) {
|
|
99
|
+
// The length comes first, each length that has a line as likely as the others, and then a line of that length.
|
|
100
|
+
const lines = GOALS['place-unmarked'].lines(c), lens = [...new Set(lines.map(l => l.to - l.from))];
|
|
101
|
+
if (!lines.length) return null;
|
|
102
|
+
const len = dice.pick(lens), { from, to } = dice.pick(lines.filter(l => l.to - l.from === len));
|
|
103
|
+
return { from, to, start: from, target: dice.pick(GOALS['place-unmarked'].targets(from, to)) };
|
|
104
|
+
},
|
|
105
|
+
page: t => ({ from: t.from, to: t.to, step: 1, marks: 'ends', labels: 'ends', point: t.start }),
|
|
106
|
+
holds(state, spec, c, t) {
|
|
107
|
+
if (!state.checked) return { done: false };
|
|
108
|
+
const off = state.point - t.target;
|
|
109
|
+
return Math.abs(off) <= (t.to - t.from) / 10 ? { done: true } : { done: false, note: off < 0 ? 'left' : 'right' };
|
|
110
|
+
},
|
|
111
|
+
reach: (spec, c, t) => t.target < t.from || t.target > t.to ? `the target ${t.target} is off the line from ${t.from} to ${t.to}` : null,
|
|
112
|
+
// The hint marks the middle, names the half the number lies in, and the guide it lies closer to.
|
|
113
|
+
hint(t) {
|
|
114
|
+
const mid = (t.from + t.to) / 2, end = t.target > mid ? t.to : t.from;
|
|
115
|
+
return { key: 'hint-place-unmarked', vars: { mid, target: t.target, lo: Math.min(mid, end), hi: Math.max(mid, end), near: Math.abs(t.target - mid) <= Math.abs(t.target - end) ? mid : end } };
|
|
116
|
+
},
|
|
117
|
+
note: sideNote,
|
|
118
|
+
},
|
|
119
|
+
// The goal draws a start and a number to add or to subtract, each sign as likely as the other where both draw, with
|
|
120
|
+
// the answer on the line. The point opens on the start, whose ring stays put, and the reader jumps it to the answer
|
|
121
|
+
// and presses Check. A wrong Check says the point went the wrong way, or made too few or too many jumps. Once the
|
|
122
|
+
// goal holds, the written line shows.
|
|
123
|
+
'jump-to': {
|
|
124
|
+
fields: ['start', 'add', 'subtract'],
|
|
125
|
+
labels: true,
|
|
126
|
+
problem(c, spec) {
|
|
127
|
+
if (!range(c.start) || c.start[0] < spec.from || c.start[1] > spec.to) return `start is ${JSON.stringify(c.start ?? null)}, write the range of the start as [low, high] inside the line from ${spec.from} to ${spec.to}, such as [2, 18]`;
|
|
128
|
+
for (const f of ['add', 'subtract']) if (c[f] !== undefined && (!range(c[f]) || c[f][0] < 1)) return `${f} is ${JSON.stringify(c[f])}, write the numbers to ${f} as [low, high] from 1, such as [2, 4]`;
|
|
129
|
+
if (c.add === undefined && c.subtract === undefined) return 'add and subtract are missing, write the numbers to add, to subtract, or both, such as add: [2, 4]';
|
|
130
|
+
return null;
|
|
131
|
+
},
|
|
132
|
+
// sums gives every start and number of one sign whose answer is a mark of the line.
|
|
133
|
+
sums(c, spec, sign) {
|
|
134
|
+
const r = sign === PLUS ? c.add : c.subtract;
|
|
135
|
+
if (!r) return [];
|
|
136
|
+
return span(c.start[0], c.start[1]).filter(n => (n - spec.from) % spec.step === 0).flatMap(start => span(r[0], r[1]).map(n => ({ start, sign, n, target: sign === PLUS ? start + n * spec.step : start - n * spec.step })))
|
|
137
|
+
.filter(d => d.target >= spec.from && d.target <= spec.to);
|
|
138
|
+
},
|
|
139
|
+
draw(c, spec, dice) {
|
|
140
|
+
const signs = [PLUS, MINUS].filter(sign => GOALS['jump-to'].sums(c, spec, sign).length);
|
|
141
|
+
return signs.length ? dice.pick(GOALS['jump-to'].sums(c, spec, dice.pick(signs))) : null;
|
|
142
|
+
},
|
|
143
|
+
page: t => ({ start: t.start, point: t.start }),
|
|
144
|
+
holds(state, spec, c, t) {
|
|
145
|
+
if (!state.checked) return { done: false };
|
|
146
|
+
if (state.point === t.target) return { done: true };
|
|
147
|
+
const way = Math.sign(t.target - t.start), went = Math.sign(state.point - t.start);
|
|
148
|
+
return { done: false, note: went === -way ? 'way' : Math.abs(state.point - t.start) < Math.abs(t.target - t.start) ? 'few' : 'many' };
|
|
149
|
+
},
|
|
150
|
+
reach: () => null,
|
|
151
|
+
// The hint says the start, the button and the numbers said at the first jumps. The calculation is written as the
|
|
152
|
+
// kit writes it, so the scene passes calc in.
|
|
153
|
+
hint(t) {
|
|
154
|
+
const dir = t.sign === PLUS ? 1 : -1, sign = t.sign === PLUS ? 'plus' : 'minus';
|
|
155
|
+
return { key: t.n === 1 ? `hint-jump-${sign}-one` : `hint-jump-${sign}`, vars: { start: t.start, n: t.n, next: t.start + dir, then: t.start + 2 * dir } };
|
|
156
|
+
},
|
|
157
|
+
// A note says which way the calculation goes, or how many jumps the point made against the number it needs.
|
|
158
|
+
note(t, note, state) {
|
|
159
|
+
const done = Math.abs(state.point - t.start);
|
|
160
|
+
if (note === 'way') return { key: `note-jump-way-${t.sign === PLUS ? 'plus' : 'minus'}`, vars: { start: t.start } };
|
|
161
|
+
if (note === 'few') return { key: done ? 'note-jump-few' : 'note-jump-few-none', vars: { start: t.start, done, n: t.n } };
|
|
162
|
+
return { key: 'note-jump-many', vars: { done, n: t.n } };
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// The reader's state as a challenge opens: the point on its start and nothing checked.
|
|
168
|
+
export const challengeStart = (spec, t) => ({ checked: false, point: t?.start ?? spec.point ?? spec.from });
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
line_lead: "Move the point along the line and read the number at its mark."
|
|
2
|
+
line_jump-left: Jump left
|
|
3
|
+
line_jump-right: Jump right
|
|
4
|
+
line_point: Number at the point
|
|
5
|
+
line_point-short: Point
|
|
6
|
+
line_second: Number at the second point
|
|
7
|
+
line_second-short: Second point
|
|
8
|
+
line_jumps: Jumps
|
|
9
|
+
line_step: Step
|
|
10
|
+
line_from: Left end
|
|
11
|
+
line_to: Right end
|
|
12
|
+
line_point-name: Point
|
|
13
|
+
line_second-name: Second point
|
|
14
|
+
line_reading-later: "{a} is greater than {b}"
|
|
15
|
+
line_reading-both: "Both points are on {a}"
|
|
16
|
+
line_goal-place: "Put the point on {target}, then press Check."
|
|
17
|
+
line_goal-place-done: "The point is on {target}."
|
|
18
|
+
line_note-place-left: "The point is to the left of {target}. Move it to the right."
|
|
19
|
+
line_note-place-right: "The point is to the right of {target}. Move it to the left."
|
|
20
|
+
line_ten-before: Ten before
|
|
21
|
+
line_ten-after: Ten after
|
|
22
|
+
line_placed: Cards placed
|
|
23
|
+
line_placed-short: Placed
|
|
24
|
+
line_placed-of: "{n} of {all}"
|
|
25
|
+
line_open-gap: "Gap from {a} to {b}"
|
|
26
|
+
line_card: "Card {x}"
|
|
27
|
+
line_find: Number to find
|
|
28
|
+
line_show: Show
|
|
29
|
+
line_next: Next number
|
|
30
|
+
line_middle: Middle
|
|
31
|
+
line_van: Van
|
|
32
|
+
line_estimate: Estimate
|
|
33
|
+
line_open-book: Open the book
|
|
34
|
+
line_bookmark: Bookmark
|
|
35
|
+
line_hint-place-unmarked: "Press Middle to mark {mid}. {target} is between {lo} and {hi}, and closer to {near}. Put the point there."
|
|
36
|
+
line_goal-place-unmarked-done: "The point is close to {target}."
|
|
37
|
+
line_between: "between {a} and {b}"
|
|
38
|
+
line_gaps-unequal: Some gaps are longer than others.
|
|
39
|
+
line_gaps-equal: "All the gaps are the same length."
|
|
40
|
+
line_mark-name: "Mark {x}"
|
|
41
|
+
line_mark-left: The gap on its left is longer
|
|
42
|
+
line_mark-right: The gap on its right is longer
|
|
43
|
+
line_mark-even: "The gaps on both sides of it are equal"
|
|
44
|
+
line_start: Start
|
|
45
|
+
line_goal-jump: "Jump from {start} to find {calc}, then press Check."
|
|
46
|
+
line_note-jump-few: "The point has made {done} of the {n} jumps that {calc} needs. Keep jumping."
|
|
47
|
+
line_note-jump-many: "The point has made {done} jumps, but {calc} needs only {n}. Jump back."
|
|
48
|
+
line_new-line: New line
|
|
49
|
+
line_goal-place-unmarked: "Put the point close to {target}, then press Check."
|
|
50
|
+
line_find-short: Find
|
|
51
|
+
line_hint-place-on: "{target} is between the long marks for {before} and {after}. Start at {before} and count on one mark at a time until you get to {target}."
|
|
52
|
+
line_hint-place-back: "{target} is between the long marks for {before} and {after}. Start at {after} and count back one mark at a time until you get to {target}."
|
|
53
|
+
line_hint-place-two-labels-on: "The labels {a} and {b} are on marks next to each other, so the step from one mark to the next is {b} − {a}. Count on from {b} in steps of that size until you get to {target}."
|
|
54
|
+
line_hint-place-two-labels-back: "The labels {a} and {b} are on marks next to each other, so the step from one mark to the next is {b} − {a}. Count back from {a} in steps of that size until you get to {target}."
|
|
55
|
+
line_hint-jump-plus: "Start at {start} and press Jump right {n} times. At each jump, say the next number. The first two are {next} and {then}."
|
|
56
|
+
line_hint-jump-minus: "Start at {start} and press Jump left {n} times. At each jump, say the number before. The first two are {next} and {then}."
|
|
57
|
+
line_hint-jump-plus-one: "Start at {start}. Press Jump right once and say the next number, {next}."
|
|
58
|
+
line_hint-jump-minus-one: "Start at {start}. Press Jump left once and say the number before, {next}."
|
|
59
|
+
line_note-jump-way-plus: "{calc} is an addition, so the jumps go to the right from {start}."
|
|
60
|
+
line_note-jump-way-minus: "{calc} is a subtraction, so the jumps go to the left from {start}."
|
|
61
|
+
line_note-jump-few-none: "The point is still on {start}. Make the jumps for {calc} from there."
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
line_lead: "Noktayı doğru boyunca hareket ettirin ve çizgisindeki sayıyı okuyun."
|
|
2
|
+
line_jump-left: Sola zıpla
|
|
3
|
+
line_jump-right: Sağa zıpla
|
|
4
|
+
line_point: Noktadaki sayı
|
|
5
|
+
line_point-short: Nokta
|
|
6
|
+
line_second: İkinci noktadaki sayı
|
|
7
|
+
line_second-short: İkinci nokta
|
|
8
|
+
line_jumps: Zıplamalar
|
|
9
|
+
line_step: Adım
|
|
10
|
+
line_from: Sol uç
|
|
11
|
+
line_to: Sağ uç
|
|
12
|
+
line_point-name: Nokta
|
|
13
|
+
line_second-name: İkinci nokta
|
|
14
|
+
line_reading-later: "{a}, {b} sayısından büyüktür"
|
|
15
|
+
line_reading-both: "İki nokta da {a} üzerinde"
|
|
16
|
+
line_goal-place: "Noktayı {target} üzerine koyun, sonra Kontrol et düğmesine basın."
|
|
17
|
+
line_goal-place-done: "Nokta {target} üzerinde."
|
|
18
|
+
line_note-place-left: Nokta sayının solunda.
|
|
19
|
+
line_note-place-right: Nokta sayının sağında.
|
|
20
|
+
line_ten-before: Önceki onluk
|
|
21
|
+
line_ten-after: Sonraki onluk
|
|
22
|
+
line_placed: Yerleşen kartlar
|
|
23
|
+
line_placed-short: Yerleşen
|
|
24
|
+
line_placed-of: "{n} / {all}"
|
|
25
|
+
line_open-gap: "{a} ile {b} arasındaki aralık"
|
|
26
|
+
line_card: "Kart {x}"
|
|
27
|
+
line_find: Bul
|
|
28
|
+
line_show: Göster
|
|
29
|
+
line_next: Sonraki
|
|
30
|
+
line_middle: Orta
|
|
31
|
+
line_van: Kamyonet
|
|
32
|
+
line_estimate: Tahmin
|
|
33
|
+
line_open-book: Kitabı aç
|
|
34
|
+
line_bookmark: Ayraç
|
|
35
|
+
line_hint-place-unmarked: "Orta düğmesine basın. Sayı ortadan önce mi sonra mı? Sonra ortaya ve yakın uca ne kadar uzak olduğunu kestirin."
|
|
36
|
+
line_goal-place-unmarked-done: "Nokta {target} sayısına yakın."
|
|
37
|
+
line_between: "{a} ile {b} arasında"
|
|
38
|
+
line_gaps-unequal: Bazı aralıklar ötekilerden uzun.
|
|
39
|
+
line_gaps-equal: Bütün aralıklar eşit.
|
|
40
|
+
line_mark-name: "Çizgi {x}"
|
|
41
|
+
line_mark-left: Solundaki aralık daha uzun
|
|
42
|
+
line_mark-right: Sağındaki aralık daha uzun
|
|
43
|
+
line_mark-even: İki aralığı eşit
|
|
44
|
+
line_start: Başlangıç
|
|
45
|
+
line_goal-jump: "{start} sayısından zıplayarak {calc} işlemini bulun, sonra Kontrol et düğmesine basın."
|
|
46
|
+
line_note-jump-few: Zıplamalar az.
|
|
47
|
+
line_note-jump-many: Zıplamalar çok.
|
|
48
|
+
line_new-line: Yeni doğru
|
|
49
|
+
line_goal-place-unmarked: "Noktayı {target} sayısına yakın koyun, sonra Kontrol et düğmesine basın."
|
|
50
|
+
line_find-short: Bul
|
|
51
|
+
line_hint-place-on: "Sayının arasında durduğu iki uzun çizgiyi bulun. Soldakinden ileri ya da sağdakinden geri zıplayarak sayın."
|
|
52
|
+
line_hint-place-back: "Sayının arasında durduğu iki uzun çizgiyi bulun. Soldakinden ileri ya da sağdakinden geri zıplayarak sayın."
|
|
53
|
+
line_hint-place-two-labels-on: "Yan yana iki etiket adımı verir. Bir etiketten sayıya kadar zıplamaları sayın."
|
|
54
|
+
line_hint-place-two-labels-back: "Yan yana iki etiket adımı verir. Bir etiketten sayıya kadar zıplamaları sayın."
|
|
55
|
+
line_hint-jump-plus: "Başlangıçtaki sayıyı söyleyin, sonra her zıplamada bir sayı sayın. + için sağa, − için sola zıplayın."
|
|
56
|
+
line_hint-jump-minus: "Başlangıçtaki sayıyı söyleyin, sonra her zıplamada bir sayı sayın. + için sağa, − için sola zıplayın."
|
|
57
|
+
line_hint-jump-plus-one: "Başlangıçtaki sayıyı söyleyin, sonra her zıplamada bir sayı sayın. + için sağa, − için sola zıplayın."
|
|
58
|
+
line_hint-jump-minus-one: "Başlangıçtaki sayıyı söyleyin, sonra her zıplamada bir sayı sayın. + için sağa, − için sola zıplayın."
|
|
59
|
+
line_note-jump-way-plus: Nokta yanlış yöne zıpladı.
|
|
60
|
+
line_note-jump-way-minus: Nokta yanlış yöne zıpladı.
|
|
61
|
+
line_note-jump-few-none: Zıplamalar az.
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// The Node half of the line family. Its one scene draws a number line with marks at equal gaps and a point the
|
|
2
|
+
// reader drags or jumps. It checks a page's fields and says what each link shows when the page opens.
|
|
3
|
+
import { schema } from '@openbooknetwork/kitap';
|
|
4
|
+
import { LOOKS, isFree, gapsKey, writtenOf, labelKeep, posOf, gapOn, LABELS_APART, PHONE, STONES_TO, GAPS, isStones, isMark, gapsOf, labelled, cardsOf, middleOf, findsOf, opening, counts, measuresOf, readoutsOf, readingOf } from './model.js';
|
|
5
|
+
import { GOALS, challengeStart } from './goals.js';
|
|
6
|
+
import { numbers } from '../../kit/format.js';
|
|
7
|
+
import { words, reading, DASH } from '../../kit/written.js';
|
|
8
|
+
import { list, string, value, challenge, drawn } from '../../node.mjs';
|
|
9
|
+
|
|
10
|
+
const { z, check } = schema;
|
|
11
|
+
// The longest line a page with moved marks takes: on a 390px phone a longer one leaves no room for a mark off its
|
|
12
|
+
// place a third of a gap with its label 10px from the next.
|
|
13
|
+
const MOVED_TO = 12;
|
|
14
|
+
const Int = z.number().int();
|
|
15
|
+
const Fields = z.object({
|
|
16
|
+
look: z.enum(LOOKS).default('line'), // The number line, or the frog's stones for the opening pages.
|
|
17
|
+
from: Int.min(0).default(0), // The number at the left end.
|
|
18
|
+
to: Int.optional(), // The number at the right end, at the page's own step.
|
|
19
|
+
// The number between two marks next to each other, or a row of steps the reader picks from.
|
|
20
|
+
step: z.union([Int.min(1), z.object({ segment: z.array(Int.min(1)).min(2), start: Int.optional() }).strict()]).default(1),
|
|
21
|
+
marks: z.enum(['all', 'ends']).default('all'), // A mark at every step, or at the two ends alone for an unmarked line.
|
|
22
|
+
// Every mark carries its number, or the two ends alone, or the multiples of a number, or the numbers of a list.
|
|
23
|
+
labels: z.union([z.enum(['all', 'ends']), Int.min(1), z.array(Int)]).optional(),
|
|
24
|
+
blank: z.array(Int).default([]), // Marks that carry an empty label box.
|
|
25
|
+
cards: z.union([z.literal(true), z.array(Int)]).optional(), // Label cards the reader drags onto the blank marks.
|
|
26
|
+
point: z.union([Int, z.literal(false)]).optional(), // The mark the point starts on, the left end when left out, or no point.
|
|
27
|
+
start: Int.optional(), // The start of the jumps, a ring the reader drags, which the point takes when point is left out.
|
|
28
|
+
// The written line of the jumps under the line, or of the difference of the start and the second point.
|
|
29
|
+
written: z.union([z.literal(true), z.literal('difference')]).optional(),
|
|
30
|
+
second: Int.optional(), // A second point, of another shape and colour.
|
|
31
|
+
flag: z.boolean().default(false), // Each point carries its number in a flag above it.
|
|
32
|
+
reading: z.boolean().default(false), // A line of words says which point's number comes later in the count.
|
|
33
|
+
jump: z.boolean().default(false), // Jump left and Jump right move the point one gap and draw an arc over it.
|
|
34
|
+
bracket: z.literal(10).optional(), // A bracket from the ten before the point to the ten after it.
|
|
35
|
+
open: z.boolean().default(false), // A tap on a gap opens it under the line, with a mark for every number in it.
|
|
36
|
+
middle: z.union([z.boolean(), z.literal('button')]).default(false), // The middle's long mark, or a button that draws it.
|
|
37
|
+
find: z.union([Int, z.array(Int).min(1)]).optional(), // The number to place, or a list of them, with Show and Next.
|
|
38
|
+
// The reader's estimate of the number at the point, on a stepper or a slider, with its estimate mark.
|
|
39
|
+
estimate: z.union([z.object({ stepper: z.tuple([Int, Int]), start: Int.optional() }).strict(), z.object({ slider: z.tuple([Int, Int]), start: Int.optional() }).strict()]).optional(),
|
|
40
|
+
// Marks that start off their places, each by a part of a gap, for the reader to drag back.
|
|
41
|
+
moved: z.array(z.object({ mark: Int, by: z.number() }).strict()).min(1).optional(),
|
|
42
|
+
draw: z.boolean().default(false), // A line of label cards drawn at random, with New line to draw another.
|
|
43
|
+
readout: z.array(z.string()).default([]),
|
|
44
|
+
// A challenge names a goal of goals.js and the ranges it draws from.
|
|
45
|
+
challenge: z.object({ goal: z.string(), target: z.tuple([Int, Int]).optional(), step: z.array(Int).optional(), from: z.tuple([Int, Int]).optional(), to: z.tuple([Int, Int]).optional(),
|
|
46
|
+
start: z.tuple([Int, Int]).optional(), add: z.tuple([Int, Int]).optional(), subtract: z.tuple([Int, Int]).optional() }).strict().optional(),
|
|
47
|
+
}).strict();
|
|
48
|
+
|
|
49
|
+
function read({ scene, ...fields }, { at }, ctx) {
|
|
50
|
+
const pg = check(Fields, fields, at), fail = words => ctx.fail(at, words), step = value(pg.step), est = value(pg.estimate);
|
|
51
|
+
// The book is an unmarked line. An unmarked line labels its ends unless the page says otherwise.
|
|
52
|
+
const marks = pg.look === 'book' ? 'ends' : pg.marks;
|
|
53
|
+
const spec = { ...pg, scene, marks, labels: pg.labels ?? (marks === 'ends' ? 'ends' : 'all'), step: step.n, stepCtl: step.ctl, estimate: est.n, estimateCtl: est.ctl };
|
|
54
|
+
const done = () => { const ids = measuresOf(spec); return { data: spec, has: id => ids.includes(id), offers: ids.length ? `one of ${list(ids)}` : 'nothing, a challenge page draws its numbers as it opens' }; };
|
|
55
|
+
// A page that draws its line of cards takes no field of the line, and the browser draws it as the page opens.
|
|
56
|
+
if (pg.draw) {
|
|
57
|
+
for (const f of ['from', 'to', 'step', 'labels', 'blank', 'cards', 'point', 'marks', 'second', 'flag', 'reading', 'jump', 'bracket', 'open', 'middle', 'find', 'estimate', 'challenge', 'start', 'written', 'moved']) if (fields[f] !== undefined) fail(`${f} is drawn with the line on a page with draw, leave it out`);
|
|
58
|
+
if (pg.look !== 'line') fail(`look is ${pg.look}, a page with draw shows the line look, leave look out`);
|
|
59
|
+
const outs = readoutsOf(spec);
|
|
60
|
+
for (const id of pg.readout) if (!outs.includes(id)) fail(`readout names "${id}", this page reads out ${list(outs)}`);
|
|
61
|
+
return done();
|
|
62
|
+
}
|
|
63
|
+
// A goal that draws its line takes no line from the page.
|
|
64
|
+
if (pg.challenge && GOALS[pg.challenge.goal]?.draws) { readDrawn(fields, pg, spec, at, ctx); return done(); }
|
|
65
|
+
if (spec.to === undefined) { fail('to is missing, write the number at the right end, such as 20'); return done(); }
|
|
66
|
+
if (step.ctl) {
|
|
67
|
+
const items = step.ctl.items;
|
|
68
|
+
if (items.some((v, i) => i && v <= items[i - 1])) fail(`step.segment is [${items}], write different steps from the least to the greatest, such as [1, 2, 5, 10]`);
|
|
69
|
+
if (!items.includes(spec.step)) fail(`step.start is ${spec.step}, write one of the steps ${list(items)}`);
|
|
70
|
+
if (spec.labels !== 'all') fail('labels is set on a page whose reader picks the step, and such a page labels every mark, leave labels out');
|
|
71
|
+
for (const f of ['blank', 'cards', 'bracket']) if (fields[f] !== undefined) fail(`${f} belongs to a line of one step, write step as a number`);
|
|
72
|
+
}
|
|
73
|
+
if (spec.to <= spec.from) return fail(`to is ${spec.to}, write a number above the left end ${spec.from}`), done();
|
|
74
|
+
if (!Number.isInteger(gapsOf(spec))) return fail(`to is ${spec.to}, and to minus from is ${spec.to - spec.from}, write a right end that is a whole number of steps of ${spec.step} from ${spec.from}`), done();
|
|
75
|
+
if (!isFree(spec) && gapsOf(spec) > GAPS) fail(`to is ${spec.to}, which gives ${gapsOf(spec)} gaps, and a marked line holds at most ${GAPS}`);
|
|
76
|
+
if (Number.isInteger(spec.labels) && spec.labels % spec.step) fail(`labels is ${spec.labels}, write a multiple of the step ${spec.step}, so each labelled number is a mark of the line`);
|
|
77
|
+
if (Array.isArray(spec.labels)) for (const n of spec.labels) if (!isMark(spec, n)) fail(`labels lists ${n}, which is no mark of the line from ${spec.from} to ${spec.to} in steps of ${spec.step}`);
|
|
78
|
+
for (const n of pg.blank) if (!isMark(spec, n) || labelled(spec, n)) fail(`blank lists ${n}, write marks of the line that carry no label`);
|
|
79
|
+
if (pg.cards !== undefined) {
|
|
80
|
+
const cards = cardsOf(spec);
|
|
81
|
+
if (!pg.blank.length) fail('cards go with blank, write the marks whose labels the cards fill');
|
|
82
|
+
if (new Set(cards).size !== cards.length) fail(`cards is [${cards}], write each number once`);
|
|
83
|
+
for (const n of pg.blank) if (!cards.includes(n)) fail(`cards leaves out ${n}, write a card for every blank mark`);
|
|
84
|
+
}
|
|
85
|
+
if (isStones(spec)) {
|
|
86
|
+
if (spec.to > STONES_TO) fail(`to is ${spec.to}, and the ${spec.look} look holds at most ${STONES_TO} stones`);
|
|
87
|
+
for (const f of ['from', 'step', 'labels', 'second', 'blank', 'cards', 'bracket', 'open', 'middle', 'find', 'challenge']) if (fields[f] !== undefined) fail(`${f} belongs to the line look, the ${spec.look} look takes to, point, jump and readout`);
|
|
88
|
+
for (const f of ['flag', 'reading']) if (pg[f]) fail(`${f} belongs to the line look, the ${spec.look} look takes to, point, jump and readout`);
|
|
89
|
+
if (pg.point === false) fail(`point is false, and the ${spec.look} look shows the frog as the point, write a number`);
|
|
90
|
+
}
|
|
91
|
+
for (const f of ['point', 'second']) {
|
|
92
|
+
const n = pg[f];
|
|
93
|
+
if (n !== undefined && n !== false && !isMark(spec, n)) fail(`${f} is ${n}, write a number on a mark from ${spec.from} to ${spec.to}`);
|
|
94
|
+
}
|
|
95
|
+
if (pg.point === false) for (const f of ['jump', 'second', 'bracket', 'flag', 'reading']) if (pg[f] !== undefined && pg[f] !== false) fail(`${f} moves or reads the point, and point is false, write the point's start or leave ${f} out`);
|
|
96
|
+
if (pg.start !== undefined) {
|
|
97
|
+
if (!pg.jump) fail('start is the start of the jumps, write jump: true');
|
|
98
|
+
if (spec.look !== 'line' || isFree(spec)) fail(`start takes a marked line in the line look, this page has look ${spec.look}${isFree(spec) ? ' and marks: ends' : ''}`);
|
|
99
|
+
if (!isMark(spec, pg.start)) fail(`start is ${pg.start}, write a number on a mark from ${spec.from} to ${spec.to}`);
|
|
100
|
+
if (pg.point === false) fail(`start carries the point, write the point's place or leave point out`);
|
|
101
|
+
if (pg.challenge) fail(`start is drawn by challenge.goal ${pg.challenge.goal}, leave it out`);
|
|
102
|
+
}
|
|
103
|
+
if (pg.written !== undefined) {
|
|
104
|
+
if (!pg.jump) fail('written writes the jumps, write jump: true');
|
|
105
|
+
if (pg.reading) fail('reading is the written line in words on a page with written, leave the field reading out');
|
|
106
|
+
if (pg.written === 'difference' && pg.second === undefined) fail('written: difference writes the second point minus the start, write second as well');
|
|
107
|
+
// The page counts on from the start to the second point, so the second point is the greater number.
|
|
108
|
+
else if (pg.written === 'difference' && pg.start !== undefined && pg.second <= pg.start) fail(`second is ${pg.second}, at or left of the start ${pg.start}, and the page counts on from the start, write a second point greater than the start, such as ${Math.min(spec.to, pg.start + 5)}`);
|
|
109
|
+
}
|
|
110
|
+
if (pg.second !== undefined && !pg.flag) fail('second goes with flag, write flag: true so each point shows its number');
|
|
111
|
+
if (pg.reading && pg.second === undefined) fail('reading compares two points, write second as well');
|
|
112
|
+
if (pg.bracket) {
|
|
113
|
+
if (10 % spec.step || spec.from % 10 || spec.to % 10) fail(`bracket reaches from a ten to a ten, which are marks of the line when from and to are tens and the step is 1, 2, 5 or 10, this line runs from ${spec.from} to ${spec.to} in steps of ${spec.step}`);
|
|
114
|
+
else if (!Array.from({ length: (spec.to - spec.from) / 10 + 1 }, (_, i) => spec.from + 10 * i).every(n => labelled(spec, n))) fail('bracket lights the labels of two tens, label every ten, such as with labels: 10');
|
|
115
|
+
}
|
|
116
|
+
if (isFree(spec)) {
|
|
117
|
+
if (spec.labels !== 'ends') fail('labels of an unmarked line are its ends, which carry the only marks, leave labels out');
|
|
118
|
+
for (const f of ['step', 'second', 'jump', 'bracket', 'open', 'blank', 'cards']) if (fields[f] !== undefined) fail(`${f} takes a marked line, and marks is ends, leave ${f} out or write marks: all`);
|
|
119
|
+
if (isStones(spec) || spec.look === 'street') fail(`marks is ends, and the ${spec.look} look has a mark at every step, leave marks out`);
|
|
120
|
+
}
|
|
121
|
+
if (spec.look === 'book') for (const f of ['marks', 'labels', 'step', 'second', 'flag', 'reading', 'jump', 'bracket', 'open', 'blank', 'cards', 'middle', 'estimate', 'challenge']) if (fields[f] !== undefined) fail(`${f} belongs to the line look, the book look takes from, to, point, find and readout`);
|
|
122
|
+
if (est.ctl) {
|
|
123
|
+
const { lo, hi } = est.ctl;
|
|
124
|
+
if (!isFree(spec)) fail('estimate takes an unmarked line, write marks: ends');
|
|
125
|
+
if (lo > hi || spec.estimate < lo || spec.estimate > hi) fail(`estimate has the range [${lo}, ${hi}] and starts at ${spec.estimate}, write [low, high] and a start between them`);
|
|
126
|
+
else if (lo < spec.from || hi > spec.to) fail(`estimate reaches [${lo}, ${hi}], write a range inside the line from ${spec.from} to ${spec.to}`);
|
|
127
|
+
for (const f of ['jump', 'find']) if (fields[f] !== undefined) fail(`${f} belongs to pages without an estimate, an estimate page leaves the point where it is`);
|
|
128
|
+
if (pg.point === false) fail(`estimate is of the number at the point, write the point's place`);
|
|
129
|
+
}
|
|
130
|
+
if (spec.look === 'street') {
|
|
131
|
+
if (!Array.isArray(spec.labels)) fail('labels of the street look are the door numbers it shows, write them as a list, such as [1, 20, 50, 60]');
|
|
132
|
+
for (const f of ['step', 'second', 'jump', 'bracket', 'open', 'blank', 'cards', 'middle', 'challenge']) if (fields[f] !== undefined) fail(`${f} belongs to the line look, the street look takes from, to, labels, point, find and readout`);
|
|
133
|
+
for (const f of ['flag', 'reading']) if (pg[f]) fail(`${f} belongs to the line look, the street look takes from, to, labels, point, find and readout`);
|
|
134
|
+
}
|
|
135
|
+
if (pg.middle) {
|
|
136
|
+
if (gapsOf(spec) % 2) fail(`middle is set, and the line from ${spec.from} to ${spec.to} has ${gapsOf(spec)} gaps, so its middle is no mark, write ends an even number of steps apart`);
|
|
137
|
+
if (spec.look !== 'line') fail(`middle belongs to the line look, leave it out of the ${spec.look} look`);
|
|
138
|
+
if (labelled(spec, middleOf(spec))) fail(`middle draws the label of ${middleOf(spec)}, which labels already gives, leave middle out or the label out`);
|
|
139
|
+
}
|
|
140
|
+
if (pg.find !== undefined) {
|
|
141
|
+
for (const n of findsOf(spec)) {
|
|
142
|
+
if (!isMark(spec, n)) fail(`find has ${n}, write numbers on marks from ${spec.from} to ${spec.to}`);
|
|
143
|
+
else if (labelled(spec, n) || (pg.middle && n === middleOf(spec))) fail(`find has ${n}, which carries a label, write numbers whose marks have none`);
|
|
144
|
+
}
|
|
145
|
+
for (const f of ['second', 'flag', 'reading']) if (pg[f] !== undefined && pg[f] !== false) fail(`${f} belongs to pages without find, a find page shows the number at the point once the reader presses Show`);
|
|
146
|
+
if (pg.challenge) fail('find belongs to pages without a challenge, leave it out');
|
|
147
|
+
}
|
|
148
|
+
if (pg.moved) {
|
|
149
|
+
if (spec.look !== 'line' || spec.from !== 0 || spec.stepCtl || spec.step !== 1 || spec.labels !== 'all' || spec.to < 4 || spec.to > MOVED_TO) fail(`moved takes the line look from 0 in steps of 1 with every mark labelled and to from 4 to ${MOVED_TO}, so a mark off its place keeps its label ${LABELS_APART}px from the next on a phone, this page has look ${spec.look}, from ${spec.from}, to ${spec.to} and step ${spec.step}`);
|
|
150
|
+
for (const f of ['second', 'blank', 'cards', 'bracket', 'middle', 'find', 'estimate', 'challenge', 'marks']) if (fields[f] !== undefined) fail(`${f} belongs to pages without moved, a moved page takes point, jump and readout`);
|
|
151
|
+
for (const f of ['flag', 'reading', 'open']) if (pg[f]) fail(`${f} belongs to pages without moved, a moved page takes point, jump and readout`);
|
|
152
|
+
const marks = pg.moved.map(m => m.mark).sort((a, b) => a - b);
|
|
153
|
+
for (const m of pg.moved) {
|
|
154
|
+
if (!Number.isInteger(m.mark) || m.mark <= spec.from || m.mark >= spec.to) fail(`moved has the mark ${m.mark}, write a mark between the ends ${spec.from} and ${spec.to}`);
|
|
155
|
+
if (Math.abs(m.by) < 0.3 || Math.abs(m.by) > 0.6) fail(`moved has ${m.mark} by ${m.by}, write by from 0.3 to 0.6 in size, so the page opens with a gap that looks wrong`);
|
|
156
|
+
}
|
|
157
|
+
if (marks.some((m, i) => i && m - marks[i - 1] < 2)) fail(`moved lists the marks ${marks.join(', ')}, write marks with no two next to each other or the same`);
|
|
158
|
+
// On a 390px phone the labels of two marks next to each other stand at least LABELS_APART pixels apart as the page opens.
|
|
159
|
+
else if (spec.to >= 4 && spec.to <= MOVED_TO) {
|
|
160
|
+
const s = opening(spec), keep = labelKeep(spec, PHONE), gap = gapOn(PHONE, gapsOf(spec), false);
|
|
161
|
+
for (let k = 0; k < gapsOf(spec); k++) {
|
|
162
|
+
const d = posOf(s, k + 1) - posOf(s, k);
|
|
163
|
+
// The largest by that keeps them apart, and when that is below the least by of 0.3, no by fits this mark.
|
|
164
|
+
const most = Math.floor((1 - keep(k, k + 1)) * 100) / 100;
|
|
165
|
+
const way = most >= 0.3 ? `write a by that leaves them ${LABELS_APART}px apart, such as one of at most ${most} in size` : `no by from 0.3 to 0.6 leaves them ${LABELS_APART}px apart, move another mark or shorten the line`;
|
|
166
|
+
if (d < keep(k, k + 1) - 1e-9) fail(`moved puts the labels of ${k} and ${k + 1} about ${Math.max(0, Math.round((d - keep(k, k + 1)) * gap + LABELS_APART))}px apart on a 390px phone, where they would read as one number, ${way}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (pg.open && spec.step === 1) fail('open shows the numbers inside a gap, and a line in ones has none, write a step above 1');
|
|
171
|
+
if (pg.challenge) readChallenge(pg, spec, at, ctx);
|
|
172
|
+
const outs = readoutsOf(spec);
|
|
173
|
+
for (const id of pg.readout) if (!outs.includes(id)) fail(`readout names "${id}", this page reads out ${list(outs) || 'nothing'}`);
|
|
174
|
+
return done();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// A challenge page names its goal and the range it draws from. The reader finds the target with the drag and the
|
|
178
|
+
// jumps, so the page shows no number that gives it away. Every target it can draw must be open as the page starts.
|
|
179
|
+
function readChallenge(pg, spec, at, ctx) {
|
|
180
|
+
const c = pg.challenge, goal = goalOf(c, at, ctx);
|
|
181
|
+
if (!goal) return;
|
|
182
|
+
const fail = words => ctx.fail(at, words);
|
|
183
|
+
if (pg.look !== 'line') fail(`look is ${pg.look}, a challenge page shows the line look, leave look out`);
|
|
184
|
+
if (pg.readout.length) fail(`readout names ${list(pg.readout)}, and a challenge page shows no readouts, which would give the answer away, leave readout out`);
|
|
185
|
+
for (const f of ['flag', 'reading']) if (pg[f]) fail(`${f} would give the answer away, a challenge page shows the point's number once the goal holds, leave ${f} out`);
|
|
186
|
+
for (const f of ['second', 'blank', 'cards', 'bracket']) if (f === 'blank' ? pg.blank.length : pg[f] !== undefined) fail(`${f} belongs to pages without a challenge, leave it out`);
|
|
187
|
+
if (pg.point === false) fail('point is false, and the reader places the point, write its start or leave point out');
|
|
188
|
+
if (spec.stepCtl) fail(`step is a segment, write the step of the challenge's line as a number`);
|
|
189
|
+
// jump-to asks for a calculation whose answer every label may show, as the reader counts the jumps.
|
|
190
|
+
if (spec.labels === 'all' && !goal.labels) fail(`labels is all, so every target would carry its label, write the labels of the line, such as labels: 10`);
|
|
191
|
+
const problem = goal.problem(c, spec);
|
|
192
|
+
if (problem) return fail(`challenge.${problem}`);
|
|
193
|
+
drawn(goal, c, spec, { at, ctx, starts: (s, t) => challengeStart(s, t) });
|
|
194
|
+
}
|
|
195
|
+
// A goal that draws its line takes the challenge alone, with no field of the line.
|
|
196
|
+
function readDrawn(fields, pg, spec, at, ctx) {
|
|
197
|
+
const c = pg.challenge, goal = goalOf(c, at, ctx);
|
|
198
|
+
if (!goal) return;
|
|
199
|
+
for (const f of Object.keys(fields)) if (f !== 'challenge' && !(goal.takes ?? []).includes(f)) ctx.fail(at, `${f} is drawn by challenge.goal ${c.goal}, which draws the line, leave it out`);
|
|
200
|
+
if (fields.middle !== undefined && fields.middle !== 'button') ctx.fail(at, `middle is ${JSON.stringify(fields.middle)}, write middle: button, so the reader draws the middle of the line the goal draws`);
|
|
201
|
+
const problem = goal.problem(c, spec);
|
|
202
|
+
if (problem) return ctx.fail(at, `challenge.${problem}`);
|
|
203
|
+
if (!goal.lines(c).length) return ctx.fail(at, `challenge.goal ${c.goal} draws no line, as ${goal.noLine(c)}, widen the ranges`);
|
|
204
|
+
drawn(goal, c, spec, { at, ctx, starts: (s, t) => challengeStart(s, t) });
|
|
205
|
+
}
|
|
206
|
+
function goalOf(c, at, ctx) {
|
|
207
|
+
const goal = challenge(c, GOALS, { scene: 'line', at, ctx });
|
|
208
|
+
if (goal) for (const f of Object.keys(c)) if (f !== 'goal' && !goal.fields.includes(f)) ctx.fail(at, `challenge.${f} belongs to another goal, ${c.goal} draws from ${list(goal.fields)}`);
|
|
209
|
+
return goal;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// A link shows a number or the line of words as the page opens. The ten before and the ten after read a dash
|
|
213
|
+
// while the point is on a ten.
|
|
214
|
+
function start(spec, lang, id) {
|
|
215
|
+
if (!measuresOf(spec).includes(id)) return null;
|
|
216
|
+
const s = opening(spec), int = numbers(lang).int;
|
|
217
|
+
if (id === 'gaps') return string(lang, `line_${gapsKey(s)}`);
|
|
218
|
+
if (id === 'written' || id === 'reading' && spec.written) { const w = writtenOf(spec, s); return id === 'written' ? words(w, int) : reading(w, int, (key, vars) => string(lang, `hesap_${key}`, vars)); }
|
|
219
|
+
if (id === 'reading') { const r = readingOf(spec, s); return string(lang, `line_${r.key}`, { a: int(r.a), b: int(r.b) }); }
|
|
220
|
+
const v = counts(spec, s)[id];
|
|
221
|
+
return v === null ? DASH : int(v);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// The two points: a red round one and a blue square one, each with a step for the dark themes.
|
|
225
|
+
const bundle = () => ({ families: { 'line-point': { color: '#d1453b', color_dark: '#f0776d' }, 'line-second': { color: '#2a6bd1', color_dark: '#6fa4f5' } } });
|
|
226
|
+
|
|
227
|
+
export default { id: 'line', scenes: ['line'], schema: z.object({}).passthrough(), read, start, bundle };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// The lens: a window above the point that shows about a dozen gaps of the line around it at full size, for a line whose
|
|
2
|
+
// gaps are too narrow to tell apart on the stage. It draws the marks, the labels and the arcs the line has there.
|
|
3
|
+
import { svg as el } from '../../kit/dom.js';
|
|
4
|
+
import { arc, house, plaque } from './figures.js';
|
|
5
|
+
|
|
6
|
+
const GAP = 21, SPAN = 16, H = 84, LINE = -56; // The lens's gap, its width in gaps, its height and the height of its line.
|
|
7
|
+
export const LENS_H = H + 8; // The room the lens and its tip take above the point.
|
|
8
|
+
let made = 0;
|
|
9
|
+
|
|
10
|
+
// lens makes the window. Its group stands with the middle of its foot at 0, 0. draw shows the line around the place
|
|
11
|
+
// c, counted in marks, on a line of n gaps. label gives the words of mark k, or null for a short mark, and arcs are
|
|
12
|
+
// the jumps of the point.
|
|
13
|
+
export function lens() {
|
|
14
|
+
const w = GAP * SPAN, id = `line-lens-${++made}`;
|
|
15
|
+
const inner = el('g', { 'clip-path': `url(#${id})` }), tip = el('path', { class: 'line-lens-tip', d: 'M -8 -1 L 0 8 L 8 -1 Z' });
|
|
16
|
+
const g = el('g', { class: 'line-lens', 'aria-hidden': 'true', display: 'none' }, [
|
|
17
|
+
el('defs', {}, [el('clipPath', { id }, [el('rect', { x: -w / 2, y: -H, width: w, height: H, rx: 10 })])]),
|
|
18
|
+
el('rect', { class: 'line-lens-box', x: -w / 2, y: -H, width: w, height: H, rx: 10 }), tip, inner,
|
|
19
|
+
]);
|
|
20
|
+
return {
|
|
21
|
+
el: g, w,
|
|
22
|
+
show(on) { g.setAttribute('display', on ? 'inline' : 'none'); },
|
|
23
|
+
// at moves the lens so that it stays on the stage, with its tip over the point at x.
|
|
24
|
+
at(x, y, lo, hi) { const cx = Math.max(lo + w / 2, Math.min(hi - w / 2, x)); g.setAttribute('transform', `translate(${cx} ${y})`); tip.setAttribute('transform', `translate(${x - cx} 0)`); },
|
|
25
|
+
// On the street look the lens shows the houses with their door numbers in place of the marks.
|
|
26
|
+
draw(c, n, label, arcs, street = false) {
|
|
27
|
+
const x = k => (k - c) * GAP, lo = Math.max(0, Math.floor(c - SPAN / 2 - 1)), hi = Math.min(n, Math.ceil(c + SPAN / 2 + 1)), kids = [];
|
|
28
|
+
if (street) {
|
|
29
|
+
kids.push(el('rect', { class: 'line-road', x: Math.max(-w / 2, x(0) - GAP / 2), y: LINE + 14, width: Math.min(w / 2, x(n) + GAP / 2) - Math.max(-w / 2, x(0) - GAP / 2), height: 8 }));
|
|
30
|
+
for (let k = lo; k <= hi; k++) { kids.push(house(x(k), LINE + 14, GAP * 0.8, 22)); const words = label(k); if (words !== null) kids.push(plaque(x(k), LINE - 16, words, 11)); }
|
|
31
|
+
kids.push(el('path', { class: 'line-dot line-c-point', d: `M -6 ${LINE + 26} L 0 ${LINE + 18} L 6 ${LINE + 26} Z` }));
|
|
32
|
+
return inner.replaceChildren(...kids);
|
|
33
|
+
}
|
|
34
|
+
kids.push(el('line', { class: 'line-axis', x1: Math.max(-w / 2, x(0)), x2: Math.min(w / 2, x(n)), y1: LINE, y2: LINE }));
|
|
35
|
+
for (let k = lo; k <= hi; k++) {
|
|
36
|
+
const words = label(k), long = words !== null;
|
|
37
|
+
kids.push(el('line', { class: 'line-mark', x1: x(k), x2: x(k), y1: LINE - (long ? 9 : 5), y2: LINE + (long ? 9 : 5) }));
|
|
38
|
+
if (long) kids.push(el('text', { class: 'line-label', x: x(k), y: LINE + 18, 'font-size': 12 }, [words]));
|
|
39
|
+
}
|
|
40
|
+
for (const a of arcs) if (Math.max(a.from, a.to) >= lo && Math.min(a.from, a.to) <= hi) {
|
|
41
|
+
// A jump to the left dips under the labels, with its head clear of them.
|
|
42
|
+
const part = arc(x(a.from), x(a.to), a.dir < 0 ? LINE + 33 : LINE - 4, a.dir < 0 ? 6 : 8, a.dir < 0);
|
|
43
|
+
kids.push(part.path, part.head);
|
|
44
|
+
}
|
|
45
|
+
kids.push(el('circle', { class: 'line-dot line-c-point', r: 7, cy: LINE }));
|
|
46
|
+
inner.replaceChildren(...kids);
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|