Restructured per ADR-0038: Abstract + bold-list Badges + Topology H2 + H3-API-Subsections (one per public function) + Conventions/Consumer pattern/CHANGELOG/References. Topology auto-populated via Sporel.exe --lint --fix. Pre-commit hook installed via --install-hooks. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
72 lines
2.3 KiB
Markdown
72 lines
2.3 KiB
Markdown
# lib-core.render
|
|
|
|
Colored-quad tile-grid renderer. Reads `lib-core.maps`'s current (or specified) map + its tilemap, iterates tiles, draws one colored rect per tile via `engine.render.draw_rect`. Fallback to magenta `[255, 0, 255]` for tiles with missing or malformed color.
|
|
|
|
**Version:** 0.1.0
|
|
**Lib-ID:** lib-core.render
|
|
**Requires:** lib-core.maps v>=0.1.1
|
|
**Tags:** render, tiles, draw, colored-quads
|
|
|
|
## Topology
|
|
|
|
<!-- topology:start (auto-generated; do not edit) -->
|
|
```mermaid
|
|
graph LR
|
|
this["lib-core.render"]
|
|
lib_core_maps["lib-core.maps"]
|
|
this --> lib_core_maps
|
|
engine["engine.*"]
|
|
this --> engine
|
|
```
|
|
<!-- topology:end -->
|
|
|
|
## API
|
|
|
|
### `render.draw_map(map_id)`
|
|
**Syntax:** `render.draw_map(map_id: string | nil) -> integer`
|
|
|
|
**Example:**
|
|
```lua
|
|
function render(ctx)
|
|
engine.render.clear_color(engine.render.rgb(20, 20, 30))
|
|
local n = render.draw_map() -- uses current-map
|
|
end
|
|
```
|
|
|
|
**Description:** Iterates the tiles of the specified map (or current-map when nil), drawing one colored rect per tile at `(tx * tile_size, ty * tile_size)`. Tile color is read from the tilemap's `tile.color = {r, g, b}`; if missing or malformed, falls back to magenta as a visible "missing-color" debug-marker. Must be called from inside a render hook. Returns the number of tiles drawn (for smoke verification + debug).
|
|
|
|
## Conventions
|
|
|
|
- Colored-quads only in v0.1.0. Texture-rendering, multi-layer composition, post-processing, parallax, shaders, hot-reload all DEPRECATED-MVP.
|
|
- World-space coords; pair with `lib-core.camera` to support panning + zoom.
|
|
- Magenta fallback `[255, 0, 255]` is intentional: high-visibility debug-marker for malformed color-data.
|
|
- Y-down-positive per ADR-0031.
|
|
|
|
## Consumer pattern
|
|
|
|
```lua
|
|
local maps = require("lib-core.maps")
|
|
local render = require("lib-core.render")
|
|
local camera = require("lib-core.camera")
|
|
|
|
function render_fn(ctx)
|
|
engine.render.clear_color(engine.render.rgb(20, 20, 30))
|
|
camera.begin()
|
|
render.draw_map()
|
|
camera.finish()
|
|
end
|
|
```
|
|
|
|
## CHANGELOG
|
|
|
|
### v0.1.0 (P.0)
|
|
- Initial release: `draw_map` colored-quad iterator.
|
|
|
|
## References
|
|
|
|
- Spec v0.1.0 (P.0): `meta/docs/superpowers/specs/2026-05-09-p0-lib-render-design.md`
|
|
- Architecture: `meta/docs/architecture/render-pipeline.md`
|
|
- ADR-0001 (engine knows verbs, libs bring nouns)
|
|
- ADR-0031 (pixel-convention: Y-down-positive)
|
|
- ADR-0038 (API-Doc-Convention)
|