diff --git a/TODO.md b/TODO.md index b1d9054..6bcb04c 100644 --- a/TODO.md +++ b/TODO.md @@ -17,9 +17,14 @@ stairsplus/API.md ### other things -* finish documentation -* unified_inventory / sfinv / i3 support -* finish legacy support -* finish compatability support +* finish updating documentation, for both users and API +* update translations (i18n, locale) +* unified_inventory / i3 support +* finish testing (and creating) legacy support * create a way to analyze and reduce node_count * ? create a way for admins to execute a command to create a config option to register a shaped node? + +### future goals + +* port other "microblocks" mods to use this framework, e.g. pkarcs and facade +* maybe integration w/ the technic cnc and such diff --git a/stairsplus/api/alias.lua b/stairsplus/api/alias.lua index a09fac6..435562f 100644 --- a/stairsplus/api/alias.lua +++ b/stairsplus/api/alias.lua @@ -7,6 +7,15 @@ function api.register_alias_single(old_node, new_node, shape) local new_shaped_node = api.format_name(new_node, shape) minetest.register_alias(old_shaped_node, new_shaped_node) + + local shape_def = api.registered_shapes[shape] + if shape_def.aliases then + local old_mod, old_name = old_node:match("^([^:]+):(.*)$") + for _, alias in ipairs(shape_def.aliases) do + old_shaped_node = ("%s:%s"):format(old_mod, alias:format(old_name)) + minetest.register_alias(old_shaped_node, new_shaped_node) + end + end end function api.register_alias_all(old_node, new_node) @@ -39,6 +48,15 @@ function api.register_alias_force_single(old_node, new_node, shape) minetest.register_alias_force(old_shaped_node, new_shaped_node) + local shape_def = api.registered_shapes[shape] + if shape_def.aliases then + local old_mod, old_name = old_node:match("^([^:]+):(.*)$") + for _, alias in ipairs(shape_def.aliases) do + old_shaped_node = ("%s:%s"):format(old_mod, alias:format(old_name)) + minetest.register_alias_force(old_shaped_node, new_shaped_node) + end + end + local nodes = api.nodes_by_shape[shape] or {} if nodes[old_node] then nodes[old_node] = nil diff --git a/stairsplus/api/group_filters.lua b/stairsplus/api/group_filters.lua index 4047608..cad6a73 100644 --- a/stairsplus/api/group_filters.lua +++ b/stairsplus/api/group_filters.lua @@ -41,7 +41,7 @@ function api.build_groups(node, shape) local groups = { [("shape_%s"):format(shape)] = 1, - not_in_creative_inventory = in_creative_inventory and 1, + not_in_creative_inventory = in_creative_inventory and 1 or nil, } local shape_def = api.registered_shapes[shape] diff --git a/stairsplus/api/node.lua b/stairsplus/api/node.lua index 90239dc..d25523f 100644 --- a/stairsplus/api/node.lua +++ b/stairsplus/api/node.lua @@ -179,6 +179,11 @@ function api.register_single(node, shape, overrides, meta) -- register node local shaped_name = api.format_name(node, shape) + for k, v in pairs(def.groups) do + if type(v) ~= "number" then + error(("%s %s group:%s = %s"):format(node, shape, k, v)) + end + end minetest.register_node(":" .. shaped_name, def) -- alias old name formats @@ -228,7 +233,9 @@ function api.register_groups(node, groups, overrides, meta) end function api.get_shapes(node) - return table_sort_keys(api.shapes_by_node[node]) + if api.shapes_by_node[node] then + return table_sort_keys(api.shapes_by_node[node]) + end end -- warning: don't mutate the return value diff --git a/stairsplus/api/recipe.lua b/stairsplus/api/recipe.lua index c49b519..60ceba6 100644 --- a/stairsplus/api/recipe.lua +++ b/stairsplus/api/recipe.lua @@ -62,7 +62,7 @@ local function verify_schema(schema) end function api.register_on_register_craft_schema(func) - table.insert(api.registered_on_register_craft_schema, func) + table.insert(api.registered_on_register_craft_schemas, func) end function api.register_craft_schema(schema) @@ -157,7 +157,7 @@ function api.register_schema_crafts_for_node(node) local shapes = api.get_shapes_hash(node) for _, schema in ipairs(api.registered_recipe_schemas) do if has_the_right_shapes(schema, shapes) then - stairsplus.log("debug", "using schema %q", minetest.serialize(schema):sub(#("return "))) + stairsplus.log("verbose", "using schema %s", minetest.serialize(schema):sub(#("return "))) register_for_schema(node, schema) end end @@ -195,7 +195,7 @@ function api.register_crafts_for_shapes(def) output = api.get_schema_recipe_item(def.output, shape), recipe = api.get_schema_recipe_item(def.recipe, shape), cooktime = def.cooktime(api.registered_shapes[shape].eighths), - groups = (not recipes_in_creative_inventory) and {not_in_creative_inventory = 1} + groups = (not recipes_in_creative_inventory) and {not_in_creative_inventory = 1} or nil }) end @@ -207,7 +207,7 @@ function api.register_crafts_for_shapes(def) type = "fuel", recipe = api.get_schema_recipe_item(def.recipe, shape), burntime = def.burntime(api.registered_shapes[shape].eighths), - groups = (not recipes_in_creative_inventory) and {not_in_creative_inventory = 1} + groups = (not recipes_in_creative_inventory) and {not_in_creative_inventory = 1} or nil }) end diff --git a/stairsplus/compat1/init.lua b/stairsplus/compat1/init.lua index 70298b5..8ef7502 100644 --- a/stairsplus/compat1/init.lua +++ b/stairsplus/compat1/init.lua @@ -1,5 +1,5 @@ -- compatability stuff for after the API is created, but before we start using it -stairsplus.dofile("compat", "i3") -stairsplus.dofile("compat", "unified_inventory") +--stairsplus.dofile("compat1", "i3") +--stairsplus.dofile("compat1", "unified_inventory") diff --git a/stairsplus/compat2/init.lua b/stairsplus/compat2/init.lua index 0d4713b..484583a 100644 --- a/stairsplus/compat2/init.lua +++ b/stairsplus/compat2/init.lua @@ -8,8 +8,8 @@ stairsplus.compat = { end } -stairsplus.dofile("compat", "stairs") -stairsplus.dofile("compat", "old_moreblocks") +stairsplus.dofile("compat2", "stairs") +stairsplus.dofile("compat2", "old_moreblocks") -- stairsplus.dofile("compat", "inventory_managers") -- unified_inventory, sfinv, i3 diff --git a/stairsplus/util.lua b/stairsplus/util.lua index f4e5a60..4070381 100644 --- a/stairsplus/util.lua +++ b/stairsplus/util.lua @@ -21,5 +21,20 @@ stairsplus.util = { table.sort(sorted) end return sorted + end, + + check_call = function(func) + -- wrap a function w/ logic to avoid crashing the game + local f = function(...) + local status, out = pcall(func, ...) + if status then + return out + else + local message = ("Error (func): %s %s"):format(out, dump({...})) + stairsplus.log("error", message) + error(message) + end + end + return f end } diff --git a/stairsplus_legacy/init.lua b/stairsplus_legacy/init.lua index f10e6b4..b4d782c 100644 --- a/stairsplus_legacy/init.lua +++ b/stairsplus_legacy/init.lua @@ -34,7 +34,7 @@ stairsplus_legacy = { stairsplus_legacy.dofile("settings") function stairsplus_legacy.register_legacy(node, overrides, meta) - if stairsplus_legacy.settings.stairsplus_legacy_mode then + if stairsplus.settings.legacy_mode then stairsplus.api.register_group(node, "legacy", overrides, meta) else stairsplus.api.register_group(node, "common", overrides, meta) diff --git a/stairsplus_legacy/settings.lua b/stairsplus_legacy/settings.lua index aec66cb..3e1ace1 100644 --- a/stairsplus_legacy/settings.lua +++ b/stairsplus_legacy/settings.lua @@ -8,6 +8,4 @@ stairsplus_legacy.settings = { technic = s:get_bool("stairsplus_legacy.technic", true), prefab = s:get_bool("stairsplus_legacy.prefab", true), wool = s:get_bool("stairsplus_legacy.wool", true), - - stairsplus_legacy_mode = s:get_bool("stairsplus.legacy_mode") }