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

Disable inventory if player's inventory formspec is blank #11827

Merged
merged 6 commits into from
Dec 13, 2021
Merged

Disable inventory if player's inventory formspec is blank #11827

merged 6 commits into from
Dec 13, 2021

Conversation

rollerozxa
Copy link
Member

@rollerozxa rollerozxa commented Dec 3, 2021

This PR intends to make it possible for games/mods to completely disable the inventory by setting the player's inventory to an empty string.

Previously if you set the player's inventory to an empty string the inventory would still exist, and opening it will open an empty default sized formspec. You could set the formspec to an extremely small value (size[0.01,0.01]) to effectively hide it, but this is a rather awful hack that will still show it and steal controls to the formspec that is now completely non-existant, and the player will now wonder if their keyboard is broken.

To do

This PR is Ready for Review.

How to test

PR tests:

  • Check that if you set your inventory to an empty string (Lua code for singleplayer: minetest.get_player_by_name("singleplayer"):set_inventory_formspec("")), pressing the inventory button will do nothing.

Test for regressions:

  • Check that you can still open custom non-empty inventories.
  • Check that the default inventory still appears.
  • Check that client-side modding formspecs don't break by this PR. (!)

@erlehmann
Copy link
Contributor

Could this affect client side formspecs?

@rollerozxa
Copy link
Member Author

Hopefully not, but that should definitively need to be tested, thank you for pointing that out. This PR changes code in Game::openInventory() which I'd hope to be separate of any other formspecs (minetest.show_formspec() still works with inventory disabled, I tested that), but I did not account for client-side modding.

@sfan5 sfan5 added the Feature ✨ PRs that add or enhance a feature label Dec 3, 2021
src/client/game.cpp Outdated Show resolved Hide resolved
@rubenwardy rubenwardy added the Roadmap The change matches an item on the current roadmap label Dec 7, 2021
src/client/game.cpp Outdated Show resolved Hide resolved
Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@erlehmann
Copy link
Contributor

@sfan5 @SmallJoker how did you test the client-side formspec part?

@sfan5
Copy link
Member

sfan5 commented Dec 10, 2021

I didn't and changes to Game::openInventory() obviously won't affect it.

@SmallJoker
Copy link
Member

@erlehmann Do you suggest to move the string.empty() check below the CSM callback? The inventory key is indeed pressed, but this callback is called when opening the inventory. If there's nothing to open, no callback is executed. What you might be talking about is a key press callback which yet does not exist.

@rollerozxa
Copy link
Member Author

rollerozxa commented Dec 10, 2021

@erlehmann Do you suggest to move the string.empty() check below the CSM callback? The inventory key is indeed pressed, but this callback is called when opening the inventory. If there's nothing to open, no callback is executed. What you might be talking about is a key press callback which yet does not exist.

If this means CSMs adding functionality on inventory event callbacks are broken I definitively need to fix that. CSMs should be able to override a game/mod's ability to disable the inventory with it's own functionality, and I do not want to break that with this PR. I moved the .empty() check because I thought it was best to put it as high up as possible as then as little code as necessary is executed, but wasn't under the impression it would affect anything.

@sfan5 sfan5 added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Dec 13, 2021
@sfan5 sfan5 removed the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Dec 13, 2021
@sfan5 sfan5 merged commit fcf86de into minetest:master Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature ✨ PRs that add or enhance a feature Roadmap The change matches an item on the current roadmap >= Two approvals ✅ ✅
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants