feat: expand campaign and refine puzzle visuals and controls
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { BoardViewport } from '../src/board-viewport.js';
|
||||
import { generateLaneLevel } from '../src/campaign-generator.js';
|
||||
import { Game, validateLevel, solveRotations } from '../src/core.js';
|
||||
import { layout, center, hitCell } from '../src/geometry.js';
|
||||
test('91 and 127 cell boards validate and their complete move sequences win',()=>{
|
||||
for(const [radius,count,target] of [[5,91,42],[6,127,60]]){
|
||||
const level=generateLaneLevel(606,{radius,target,axis:0});assert.equal(level.cells.length,count);assert.equal(level.tiles.length,target);assert.deepEqual(validateLevel(level),[]);
|
||||
const plan=solveRotations(level);assert.ok(plan.solvable);const game=new Game(level);
|
||||
for(const action of plan.actions){if(action.type==='tap')assert.equal(game.tap(action.id).status,'exit');else game.rotate(action.direction);}
|
||||
assert.ok(game.won);
|
||||
}
|
||||
});
|
||||
test('pinch anchoring, panning, and hit testing use the same transformed coordinates',()=>{
|
||||
const level=generateLaneLevel(606,{radius:5,target:42}),camera=new BoardViewport(),base=layout(level.cells,390,390);
|
||||
camera.zoom(2,120,150,390,390);assert.equal(camera.x,-120);assert.equal(camera.y,-150);
|
||||
camera.pan(30,-20,390,390);
|
||||
const view=camera.apply(base);
|
||||
for(const cell of level.cells){const p=center(cell,view);assert.equal(hitCell(level.cells,view,p.x,p.y),cell);}
|
||||
camera.zoom(99,195,195,390,390);assert.equal(camera.scale,4);
|
||||
camera.zoom(.001,195,195,390,390);assert.equal(camera.scale,1);assert.equal(camera.x,0);assert.equal(camera.y,0);
|
||||
});
|
||||
test('board zoom and vertical dragging keep the complete board visible after resizing',()=>{
|
||||
const level=generateLaneLevel(606,{radius:5,target:42}),camera=new BoardViewport();
|
||||
for(const [width,height] of [[334,620],[390,300],[334,720]]){
|
||||
const base=layout(level.cells,width,height);
|
||||
camera.fit(base,width,height);
|
||||
camera.zoom(99,40,30,width,height);
|
||||
assert.ok(camera.scale<=height/(base.bounds.bottom-base.bounds.top)+1e-9);
|
||||
for(const dy of [-10000,10000]){
|
||||
camera.pan(0,dy,width,height);
|
||||
assert.ok(base.bounds.top*camera.scale+camera.y>=-1e-9);
|
||||
assert.ok(base.bounds.bottom*camera.scale+camera.y<=height+1e-9);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user