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

Refactoring underlying architecture to support various input types #483

Closed
2 of 6 tasks
Shute052 opened this issue Feb 22, 2024 · 14 comments
Closed
2 of 6 tasks

Refactoring underlying architecture to support various input types #483

Shute052 opened this issue Feb 22, 2024 · 14 comments
Labels
breaking-change A breaking change that requires a new major version code-quality Make the code faster or prettier controversial Requires a heightened standard of review enhancement New feature or request help wanted Extra attention is needed usability Reduce user friction

Comments

@Shute052
Copy link
Collaborator

Shute052 commented Feb 22, 2024

Motivation

Setting the stage for future additions (maybe):

This also gives users the freedom to tailor the input kinds they want.

Tasks

Undecided Changes

InputStream trait

Replace the large InputStreams with smaller, single-responsibility implementations:

/// Allows defining a specific kind of stream collecting user inputs.
pub trait InputStream<'a> {
    /// Collects the inputs from a [`World`] for testing.
    fn from_world(world: &'a World) -> Self;
}

/// Bulit-in support for `ButtonInput<KeyCode>`.
pub type KeyCodeStream = ButtonInput<KeyCode>
impl<'a> InputStream<'a> for ButtonInput<KeyCode> {
    fn from_world(world: &'a World) -> Self {
        world.resource::<Self>().clone()
    }
}

InputQuery

Similar to Bevy's Query:

fn button_pressed(input_query: InputQuery<KeyCodeStream>, button: KeyCode) -> bool {
    let keycode_input: KeyCodeStream = input_query.get();
    keycode_input.pressed(button)
}
@Shute052 Shute052 added the usability Reduce user friction label Feb 22, 2024
@Shute052
Copy link
Collaborator Author

It's a huge task, but I'm hoping this setup will work out. This makes it easy to add new stuff later on, like touchscreens and gestures, and allowing users to customize their input types.

Any other ideas for now?

@Shute052 Shute052 added enhancement New feature or request help wanted Extra attention is needed code-quality Make the code faster or prettier breaking-change A breaking change that requires a new major version labels Feb 22, 2024
@Shute052
Copy link
Collaborator Author

Should we prioritize removing input_mocking.rs first? See the comment.

@Shute052 Shute052 changed the title Rethinking New Underlying Architecture Rethinking New Architecture Feb 22, 2024
@alice-i-cecile
Copy link
Contributor

Not fully sold on the rename: I like the way that the current API makes the state machine nature clear.

Otherwise this looks good. And yes, we should swap out for a lighter solution to input mocking for tests: I think that will make the refactoring much easier.

@Shute052 Shute052 changed the title Rethinking New Architecture Refactoring underlying architecture to support various input types Feb 23, 2024
@Shute052
Copy link
Collaborator Author

Shute052 commented Feb 23, 2024

Updated the description.


image


And how do I make all the references look like the one above? Even though the content in markdown is the same!

@alice-i-cecile
Copy link
Contributor

And how do I make all the references look like the one above? Even though the content in markdown is the same!

Yeah, Github works in mysterious ways sometimes. I haven't been able to figure out what triggers the "expand issue number" formatting either!

@jnhyatt
Copy link
Contributor

jnhyatt commented Feb 29, 2024

@Shute052 I just opened #496 based on some issues I was seeing. The current bevy_ui integration is somewhat hacky, and this new interface looks like it could significantly simplify that API and impl. Have you looked into adding UI interactions as an input type? I notice you have bevy_mod_picking listed as a potential input frontend, and I was considering that bevy_ui and bevy_mod_picking could potentially use a similar/the same API to generate input events. I'd love to collaborate on the rewrite if you think there's room for it.

@Shute052
Copy link
Collaborator Author

Shute052 commented Mar 3, 2024

I'd love to collaborate on the rewrite if you think there's room for it

I'm totally on board with this plan, but I'll be away from work for 10 days and won't be able to continue working on this until I get back

@michael-jaquier
Copy link

Hey. First thanks for the lib.

This

input sequences (#485)

would be very cool for me. i wanted to setup some "input modes" that toggle and this would let me do it directly with leafwing no need for anything ontop. If im understanding correctly though this is blocked until this larger story gets wrapped up?

@Shute052
Copy link
Collaborator Author

Shute052 commented Mar 21, 2024

until this larger story gets wrapped up?

@michael-jaquier Hi! Which input modes were you interested in?
Adding support for some of these could be very beneficial for other users as well.

I'm currently working on #494 first. The code and documentation are nearly complete, but I'm holding off on pushing it just yet.
I've actually explored different approaches, and I want to make sure the latest one is thoroughly tested before pushing it.

After that, I'll move on to #490. I think this will pave the way for a more straightforward implementation of InputSequence. Attempting to implement it now would be a complex and disruptive undertaking, due to the lack of separation of concerns and high coupling among the current underlying code.

@michael-jaquier
Copy link

Hey @Shute052 the idea for me was to have a system where users can input the "B" key to enter "Build Mode" then another key press would give them something from that mode.

Something like

delay = 1.5 seconds
input_map.insert_sequence(Action::BuildRedBox, [KeyB, KeyR], delay)

Does that make sense? Reading the abstract from here #485 I think this would fit my use case perfectly and not force me to build a

struct BuildMode(bool)

Ontop of your library

@Shute052
Copy link
Collaborator Author

Shute052 commented Mar 22, 2024

@michael-jaquier Here is my recent draft. While English isn't my native language, I struggle with naming and writing documentation.

/// Specifies the interval in milliseconds.
pub enum InputInterval {
    Min(f32),
    Max(f32),
    Range(f32, f32),
}

/// Specifies the timing rules for each user input in a sequence.
pub enum InputTimingRules {
    Every(InputInterval),
    EachBetween(Vec<InputInterval>),
}

/// Inserts a sequence of user inputs with specified timing rules.
fn insert_sequence(action: impl Actionlike, sequence: Vec<UserInput>, intervals: InputTimingRules);

@michael-jaquier
Copy link

Thats exactly what I needed indeed. That's the root of my query -- Will that implementation need to wait for this larger refactor? Or is there perhaps a dev branch I could use to test this feature ( once its out of draft mode )

@Shute052
Copy link
Collaborator Author

If things go smoothly, we should have that trial branch in less than a month. I'm aiming to wrap up #494 in the next few days, and then move on to #490 which will make it easier for us to add new input types. After that, we can give implementing Sequence a try.

@alice-i-cecile
Copy link
Contributor

#534 is getting merged; I'm going to close this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change A breaking change that requires a new major version code-quality Make the code faster or prettier controversial Requires a heightened standard of review enhancement New feature or request help wanted Extra attention is needed usability Reduce user friction
Projects
None yet
Development

No branches or pull requests

4 participants