Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- nsp_core = {}
- function nsp_core.serialize(data, name)
- if not fs.exists('/data') then
- fs.makeDir('/data')
- end
- local f = fs.open('/data/'..name, 'w')
- f.write(textutils.serialize(data))
- f.close()
- end
- function nsp_core.unserialize(name)
- if fs.exists('/data/'..name) then
- local f = fs.open('/data/'..name, 'r')
- local data = textutils.unserialize(f.readAll())
- f.close()
- return data
- else
- return nil
- end
- end
- function nsp_core.serialize_location(data)
- nsp_core.serialize(data, "location/".. data["name"])
- end
- function nsp_core.unserialize_location(name)
- return nsp_core.unserialize("location/" .. name)
- end
- function nsp_core.serialize_chunk(data)
- nsp_core.serialize(data, "chunk/".. data["x"] .. ",".. data["z"])
- end
- function nsp_core.unserialize_chunk(x,z)
- return nsp_core.unserialize("chunk/" .. x .. "," ..z)
- end
- function nsp_core.is_direction(nsew)
- if nsew == "N" or nsew == "S" or nsew == "E" or nsew == "W" then
- return true
- else
- return false
- end
- end
- function nsp_core.set_location(name, x, z, y, ...)
- local args = { ... }
- local x_num = tonumber(x)
- local y_num = tonumber(y)
- local z_num = tonumber(z)
- if type(x_num) == "number"
- and type(z_num) == "number"
- and type(y_num) == "number"
- and type(name) == "string" then
- local location = {["x"] = x_num,["z"] = z_num,["y"] = y_num, ["name"] = name}
- if #args == 1 and nsp_core.is_direction(args[1]) then
- location["f"] = args[1]
- end
- nsp_core.serialize_location(location)
- else
- print("Not applicable data to set location")
- end
- end
- --local chunk_location = {["x"] = 0,["z"] = 0,["name"] = "unnamed"}
- function nsp_core.find_chunk(x, z)
- local x_num = tonumber(x)
- x_num = math.floor(x_num/16)
- local z_num = tonumber(z)
- z_num = math.floor(z_num/16)
- local chunk_data = nil
- if type(x_num) == "number" and type(z_num) == "number" then
- chunk_data = nsp_core.unserialize_chunk(x_num,z_num)
- if chunk_data == nil then
- chunk_data = {["x"] = x_num,["z"] = z_num,["name"] = "unnamed"}
- end
- print(textutils.serialize(chunk_data))
- return chunk_data
- end
- end
- return nsp_core
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement