Advertisement
Pirnogion

FIO

Nov 24th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | None | 0 0
  1. ----------------------------
  2. -- Programm: FIO          --
  3. -- Author:  JaggerDer     --
  4. -- Created: --.--.14      --
  5. ----------------------------
  6.  
  7. local tDecToPaint =
  8. {
  9.  ["0"]     = "x",
  10.  ["1"]     = "0",
  11.  ["2"]     = "1",
  12.  ["4"]     = "2",
  13.  ["8"]     = "3",
  14.  ["16"]    = "4",
  15.  ["32"]    = "5",
  16.  ["64"]    = "6",
  17.  ["128"]   = "7",
  18.  ["256"]   = "8",
  19.  ["512"]   = "9",
  20.  ["1024"]  = "a",
  21.  ["2048"]  = "b",
  22.  ["4096"]  = "c",
  23.  ["8192"]  = "d",
  24.  ["16384"] = "e",
  25.  ["32768"] = "f"
  26. }
  27.  
  28. local tPaintToDec =
  29. {
  30.  ["x"] =     0,
  31.  ["0"] =     1,
  32.  ["1"] =     2,
  33.  ["2"] =     4,
  34.  ["3"] =     8,
  35.  ["4"] =    16,
  36.  ["5"] =    32,
  37.  ["6"] =    64,
  38.  ["7"] =   128,
  39.  ["8"] =   256,
  40.  ["9"] =   512,
  41.  ["a"] =  1024,
  42.  ["b"] =  2048,
  43.  ["c"] =  4096,
  44.  ["d"] =  8192,
  45.  ["e"] = 16384,
  46.  ["f"] = 32768
  47. }
  48.  
  49. local ParseData = function(asData)
  50.  local _sChar = string.sub(asData, 1, 1)
  51.  local _nCharColor = string.sub(asData, 2, 2)
  52.  local _nColor = string.sub(asData, 3, 3)
  53.  
  54.  return _sChar, tPaintToDec[_nCharColor], tPaintToDec[_nColor]
  55. end
  56.  
  57. SaveToFile = function(asFilename, aloLayer)
  58.  _fFile = fs.open(asFilename .. ".lyr", "w")
  59.  
  60.  local _, _nWidth, _nHeight = aloLayer:GetParameters()
  61.  local _sXLine = ""
  62.  
  63.  for i = 1, _nHeight, 1 do
  64.   for j = 1, _nWidth, 1 do
  65.     local _sText, _nTextColor, _nColor = aloLayer:GetPixel(j, i)
  66.    _sXLine = _sXLine .. _sText .. tDecToPaint[_nTextColor .. ""] .. tDecToPaint[_nColor .. ""]
  67.   end
  68.   _fFile.writeLine(_sXLine)
  69.   _sXLine = ""
  70.  end
  71.  
  72.   _fFile.writeLine("eof")
  73.  _fFile.close()
  74. end
  75.  
  76. ReadFromFile = function(asFilename, aloLayer)
  77.  local _sData = nil
  78.  local _sChar = nil
  79.  local _nCharColor = nil
  80.  local _nColor = nil
  81.  local _, _nWidth, _nHeight = aloLayer:GetParameters()
  82.  local _nX = 1
  83.  local _nY = 1
  84.  
  85.  if (fs.exists(asFilename .. ".lyr")) then
  86.   _fFile = fs.open(asFilename .. ".lyr", "r")
  87.  
  88.   while true do
  89.    _sData = _fFile.readLine()
  90.    if (_sData == "eof") then break end
  91.  
  92.    for inf in string.gmatch(_sData, "...") do
  93.     _sChar, _nCharColor, _nColor = ParseData(inf)
  94.    
  95.     aloLayer:SetPixel(_nX, _nY, _sChar, _nCharColor, _nColor)
  96.     if (_nX < _nWidth) then _nX = _nX + 1 else _nX = 1 _nY = _nY + 1 end
  97.    end
  98.   end
  99.  
  100.  _fFile.close()
  101.  end
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement