Skip to content

feat(world-builder): rectangle fill and tile mutation API with bounds check (#7) - #134

Open
angelTomo9 wants to merge 11 commits into
Bitcoindefi:mainfrom
angelTomo9:feat-world-builder-rectangle-fill-1787672043685
Open

feat(world-builder): rectangle fill and tile mutation API with bounds check (#7)#134
angelTomo9 wants to merge 11 commits into
Bitcoindefi:mainfrom
angelTomo9:feat-world-builder-rectangle-fill-1787672043685

Conversation

@angelTomo9

Copy link
Copy Markdown

Closes #7

Summary of Changes

Implements atomic batch rectangle filling and region query endpoints for the in-game World Builder / Map Editor, with strict 100x100 grid bounds checking and a 500-tile safety cap per mutation.

Features & Deliverables

  • Atomic Rectangle Fill: Endpoint PUT /admin/game-data/maps/:mapNum/rectangle supporting bulk paint of rectangular zones (fromX, fromY, toX, toY) up to 500 tiles per request.
  • Bounding Box Query: Endpoint GET /admin/game-data/maps/:mapNum/region allowing the client editor to inspect specific viewport regions.
  • Strict Bounds Validation: Validates all coordinates within 1..100 and enforces graphic existence guards before executing atomic database writes.
  • Integration Tests: Added unit & integration tests in api/src/tests/worldBuilder_rectangle.integration.test.ts.

Comment thread api/src/server.ts Outdated
Comment thread api/src/repositories/worldBuilder.ts Outdated
@gitar-bot

gitar-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 resolved / 2 findings

Implements atomic batch rectangle filling and region query endpoints for the World Builder with strict grid bounds checking, addressing the unvalidated region query params and invalid dead-zone indices findings.

✅ 2 resolved
Edge Case: /region query params not validated; NaN reaches SQL

📄 api/src/server.ts:1079-1084 📄 api/src/repositories/worldBuilder.ts:334-345
In the GET /region handler, fromX/fromY/toX/toY are parsed with Number.parseInt on raw query strings with no NaN check and no clamping to the documented 1..100 grid. A non-numeric or empty param (e.g. ?fromX=abc or ?fromX=) yields NaN, which is passed straight into the parameterized integer columns and causes a Postgres 'invalid input syntax' error surfaced as a confusing 400. Validate/parse the coordinates (default + Number.isInteger guard + clamp to 1..MAP_SIZE) before calling getMapRegion, mirroring the strict bounds enforcement used elsewhere.

Edge Case: Rectangle/tile grhIndex allows invalid dead-zone indices

📄 api/src/repositories/worldBuilder.ts:283-284 📄 api/src/repositories/worldBuilder.ts:225-239 📄 api/src/repositories/worldBuilder.ts:716-720
paintRectangleSchema (and tilePaintSchema/paintTiles) only reject uploaded graphics that don't exist when grhIndex >= UPLOADED_GRAPHIC_INDEX_START (1,000,000); any value below that just needs to be non-negative. This lets a caller store an out-of-range original index — e.g. the dead zone between 320151 and 1,000,000 — which upsertPaletteEntry explicitly rejects with 'fuera de rango'. Add an upper-bound/existence check for original indices (1..320151) in paintRectangleSchema/paintTiles so tile painting matches the palette validation.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Important

Your trial ends in 7 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more.

Was this helpful? React with 👍 / 👎 | Gitar

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.

Etapa 1: API para pintar el piso del mapa

1 participant