chroma_solstice/level_editor/object_attributes.lua

82 lines
3.1 KiB
Lua
Raw Normal View History

2015-03-25 01:38:53 -04:00
require "libs/TSerial"
local BoxVariants = require "box_variants"
2015-03-25 01:38:53 -04:00
local targetFolder = "art"
local reanalyzeCells = true
2015-03-25 01:38:53 -04:00
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)
2015-03-25 01:38:53 -04:00
-- 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)
2026-08-07 00:56:33 -04:00
if not globalAssetProperties[name] then
globalAssetProperties[name] = {}
globalAssetProperties[name].directory = folder
globalAssetProperties[name].sprites = {}
globalAssetProperties[name].preload = false
2015-03-25 01:38:53 -04:00
end
2026-08-07 00:56:33 -04:00
-- class comes from a <name>.meta sitting next to the art
-- (authoritative); default to immoveable if none exists
local metaPath = topFolder .. "/" .. folder .. "/" .. name .. ".meta"
2026-08-07 20:56:42 -04:00
if love.filesystem.getInfo(metaPath, "file") then
2026-08-07 00:56:33 -04:00
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
2026-08-07 20:56:42 -04:00
globalAssetProperties[name].cells[color] = getCellsFromSprite(sprite)
end
2015-03-25 01:38:53 -04:00
end
end
end
end
end
2026-08-11 22:55:58 -04:00
-- Wired devices intentionally reuse the familiar switch/door artwork. Their
-- white terminal marker is drawn by the entity class, while these synthetic
-- asset records make them available to the ordinary palette and brush.
local function synthetic(name, source, behavior)
local original = globalAssetProperties[source]
if not original then return end
globalAssetProperties[name] = {
directory = original.directory,
sprites = original.sprites,
cells = original.cells,
class = behavior,
preload = false,
synthetic = true,
}
end
synthetic("wired_switch", "switch", "wired_switch")
synthetic("wired_door", "door", "wired_door")
return BoxVariants.addTo(globalAssetProperties)
2026-08-07 20:56:42 -04:00
end