Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- cutAtlas.lua
- -- Chops up Dragon Bones atlas files that target multiple sheets.
- require "lfs"
- local function getExt(filename)
- local div = filename:find("%.[^%.]*$")
- if not div then return filename end
- return filename:sub(1, div - 1), filename:sub(div + 1):lower()
- end
- local function checkAtlasDir(dir)
- for entry in lfs.dir(dir) do
- local path = dir .. "/" .. entry
- local attribs = lfs.attributes(path)
- if attribs then
- if entry ~= "." and entry ~= ".." and attribs.mode == "directory" then
- checkAtlasDir(path)
- elseif attribs.mode == "file" and (entry:sub(-6):lower() == ".atlas" or entry:sub(-10):lower() == ".atlas.txt") then
- local output
- for line in io.lines(path) do
- if line:sub(-4):lower() == ".png" then
- if output then output:close() end
- local name, ext = getExt(line)
- if not lfs.attributes(dir .. "/" .. name .. ".atlas") then output = io.open(dir .. "/" .. name .. ".atlas", "w") end
- if output then output:write("\n" .. line .. "\n") end
- else
- if output then output:write(line .. "\n") end
- end
- end
- end
- end
- end
- end
- checkAtlasDir(".")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement