@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
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
.hesap-counters .counters-tag-text{font-size:12px;font-weight:700}
|
|
121
121
|
.hesap-counters .counters-pale .counters-body{fill:var(--panel);stroke:var(--rule)}
|
|
122
122
|
.hesap-counters .counters-pale .counters-ring{display:none}
|
|
123
|
-
.hesap-counters .counters-marked .counters-body{stroke:var(--
|
|
123
|
+
.hesap-counters .counters-marked .counters-body{stroke:var(--ink);stroke-width:3.5}
|
|
124
124
|
.hesap-counters .counters-gap{fill:none;stroke:var(--rule);stroke-width:2;stroke-dasharray:4 3;opacity:0;pointer-events:none;outline:none}
|
|
125
125
|
.hesap-counters .counters-gap-on{opacity:1;pointer-events:all;cursor:pointer}
|
|
126
126
|
.hesap-counters .counters-gap-on:focus-visible{stroke:var(--accent);stroke-width:3}
|
|
@@ -148,3 +148,128 @@
|
|
|
148
148
|
.hesap-counters .counters-kerb{stroke:var(--ink-2);stroke-width:3}
|
|
149
149
|
.hesap-counters .counters-stairs{fill:var(--panel);stroke:var(--ink-2);stroke-width:2;stroke-linejoin:round}
|
|
150
150
|
.hesap-counters .counters-step-num{font-size:11px;font-weight:600;fill:var(--ink-2)}
|
|
151
|
+
|
|
152
|
+
/* The match scene: the pair lines, the ring on a counter without a partner, the words between the rows, and the
|
|
153
|
+
cups and saucers. */
|
|
154
|
+
.hesap-counters .counters-wire{stroke:var(--ink);stroke-width:3;stroke-linecap:round}
|
|
155
|
+
.hesap-counters .counters-rubber{stroke:var(--accent);stroke-width:3;stroke-linecap:round;pointer-events:none}
|
|
156
|
+
.hesap-counters .counters-lone{fill:none;stroke:var(--ink);stroke-width:3;pointer-events:none}
|
|
157
|
+
.hesap-counters .counters-picked .counters-body{stroke:var(--ink);stroke-width:3}
|
|
158
|
+
.hesap-counters .counters-word{pointer-events:none}
|
|
159
|
+
.hesap-counters .counters-word-box{fill:var(--paper);stroke:var(--accent);stroke-width:2}
|
|
160
|
+
.hesap-counters .counters-word-text{font-size:17px;font-weight:700}
|
|
161
|
+
.hesap-counters .counters-handle{fill:none;stroke:var(--c);stroke-width:3.5;stroke-linecap:round}
|
|
162
|
+
.hesap-counters .counters-saucer .counters-body{fill:var(--paper);stroke:var(--c);stroke-width:2.5}
|
|
163
|
+
.hesap-counters .counters-well{fill:none;stroke:var(--c);stroke-width:1.5;opacity:.5}
|
|
164
|
+
.hesap-counters .counters-rowtag{pointer-events:none}
|
|
165
|
+
.hesap-counters .counters-rowtag-box{fill:var(--paper);stroke:var(--c);stroke-width:2}
|
|
166
|
+
.hesap-counters .counters-rowtag-text{font-size:15px;font-weight:700;stroke:none}
|
|
167
|
+
.hesap-counters .counters-rowtag.counters-hot .counters-rowtag-box{stroke:var(--accent);stroke-width:3}
|
|
168
|
+
.hesap-counters .counters-hollow .counters-body{fill:var(--paper);stroke:var(--c);stroke-width:3}
|
|
169
|
+
.hesap-counters .counters-hollow .counters-ring{display:none}
|
|
170
|
+
.hesap-counters .counters-void{fill:none;stroke:var(--ink-2);stroke-width:2;stroke-dasharray:4 3}
|
|
171
|
+
.hesap-counters .counters-chair .counters-legs{stroke:var(--c);stroke-width:3.5}
|
|
172
|
+
.hesap-counters .counters-crown{fill:#d99a1f;stroke:var(--ink);stroke-width:1.5;stroke-linejoin:round;pointer-events:none}
|
|
173
|
+
.hesap-counters .counters-sway{animation:counters-sway 1.1s ease-in-out infinite alternate;transform-box:fill-box;transform-origin:50% 100%}
|
|
174
|
+
@keyframes counters-sway{from{transform:rotate(-7deg)}to{transform:rotate(7deg)}}
|
|
175
|
+
.hesap-counters .counters-row-name{font-size:20px;font-weight:600;fill:var(--ink-2);text-anchor:start}
|
|
176
|
+
|
|
177
|
+
/* The tiles of a sides page: the number, with the number before and the number after to tap. */
|
|
178
|
+
.hesap-counters .counters-tile-box{fill:var(--panel);stroke:var(--rule);stroke-width:2}
|
|
179
|
+
.hesap-counters .counters-tile-num{font-size:24px;font-weight:700;fill:var(--ink-2)}
|
|
180
|
+
.hesap-counters .counters-tile-main{font-size:34px;fill:var(--ink)}
|
|
181
|
+
.hesap-counters .counters-tile-word{font-size:13px;font-weight:600;fill:var(--ink-2)}
|
|
182
|
+
.hesap-counters .counters-tile-open{cursor:pointer;outline:none}
|
|
183
|
+
.hesap-counters .counters-tile-open .counters-tile-box{fill:var(--paper);stroke:var(--ink);stroke-width:2.5}
|
|
184
|
+
.hesap-counters .counters-tile-open .counters-tile-num{fill:var(--ink)}
|
|
185
|
+
.hesap-counters .counters-tile-open:focus-visible .counters-tile-box,.hesap-counters .counters-tile.counters-hot .counters-tile-box{stroke:var(--accent);stroke-width:4}
|
|
186
|
+
.hesap-counters .counters-tile.counters-hot{stroke:none}
|
|
187
|
+
.hesap-counters .counters-next{fill:none;stroke:var(--ink-2);stroke-width:2;stroke-dasharray:4 3;pointer-events:none}
|
|
188
|
+
.hesap-counters .counters-row-name.counters-hot{stroke:none;fill:var(--accent)}
|
|
189
|
+
|
|
190
|
+
/* The order scene: markers on one count, blocks of rows of ten, the line of words and the number cards. */
|
|
191
|
+
.hesap-counters .counters-reading{font-size:22px;font-weight:700}
|
|
192
|
+
.hesap-counters .counters-reading.counters-hot,.hesap-counters .counters-block-num.counters-hot{stroke:none;fill:var(--accent)}
|
|
193
|
+
.hesap-counters .counters-both .counters-body{fill:var(--ink-2)}
|
|
194
|
+
.hesap-counters .counters-light{opacity:.5}
|
|
195
|
+
.hesap-counters .counters-pin{pointer-events:none}
|
|
196
|
+
.hesap-counters .counters-pin-ring{fill:none;stroke:var(--c);stroke-width:3;pointer-events:none}
|
|
197
|
+
.hesap-counters .counters-pin-box{fill:var(--c);stroke:var(--paper);stroke-width:1.5}
|
|
198
|
+
.hesap-counters .counters-pin-num{font-size:13px;font-weight:700;fill:#fff}
|
|
199
|
+
.hesap-counters .counters-pin.counters-hot{stroke:none}
|
|
200
|
+
.hesap-counters .counters-pin.counters-hot .counters-pin-box{stroke:var(--accent);stroke-width:3}
|
|
201
|
+
.hesap-counters .counters-block-num{font-size:32px;font-weight:700;fill:var(--c)}
|
|
202
|
+
.hesap-counters .counters-decide{fill:none;stroke:var(--accent);stroke-width:3.5;pointer-events:none}
|
|
203
|
+
.hesap-counters .counters-cover rect{fill:var(--panel);stroke:var(--ink-2);stroke-width:2}
|
|
204
|
+
.hesap-counters .counters-cover-mark{font-size:64px;font-weight:700;fill:var(--ink-2)}
|
|
205
|
+
.hesap-counters .counters-card-box{fill:var(--paper);stroke:var(--ink);stroke-width:2}
|
|
206
|
+
.hesap-counters .counters-card:focus-visible .counters-card-box{stroke:var(--accent);stroke-width:3.5}
|
|
207
|
+
.hesap-counters .counters-card-num{font-size:26px;font-weight:700}
|
|
208
|
+
.hesap-counters .counters-mini{fill:var(--z-counters-blue,#2a6bd1)}
|
|
209
|
+
.hesap-counters .counters-place{fill:none;stroke:var(--ink-2);stroke-width:2;stroke-dasharray:6 5}
|
|
210
|
+
.hesap-counters .counters-place-word{font-size:16px;font-weight:600;fill:var(--ink-2)}
|
|
211
|
+
.hesap-counters .counters-between{font-size:14px;font-weight:700}
|
|
212
|
+
.hesap-counters .counters-tick{fill:none;stroke:var(--accent);stroke-width:4;stroke-linecap:round;stroke-linejoin:round}
|
|
213
|
+
|
|
214
|
+
/* A line of two numbers with a sign: the sign tile, the mark that says true or false, and the scoreboard. */
|
|
215
|
+
.hesap-counters .counters-line-num{font-size:34px;font-weight:700;fill:var(--c)}
|
|
216
|
+
.hesap-counters .counters-line-num.counters-hot{stroke:none;text-decoration:underline}
|
|
217
|
+
.hesap-counters .counters-sign-tile-box{fill:none;stroke:none}
|
|
218
|
+
.hesap-counters .counters-sign-tile-text{font-size:36px;font-weight:700}
|
|
219
|
+
.hesap-counters .counters-sign-tile-open{cursor:pointer;outline:none}
|
|
220
|
+
.hesap-counters .counters-sign-tile-open .counters-sign-tile-box{fill:var(--paper);stroke:var(--ink);stroke-width:2.5}
|
|
221
|
+
.hesap-counters .counters-sign-tile-open:focus-visible .counters-sign-tile-box{stroke:var(--accent);stroke-width:4}
|
|
222
|
+
.hesap-counters .counters-mark{pointer-events:none}
|
|
223
|
+
.hesap-counters .counters-mark.counters-hot{stroke:none}
|
|
224
|
+
.hesap-counters .counters-mark-sign{fill:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:round}
|
|
225
|
+
.hesap-counters .counters-mark-word{font-size:20px;font-weight:700;text-anchor:start}
|
|
226
|
+
.hesap-counters .counters-mark-true .counters-mark-sign{stroke:#2e9d5b}
|
|
227
|
+
.hesap-counters .counters-mark-false .counters-mark-sign{stroke:var(--ink-2)}
|
|
228
|
+
.hesap-counters .counters-mark-false .counters-mark-word{fill:var(--ink-2)}
|
|
229
|
+
.hesap-counters .counters-board{fill:var(--panel);stroke:var(--ink);stroke-width:3}
|
|
230
|
+
.hesap-counters .counters-team{font-size:18px;font-weight:700;fill:var(--c)}
|
|
231
|
+
.hesap-counters .counters-score{font-size:60px;font-weight:700}
|
|
232
|
+
.hesap-counters .counters-score.counters-hot{stroke:none;fill:var(--accent)}
|
|
233
|
+
.hesap-counters .counters-score-sign{font-size:44px;font-weight:700}
|
|
234
|
+
.hesap-counters .counters-patch{fill:var(--paper);opacity:.85}
|
|
235
|
+
.hesap-counters .counters-chip-wide{flex:1 0 100%}
|
|
236
|
+
.hesap-counters .counters-line-card{fill:var(--panel);stroke:var(--c);stroke-width:2}
|
|
237
|
+
.hesap-counters .counters-added .counters-ring{display:none}
|
|
238
|
+
.hesap-counters .counters-plus{fill:none;stroke:var(--paper);stroke-width:4;stroke-linecap:round;pointer-events:none}
|
|
239
|
+
|
|
240
|
+
/* The add scene: the dice over the frames and the tray, and the counters a link lights. */
|
|
241
|
+
.hesap-counters .counters-die-box{fill:var(--paper);stroke:var(--ink);stroke-width:2.5}
|
|
242
|
+
.hesap-counters .counters-pip{fill:var(--ink);stroke:none}
|
|
243
|
+
.hesap-counters .counters-die.counters-hot{stroke:none}
|
|
244
|
+
.hesap-counters .counters-die.counters-hot .counters-die-box{stroke:var(--accent);stroke-width:4}
|
|
245
|
+
.hesap-counters .counters-lit .counters-body{stroke:var(--accent);stroke-width:4}
|
|
246
|
+
/* A counter taken away leaves a dashed ring in its cell. */
|
|
247
|
+
.hesap-counters .counters-gone{display:none}
|
|
248
|
+
.hesap-counters .counters-taken .counters-gone{display:inline}
|
|
249
|
+
.hesap-counters .counters-taken .counters-body,.hesap-counters .counters-taken .counters-ring{display:none}
|
|
250
|
+
.hesap-counters .counters-lit .counters-gone{stroke:var(--accent);stroke-width:3.5}
|
|
251
|
+
/* The jam shelf: jars on wooden boards, and two crates for the jars sold. A sold jar's lid takes its crate's colour. */
|
|
252
|
+
.hesap-counters .counters-jar-glass{fill:var(--paper);fill-opacity:.4;stroke:var(--ink-2);stroke-width:2}
|
|
253
|
+
.hesap-counters .counters-jam{fill:#e08a1e}
|
|
254
|
+
.hesap-counters .counters-jar-lid{fill:var(--c,var(--ink-2));stroke:var(--paper);stroke-width:1}
|
|
255
|
+
.hesap-counters .counters-lit .counters-jar-glass{stroke:var(--accent);stroke-width:3.5}
|
|
256
|
+
.hesap-counters .counters-shelf-board{fill:#b98a5a;stroke:#8a6238;stroke-width:2}
|
|
257
|
+
.hesap-counters rect.counters-crate.counters-press{fill:var(--panel);stroke:#8a6238;stroke-width:3}
|
|
258
|
+
.hesap-counters .counters-crate-name{font-size:16px;font-weight:700;fill:var(--ink-2)}
|
|
259
|
+
.hesap-counters .counters-crate-name.counters-hot{stroke:none;fill:var(--accent)}
|
|
260
|
+
/* The seed tray: cells of bare soil, grown seedlings and small sprouts. */
|
|
261
|
+
.hesap-counters .counters-seedtray{fill:#8a6238;stroke:#5c3f22;stroke-width:2.5}
|
|
262
|
+
.hesap-counters .counters-soil{fill:#6b4a2b;stroke:#5c3f22;stroke-width:1}
|
|
263
|
+
.hesap-counters .counters-plant-stem{fill:none;stroke:#3f9a4a;stroke-width:3;stroke-linecap:round}
|
|
264
|
+
/* The seed packet of the seed tray: a paper packet with a folded top, whose seeds turn into sprouts when sown. */
|
|
265
|
+
.hesap-counters .counters-packet-paper{fill:#efe2c4;stroke:#a88a55;stroke-width:2}
|
|
266
|
+
.hesap-counters .counters-packet-fold{stroke:#a88a55;stroke-width:2;stroke-dasharray:5 4}
|
|
267
|
+
.hesap-counters .counters-packet.counters-hot .counters-packet-paper{stroke:var(--accent);stroke-width:4}
|
|
268
|
+
.hesap-counters .counters-seed{display:none}
|
|
269
|
+
.hesap-counters .counters-in-packet .counters-seed{display:inline}
|
|
270
|
+
.hesap-counters .counters-in-packet .counters-body:not(.counters-seed),.hesap-counters .counters-in-packet .counters-plant-stem{display:none}
|
|
271
|
+
/* The link pairs lights each paired counter with a filled halo of the accent, which stays plain on a small phone
|
|
272
|
+
figure and differs from the ink ring of a counter without a partner. */
|
|
273
|
+
.hesap-counters .counters-paired-lit .counters-hit{fill:var(--accent);fill-opacity:.6;stroke:var(--accent);stroke-width:4}
|
|
274
|
+
.hesap-counters .counters-paired-lit .counters-body{stroke:var(--paper);stroke-width:2.5}
|
|
275
|
+
.hesap-counters .counters-wire.counters-hot{stroke:var(--accent);stroke-width:5}
|
|
@@ -2,21 +2,19 @@
|
|
|
2
2
|
// family's counters, ten frames, places and motion.
|
|
3
3
|
import bonds from './bonds.js';
|
|
4
4
|
import count from './count.js';
|
|
5
|
+
import match from './match.js';
|
|
6
|
+
import order from './order.js';
|
|
7
|
+
import add from './add.js';
|
|
8
|
+
import { scenes } from './scenes.js';
|
|
5
9
|
|
|
6
|
-
const SCENES = { bonds, count };
|
|
10
|
+
const SCENES = { bonds, count, match, order, add };
|
|
7
11
|
|
|
8
12
|
export default function counters(api) {
|
|
9
|
-
|
|
10
|
-
const made = {};
|
|
11
|
-
let now = null;
|
|
13
|
+
const all = scenes(Object.fromEntries(Object.entries(SCENES).map(([name, make]) => [name, () => make(api)])), api.stage);
|
|
12
14
|
return {
|
|
13
|
-
show(spec, page) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
hide() { now?.hide(); now = null; },
|
|
19
|
-
point(id, on) { now?.point(id, on); },
|
|
20
|
-
lang() { now?.lang(); },
|
|
15
|
+
show(spec, page) { all.show(spec.scene, spec, page); },
|
|
16
|
+
hide() { all.hide(); },
|
|
17
|
+
point(id, on) { all.now()?.point(id, on); },
|
|
18
|
+
lang() { all.now()?.lang(); },
|
|
21
19
|
};
|
|
22
20
|
}
|
|
@@ -59,12 +59,16 @@ function line(look, n) {
|
|
|
59
59
|
} }];
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
// tenPlace gives the place of counter i in rows of ten, with a gap after the fifth of each row. Every scene that
|
|
63
|
+
// lays a number out in rows of ten places its counters here.
|
|
64
|
+
export const tenPlace = (i, gap = ROW, five = FIVE) => ({ x: (i % 10 + 0.5) * gap + (i % 10 >= 5 ? five : 0), y: (Math.floor(i / 10) + 0.5) * gap });
|
|
65
|
+
|
|
62
66
|
// rows stands n counters in rows of ten, with a gap after the fifth of each row and the count of each full row at
|
|
63
|
-
// its end.
|
|
67
|
+
// its end. tray is the width of the tray alone, without the counts.
|
|
64
68
|
export function rows(n) {
|
|
65
69
|
const lines = Math.ceil(n / 10), inner = 10 * ROW + FIVE, w = inner + 62, h = lines * ROW + 16;
|
|
66
|
-
return [{ w, h, draw(x, y) {
|
|
67
|
-
const ox = x + 8, oy = y + 8, spots = Array.from({ length: n }, (_, i) =>
|
|
70
|
+
return [{ w, h, tray: inner + 16, draw(x, y) {
|
|
71
|
+
const ox = x + 8, oy = y + 8, spots = Array.from({ length: n }, (_, i) => { const p = tenPlace(i); return { x: ox + p.x, y: oy + p.y }; });
|
|
68
72
|
const labels = [];
|
|
69
73
|
for (let k = 1; k <= lines; k++) if (n >= 10 * k) labels.push({ t: txt('counters-row-label', ox + inner + 32, oy + (k - 0.5) * ROW), n: 10 * k });
|
|
70
74
|
const nodes = [el('rect', { class: 'counters-tray', x, y, width: inner + 16, height: h, rx: 10 }), ...labels.map(l => l.t)];
|
|
@@ -72,6 +76,22 @@ export function rows(n) {
|
|
|
72
76
|
} }];
|
|
73
77
|
}
|
|
74
78
|
|
|
79
|
+
// sides is a strip of three tiles: the number before, the number in larger type and the number after. The outer
|
|
80
|
+
// tiles carry the words less and more and take a tap.
|
|
81
|
+
export function sides(less, more) {
|
|
82
|
+
const tw = 92, th = 62, mid = 104, gap = 12, w = 2 * tw + mid + 2 * gap, h = th + 30;
|
|
83
|
+
return [{ w, h, draw(x, y) {
|
|
84
|
+
const tile = (id, tx, wide, words) => {
|
|
85
|
+
const box = el('rect', { class: 'counters-tile-box', x: tx, y: y + 22, width: wide, height: th, rx: 10 });
|
|
86
|
+
const num = txt(`counters-tile-num${id === 'count' ? ' counters-tile-main' : ''}`, tx + wide / 2, y + 22 + th / 2 + 2);
|
|
87
|
+
const g = el('g', { class: 'counters-tile', 'data-ref': id }, [box, num, ...(words ? [txt('counters-tile-word', tx + wide / 2, y + 9, words)] : [])]);
|
|
88
|
+
return { g, num };
|
|
89
|
+
};
|
|
90
|
+
const tiles = { before: tile('before', x, tw, less), count: tile('count', x + tw + gap, mid), after: tile('after', x + tw + gap + mid + gap, tw, more) };
|
|
91
|
+
return { nodes: Object.values(tiles).map(t => t.g), refs: { tiles } };
|
|
92
|
+
} }];
|
|
93
|
+
}
|
|
94
|
+
|
|
75
95
|
// boxRow is a closed box with its number on the front, and room beside it for cap counters in rows of six.
|
|
76
96
|
export function boxRow(cap) {
|
|
77
97
|
const bw = 96, bh = 84, cols = Math.min(6, cap), lines = Math.ceil(cap / 6), g = 42, sw = cols * g, sh = lines * g;
|
|
@@ -11,10 +11,12 @@ export const ROOM = { tray: 20, stall: 20, sand: 20, wire: 12 };
|
|
|
11
11
|
export const SEATS = 12; // The seats of the bus, on two decks.
|
|
12
12
|
export const STOP = 10; // The people a bus stop holds.
|
|
13
13
|
export const STEPS = 20; // The steps of the staircase.
|
|
14
|
+
export const SIDES = [1, 99]; // The numbers a sides page steps through, each with a number on either side.
|
|
14
15
|
|
|
15
16
|
// modeOf names what a page does: a world page, a marker in the rows, a pile beside a box, or the page's tap.
|
|
16
17
|
export function modeOf(spec) {
|
|
17
18
|
if (spec.look === 'bus' || spec.look === 'stairs') return spec.look;
|
|
19
|
+
if (spec.sides) return 'sides';
|
|
18
20
|
if (spec.marker != null) return 'marker';
|
|
19
21
|
if (spec.pile != null) return 'pile';
|
|
20
22
|
return spec.tap;
|
|
@@ -39,6 +41,8 @@ export function counts(spec, s) {
|
|
|
39
41
|
const count = s.box + s.said;
|
|
40
42
|
return { count, total: s.tags.length && s.tags.every(t => t.length === 1) ? count : null };
|
|
41
43
|
}
|
|
44
|
+
// A sides page shows the number of its counters with the number before and the number after.
|
|
45
|
+
if (mode === 'sides') { const n = s.here.filter(Boolean).length; return { count: n, before: n - 1, after: n + 1 }; }
|
|
42
46
|
const count = { place: s.last, take: s.here.filter(Boolean).length, marker: s.marker, pile: s.box + s.beside, bus: s.riders, stairs: s.step }[mode];
|
|
43
47
|
return { count };
|
|
44
48
|
}
|
|
@@ -53,5 +57,6 @@ export function contextOf(spec) {
|
|
|
53
57
|
export function measuresOf(spec) {
|
|
54
58
|
if (spec.challenge) return [];
|
|
55
59
|
const mode = modeOf(spec);
|
|
60
|
+
if (mode === 'sides') return ['count', 'before', 'after'];
|
|
56
61
|
return mode === 'tag' || mode === 'again' ? ['count', 'total'] : ['count'];
|
|
57
62
|
}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
// The count scene: objects counted one by one. The reader taps an object to give it the next number, counts on from
|
|
2
2
|
// a closed box, takes counters out of a tray, steps a marker through rows of ten, fills a bus and climbs a staircase.
|
|
3
|
-
import { modeOf, sizeOf, counts, contextOf, measuresOf, SEATS, STEPS } from './count-model.js';
|
|
3
|
+
import { modeOf, sizeOf, counts, contextOf, measuresOf, SEATS, STEPS, SIDES } from './count-model.js';
|
|
4
4
|
import { COUNT_GOALS, APPLES, LOOSE, countStart } from './count-goals.js';
|
|
5
|
-
import { another } from './goals.js';
|
|
6
5
|
import { counter, show, put, R } from './counter.js';
|
|
7
6
|
import { arrange } from './places.js';
|
|
8
|
-
import { place, rows, boxRow, pile, basket, bus, stairs } from './count-figures.js';
|
|
7
|
+
import { place, rows, boxRow, pile, basket, bus, stairs, sides } from './count-figures.js';
|
|
9
8
|
import { carry, press } from './move.js';
|
|
10
9
|
import { driver } from './driver.js';
|
|
11
10
|
import { svg as el, svgPoint } from '../../kit/dom.js';
|
|
12
11
|
import { nudge } from '../../kit/drag.js';
|
|
13
|
-
import { stepper, chip, button, row } from '../../kit/panel.js';
|
|
12
|
+
import { stepper, chip, button, row, check } from '../../kit/panel.js';
|
|
14
13
|
import { goalRow } from '../../kit/goal.js';
|
|
15
14
|
import { live } from '../../kit/text.js';
|
|
16
15
|
import { numbers } from '../../kit/format.js';
|
|
17
|
-
import { dice, fresh } from '../../kit/random.js';
|
|
16
|
+
import { dice, fresh, another } from '../../kit/random.js';
|
|
18
17
|
|
|
19
18
|
const MAX = 1.7; // A figure grows to at most this scale on a wide stage.
|
|
20
19
|
const PAD = 14; // The figure keeps this far from the stage's edges, in pixels.
|
|
@@ -85,6 +84,7 @@ export default function count({ host, stage, panel, T, lang, moving, motion: fx
|
|
|
85
84
|
if (mode === 'bus') return [bus(T('stop-sign'))];
|
|
86
85
|
if (mode === 'stairs') return [stairs()];
|
|
87
86
|
if (mode === 'pile') return [boxRow(spec.pile), pile(spec.pile, T('pile'))];
|
|
87
|
+
if (mode === 'sides') return [rows(100), sides(T('one-less'), T('one-more'))];
|
|
88
88
|
if (spec.box != null) return [boxRow(sizeOf(spec))];
|
|
89
89
|
return [spec.rows ? rows(sizeOf(spec)) : place(spec.look, sizeOf(spec))];
|
|
90
90
|
}
|
|
@@ -103,7 +103,10 @@ export default function count({ host, stage, panel, T, lang, moving, motion: fx
|
|
|
103
103
|
drawn.push(...d.nodes); Object.assign(geo.places, d.places ?? {}); Object.assign(geo.refs, refs); geo.refs.press.push(...presses);
|
|
104
104
|
}
|
|
105
105
|
gaps = gapsOf();
|
|
106
|
-
|
|
106
|
+
// A sides page outlines the place of the next counter, and a tap on an outer tile steps the group to its number.
|
|
107
|
+
geo.next = modeNow() === 'sides' ? el('circle', { class: 'counters-next', r: R - 2 }) : null;
|
|
108
|
+
for (const [id, by] of [['before', -1], ['after', 1]]) if (geo.refs.tiles) press(geo.refs.tiles[id].g, () => stepTo(s.ids.length + by));
|
|
109
|
+
back.replaceChildren(...drawn, ...gaps, ...(geo.next ? [geo.next] : []));
|
|
107
110
|
for (const n of nodes.values()) n.tween?.pause();
|
|
108
111
|
layer.replaceChildren(); nodes = new Map();
|
|
109
112
|
for (const p of geo.refs.press) press(p, () => { const from = p.dataset.place, id = s.lists[from].at(-1); if (id) moveTo(id, otherOf(from)); });
|
|
@@ -171,7 +174,7 @@ export default function count({ host, stage, panel, T, lang, moving, motion: fx
|
|
|
171
174
|
}
|
|
172
175
|
const mode = modeNow(), fixed = s.ids.includes(id), home = homeOf(id);
|
|
173
176
|
if (kind === 'walker') return walker(n);
|
|
174
|
-
if (mode === 'marker' || spec.counted || (!fixed && !home)) return n;
|
|
177
|
+
if (mode === 'marker' || mode === 'sides' || spec.counted || (!fixed && !home)) return n;
|
|
175
178
|
n.g.setAttribute('tabindex', 0); n.g.setAttribute('role', 'button'); n.g.setAttribute('aria-label', T(`kind-${kind}`));
|
|
176
179
|
if (fixed && !spec.drag) { press(n.g, () => tapFixed(id)); return n; }
|
|
177
180
|
if (home === 'seats' || home === 'stop') { press(n.g, () => moveTo(id, otherOf(homeOf(id)))); return n; }
|
|
@@ -226,6 +229,12 @@ export default function count({ host, stage, panel, T, lang, moving, motion: fx
|
|
|
226
229
|
if (to === 'seats') s.seats[s.seats.indexOf(null)] = id; else s.lists[to].push(id);
|
|
227
230
|
changed();
|
|
228
231
|
}
|
|
232
|
+
// stepTo sets the group of a sides page to n counters, one more or one fewer than it holds.
|
|
233
|
+
function stepTo(n) {
|
|
234
|
+
if (n < SIDES[0] || n > SIDES[1]) return;
|
|
235
|
+
if (n > s.ids.length) { s.ids.push(`o${seq++}`); s.here.push(true); } else { s.ids.pop(); s.here.pop(); }
|
|
236
|
+
changed();
|
|
237
|
+
}
|
|
229
238
|
// A change takes back a challenge's check, so the reader checks again.
|
|
230
239
|
function changed() { if (cs) cs.checked = false; render('move'); }
|
|
231
240
|
|
|
@@ -250,6 +259,19 @@ export default function count({ host, stage, panel, T, lang, moving, motion: fx
|
|
|
250
259
|
trail.setAttribute('points', path.map(p => `${p.x},${p.y}`).join(' '));
|
|
251
260
|
if (geo.refs.num) geo.refs.num.textContent = int(s.box);
|
|
252
261
|
for (const l of geo.refs.labels ?? []) l.t.textContent = int(l.n);
|
|
262
|
+
if (mode === 'sides') {
|
|
263
|
+
// The last counter wears the ring, and the count stands at the end of each full row.
|
|
264
|
+
const n = s.ids.length, p = geo.places.slots.pos(n);
|
|
265
|
+
for (const [id, c] of nodes) c.g.classList.toggle('counters-marked', id === s.ids.at(-1));
|
|
266
|
+
geo.next.setAttribute('cx', p.x); geo.next.setAttribute('cy', p.y);
|
|
267
|
+
for (const l of geo.refs.labels) l.t.setAttribute('display', l.n <= n ? 'inline' : 'none');
|
|
268
|
+
for (const [id, v] of [['before', n - 1], ['count', n], ['after', n + 1]]) {
|
|
269
|
+
const t = geo.refs.tiles[id], open = id !== 'count' && v >= SIDES[0] && v <= SIDES[1];
|
|
270
|
+
if (t.num.textContent !== int(v)) { t.num.textContent = int(v); if (anim) go.flash(t.num); }
|
|
271
|
+
t.g.classList.toggle('counters-tile-open', open);
|
|
272
|
+
for (const [name, val] of [['tabindex', 0], ['role', 'button'], ['aria-label', `${T(id === 'before' ? 'one-less' : 'one-more')}: ${int(v)}`]]) if (open) t.g.setAttribute(name, val); else t.g.removeAttribute(name);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
253
275
|
}
|
|
254
276
|
function tag(n, words, anim) {
|
|
255
277
|
const text = n.tagPop.lastChild;
|
|
@@ -278,7 +300,7 @@ export default function count({ host, stage, panel, T, lang, moving, motion: fx
|
|
|
278
300
|
const g = COUNT_GOALS[c.goal];
|
|
279
301
|
goal.say(T(`goal-${c.goal}`, g.words(c, target, { int })));
|
|
280
302
|
const r = g.holds({ ...cs, basket: s.lists.basket.length, beside: s.lists.beside.length, left: s.here.filter(Boolean).length }, spec, c, target);
|
|
281
|
-
const first = goal.show(r.done, r.note ? T(`note-${c.goal}-${r.note}
|
|
303
|
+
const first = goal.show(r.done, r.note ? T(`note-${c.goal}-${r.note}`, g.words(c, target, { int })) : undefined);
|
|
282
304
|
if (first && moving()) go.cheer([...nodes.values()].map(n => n.pop));
|
|
283
305
|
}
|
|
284
306
|
|
|
@@ -289,7 +311,7 @@ export default function count({ host, stage, panel, T, lang, moving, motion: fx
|
|
|
289
311
|
if (c) {
|
|
290
312
|
goal = goalRow({ T, motion: moving() ? fx : null, hint: on => on ? T(`hint-${c.goal}`, COUNT_GOALS[c.goal].words(c, target, { int })) : null,
|
|
291
313
|
another: () => { begin(); goal.reset(); build(); if (!geo) refresh(); } });
|
|
292
|
-
ctls.push(
|
|
314
|
+
ctls.push(check({ T, press: () => { if (!cs.checked) { cs.checked = true; judge(); } } }));
|
|
293
315
|
} else {
|
|
294
316
|
const step = (id, key, ctl, value, set) => stepper({ id, label: T(key), min: ctl.lo, max: ctl.hi, value, write: int, change: v => { set(v); changed(); } });
|
|
295
317
|
if (spec.boxCtl) ctls.push(step('box', 'ctl-box', spec.boxCtl, s.box, v => { s.box = v; }));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The Node half of the count scene: objects counted one by one. It checks a page's fields and says what each link
|
|
2
2
|
// shows when the page opens.
|
|
3
3
|
import { schema } from '@openbooknetwork/kitap';
|
|
4
|
-
import { COUNT_LOOKS, TAPS, ROOM, STOP, STEPS, modeOf, sizeOf, opening, counts, measuresOf } from './count-model.js';
|
|
4
|
+
import { COUNT_LOOKS, TAPS, ROOM, STOP, STEPS, SIDES, modeOf, sizeOf, opening, counts, measuresOf } from './count-model.js';
|
|
5
5
|
import { COUNT_GOALS, LOOSE, countStart } from './count-goals.js';
|
|
6
6
|
import { numbers } from '../../kit/format.js';
|
|
7
7
|
import { list, challenge, drawn, value } from '../../node.mjs';
|
|
@@ -24,6 +24,7 @@ const Fields = z.object({
|
|
|
24
24
|
marker: z.union([Int, Stepper]).optional(), // A marker on one counter of the rows.
|
|
25
25
|
waiting: Int.min(0).max(STOP).optional(), // The people at the bus stop.
|
|
26
26
|
step: z.union([Int, Stepper]).optional(), // The step of the staircase the walker stands on.
|
|
27
|
+
sides: z.boolean().default(false), // Tiles show the number before and the number after, and a tap steps to one.
|
|
27
28
|
readout: z.array(z.string()).default([]),
|
|
28
29
|
// A challenge names a goal of count-goals.js and the ranges it draws its targets from.
|
|
29
30
|
challenge: z.object({ goal: z.string(), target: Range.optional(), box: Range.optional(), more: Range.optional(),
|
|
@@ -34,9 +35,9 @@ const Fields = z.object({
|
|
|
34
35
|
const USES = {
|
|
35
36
|
tag: ['look', 'n', 'rows', 'tap', 'drag', 'clear', 'path', 'counted', 'box'], again: ['look', 'n', 'tap', 'clear'],
|
|
36
37
|
place: ['look', 'n', 'rows', 'tap'], take: ['look', 'n', 'rows', 'tap'], marker: ['look', 'n', 'rows', 'marker'],
|
|
37
|
-
pile: ['look', 'box', 'pile'], bus: ['look', 'n', 'waiting'], stairs: ['look', 'step'],
|
|
38
|
+
pile: ['look', 'box', 'pile'], sides: ['look', 'n', 'rows', 'sides'], bus: ['look', 'n', 'waiting'], stairs: ['look', 'step'],
|
|
38
39
|
};
|
|
39
|
-
const DEFAULTS = { look: 'tray', rows: false, drag: false, clear: false, path: false, counted: false };
|
|
40
|
+
const DEFAULTS = { look: 'tray', rows: false, drag: false, clear: false, path: false, counted: false, sides: false };
|
|
40
41
|
|
|
41
42
|
function read(fields, { at }, ctx) {
|
|
42
43
|
const pg = check(Fields, fields, at), fail = words => ctx.fail(at, words);
|
|
@@ -50,6 +51,7 @@ function read(fields, { at }, ctx) {
|
|
|
50
51
|
for (const [f, v] of Object.entries(pg)) if (!['readout', ...(USES[mode] ?? [])].includes(f) && v !== undefined && v !== DEFAULTS[f]) fail(`${f} belongs to other pages, leave it out of this one`);
|
|
51
52
|
if (mode === 'stairs' && (step.n == null || step.n < 0 || (step.ctl?.hi ?? step.n) > STEPS)) fail(`step is missing or past the staircase, write a step from 0 to ${STEPS}, or { stepper: [0, ${STEPS}], start: 3 }`);
|
|
52
53
|
if (mode === 'bus' && (pg.n == null || pg.waiting == null || pg.n + pg.waiting > STOP)) fail(`n and waiting are the people on the bus and at the stop, write both, ${STOP} people in all at most`);
|
|
54
|
+
if (mode === 'sides' && (!pg.rows || pg.look !== 'tray' || pg.n == null || pg.n < SIDES[0] || pg.n > SIDES[1])) fail(`sides steps a group in rows of ten, write rows: true and n from ${SIDES[0]} to ${SIDES[1]}`);
|
|
53
55
|
if (mode === 'pile' && (box.n == null || box.n < 0)) fail('box is missing, write the number the closed box holds, such as 5, or { stepper: [3, 20], start: 5 }');
|
|
54
56
|
if (mode === 'marker' && (!pg.rows || (marker.ctl?.lo ?? marker.n) < 1 || (marker.ctl?.hi ?? marker.n) > n)) fail(`marker stands on a counter of the rows, write rows: true and a marker from 1 to ${n}`);
|
|
55
57
|
if (['tag', 'again', 'place', 'take'].includes(mode)) {
|
|
@@ -21,10 +21,35 @@ const OBJECTS = {
|
|
|
21
21
|
walker: r => [el('path', { class: 'counters-legs', d: `M ${-r * 0.2} ${-r} L ${-r * 0.3} 0 M ${r * 0.2} ${-r} L ${r * 0.35} 0` }),
|
|
22
22
|
el('rect', { class: 'counters-body', x: -r * 0.45, y: -r * 2.05, width: r * 0.9, height: r * 1.2, rx: r * 0.35 }),
|
|
23
23
|
el('circle', { class: 'counters-skin', cy: -r * 2.5, r: r * 0.42 })],
|
|
24
|
+
// A cup seen from the side with its handle, and a saucer seen from above the table's edge.
|
|
25
|
+
mug: r => [el('path', { class: 'counters-handle', d: `M ${r * 0.62} ${-r * 0.4} Q ${r * 1.3} ${-r * 0.35} ${r * 1.12} ${r * 0.2} Q ${r * 0.98} ${r * 0.55} ${r * 0.56} ${r * 0.45}` }),
|
|
26
|
+
el('path', { class: 'counters-body', d: `M ${-r * 0.72} ${-r * 0.75} L ${r * 0.72} ${-r * 0.75} L ${r * 0.56} ${r * 0.78} Q 0 ${r * 0.95} ${-r * 0.56} ${r * 0.78} Z` }),
|
|
27
|
+
el('ellipse', { class: 'counters-shine', cy: -r * 0.75, rx: r * 0.72, ry: r * 0.17 })],
|
|
28
|
+
// A chair seen from the side: its back, its seat and two legs.
|
|
29
|
+
chair: r => [el('path', { class: 'counters-legs', d: `M ${-r * 0.55} ${r * 0.15} L ${-r * 0.55} ${r} M ${r * 0.6} ${r * 0.15} L ${r * 0.6} ${r}` }),
|
|
30
|
+
el('rect', { class: 'counters-body', x: -r * 0.75, y: -r, width: r * 0.4, height: r * 1.3, rx: r * 0.15 }),
|
|
31
|
+
el('rect', { class: 'counters-body', x: -r * 0.75, y: -r * 0.05, width: r * 1.55, height: r * 0.4, rx: r * 0.15 })],
|
|
32
|
+
// A football: a ball in its team's colour with a patch.
|
|
33
|
+
ball: r => [el('circle', { class: 'counters-body', r }), el('path', { class: 'counters-patch', d: `M 0 ${-r * 0.5} L ${r * 0.48} ${-r * 0.15} L ${r * 0.3} ${r * 0.42} L ${-r * 0.3} ${r * 0.42} L ${-r * 0.48} ${-r * 0.15} Z` })],
|
|
34
|
+
saucer: r => [el('ellipse', { class: 'counters-body', rx: r * 1.5, ry: r * 0.5 }), el('ellipse', { class: 'counters-well', rx: r * 0.8, ry: r * 0.24 })],
|
|
24
35
|
};
|
|
25
36
|
|
|
26
37
|
function glyph(kind, r) {
|
|
27
38
|
if (OBJECTS[kind]) return OBJECTS[kind](r);
|
|
39
|
+
// A grown seedling with two large leaves, and a small sprout with two small ones, so the two groups of the seed
|
|
40
|
+
// tray differ by size and shape.
|
|
41
|
+
if (kind === 'seedling') return [el('path', { class: 'counters-plant-stem', d: `M 0 ${r * 0.95} L 0 ${-r * 0.35}` }),
|
|
42
|
+
el('ellipse', { class: 'counters-body', cx: -r * 0.45, cy: -r * 0.45, rx: r * 0.55, ry: r * 0.3, transform: `rotate(-30 ${-r * 0.45} ${-r * 0.45})` }),
|
|
43
|
+
el('ellipse', { class: 'counters-body', cx: r * 0.45, cy: -r * 0.6, rx: r * 0.55, ry: r * 0.3, transform: `rotate(30 ${r * 0.45} ${-r * 0.6})` })];
|
|
44
|
+
if (kind === 'sprout') return [el('path', { class: 'counters-plant-stem', d: `M 0 ${r * 0.95} L 0 ${r * 0.3}` }),
|
|
45
|
+
el('ellipse', { class: 'counters-body', cx: -r * 0.25, cy: r * 0.2, rx: r * 0.27, ry: r * 0.15, transform: `rotate(-30 ${-r * 0.25} ${r * 0.2})` }),
|
|
46
|
+
el('ellipse', { class: 'counters-body', cx: r * 0.25, cy: r * 0.12, rx: r * 0.27, ry: r * 0.15, transform: `rotate(30 ${r * 0.25} ${r * 0.12})` })];
|
|
47
|
+
// A jar of jam with its lid. The lid takes the colour of the crate the jar was sold into.
|
|
48
|
+
if (kind === 'jar') return [el('rect', { class: 'counters-jar-glass', x: -r * 0.78, y: -r * 0.72, width: r * 1.56, height: r * 1.72, rx: r * 0.32 }),
|
|
49
|
+
el('rect', { class: 'counters-jam', x: -r * 0.62, y: -r * 0.36, width: r * 1.24, height: r * 1.2, rx: r * 0.22 }),
|
|
50
|
+
el('rect', { class: 'counters-jar-lid', x: -r * 0.86, y: -r * 1.08, width: r * 1.72, height: r * 0.46, rx: r * 0.12 })];
|
|
51
|
+
// A square counter tells the second group of counters/add from the round first group by its shape.
|
|
52
|
+
if (kind === 'square') return [el('rect', { class: 'counters-body', x: -r * 0.9, y: -r * 0.9, width: r * 1.8, height: r * 1.8, rx: r * 0.22 }), el('rect', { class: 'counters-ring', x: -r * 0.52, y: -r * 0.52, width: r * 1.04, height: r * 1.04, rx: r * 0.1 })];
|
|
28
53
|
if (kind === 'bead') return [el('circle', { class: 'counters-body', r }), el('circle', { class: 'counters-shine', r: r * 0.32, cx: -r * 0.35, cy: -r * 0.35 })];
|
|
29
54
|
if (kind === 'car') {
|
|
30
55
|
const w = r * 1.5, l = r * 2.5;
|
|
@@ -42,7 +42,7 @@ export const GOALS = {
|
|
|
42
42
|
looks: ['diagram'],
|
|
43
43
|
problem(c) {
|
|
44
44
|
if (!range(c.whole) || c.whole[0] < 2 || c.whole[1] > PILE) return `whole is ${JSON.stringify(c.whole)}, write the range of the whole as [low, high] from 2 to ${PILE}, such as [5, 20]`;
|
|
45
|
-
if (c.part !== undefined && !range(c.part)) return 'part is not a range, write the part
|
|
45
|
+
if (c.part !== undefined && !range(c.part)) return 'part is not a range, write the known part as [low, high], or leave it out for 1 to one less than the whole';
|
|
46
46
|
return null;
|
|
47
47
|
},
|
|
48
48
|
draw(c, spec, dice) {
|
|
@@ -65,11 +65,3 @@ export const GOALS = {
|
|
|
65
65
|
// The reader's state as a challenge opens: no blue counters checked, an empty tray and the cup down.
|
|
66
66
|
export const challengeStart = () => ({ blue: 0, checked: false, tray: 0, lifted: false });
|
|
67
67
|
|
|
68
|
-
// another draws a target that differs from the last one, so Another one always changes the figure.
|
|
69
|
-
export function another(goal, c, spec, dice, last) {
|
|
70
|
-
for (let i = 0; i < 40; i++) {
|
|
71
|
-
const t = goal.draw(c, spec, dice);
|
|
72
|
-
if (!last || JSON.stringify(t) !== JSON.stringify(last)) return t;
|
|
73
|
-
}
|
|
74
|
-
return goal.draw(c, spec, dice);
|
|
75
|
-
}
|