Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local EU = require("ExtraUtilits")
- local io = require("io")
- local computer = require("computer")
- local serialization = require("serialization")
- local path = table.unpack({...})
- local file = io.open(path, "r")
- local data = serialization.unserialize(file:read())
- local w, h = data.w, data.h
- local field = {}
- for i = 1, w do
- field[i] = {}
- for j = 1, h do
- field[i][j] = {}
- local line = file:read()
- if line ~= "-" then
- local backstring = string.sub(line, 1, 3)
- local forestring = string.sub(line, 4, 6)
- local symbol = string.sub(line, 7, 7)
- local backgroundchars = {string.sub(backstring, 1, 1), string.sub(backstring, 2, 2), string.sub(backstring, 3, 3)}
- local foregroundchars = {string.sub(forestring, 1, 1), string.sub(forestring, 2, 2), string.sub(forestring, 3, 3)}
- local backRGB = {string.byte(backgroundchars[1]) or 0, string.byte(backgroundchars[2]) or 0, string.byte(backgroundchars[3]) or 0}
- local foreRGB = {string.byte(foregroundchars[1]) or 0, string.byte(foregroundchars[2]) or 0, string.byte(foregroundchars[3]) or 0}
- field[i][j].background = EU.Color.Pack(table.unpack(backRGB))
- field[i][j].foreground = EU.Color.Pack(table.unpack(foreRGB))
- field[i][j].symbol = symbol
- end
- end
- end
- file:close()
- return {field = field, width = w, height = h}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement