Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Blueprint manager API
- -- by CrispyPin
- layer_sep = "--"
- blueprint = {}
- keys = {}
- function string:split(delimiter)
- -- stolen from jaredallard
- local result = {}
- local from = 1
- local delim_from, delim_to = string.find(self, delimiter, from)
- while delim_from do
- table.insert(result, string.sub(self, from , delim_from-1))
- from = delim_to + 1
- delim_from, delim_to = string.find(self, delimiter, from)
- end
- table.insert(result, string.sub(self, from))
- return result
- end
- local function join(strA, strB)
- return table.concat({strA, strB}, "")
- end
- local function loadLayer(data)
- bp = {}
- row = {}
- x = 1
- y = 1
- for i = 1, string.len(data) do
- b = string.sub(data, i, i)
- if b == "\n" then
- bp[y] = row
- row = {}
- x = 1
- y = y + 1
- else
- row[x] = b
- x = x + 1
- end
- end
- return bp
- end
- function loadBlueprint(filePath)
- f = fs.open(filePath, "r")
- if f == nil then
- return false
- end
- while true do
- local data = f.readLine()
- if data == "--" then
- break
- end
- local k = string.sub(data, 1, 1)
- local id = string.sub(data, 3)
- keys[k] = id
- end
- rawBlueprint = f.readAll()
- print(rawBlueprint)
- f.close()
- local layers = string.split(rawBlueprint, join(join("\n", layer_sep), "\n"))
- for L = 1, table.maxn(layers) do
- blueprint[L] = loadLayer(layers[L])
- end
- return true
- end
- function getBlock(x, y, layer)
- return keys[blueprint[layer][y][x]]
- end
- function getFootprint()
- -- returns width, length
- return table.maxn(blueprint[1][1]), table.maxn(blueprint[1])
- end
- function getLayers()
- return table.maxn(blueprint)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement