Skip to content
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

Merged
merged 5 commits into from
Sep 11, 2023
Merged

Conversation

tenplus1
Copy link
Contributor

@tenplus1 tenplus1 commented Sep 3, 2023

Use function to tidy stair textures

Use function to tidy stair textures
Simplify set_textures function (thx Sfan5)
@tenplus1
Copy link
Contributor Author

tenplus1 commented Sep 4, 2023

@sfan5 - Thanks, amended pull. Also, what do you think about stairs automatically using node sounds ?

@sfan5
Copy link
Member

sfan5 commented Sep 4, 2023

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.
fix typo
@@ -69,10 +69,10 @@ local function get_node_vars(nodename)
local def = minetest.registered_nodes[nodename]
Copy link
Contributor

@appgurueu appgurueu Sep 5, 2023

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.

Copy link
Contributor

@appgurueu appgurueu left a 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.

@tenplus1
Copy link
Contributor Author

tenplus1 commented Sep 5, 2023

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.
@sfan5 sfan5 merged commit 03177f1 into minetest:master Sep 11, 2023
1 check passed
MoNTE48 pushed a commit to MoNTE48/minetest_game that referenced this pull request Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants