Skip to content

Commit 12be734

Browse files
committed
collapse game mode
1 parent 2ce544a commit 12be734

10 files changed

Lines changed: 1031 additions & 1032 deletions

File tree

experiments/wordsearch/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,4 @@ <h1>Markov Wordsearch</h1>
219219

220220
<a class="home-link" href="../../index.html" title="Back to home">← Home</a>
221221
</body>
222-
</html>
222+
</html>

experiments/wordsearch/src/fill/filler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,4 @@ export function fillGrid(grid, model, config = {}) {
234234
grid.set(x, y, ch);
235235
}
236236
return grid;
237-
}
237+
}

experiments/wordsearch/src/generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@ export function preparePuzzle(opts) {
8888
const grid = new Grid(width, height);
8989
const placement = placeWords(grid, selectedWords, rng, { lattice, includeBackwards });
9090
return { grid, placement, model, reverseModel, selectedWords };
91-
}
91+
}

experiments/wordsearch/src/pwa/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ self.addEventListener('fetch', (event) => {
7070
.catch(() => cached)
7171
)
7272
);
73-
});
73+
});

experiments/wordsearch/src/ui/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,4 @@ export async function initApp(root = document) {
304304
} else {
305305
persistModeToUrl(mode);
306306
}
307-
}
307+
}

experiments/wordsearch/src/ui/collapseMode.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ function evaluateSelection(cells) {
151151
/**
152152
* Remove the given cells, collapse columns downward, and refill the
153153
* vacated top cells using the Markov model.
154-
* Returns a map of cellKey -> drop distance (in rows) for animation:
155-
* - survivors that fell: positive number of rows dropped
156-
* - freshly spawned top cells: marked with `spawn` set
154+
* Returns a map of cellKey -> drop distance (in rows) for animation:
155+
* - survivors that fell: positive number of rows dropped
156+
* - freshly spawned top cells: marked with `spawn` set
157157
* @param {Array<{x:number,y:number}>} cells
158158
*/
159159
function collapseAndRefill(cells) {
@@ -302,13 +302,13 @@ function flashCleared(cells, done) {
302302
setTimeout(done, 260);
303303
}
304304
/**
305-
* Animate dropped + spawned tiles into place. Each affected cell starts
306-
* offset upward by its fall distance (in cell heights) and transitions back
307-
* to its final position, giving a "tiles falling" effect.
308-
* @param {HTMLTableElement} table
309-
* @param {Map<string, number>} dropRows key -> rows fallen
310-
* @param {Set<string>} spawned keys of freshly spawned top cells
311-
*/
305+
* Animate dropped + spawned tiles into place. Each affected cell starts
306+
* offset upward by its fall distance (in cell heights) and transitions back
307+
* to its final position, giving a "tiles falling" effect.
308+
* @param {HTMLTableElement} table
309+
* @param {Map<string, number>} dropRows key -> rows fallen
310+
* @param {Set<string>} spawned keys of freshly spawned top cells
311+
*/
312312
function animateDrops(table, dropRows, spawned) {
313313
if ((!dropRows || dropRows.size === 0) && (!spawned || spawned.size === 0)) return;
314314
// Determine the cell height (px) from the table's CSS variable plus the
@@ -493,4 +493,4 @@ export function togglePauseCollapse() {
493493
export function stopCollapse() {
494494
if (state && state.tick) clearInterval(state.tick);
495495
state = null;
496-
}
496+
}

experiments/wordsearch/src/ui/controls.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export function readConfig(root = document) {
4242
// the goal is to FIND words. Default on.
4343
const avoidWords = !(root.querySelector('#cfg-no-avoid-words') || {}).checked;
4444

45-
4645
const words = val('cfg-words', '')
4746
.split(/[\n,]+/)
4847
.map((w) => w.trim())
@@ -138,4 +137,4 @@ export function wireConfigPersistence(root = document, onChange) {
138137
if (typeof onChange === 'function') onChange();
139138
});
140139
}
141-
}
140+
}
Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
11
// Make the <aside> sidebar resizable via a draggable handle. The chosen
2-
// width is persisted to localStorage so it survives reloads.
2+
// width is persisted to localStorage so it survives reloads.
33

4-
const STORAGE_KEY = 'mws-sidebar-width';
5-
const MIN_WIDTH = 220;
6-
const MAX_WIDTH = 900;
4+
const STORAGE_KEY = 'mws-sidebar-width';
5+
const MIN_WIDTH = 220;
6+
const MAX_WIDTH = 900;
77

