Advertisement
HangMan23

paint_load.lua

Aug 3rd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. local EU = require("ExtraUtilits")
  2. local io = require("io")
  3. local serialization = require("serialization")
  4.  
  5. local path = table.unpack({...})
  6.  
  7. local file = io.open(path, "r")
  8.  
  9. local data = serialization.unserialize(file:read())
  10.  
  11. local w, h = data.w, data.h
  12.  
  13. local field = {}
  14.  
  15. for i = 1, w do
  16.  
  17. field[i] = {}
  18.  
  19. for j = 1, h do
  20.  
  21. field[i][j] = {}
  22.  
  23. local line = file:read()
  24.  
  25. if line ~= "-" then
  26.  
  27. local backstring = string.sub(line, 1, 3)
  28. local forestring = string.sub(line, 4, 6)
  29. local symbol = string.sub(line, 7, 7)
  30.  
  31. local backgroundchars = {string.sub(backstring, 1, 1), string.sub(backstring, 2, 2), string.sub(backstring, 3, 3)}
  32. local foregroundchars = {string.sub(forestring, 1, 1), string.sub(forestring, 2, 2), string.sub(forestring, 3, 3)}
  33.  
  34. local backRGB = {string.byte(backgroundchars[1]) or 0, string.byte(backgroundchars[2]) or 0, string.byte(backgroundchars[3]) or 0}
  35. local foreRGB = {string.byte(foregroundchars[1]) or 0, string.byte(foregroundchars[2]) or 0, string.byte(foregroundchars[3]) or 0}
  36.  
  37. field[i][j].background = EU.Color.Pack(table.unpack(backRGB))
  38. field[i][j].foreground = EU.Color.Pack(table.unpack(foreRGB))
  39. field[i][j].symbol = symbol
  40.  
  41. end
  42.  
  43. end
  44.  
  45. end
  46.  
  47. file:close()
  48.  
  49. return {field = field, width = w, height = h}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement