Advertisement
HangMan23

paint_load.lua

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