CometWolf

TA converter

Jan 16th, 2014
206
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local program = shell.getRunningProgram()
  2. local tArg = {...}
  3. if not tArg[1] then
  4.   print("Usage: "..program.." fileName")
  5.   return
  6. end
  7. if fs.exists(tArg[1]) then
  8.   local file = fs.open(tArg[1],"r")
  9.   local tBlueprint = {}
  10.   local tColorSlots = {}
  11.   local tOrigin = {}
  12.   if file.readLine() == "Blueprint file for CometWolf's Turtle Architect. Pastebin: Kt4D8uyE" then
  13.     tBlueprint = textutils.unserialize(file.readLine())
  14.     local colors = file.readLine()
  15.     if colors then
  16.       tColorSlots = textutils.unserialize(colors)
  17.     end
  18.   end
  19.   file.close()
  20.   if tBlueprint and #tBlueprint > 0 then
  21.     local file = fs.open(tArg[1],"w")
  22.     file.writeLine("Blueprint file for CometWolf's Turtle Architect. Pastebin: Kt4D8uyE")
  23.     for layer=1,#tBlueprint do
  24.       file.writeLine("Layer "..layer.." :")
  25.       tBlueprint[layer] = tBlueprint[layer] or {}
  26.       for x=1,#tBlueprint[layer] do
  27.         local line = "X"..x..string.rep(" ",#string.format(#tBlueprint[layer])-#string.format(x))..": "
  28.         for z=1,#tBlueprint[layer][x] do
  29.           local block = tBlueprint[layer][x][z] or "0"
  30.           line = line..block..string.rep(" ",3-#string.format(block))
  31.         end
  32.         file.writeLine(line)
  33.       end
  34.     end
  35.     file.writeLine"Color slots table:"
  36.     file.writeLine(textutils.serialize(tColorSlots))
  37.     file.writeLine"Build origin data:"
  38.     file.writeLine(textutils.serialize(tOrigin))
  39.     file.close()
  40.     print("Sucessfully converted :"..tArg[1])
  41.     return
  42.   end
  43. end
  44. error("Invalid file: "..tArg[1])
RAW Paste Data