mirror of
https://github.com/minetest-mods/moreblocks.git
synced 2024-11-15 23:10:18 +01:00
refactor common.lua: simplify code and make locale strings searchable
This commit is contained in:
parent
16b6759b8a
commit
d90777fdd4
|
@ -6,35 +6,35 @@ Licensed under the zlib license. See LICENSE.md for more information.
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local S = moreblocks.intllib
|
local S = moreblocks.intllib
|
||||||
|
local descriptions = {
|
||||||
|
["micro"] = S("%s Microblock"),
|
||||||
|
["slab"] = S("%s Slab"),
|
||||||
|
["slope"] = S("%s Slope"),
|
||||||
|
["panel"] = S("%s Panel"),
|
||||||
|
["stair"] = S("%s Stairs"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
stairsplus.register_single = function(category, alternate, info, modname, subname, recipeitem, fields)
|
stairsplus.register_single = function(category, alternate, info, modname, subname, recipeitem, fields)
|
||||||
local descriptions = {
|
local desc_base = descriptions[category]:format(fields.description)
|
||||||
["micro"] = "Microblock",
|
|
||||||
["slab"] = "Slab",
|
|
||||||
["slope"] = "Slope",
|
|
||||||
["panel"] = "Panel",
|
|
||||||
["stair"] = "Stairs",
|
|
||||||
}
|
|
||||||
local def = {}
|
local def = {}
|
||||||
|
|
||||||
if category ~= "slab" then
|
if category ~= "slab" then
|
||||||
def = table.copy(info)
|
def = table.copy(info)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- copy fields to def
|
||||||
for k, v in pairs(fields) do
|
for k, v in pairs(fields) do
|
||||||
def[k] = v
|
def[k] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
def.drawtype = "nodebox"
|
def.drawtype = "nodebox"
|
||||||
if category == "slope" then
|
|
||||||
def.drawtype = "mesh"
|
|
||||||
end
|
|
||||||
def.paramtype = "light"
|
def.paramtype = "light"
|
||||||
def.paramtype2 = def.paramtype2 or "facedir"
|
def.paramtype2 = def.paramtype2 or "facedir"
|
||||||
def.on_place = minetest.rotate_node
|
def.on_place = minetest.rotate_node
|
||||||
if category ~= "slab" then
|
def.groups = stairsplus:prepare_groups(fields.groups)
|
||||||
def.description = S("%s " .. descriptions[category]):format(fields.description)
|
|
||||||
else
|
if category == "slab" then
|
||||||
local desc_base = S("%s " .. descriptions[category]):format(fields.description)
|
|
||||||
if type(info) ~= "table" then
|
if type(info) ~= "table" then
|
||||||
def.node_box = {
|
def.node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
|
@ -48,14 +48,19 @@ stairsplus.register_single = function(category, alternate, info, modname, subnam
|
||||||
}
|
}
|
||||||
def.description = desc_base .. alternate:gsub("_", " "):gsub("(%a)(%S*)", function(a, b) return a:upper() .. b end)
|
def.description = desc_base .. alternate:gsub("_", " "):gsub("(%a)(%S*)", function(a, b) return a:upper() .. b end)
|
||||||
end
|
end
|
||||||
end
|
else
|
||||||
def.groups = stairsplus:prepare_groups(fields.groups)
|
def.description = desc_base
|
||||||
if category == "stair" and alternate == "" then
|
if category == "slope" then
|
||||||
|
def.drawtype = "mesh"
|
||||||
|
elseif category == "stair" and alternate == "" then
|
||||||
def.groups.stair = 1
|
def.groups.stair = 1
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if fields.drop and not (type(fields.drop) == "table") then
|
if fields.drop and not (type(fields.drop) == "table") then
|
||||||
def.drop = modname.. ":" .. category .. "_" .. fields.drop .. alternate
|
def.drop = modname.. ":" .. category .. "_" .. fields.drop .. alternate
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node(":" ..modname.. ":" .. category .. "_" .. subname .. alternate, def)
|
minetest.register_node(":" ..modname.. ":" .. category .. "_" .. subname .. alternate, def)
|
||||||
stairsplus.register_recipes(category, alternate, modname, subname, recipeitem)
|
stairsplus.register_recipes(category, alternate, modname, subname, recipeitem)
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user