fix a bunch of bugs. still need to do more work on the station/circular saw distinction

This commit is contained in:
flux 2022-06-17 12:22:47 -07:00
parent 21d4fab1f5
commit 21f36e6c1c
10 changed files with 60 additions and 17 deletions

13
TODO.md
View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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")

View File

@ -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

View File

@ -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
}

View File

@ -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)

View File

@ -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")
}