Advertisement
BombBloke

cutAtlas.lua

Nov 7th, 2020
2,148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. -- cutAtlas.lua
  2. -- Chops up Dragon Bones atlas files that target multiple sheets.
  3.  
  4. require "lfs"
  5.  
  6. local function getExt(filename)
  7.     local div = filename:find("%.[^%.]*$")
  8.     if not div then return filename end
  9.     return filename:sub(1, div - 1), filename:sub(div + 1):lower()
  10. end
  11.  
  12. local function checkAtlasDir(dir)
  13.     for entry in lfs.dir(dir) do
  14.         local path = dir .. "/" .. entry
  15.         local attribs = lfs.attributes(path)
  16.        
  17.         if attribs then
  18.             if entry ~= "." and entry ~= ".." and attribs.mode == "directory" then
  19.                 checkAtlasDir(path)
  20.             elseif attribs.mode == "file" and (entry:sub(-6):lower() == ".atlas" or entry:sub(-10):lower() == ".atlas.txt") then
  21.                 local output
  22.                
  23.                 for line in io.lines(path) do
  24.                     if line:sub(-4):lower() == ".png" then
  25.                         if output then output:close() end
  26.                         local name, ext = getExt(line)
  27.                         if not lfs.attributes(dir .. "/" .. name .. ".atlas") then output = io.open(dir .. "/" .. name .. ".atlas", "w") end
  28.                         if output then output:write("\n" .. line .. "\n") end
  29.                     else
  30.                         if output then output:write(line .. "\n") end
  31.                     end
  32.                 end
  33.             end
  34.         end
  35.     end
  36. end
  37.  
  38. checkAtlasDir(".")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement