From 654c038030c102971dbcb9356ba1bd65e3f36037 Mon Sep 17 00:00:00 2001 From: Axel Meyer Date: Sat, 9 May 2026 20:09:00 +0200 Subject: [PATCH] feat: P.0.lib.render colored-quad tile-grid renderer --- .gitignore | 2 ++ README.md | 30 ++++++++++++++++++++++++++ init.lua | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ manifest.lib | 1 + 4 files changed, 94 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 init.lua create mode 100644 manifest.lib diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..41ae811 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +*.log diff --git a/README.md b/README.md new file mode 100644 index 0000000..3bd1f6d --- /dev/null +++ b/README.md @@ -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 +``` diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..300806f --- /dev/null +++ b/init.lua @@ -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 diff --git a/manifest.lib b/manifest.lib new file mode 100644 index 0000000..daf9fb8 --- /dev/null +++ b/manifest.lib @@ -0,0 +1 @@ +{"id":"lib-core.render","version":"0.1.0","api_min":"0.1"}