You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.1 KiB
69 lines
2.1 KiB
creative_regions.astore = AreaStore()
|
|
creative_regions.mod_storage = minetest.get_mod_storage()
|
|
|
|
creative_regions.region_privs = {}
|
|
|
|
function creative_regions:load_regions()
|
|
self.astore:from_file(minetest.get_worldpath().."/creative_regions_regions")
|
|
creative_regions.region_privs = minetest.deserialize(creative_regions.mod_storage:get_string("astore_privs")) or {}
|
|
-- local edge1 = { x=-10, y=-10, z=-10 }
|
|
-- local edge2 = { x=10, y=10, z=10 }
|
|
-- local data = "Testregion"
|
|
-- local astore_id = self.astore:insert_area(edge1, edge2, tostring(data))
|
|
--
|
|
-- creative_regions:set_region_privs("r"..astore_id, "+creative, +fast, +fly")
|
|
end
|
|
|
|
function creative_regions:save_regions()
|
|
self.astore:to_file(minetest.get_worldpath().."/creative_regions_regions")
|
|
local datastr = minetest.serialize(creative_regions.region_privs)
|
|
if not datastr then
|
|
minetest.log("error", "[creative_regions] Failed to serialize region_privs data!")
|
|
return
|
|
end
|
|
creative_regions.mod_storage:set_string("astore_privs", datastr)
|
|
end
|
|
|
|
function creative_regions:get_region_size(astore_area)
|
|
local pos1 = astore_area.min
|
|
local pos2 = astore_area.max
|
|
local x = math.abs( pos2.x - pos1.x )
|
|
local z = math.abs( pos2.z - pos1.x )
|
|
return x*z
|
|
end
|
|
|
|
function creative_regions:set_region_privs(id, privs_string)
|
|
creative_regions.region_privs[tostring(id)] = privs_string
|
|
end
|
|
|
|
function creative_regions:decode_privs_table(privs_table)
|
|
local privs_grant = {}
|
|
local privs_revoke = {}
|
|
|
|
--table is sorted ascending with priority
|
|
for _, priv in ipairs(privs_table) do
|
|
local toggle = string.sub(priv, 1, 1)
|
|
priv = string.sub(priv, 2)
|
|
if toggle == '+' then
|
|
privs_grant[priv] = true
|
|
privs_revoke[priv] = nil
|
|
elseif toggle == '-' then
|
|
privs_revoke[priv] = true
|
|
privs_grant[priv] = nil
|
|
end
|
|
end
|
|
|
|
return privs_grant, privs_revoke
|
|
end
|
|
|
|
function creative_regions:add_privs_from_string(privs_table, str)
|
|
-- minetest/builtin/common/misc_helpers.lua:core.string_to_privs()
|
|
assert(type(str) == "string")
|
|
local delim = ','
|
|
local privs = {}
|
|
for _, priv in pairs(string.split(str, delim)) do
|
|
priv = priv:trim()
|
|
table.insert(privs_table, priv)
|
|
end
|
|
return privs
|
|
end
|
|
|