-
Notifications
You must be signed in to change notification settings - Fork 17
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
Roads API #102
Comments
I've not read this in detail yet, but after skimming this, it seems to look good. One little problem: You can't register anything in minetest.after(). This is a limitation of the Minetest engine. I suggest to run minetest.register_node() directly inside the streets.roads.register_label() function. |
Ah, so this is still not possible? I always thought minetest.after(0, function) would be run before the first server step, but it seems like it's running on the first server step. I'll need to think of something different then. It's not possible to register the node directly within register_label() because this would mean that surfaces registered after this will be ignored. |
As far as I can see, surfaces can only be different colors of asphalt. Maybe we then could avoid the register_surface() by controlling the available asphalt colors ( = different surfaces) with a setting. I know, this is not very elegant, but it would be a simple and light-weight approach. |
We would still need a way to the the API which nodes are "base nodes" for markings though. |
We could do this with three simple settings:
The lines above are no final suggestions, they should only show the concept. |
What I meant was: How do we tell the API which nodes to put the labels on? I really don't want to hardcode this... |
I fear the only possible way would be hardcoding. As far as I can see, only customization with settings would be technically possible. I would prefer a register_surface() function, too, but I don't think this is possible. |
I'm sure there is a way. Nothing's impossible ;) I'll think about it this weekend. |
I think I found a possible solution. I'll code it today to see if it works as expected. |
What do you think about this code? (untested) streets.roads = {}
streets.roads.registered_labels = {}
streets.roads.registered_surfaces = {}
local register_combination = function(label_name, label_def, surface_name, surface_def)
-- register nodes
end
streets.roads.register_surface = function(name, def)
streets.roads.registered_surfaces[name] = def
for label_name, label_def in streets.roads.registered_labels do
register_combination(label_name, label_def, name, def)
end
end
streets.roads.register_label = function(name, def)
streets.roads.registered_labels[name] = def
for surface_name, surface_def in streets.roads.registered_surfaces do
register_combination(name, def, surface_name, surface_def)
end
end |
I made a new suggestion for the roads API based on your suggestion and the signs API in 1eccfa0. Quote from Road Markings
|
(This is still WIP, details following within the next days)
streets.roads.register_surface(name, surface_definition)
This will put the definition into a local table
streets.roads.register_label(name, label_definition)
This will put the definition into a local table
To allow for other mods (and therefore our own submods) to register their own surfaces and labels, this code only puts the definition into the private tables. They will be registered in a minetest.after(0, function) function to make sure that all other code has already been run, so that all definitions are there.
streets.roads.register_registration_hook(function)
Additionally, there should be streets.roads.register_registration_hook(function) function to allow other mods and submods to execute custom code during the registration of a road node. This could be used by #101 to register stairs.
The text was updated successfully, but these errors were encountered: