Advertisement
HangMan23

paint_save.lua

Aug 14th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1. local io = require("io")
  2. local serialization = require("serialization")
  3. local EU = require("ExtraUtilits")
  4. local fs =  require("filesystem")
  5.  
  6. local field, w, h, path = table.unpack({...})
  7.  
  8. local file = io.open(path, "wb")
  9.  
  10. file:write(serialization.serialize({w = w, h = h}) .. "\n")
  11.  
  12. for i = 1, w do
  13.  
  14.   for j = 1, h do
  15.  
  16.     if field[i][j].symbol then
  17.  
  18.       local background = {EU.Color.Extract(field[i][j].background)}
  19.       local foreground = {EU.Color.Extract(field[i][j].foreground)}
  20.       local symbol = field[i][j].symbol
  21.  
  22.       local back = string.char(background[1]) .. string.char(background[2]) .. string.char(background[3])
  23.       local fore = string.char(foreground[1]) .. string.char(foreground[2]) .. string.char(foreground[3])
  24.  
  25.       file:write(back .. fore .. symbol .. "\n")
  26.  
  27.     else
  28.  
  29.       file:write("-\n")
  30.  
  31.     end
  32.  
  33.   end
  34.  
  35. end
  36.  
  37. file:close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement