-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add function to get all hud elements #14042
Conversation
I think it could still be possible: Add HUD elements until you get two consecutive IDs. That gives you an upper bound up until which you could enumerate HUD elements ;) On a more serious note, what's the use case for this? It seems to me so far that forcing modders to keep track of HUD IDs themselves is the better solution. |
There could always be a gap of more than two IDs, if they get removed, so I don't see how this could be a solution, but maybe I didn't understand you correctly. Also currently removed IDs get reused, so you don't get much information from adding new elements. (Maybe HUD IDs shouldn't be reused, but unique anyways.) In practice you could just assume that there are at most 1000 or so elements, since it is very unlikely that there are more, but this would just be inefficient.
Mods must still keep track of their own HUD IDs for unambiguous identification (the ID is the only unique identifier), but most of the time they don't expose them for others to see. So from another mod you can't know for sure which elements exist. Some use cases:
|
Yes, and I think this is a feature: You are forced to use the APIs of other mods (or your own APIs / tables) to manage HUD elements. This helps prevent mod incompatibilities since it makes it harder to "pull the rug" from under other mods. Frankly, I'm worried that such an API would be used mostly irresponsible. The only "responsible use" I can imagine is one regarding HUD elements you control yourself, which is already what modders do given the current API(s), and which is probably cleaner (and more efficient) to keep this way. I'm not really opposed to adding such a feature, but I believe it should probably at least get a warning in the docs, considering e.g. your use cases, all of which have high potential to "pull the rug" from under other mods:
Effectively, whenever you're messing with "foreign" HUD elements, you're likely to break stuff. Using this API to get a hold of HUD IDs to modify foreign elements should thus be discouraged. Furthermore, using this API to let Minetest manage your own elements should be discouraged as well: Managing them yourself is cleaner and more efficient. TL;DR: You're right, this feature is useful, as esp. your last use case shows. I'm worried that modders will abuse this though, so I'd recommend that the docs discourage (1) messing with foreign HUD elements; (2) foregoing keeping track of their HUD elements themselves. |
I get what you mean, but other mods not knowing whether HUD elements already exist can also create incompatibilities (e.g. multiple minimaps or overlapping elements). And you have the same problem almost everywhere else too. (e.g. item metadata description, player physics override, global callbacks, ...)
Yeah, a better use case would be to find the biggest or smallest z_index
I meant it to be used like
I added this to the API documentation. |
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.
Tested, works. Code is fine too. (Not sure we want to nothing vs. nil
, but that's a nitpick; also not duplicating HUD code would be ideal, but is out of scope for this PR to resolve.)
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.
Works on my PC.
player:hud_get_all()
function which returns a table indexed by all present HUD ID's and containing the corresponding HUD element definition structures.get_lists()
function for inventories, it allows bulk access and makes it easy to iterate through all HUD elements.Does it resolve any reported issue?
No.
Does this relate to a goal in the roadmap?
No.
To do
Ready for Review.
How to test
/hudprint
chat commandand use
/hudprint
again orprint(dump(player:hud_get_all()))
To check whether the ids are correct