Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------
- -- Programm: FIO --
- -- Author: JaggerDer --
- -- Created: --.--.14 --
- ----------------------------
- local tDecToPaint =
- {
- ["0"] = "x",
- ["1"] = "0",
- ["2"] = "1",
- ["4"] = "2",
- ["8"] = "3",
- ["16"] = "4",
- ["32"] = "5",
- ["64"] = "6",
- ["128"] = "7",
- ["256"] = "8",
- ["512"] = "9",
- ["1024"] = "a",
- ["2048"] = "b",
- ["4096"] = "c",
- ["8192"] = "d",
- ["16384"] = "e",
- ["32768"] = "f"
- }
- local tPaintToDec =
- {
- ["x"] = 0,
- ["0"] = 1,
- ["1"] = 2,
- ["2"] = 4,
- ["3"] = 8,
- ["4"] = 16,
- ["5"] = 32,
- ["6"] = 64,
- ["7"] = 128,
- ["8"] = 256,
- ["9"] = 512,
- ["a"] = 1024,
- ["b"] = 2048,
- ["c"] = 4096,
- ["d"] = 8192,
- ["e"] = 16384,
- ["f"] = 32768
- }
- local ParseData = function(asData)
- local _sChar = string.sub(asData, 1, 1)
- local _nCharColor = string.sub(asData, 2, 2)
- local _nColor = string.sub(asData, 3, 3)
- return _sChar, tPaintToDec[_nCharColor], tPaintToDec[_nColor]
- end
- SaveToFile = function(asFilename, aloLayer)
- _fFile = fs.open(asFilename .. ".lyr", "w")
- local _, _nWidth, _nHeight = aloLayer:GetParameters()
- local _sXLine = ""
- for i = 1, _nHeight, 1 do
- for j = 1, _nWidth, 1 do
- local _sText, _nTextColor, _nColor = aloLayer:GetPixel(j, i)
- _sXLine = _sXLine .. _sText .. tDecToPaint[_nTextColor .. ""] .. tDecToPaint[_nColor .. ""]
- end
- _fFile.writeLine(_sXLine)
- _sXLine = ""
- end
- _fFile.writeLine("eof")
- _fFile.close()
- end
- ReadFromFile = function(asFilename, aloLayer)
- local _sData = nil
- local _sChar = nil
- local _nCharColor = nil
- local _nColor = nil
- local _, _nWidth, _nHeight = aloLayer:GetParameters()
- local _nX = 1
- local _nY = 1
- if (fs.exists(asFilename .. ".lyr")) then
- _fFile = fs.open(asFilename .. ".lyr", "r")
- while true do
- _sData = _fFile.readLine()
- if (_sData == "eof") then break end
- for inf in string.gmatch(_sData, "...") do
- _sChar, _nCharColor, _nColor = ParseData(inf)
- aloLayer:SetPixel(_nX, _nY, _sChar, _nCharColor, _nColor)
- if (_nX < _nWidth) then _nX = _nX + 1 else _nX = 1 _nY = _nY + 1 end
- end
- end
- _fFile.close()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement