-
Notifications
You must be signed in to change notification settings - Fork 574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stairs: Add helper function for textures #3060
Conversation
Use function to tidy stair textures
Simplify set_textures function (thx Sfan5)
@sfan5 - Thanks, amended pull. Also, what do you think about stairs automatically using node sounds ? |
sounds useful |
If sounds is nil when registering stairs, node sounds can be used.
mods/stairs/init.lua
Outdated
@@ -69,10 +69,10 @@ local function get_node_vars(nodename) | |||
local def = minetest.registered_nodes[nodename] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm seeing this correctly, the only thing this function is ever used for is to "transplant" a few definition fields? Why not refactor it to be a local function transplant_def_fields(nodename, to_def)
?
The code would then become something like
local def = minetest.registered_nodes[nodename]
if not def then return end
for _, field in ipairs({"light_source", "use_texture_alpha", "sunlight_propagates", "sounds"}) do
if to_def[field] == nil then
to_def[field] = def[field]
end
end
Or alternatively, something like register_node_based_on(nodename, base_nodename, def)
?
Another alternative to get rid of get_node_vars
: Replace its usage with local def = minetest.registered_nodes[nodename] or {}
, then you can directly access def
fields as def.light_source
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine as the "minimal change" for the sounds, but ideally get_node_vars
with its 4 return values - which fulfill pretty much just the purpose of implementing JS's ?.
- is a pretty dirty function.
This is how I handle it in Stairs Redo, seems a lot tidier too :) |
Remove get_vars function and simplify getting of texure_alpha, light_source, sunlight_propagates and sounds.
Use function to tidy stair textures