chroma_solstice/level_editor/object_attributes.lua
Your Name d96f57efb6 Add multi-cell box shapes with per-cell collision
Generate 1x2/2x1 dominoes, 2x2 (square + 4 L-trominoes) and all
connected 3x2/2x3 polyominoes as R/G/B channel masks, reusing the
distance-based concentric-ring format that reproduces box_r/g/b
exactly. Outer silhouette keeps a 1px margin; connected cells stay
seamless. Each shape ships a {class="moveable"} .meta so getAllAssets
auto-registers it as a GenericMoveable.

Wire the occupied-cell shape (precomputed once by getAllAssets via
getCellsFromSprite) through to entities: createEntity now passes the
cached cells as cellShape, so an L/U/notched block collides on its real
cells and its gaps read as empty space. Fix the per-colour cache that
was reset every channel so only one colour survived.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 12:42:33 -04:00

61 lines
2.4 KiB
Lua

require "libs/TSerial"
local targetFolder = "art"
local reanalyzeCells = true
function getAllAssets()
local objectnames = {}
local topFolder = "art"
local files = love.filesystem.getDirectoryItems(topFolder)
for _, folder in pairs(files) do
if string.sub(folder, 1, 1) ~= "_" then
-- we ignore directories which are prepended w/ an underscore
if not string.find(folder, "%.") then
objectnames[folder] = {}
-- love.filesystem.createDirectory("art/" .. folder)
-- this is a folder, probably
local newFiles = love.filesystem.getDirectoryItems(topFolder .. "/" .. folder)
for _, fileToAnalyze in pairs(newFiles) do
if fileToAnalyze:find("_r.png") or fileToAnalyze:find("_g.png") or fileToAnalyze:find("_b.png")then
local color
if fileToAnalyze:find("_r.png") then color = "red"
elseif fileToAnalyze:find("_g.png") then color = "green"
elseif fileToAnalyze:find("_b.png") then color = "blue" end
local name = fileToAnalyze:sub(1, fileToAnalyze:len() - 6)
if not globalAssetProperties[name] then
globalAssetProperties[name] = {}
globalAssetProperties[name].directory = folder
globalAssetProperties[name].sprites = {}
globalAssetProperties[name].preload = false
end
-- class comes from a <name>.meta sitting next to the art
-- (authoritative); default to immoveable if none exists
local metaPath = topFolder .. "/" .. folder .. "/" .. name .. ".meta"
if love.filesystem.getInfo(metaPath, "file") then
globalAssetProperties[name].class = TSerial.unpack(love.filesystem.read(metaPath)).class
elseif not globalAssetProperties[name].class then
globalAssetProperties[name].class = "immoveable"
end
local sprite = topFolder .. "/" .. folder .. "/" .. fileToAnalyze
globalAssetProperties[name].sprites[color] = sprite
-- Precompute the occupied-cell shape once per asset/colour and
-- cache it here; entities share this table by reference so
-- collision never rescans pixels at runtime. Keyed per colour
-- (each channel leaves its own gaps) rather than reset per file.
globalAssetProperties[name].cells = globalAssetProperties[name].cells or {}
if not globalAssetProperties[name].cells[color] or reanalyzeCells then
globalAssetProperties[name].cells[color] = getCellsFromSprite(sprite)
end
end
end
end
end
end
return globalAssetProperties
end