8-
/**
9-
* Wire a draggable resize handle onto the sidebar.
10-
* @param {Document|HTMLElement} root
11-
*/
12-
export function wireSidebarResize(root = document) {
13-
const aside = root.querySelector('aside');
14-
if (!aside) return;
8+
/**
9+
* Wire a draggable resize handle onto the sidebar.
10+
* @param {Document|HTMLElement} root
11+
*/
12+
export function wireSidebarResize(root = document) {
13+
const aside = root.querySelector('aside');
14+
if (!aside) return;
1515

16-
// Restore any persisted width.
17-
try {
18-
const saved = parseFloat(localStorage.getItem(STORAGE_KEY));
19-
if (Number.isFinite(saved) && saved >= MIN_WIDTH) {
20-
aside.style.width = `${saved}px`;
21-
}
22-
} catch {
23-
/* ignore storage errors */
24-
}
16+
// Restore any persisted width.
17+
try {
18+
const saved = parseFloat(localStorage.getItem(STORAGE_KEY));
19+
if (Number.isFinite(saved) && saved >= MIN_WIDTH) {
20+
aside.style.width = `${saved}px`;
21+
}
22+
} catch {
23+
/* ignore storage errors */
24+
}
2525

26-
// Create the handle if it doesn't already exist.
27-
let handle = aside.querySelector('.sidebar-resize-handle');
28-
if (!handle) {
29-
handle = document.createElement('div');
30-
handle.className = 'sidebar-resize-handle';
31-
handle.title = 'Drag to resize';
32-
aside.appendChild(handle);
33-
}
26+
// Create the handle if it doesn't already exist.
27+
let handle = aside.querySelector('.sidebar-resize-handle');
28+
if (!handle) {
29+
handle = document.createElement('div');
30+
handle.className = 'sidebar-resize-handle';
31+
handle.title = 'Drag to resize';
32+
aside.appendChild(handle);
33+
}
3434

35-
let startX = 0;
36-
let startWidth = 0;
35+
let startX = 0;
36+
let startWidth = 0;
3737

38-
const onMove = (e) => {
39-
const clientX = e.touches ? e.touches[0].clientX : e.clientX;
40-
let next = startWidth + (clientX - startX);
41-
next = Math.max(MIN_WIDTH, Math.min(MAX_WIDTH, next));
42-
aside.style.width = `${next}px`;
43-
};
38+
const onMove = (e) => {
39+
const clientX = e.touches ? e.touches[0].clientX : e.clientX;
40+
let next = startWidth + (clientX - startX);
41+
next = Math.max(MIN_WIDTH, Math.min(MAX_WIDTH, next));
42+
aside.style.width = `${next}px`;
43+
};
4444

45-
const onUp = () => {
46-
document.removeEventListener('mousemove', onMove);
47-
document.removeEventListener('mouseup', onUp);
48-
document.removeEventListener('touchmove', onMove);
49-
document.removeEventListener('touchend', onUp);
50-
document.body.classList.remove('resizing-sidebar');
51-
try {
52-
localStorage.setItem(STORAGE_KEY, String(parseFloat(aside.style.width) || MIN_WIDTH));
53-
} catch {
54-
/* ignore */
55-
}
56-
// Notify listeners (e.g. grid re-fit) that layout changed.
57-
window.dispatchEvent(new Event('resize'));
58-
};
45+
const onUp = () => {
46+
document.removeEventListener('mousemove', onMove);
47+
document.removeEventListener('mouseup', onUp);
48+
document.removeEventListener('touchmove', onMove);
49+
document.removeEventListener('touchend', onUp);
50+
document.body.classList.remove('resizing-sidebar');
51+
try {
52+
localStorage.setItem(STORAGE_KEY, String(parseFloat(aside.style.width) || MIN_WIDTH));
53+
} catch {
54+
/* ignore */
55+
}
56+
// Notify listeners (e.g. grid re-fit) that layout changed.
57+
window.dispatchEvent(new Event('resize'));
58+
};
5959

60-
const onDown = (e) => {
61-
e.preventDefault();
62-
startX = e.touches ? e.touches[0].clientX : e.clientX;
63-
startWidth = aside.getBoundingClientRect().width;
64-
document.body.classList.add('resizing-sidebar');
65-
document.addEventListener('mousemove', onMove);
66-
document.addEventListener('mouseup', onUp);
67-
document.addEventListener('touchmove', onMove, { passive: false });
68-
document.addEventListener('touchend', onUp);
69-
};
60+
const onDown = (e) => {
61+
e.preventDefault();
62+
startX = e.touches ? e.touches[0].clientX : e.clientX;
63+
startWidth = aside.getBoundingClientRect().width;
64+
document.body.classList.add('resizing-sidebar');
65+
document.addEventListener('mousemove', onMove);
66+
document.addEventListener('mouseup', onUp);
67+
document.addEventListener('touchmove', onMove, { passive: false });
68+
document.addEventListener('touchend', onUp);
69+
};
7070

71-
handle.addEventListener('mousedown', onDown);
72-
handle.addEventListener('touchstart', onDown, { passive: false });
73-
}
71+
handle.addEventListener('mousedown', onDown);
72+
handle.addEventListener('touchstart', onDown, { passive: false });
73+
}

experiments/wordsearch/src/ui/urlState.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ export function persistConfigToUrl(root = document) {
103103
const qs = params.toString();
104104
const newUrl = `${window.location.pathname}${qs ? `?${qs}` : ''}${window.location.hash}`;
105105
window.history.replaceState(null, '', newUrl);
106-
}
106+
}

0 commit comments

Comments
 (0)