feat: P.0.lib.render colored-quad tile-grid renderer
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
build/
|
||||
*.log
|
||||
30
README.md
Normal file
30
README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# lib-core.render
|
||||
|
||||
P.0 colored-quad tile-grid renderer. Reads `lib-core.maps`'s current map +
|
||||
its tilemap, iterates tiles, draws a colored rect per tile via
|
||||
`engine.render.draw_rect`. Fallback to magenta `[255, 0, 255]` for tiles
|
||||
with missing/malformed color.
|
||||
|
||||
- Lib-ID: `lib-core.render`
|
||||
- Version: `0.1.0`
|
||||
- Spec: `meta/docs/superpowers/specs/2026-05-09-p0-lib-render-design.md`
|
||||
|
||||
Forward-compat stubs (DEPRECATED-MVP) for texture-rendering,
|
||||
PROTOTYPE-Lib-Pattern, camera, layers, post-processing, parallax,
|
||||
shaders, hot-reload. See `meta/docs/architecture/render-pipeline.md`
|
||||
for the full target spec (941 lines).
|
||||
|
||||
## API
|
||||
- `r_lib.draw_map(map_id?)` — iterates current (or specified) map's tiles,
|
||||
draws colored rect per tile. Must be called inside a render hook.
|
||||
Returns count of tiles drawn.
|
||||
|
||||
## Consumer pattern
|
||||
```lua
|
||||
local maps = require("lib-core.maps")
|
||||
local r_lib = require("lib-core.render")
|
||||
function render(ctx)
|
||||
engine.render.clear_color(engine.render.rgb(20, 20, 30))
|
||||
r_lib.draw_map()
|
||||
end
|
||||
```
|
||||
61
init.lua
Normal file
61
init.lua
Normal file
@@ -0,0 +1,61 @@
|
||||
-- =====================================================================
|
||||
-- lib-core.render — Tile-Grid Rendering (P.0)
|
||||
-- See: meta/docs/superpowers/specs/2026-05-09-p0-lib-render-design.md
|
||||
--
|
||||
-- Scope: colored-quads only. Texture-rendering, PROTOTYPE-Lib-Pattern,
|
||||
-- camera, layers, post-processing, parallax, shaders, hot-reload —
|
||||
-- alle DEPRECATED-MVP, kommen in späteren Slices.
|
||||
-- =====================================================================
|
||||
|
||||
local maps = require("lib-core.maps")
|
||||
|
||||
local FALLBACK_COLOR = {255, 0, 255} -- magenta — "missing color" debug-marker
|
||||
|
||||
-- Reads tile-color from TileType-table; fallback to magenta if missing or malformed.
|
||||
local function tile_color(tile_type)
|
||||
local c = tile_type.color
|
||||
if type(c) ~= "table" or #c < 3 then return FALLBACK_COLOR end
|
||||
return c
|
||||
end
|
||||
|
||||
local M = {}
|
||||
|
||||
-- Iterates current (or specified) map's tiles, draws a colored rect per tile.
|
||||
-- Must be called from inside a render hook (engine.render.* enforces this).
|
||||
-- Returns the number of tiles drawn (for smoke verification + debug).
|
||||
function M.draw_map(map_id)
|
||||
local size = maps.size(map_id)
|
||||
local tile_size = maps.tile_size(map_id)
|
||||
local count = 0
|
||||
for ty = 0, size.h - 1 do
|
||||
for tx = 0, size.w - 1 do
|
||||
-- maps.tile_at uses arity-dispatch: 2-arg form falls back to current map,
|
||||
-- 3-arg form requires non-nil map_id. Branch to keep both call-shapes happy.
|
||||
local t
|
||||
if map_id == nil then
|
||||
t = maps.tile_at(tx, ty)
|
||||
else
|
||||
t = maps.tile_at(map_id, tx, ty)
|
||||
end
|
||||
if t ~= nil then
|
||||
local c = tile_color(t)
|
||||
local color = engine.render.rgb(c[1], c[2], c[3])
|
||||
engine.render.draw_rect(
|
||||
tx * tile_size, ty * tile_size,
|
||||
tile_size, tile_size,
|
||||
color)
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
-- Forward-compat stubs for later slices (kept as comments to avoid table-pollution):
|
||||
-- DEPRECATED-MVP: function M.draw_sprites(...) -- texture-slice
|
||||
-- DEPRECATED-MVP: function M.set_camera(camera) -- lib-core.camera slice
|
||||
-- DEPRECATED-MVP: function M.push_layer(name, order) -- multi-layer slice
|
||||
-- DEPRECATED-MVP: function M.register_pass(...) -- post-processing slice (spec §6)
|
||||
-- DEPRECATED-MVP: function M.set_clear_color(rgb) -- per-layer clear-color (spec §4)
|
||||
|
||||
return M
|
||||
1
manifest.lib
Normal file
1
manifest.lib
Normal file
@@ -0,0 +1 @@
|
||||
{"id":"lib-core.render","version":"0.1.0","api_min":"0.1"}
|
||||
Reference in New Issue
Block a user