mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 15:33:00 +00:00
sets (not working)
This commit is contained in:
parent
fa2c0642c1
commit
0b01520118
2 changed files with 156 additions and 0 deletions
|
@ -6,6 +6,61 @@
|
||||||
-- @author Starbeamrainbowlabs
|
-- @author Starbeamrainbowlabs
|
||||||
|
|
||||||
worldeditadditions = {}
|
worldeditadditions = {}
|
||||||
|
worldeditadditions.modpath = minetest.get_modpath("worldeditadditions")
|
||||||
|
dofile(worldeditadditions.modpath.."/utils/vector.lua")
|
||||||
|
worldeditadditions.Set = dofile(worldeditadditions.modpath.."/utils/set.lua")
|
||||||
|
worldeditadditions.Vector3 = dofile(worldeditadditions.modpath.."/utils/vector3.lua")
|
||||||
|
worldeditadditions.Mesh,
|
||||||
|
worldeditadditions.Face = dofile(worldeditadditions.modpath.."/utils/mesh.lua")
|
||||||
|
|
||||||
|
worldeditadditions.Queue = dofile(worldeditadditions.modpath.."/utils/queue.lua")
|
||||||
|
worldeditadditions.LRU = dofile(worldeditadditions.modpath.."/utils/lru.lua")
|
||||||
|
|
||||||
|
|
||||||
|
dofile(worldeditadditions.modpath.."/utils/strings/init.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/utils/format/init.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/utils/parse/init.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/utils/tables/init.lua")
|
||||||
|
|
||||||
|
dofile(worldeditadditions.modpath.."/utils/numbers.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/utils/nodes.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/utils/node_identification.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/utils/terrain.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/utils/raycast_adv.lua") -- For the farwand
|
||||||
|
dofile(worldeditadditions.modpath.."/utils/axes.lua")
|
||||||
|
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/compat/saplingnames.lua")
|
||||||
|
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/floodfill.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/overlay.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/layers.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/fillcaves.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/ellipsoid.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/torus.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/line.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/walls.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/replacemix.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/maze2d.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/maze3d.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/hollow.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/scale_up.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/scale_down.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/scale.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/conv/conv.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/erode/erode.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/noise/init.lua")
|
||||||
|
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/count.lua")
|
||||||
|
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/bonemeal.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/forest.lua")
|
||||||
|
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/ellipsoidapply.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/airapply.lua")
|
||||||
|
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/subdivide.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/selection/stack.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/lib/selection/cloud.lua")
|
||||||
local wea = worldeditadditions
|
local wea = worldeditadditions
|
||||||
wea.modpath = minetest.get_modpath("worldeditadditions")
|
wea.modpath = minetest.get_modpath("worldeditadditions")
|
||||||
|
|
||||||
|
|
101
worldeditadditions/utils/set.lua
Normal file
101
worldeditadditions/utils/set.lua
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
--- Sets for lua!
|
||||||
|
-- local Set = {}
|
||||||
|
--- Option 1:
|
||||||
|
-- Set.__index = Set
|
||||||
|
-- Set.__newindex = function(tbl, key, value)
|
||||||
|
-- if not tbl.__protected[key] then
|
||||||
|
-- rawset(tbl,key,value)
|
||||||
|
-- else
|
||||||
|
-- error("Protected!")
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
-- Set.__protected = {
|
||||||
|
-- __protected=true,
|
||||||
|
-- new=true,
|
||||||
|
-- add=true,
|
||||||
|
-- delete=true,
|
||||||
|
-- has=true
|
||||||
|
-- }
|
||||||
|
|
||||||
|
--- Option 2:
|
||||||
|
local Set = {}
|
||||||
|
Set.__index = Set
|
||||||
|
Set.__newindex = function(tbl, key, value)
|
||||||
|
rawset(tbl.set,key,value)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Creates a new set.
|
||||||
|
-- @param i any Initial values(s) of the set.
|
||||||
|
-- @returns Set A table of keys equal to true.
|
||||||
|
function Set.new(i)
|
||||||
|
local result = {set={}}
|
||||||
|
setmetatable(result, Set)
|
||||||
|
if type(i) == "table" then
|
||||||
|
for k,v in pairs(i) do result[v] = true end
|
||||||
|
elseif i then
|
||||||
|
result[i] = true
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
-- a = Set.new({"add","new","thing"})
|
||||||
|
|
||||||
|
--- Adds item(s) to set.
|
||||||
|
-- @param a set Set to manipulate.
|
||||||
|
-- @param i not nil Values(s) to add.
|
||||||
|
-- @returns bool Success of operation.
|
||||||
|
function Set.add(a,i)
|
||||||
|
if type(i) == "table" then
|
||||||
|
for k,v in pairs(i) do a[v] = true end
|
||||||
|
else
|
||||||
|
a[i] = true
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Deletes item(s) from set.
|
||||||
|
-- @param a set Set to manipulate.
|
||||||
|
-- @param i not nil Values(s) to delete.
|
||||||
|
-- @returns bool Success of operation.
|
||||||
|
function Set.delete(a,i)
|
||||||
|
if type(i) == "table" then
|
||||||
|
for k,v in pairs(i) do a[v] = nil end
|
||||||
|
else
|
||||||
|
a[i] = nil
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Checks if value(s) are present in set.
|
||||||
|
-- @param a set Set to inspect.
|
||||||
|
-- @param i not nil Values(s) to check.
|
||||||
|
-- @returns bool Value(s) are present?
|
||||||
|
function Set.has(a,i)
|
||||||
|
if type(i) == "table" then
|
||||||
|
for k,v in pairs(i) do
|
||||||
|
if not a[k] then return false end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return a[i] ~= nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ██████ ██████ ███████ ██████ █████ ████████ ██████ ██████
|
||||||
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
-- ██ ██ ██████ █████ ██████ ███████ ██ ██ ██ ██████
|
||||||
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
-- ██████ ██ ███████ ██ ██ ██ ██ ██ ██████ ██ ██
|
||||||
|
--
|
||||||
|
-- ██████ ██ ██ ███████ ██████ ██████ ██ ██████ ███████ ███████
|
||||||
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
-- ██ ██ ██ ██ █████ ██████ ██████ ██ ██ ██ █████ ███████
|
||||||
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
-- ██████ ████ ███████ ██ ██ ██ ██ ██ ██████ ███████ ███████
|
||||||
|
|
||||||
|
function Set.__call(i) return Set.new(i) end
|
||||||
|
|
||||||
|
|
||||||
|
-- Main Return:
|
||||||
|
return Set
|
Loading…
Reference in a new issue