?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. UPGRADE = 1     // upgrade sprites or levels data
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.         if UPGRADE
  10.  
  11.         lua ;ALLPASS
  12.  
  13.         function fileList(path)
  14.                 return io.popen("dir \""..path.."\" /a /b", "r"):lines()
  15.         end
  16.  
  17.         function save(data)
  18.                 local file,err = io.open("sprites/storage.asm",'w')
  19.                 if file then
  20.                         file:write(tostring(data))
  21.                         file:close()
  22.                 else
  23.                         print("error:", err) -- not so hard?
  24.                 end
  25.         end
  26. --              .PBM to asm
  27.         local path = "sprites/bmp/"
  28.         local data = ""
  29.         --// read path for names
  30.         for fileName in io.popen("dir \""..path.."\" /a /b", "r"):lines() do
  31.             local lines = {}
  32.             local file = assert(io.open(path..fileName, "rb"))
  33.             --// read lines from file.pbm 'PBM' format
  34.             for line in io.lines(path..fileName) do
  35.                 --// [1] format
  36.                 --// [2] width
  37.                 --// [3] height
  38.                 --// [4] sprite data
  39.                 lines[#lines + 1] = line
  40.             end
  41.             --// reformat name for asm label
  42.             uppercaseName = string.upper(fileName)
  43.             dotUnderscore = string.gsub(string.upper(fileName),"%.", "_")
  44.             local strData = ""
  45.             for c in  (lines[4] or ''):gmatch'.' do
  46.                 strData = strData..c:byte()..","
  47.             end
  48.             data = data..dotUnderscore..':\tdb '..string.sub(strData, 1, #strData-1).."\n"
  49.             file:close()
  50.         end
  51.         save(data)
  52.  
  53. --              Tiled to asm
  54.         local mapsPath = "maps/"
  55.         for levelName in fileList(mapsPath) do
  56.                 local file = assert(io.open(mapsPath..levelName, "r"))
  57.                 local t = file:read("*a")
  58.                 print(t)
  59.                 file:close()
  60.         end
  61.  
  62.  
  63.         endlua
  64.  
  65.         endif