Add Alias Functions (#54)

* register_alias
* register_alias_force
This commit is contained in:
Thomas--S 2016-10-03 12:14:34 +02:00 committed by Hugo Locurcio
parent ab2c63270f
commit 7f06db2200
6 changed files with 367 additions and 262 deletions

View File

@ -17,6 +17,21 @@ and minetest.setting_getbool("creative_mode") then
stairsplus.expect_infinite_stacks = true
end
function stairsplus.copytable(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[stairsplus.copytable(orig_key)] = stairsplus.copytable(orig_value)
end
setmetatable(copy, stairsplus.copytable(getmetatable(orig)))
else
copy = orig
end
return copy
end
function stairsplus:prepare_groups(groups)
local result = {}
if groups then
@ -41,6 +56,21 @@ function stairsplus:register_all(modname, subname, recipeitem, fields)
-- self:register_6dfacedir_conversion(modname, subname) -- Not needed as of Q3 2013, uncomment to fix old maps.
end
function stairsplus:register_alias_all(modname_old, subname_old, modname_new, subname_new)
self:register_stair_alias(modname_old, subname_old, modname_new, subname_new)
self:register_slab_alias(modname_old, subname_old, modname_new, subname_new)
self:register_slope_alias(modname_old, subname_old, modname_new, subname_new)
self:register_panel_alias(modname_old, subname_old, modname_new, subname_new)
self:register_micro_alias(modname_old, subname_old, modname_new, subname_new)
end
function stairsplus:register_alias_force_all(modname_old, subname_old, modname_new, subname_new)
self:register_stair_alias_force(modname_old, subname_old, modname_new, subname_new)
self:register_slab_alias_force(modname_old, subname_old, modname_new, subname_new)
self:register_slope_alias_force(modname_old, subname_old, modname_new, subname_new)
self:register_panel_alias_force(modname_old, subname_old, modname_new, subname_new)
self:register_micro_alias_force(modname_old, subname_old, modname_new, subname_new)
end
function register_stair_slab_panel_micro(modname, subname, recipeitem, groups, images, description, drop, light)
stairsplus:register_all(modname, subname, recipeitem, {
groups = groups,

View File

@ -20,8 +20,7 @@ function register_micro(modname, subname, recipeitem, groups, images, descriptio
})
end
function stairsplus:register_micro(modname, subname, recipeitem, fields)
local defs = {
local microblocks_defs = {
[""] = {
node_box = {
type = "fixed",
@ -64,8 +63,24 @@ function stairsplus:register_micro(modname, subname, recipeitem, fields)
fixed = {-0.5, -0.5, 0, 0, 0.4375, 0.5},
},
}
}
}
function stairsplus:register_micro_alias(modname_old, subname_old, modname_new, subname_new)
local defs = stairsplus.copytable(microblocks_defs)
for alternate, def in pairs(defs) do
minetest.register_alias(modname_old .. ":micro_" .. subname_old .. alternate, modname_new .. ":micro_" .. subname_new .. alternate)
end
end
function stairsplus:register_micro_alias_force(modname_old, subname_old, modname_new, subname_new)
local defs = stairsplus.copytable(microblocks_defs)
for alternate, def in pairs(defs) do
minetest.register_alias_force(modname_old .. ":micro_" .. subname_old .. alternate, modname_new .. ":micro_" .. subname_new .. alternate)
end
end
function stairsplus:register_micro(modname, subname, recipeitem, fields)
local defs = stairsplus.copytable(microblocks_defs)
local desc = S("%s Microblock"):format(fields.description)
for alternate, def in pairs(defs) do
for k, v in pairs(fields) do

View File

@ -20,8 +20,7 @@ function register_panel(modname, subname, recipeitem, groups, images, descriptio
})
end
function stairsplus:register_panel(modname, subname, recipeitem, fields)
local defs = {
local panels_defs = {
[""] = {
node_box = {
type = "fixed",
@ -64,8 +63,24 @@ function stairsplus:register_panel(modname, subname, recipeitem, fields)
fixed = {-0.5, -0.5, 0, 0.5, 0.4375, 0.5},
},
}
}
}
function stairsplus:register_panel_alias(modname_old, subname_old, modname_new, subname_new)
local defs = stairsplus.copytable(panels_defs)
for alternate, def in pairs(defs) do
minetest.register_alias(modname_old .. ":panel_" .. subname_old .. alternate, modname_new .. ":panel_" .. subname_new .. alternate)
end
end
function stairsplus:register_panel_alias_force(modname_old, subname_old, modname_new, subname_new)
local defs = stairsplus.copytable(panels_defs)
for alternate, def in pairs(defs) do
minetest.register_alias_force(modname_old .. ":panel_" .. subname_old .. alternate, modname_new .. ":panel_" .. subname_new .. alternate)
end
end
function stairsplus:register_panel(modname, subname, recipeitem, fields)
local defs = stairsplus.copytable(panels_defs)
local desc = S("%s Panel"):format(fields.description)
for alternate, def in pairs(defs) do
for k, v in pairs(fields) do

View File

@ -20,8 +20,7 @@ function register_slab(modname, subname, recipeitem, groups, images, description
})
end
function stairsplus:register_slab(modname, subname, recipeitem, fields)
local defs = {
local slabs_defs = {
[""] = 8,
["_quarter"] = 4,
["_three_quarter"] = 12,
@ -29,8 +28,24 @@ function stairsplus:register_slab(modname, subname, recipeitem, fields)
["_2"] = 2,
["_14"] = 14,
["_15"] = 15,
}
}
function stairsplus:register_slab_alias(modname_old, subname_old, modname_new, subname_new)
local defs = stairsplus.copytable(slabs_defs)
for alternate, def in pairs(defs) do
minetest.register_alias(modname_old .. ":slab_" .. subname_old .. alternate, modname_new .. ":slab_" .. subname_new .. alternate)
end
end
function stairsplus:register_slab_alias_force(modname_old, subname_old, modname_new, subname_new)
local defs = stairsplus.copytable(slabs_defs)
for alternate, def in pairs(defs) do
minetest.register_alias_force(modname_old .. ":slab_" .. subname_old .. alternate, modname_new .. ":slab_" .. subname_new .. alternate)
end
end
function stairsplus:register_slab(modname, subname, recipeitem, fields)
local defs = stairsplus.copytable(slabs_defs)
local desc_base = S("%s Slab"):format(fields.description)
for alternate, num in pairs(defs) do
local def = {

View File

@ -123,8 +123,7 @@ function register_slope(modname, subname, recipeitem, groups, images, descriptio
})
end
function stairsplus:register_slope(modname, subname, recipeitem, fields)
local defs = {
local slopes_defs = {
[""] = {
mesh = "moreblocks_slope.obj",
collision_box = box_slope,
@ -142,7 +141,7 @@ function stairsplus:register_slope(modname, subname, recipeitem, fields)
selection_box = box_slope_half_raised,
},
--==============================================================
--==============================================================
["_inner"] = {
mesh = "moreblocks_slope_inner.obj",
@ -160,7 +159,7 @@ function stairsplus:register_slope(modname, subname, recipeitem, fields)
selection_box = box_slope_inner_half_raised,
},
--==============================================================
--==============================================================
["_inner_cut"] = {
mesh = "moreblocks_slope_inner_cut.obj",
@ -178,7 +177,7 @@ function stairsplus:register_slope(modname, subname, recipeitem, fields)
selection_box = box_slope_inner_half_raised,
},
--==============================================================
--==============================================================
["_outer"] = {
mesh = "moreblocks_slope_outer.obj",
@ -196,7 +195,7 @@ function stairsplus:register_slope(modname, subname, recipeitem, fields)
selection_box = box_slope_outer_half_raised,
},
--==============================================================
--==============================================================
["_outer_cut"] = {
mesh = "moreblocks_slope_outer_cut.obj",
@ -218,8 +217,24 @@ function stairsplus:register_slope(modname, subname, recipeitem, fields)
collision_box = box_slope_outer,
selection_box = box_slope_outer,
},
}
}
function stairsplus:register_slope_alias(modname_old, subname_old, modname_new, subname_new)
local defs = stairsplus.copytable(slopes_defs)
for alternate, def in pairs(defs) do
minetest.register_alias(modname_old .. ":slope_" .. subname_old .. alternate, modname_new .. ":slope_" .. subname_new .. alternate)
end
end
function stairsplus:register_slope_alias_force(modname_old, subname_old, modname_new, subname_new)
local defs = stairsplus.copytable(slopes_defs)
for alternate, def in pairs(defs) do
minetest.register_alias_force(modname_old .. ":slope_" .. subname_old .. alternate, modname_new .. ":slope_" .. subname_new .. alternate)
end
end
function stairsplus:register_slope(modname, subname, recipeitem, fields)
local defs = stairsplus.copytable(slopes_defs)
local desc = S("%s Slope"):format(fields.description)
for alternate, def in pairs(defs) do
for k, v in pairs(fields) do

View File

@ -20,8 +20,7 @@ function register_stair(modname, subname, recipeitem, groups, images, descriptio
})
end
function stairsplus:register_stair(modname, subname, recipeitem, fields)
local defs = {
local stairs_defs = {
[""] = {
node_box = {
type = "fixed",
@ -104,8 +103,24 @@ function stairsplus:register_stair(modname, subname, recipeitem, fields)
},
},
},
}
}
function stairsplus:register_stair_alias(modname_old, subname_old, modname_new, subname_new)
local defs = stairsplus.copytable(stairs_defs)
for alternate, def in pairs(defs) do
minetest.register_alias(modname_old .. ":stair_" .. subname_old .. alternate, modname_new .. ":stair_" .. subname_new .. alternate)
end
end
function stairsplus:register_stair_alias_force(modname_old, subname_old, modname_new, subname_new)
local defs = stairsplus.copytable(stairs_defs)
for alternate, def in pairs(defs) do
minetest.register_alias_force(modname_old .. ":stair_" .. subname_old .. alternate, modname_new .. ":stair_" .. subname_new .. alternate)
end
end
function stairsplus:register_stair(modname, subname, recipeitem, fields)
local defs = stairsplus.copytable(stairs_defs)
local desc = S("%s Stairs"):format(fields.description)
for alternate, def in pairs(defs) do
for k, v in pairs(fields) do