57 lines
No EOL
2.1 KiB
Lua
57 lines
No EOL
2.1 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.exists(metaPath) 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
|
|
|
|
if not globalAssetProperties[name].cells or reanalyzeCells then
|
|
globalAssetProperties[name].cells = {}
|
|
globalAssetProperties[name].cells[color] = getCellsFromSprite(love.graphics.newImage(sprite))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
return globalAssetProperties
|
|
end |