2024-04-17 21:08:44 +00:00
|
|
|
-- This file takes care of the cave shapes.
|
|
|
|
|
|
|
|
noordstar_caves.registered_shapes = {}
|
|
|
|
|
|
|
|
-- Clean the input and return a valid shape def
|
|
|
|
-- If the input is invalid, return nil
|
|
|
|
local function clean_def(def)
|
|
|
|
if type(def.name) ~= "string" then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
if type(def.connectivity_point) ~= "number" then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
if type(def.verticality_point) ~= "number" then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local d = {
|
|
|
|
name = def.name,
|
|
|
|
connectivity_point = def.connectivity_point,
|
|
|
|
verticality_point = def.verticality_point
|
|
|
|
}
|
|
|
|
|
|
|
|
if type(def.noise_params) == "table" then
|
|
|
|
d.noise_params = def.noise_params
|
|
|
|
end
|
|
|
|
|
|
|
|
if type(def.func) == "function" then
|
|
|
|
d.func = def.func
|
|
|
|
else
|
|
|
|
d.func = function(pos, v) return v end
|
|
|
|
end
|
|
|
|
|
|
|
|
if type(def.y_min) == "number" and type(def.y_max) == "number" then
|
|
|
|
d.y_min = def.y_min
|
|
|
|
d.y_max = def.y_max
|
|
|
|
end
|
|
|
|
|
|
|
|
return d
|
|
|
|
end
|
|
|
|
|
|
|
|
function noordstar_caves.register_shape(def)
|
|
|
|
local d = clean_def(def)
|
|
|
|
|
|
|
|
if d ~= nil then
|
|
|
|
noordstar_caves.registered_shapes[d.name] = d
|
|
|
|
end
|
|
|
|
end
|
2024-04-20 19:31:50 +00:00
|
|
|
|
|
|
|
function noordstar_caves.clear_registered_shapes()
|
|
|
|
noordstar_caves.registered_shapes = {}
|
|
|
|
end
|