Skip to content

The simulator's camera moves on Center View - #95

Closed
mstephenhunt wants to merge 1 commit into
scm-js:mainfrom
mstephenhunt:sim-center-view-camera
Closed

mstephenhunt wants to merge 1 commit into
scm-js:mainfrom
mstephenhunt:sim-center-view-camera

Conversation

@mstephenhunt

Copy link
Copy Markdown
Contributor

Why

I'm building an auto-cast toggle for Medics in a Remastered map, and part of it reads local.camera after a centerView(). In map build --test the camera never moved: local.camera stayed at 0, 0, so none of that logic could be covered by a test. In the real game the camera moves.

Fixes #94

What changes

  • Center View moves the simulated camera. The camera of the player whose program ran it goes to the location's center minus 320, 240 (a 640 × 480 Classic screen), snapped down to a multiple of 8 and kept on the map: at most 648 px short of the right edge and 488 short of the bottom. Those stops are what Center View did when played in Remastered with Classic graphics on a 64 × 64 map (centering on the middle gave 704, 784; on the bottom-right corner, 1400, 1560). Remastered's wider screen isn't modeled.
  • The mouse stays on the screen. When a test has placed the mouse, its map position moves with the camera, so local.mouse reads the same before and after.
  • A test world can know the map's size. TestWorld.mapSize (tiles) is read as memory.map.width / .height and used for the clamp; the build step fills it in from the open map. Without it the simulator assumes 128 × 128, as the fog already did.

Testing

  • npm test: 1446 passed, 9 skipped.
  • npm run typecheck: clean.
  • The new test in tests/testing.test.ts fails on main (prints middle 0, 0 / corner 0, 0) and passes with the change.

centerView() in a program left local.camera at 0, 0 in a test: the action
was only logged, and only the test's moveCamera() moved the camera. Now Center
View sets the camera of the player whose program ran it, centered on the
location for a 640 x 480 screen, snapped down to 8 pixels, and kept on the
map: 648 pixels short of its right edge and 488 short of its bottom, as played
in Classic graphics. The mouse stays where it is on the screen.

A test world can be given the map's size (mapSize, in tiles), which the build
step fills in from the open map; memory.map.width and .height read it.

Fixes scm-js#94

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mstephenhunt

Copy link
Copy Markdown
Contributor Author

Closing in favor of #96, which now carries this PR's commits along with the rest of the auto-mining, auto-restore and toggle work, so it can be reviewed and merged as one PR.

@mstephenhunt
mstephenhunt deleted the sim-center-view-camera branch November 13, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simulator: centerView() doesn't move local.camera

1 participant