feat(render): per-entity sprite_scale on the Atlas-UV path
draw_entities path-1 reads an optional sprite_scale (number, default 1.0) and applies it as uniform scaleX/scaleY in draw_sprite_transform around the visual center. Lets templates whose native sprite resolution (e.g. TC_Basics 300×300 bed) doesn't match the project tile-scale (~/sporel_tile_scale.md: 64 px = 0.5 m via the puppet shoulder anchor) render at credible real-world sizes without re-baking the atlas. Consumers compute their per-atlas scale from atlas_meta.pixels_per_meter (atlas-baker v0.4.0+ output) divided into their project canonical px/m — one line in M.init, no per-entity constants in the template. Unset sprite_scale preserves v0.2.0 behavior — spine-prototype, map-editor, vagrant's pre-TC_Basics items unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
17
README.md
17
README.md
@@ -4,9 +4,9 @@ Colored-quad tile-grid renderer + tag-driven entity-render. Reads
|
||||
`lib-core.maps`'s tilemap (v0.1: `draw_map`), and `lib-core.composition`'s
|
||||
tag-index (v0.2: `draw_entities`).
|
||||
|
||||
**Version:** 0.2.0
|
||||
**Version:** 0.3.0
|
||||
**Lib-ID:** lib-core.render
|
||||
**Requires:** lib-core.maps v>=0.5.7, lib-core.composition v>=0.1.0
|
||||
**Requires:** lib-core.maps v>=0.5.7, lib-core.composition v>=0.3.0
|
||||
**Tags:** render, tiles, draw, colored-quads, entities
|
||||
|
||||
## Topology
|
||||
@@ -62,7 +62,10 @@ Three sprite-property paths are tried per entity, in order:
|
||||
|
||||
1. **`sprite_atlas` (string, atlas-texture-path) + `sprite_uv.{x,y,w,h}`
|
||||
(numbers)** — renders the sub-rectangle of the atlas via
|
||||
`engine.render.draw_sprite_transform`. Atlas textures are loaded
|
||||
`engine.render.draw_sprite_transform`. Optional `sprite_scale`
|
||||
(number, default 1.0) scales the rendered quad uniformly around its
|
||||
visual center; useful when a sprite-atlas's native pixel size
|
||||
doesn't match the project tile-scale. Atlas textures are loaded
|
||||
once and cached internally on first use; no eviction.
|
||||
2. **`sprite_color` (uint32 0xRRGGBBAA) + `sprite_w` + `sprite_h`
|
||||
(numbers)** — renders a colored rect via `engine.render.draw_rect`.
|
||||
@@ -96,6 +99,14 @@ end
|
||||
|
||||
## CHANGELOG
|
||||
|
||||
### v0.3.0 (2026-06-20)
|
||||
- Added optional `sprite_scale` (number) on path (1). Defaults to 1.0
|
||||
when absent — v0.2.0 consumers unchanged. Lets templates whose
|
||||
native sprite resolution doesn't match the project tile-scale
|
||||
rescale at render time without re-baking the atlas.
|
||||
- Composition dep tightened to v0.3.0 (matches current sibling-tree
|
||||
state; no API impact, just resolution-correctness).
|
||||
|
||||
### v0.2.0 (Phase A.2 — 2026-06-09)
|
||||
- Added `draw_entities(filter)` tag-driven entity-render. Two sprite-
|
||||
property paths (`sprite_atlas`+`sprite_uv` / `sprite_color`+`sprite_w`+
|
||||
|
||||
20
init.lua
20
init.lua
@@ -1,8 +1,17 @@
|
||||
-- =====================================================================
|
||||
-- lib-core.render v0.2.0 — Tile-Grid + Entity Rendering
|
||||
-- lib-core.render v0.3.0 — Tile-Grid + Entity Rendering
|
||||
-- See: meta/docs/superpowers/specs/2026-05-09-p0-lib-render-design.md
|
||||
-- meta/docs/superpowers/specs/2026-06-09-phase-A-...
|
||||
--
|
||||
-- v0.3.0 additions:
|
||||
-- - draw_entities path (1) reads optional `sprite_scale` (number,
|
||||
-- default 1.0); applied uniformly as scaleX/scaleY in
|
||||
-- draw_sprite_transform. Lets templates whose native sprite size
|
||||
-- doesn't match the project tile-scale (e.g. TC_Basics 600×300
|
||||
-- bed at 64 px = 0.5 m) scale down without per-entity baker
|
||||
-- re-runs or render-time hacks. Default 1.0 preserves v0.2.0
|
||||
-- behaviour for unset consumers.
|
||||
--
|
||||
-- v0.2.0 additions:
|
||||
-- - draw_entities(filter) — tag-based entity-render via composition.
|
||||
-- Supports two sprite-property paths and a fallback:
|
||||
@@ -124,9 +133,14 @@ function M.draw_entities(filter)
|
||||
local uvh = get_num(e, "sprite_uv.h")
|
||||
if uvx and uvy and uvw and uvh then
|
||||
local tex = load_atlas(atlas)
|
||||
-- position is visual-center: origin = uv center
|
||||
-- v0.3.0: optional sprite_scale; default 1.0 keeps
|
||||
-- v0.2.0 behaviour for entities that don't set it.
|
||||
local s = get_num(e, "sprite_scale") or 1.0
|
||||
-- position is visual-center: origin = uv center.
|
||||
-- Origin stays in source-uv coords (pre-scale), so
|
||||
-- draw_sprite_transform applies scale around it.
|
||||
engine.render.draw_sprite_transform(
|
||||
tex, px, py, 0, 1, 1, uvw / 2, uvh / 2,
|
||||
tex, px, py, 0, s, s, uvw / 2, uvh / 2,
|
||||
0xFFFFFFFF, uvx, uvy, uvw, uvh)
|
||||
count = count + 1
|
||||
end
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"id":"lib-core.render","version":"0.2.0","api_min":"0.1","deps":[{"id":"lib-core.maps","version":"0.5.7"},{"id":"lib-core.composition","version":"0.3.0"}]}
|
||||
{"id":"lib-core.render","version":"0.3.0","api_min":"0.1","deps":[{"id":"lib-core.maps","version":"0.5.7"},{"id":"lib-core.composition","version":"0.3.0"}]}
|
||||
|
||||
Reference in New Issue
Block a user