'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { makeGame, GameCore } = require('./helpers.js'); describe('Cell-based grab picking (t1109)', () => { it('a press anywhere inside the cell, including each corner, grabs that block', () => { const g = makeGame({ noSpawn: true }); const block = g.place(2, 3, 1); g.place(2, 2, 0); g.place(2, 4, 2); const corners = [ [2.01, 3.01], [2.01, 3.99], [2.99, 3.01], [2.99, 3.99], [2.5, 3.5], [2.15, 3.15], [2.85, 3.85] ]; for (const [col, y] of corners) { assert.ok(g.beginDrag(col, y), 'should grab at (' + col + ', ' + y + ')'); assert.equal(g.drag.blockId, block.id, 'wrong block at (' + col + ', ' + y + ')'); g.endDrag(); } }); it('a press in the padding / gap of a cell still grabs the occupant (not the sprite box)', () => { const g = makeGame({ noSpawn: true }); const block = g.place(4, 1, 3); g.place(4, 0, 0); // Near the edges — "gaps between sprites" if sprites are inset. assert.ok(g.beginDrag(4.02, 1.02)); assert.equal(g.drag.blockId, block.id); g.endDrag(); assert.ok(g.beginDrag(4.98, 1.98)); assert.equal(g.drag.blockId, block.id); g.endDrag(); }); it('when a block is mid-animation (non-integer y), the nearest in the column within half a tile is grabbed', () => { const g = makeGame({ noSpawn: true }); const block = g.place(1, 2, 2); g.place(1, 0, 0); // Simulate a bounce / settle offset: the block sits at 2.35. block.y = 2.35; // Press in cell 2 (overlaps the footprint [2.35, 3.35)). assert.ok(g.beginDrag(1.4, 2.5)); assert.equal(g.drag.blockId, block.id); g.endDrag(); // Press in cell 3, just above the footprint — fallback within 0.5. // Footprint ends at 3.35; press at 3.55 is 0.20 away. assert.ok(g.beginDrag(1.4, 3.55)); assert.equal(g.drag.blockId, block.id); g.endDrag(); // Further than SNAP_Y (0.5) above 3.35: at 3.35+0.5+0.15=4.0, no grab. assert.equal(g.beginDrag(1.4, 3.35 + GameCore.SNAP_Y + 0.15), false); }); it('floor of the pointer chooses the cell; the cell above is a different block', () => { const g = makeGame({ noSpawn: true }); const lower = g.place(0, 5, 1); const upper = g.place(0, 6, 2); g.place(0, 4, 0); assert.ok(g.beginDrag(0.99, 5.99)); assert.equal(g.drag.blockId, lower.id); g.endDrag(); assert.ok(g.beginDrag(0.01, 6.01)); assert.equal(g.drag.blockId, upper.id); g.endDrag(); }); });