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

General cleanup; keypress handling; tripod storage; FreecamPosition #126

Merged
merged 8 commits into from
Dec 26, 2023

Conversation

MattSturgeon
Copy link
Member

@MattSturgeon MattSturgeon commented Dec 14, 2023

This PR refactors the tripod storage system, tick handlers, position setting & minor related changes.

User-facing changes:

  • Toggle keybind is consumed on release.
    • More intuitive when held to toggle tripods.
    • Toggles only if it wasn't used to toggle a tripod.
    • Toggles only if it warn't held for over 10 ticks.
    • Still works if pressed for less than one tick.
  • Resetting a tripod no longer moves the camera to the player's feet.
  • Tripods should get stored separately for modded dimensions.

Internal changes:

  • Reduced mixin usage for tick events
  • Refactored keypress handling in postTick
    • Added reset to ModBinding
    • Updated ModBinding's wrapper method names to new mappings.
    • (See user-facing changes)
  • Extracted tripod storage to TripodRegistry
  • Access tripods using TripodSlot enum
    • enables using EnumMap, which is just an array that implements Map and therefore very efficient.
    • removes the need to convert keyCode to a number all over the place
  • Remove FreecamPosition.getSwimmingPose() since we always want the swimming pose
    • This fixed at least one bug (mentioned above) and will likely prevent others
  • (in the final commit) I refactored position setting a bit
    • Intended to centralize logic, in particular "initial perspective"
    • Should also help with stuff like Goto GUI (Jump to Player) #116
    • This commit could be dropped if not considered necessary

@MattSturgeon MattSturgeon changed the title General cleanup & refactoring of the main class General cleanup; keypress handling; tripod storage; FreecamPosition Dec 19, 2023
@hashalite
Copy link
Collaborator

I agree with most of the changes here, however I'm not sure I understand the motivation behind limiting the amount of time the toggle bind can be held. It doesn't feel any more natural to me. Could you explain further?

@MattSturgeon
Copy link
Member Author

MattSturgeon commented Dec 23, 2023

I agree with most of the changes here,

Great!

I'm not sure I understand the motivation behind limiting the amount of time the toggle bind can be held.

One scenario: you've held it down for a while, thinking about which tripod to open, but you then change your mind. I think toggling on release here is unintuitive.

For me, pressing the key for more than ~0.2s stops feeling like I'm "hitting" the toggle key and starts to feel like "holding" it down. A "normal" key bind would probably toggle every tick in this scenario, which would feel intuitive (although janky).

Another analogy is tapping vs holding on touchscreen devices...

0.5s (10 ticks) felt like a reasonable cut-off for distinguished a slightly long tap from a mistakenly held key, but this could be set to anything really.

If you disagree, TOGGLE_KEY_MAX_TICKS could be changed or removed entirely.

@MattSturgeon
Copy link
Member Author

This has been rebased too.

- General cleanup of keybind code.
- Allow toggle bind to be held while waiting for tripod combos.
- Only toggle when bind is released & no tripods were activated.
- Only toggle when bind wasn't held _too_ long.

Also:
- Added a `reset` method to `ModBinding`.
- Updated "wrapper" methods to Mojang mappings.
- Use format string for tripod notification translations
- Move tripod storage to `TripodRegistry`
- Support modded dimensions by using a `HashMap` of `DimensionType`s
- Store tripod slots efficiently using an `EnumMap` (i.e. an array)
We can safely assume that we _always_ want the swimming height and that `FreeCamera` will always be swimming.
Fixes `resetCamera` moving freecam to the player's feet.
@hashalite
Copy link
Collaborator

One scenario: you've held it down for a while, thinking about which tripod to open, but you then change your mind. I think toggling on release here is unintuitive.

This is a good point!

Another analogy is tapping vs holding on touchscreen devices...

Also a good point.

Everything looks good, will go ahead and merge. Thanks again, all of this code cleanup has been 🤌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants