-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Externalize behaviors #7
Comments
This to me feels like allowing users to implement their own joystick behaviours. So that means the existing behaviour Existing behaviours then become more of an opt-in rather than default. Just a thought. |
TOTALLY, with this comment you gave me the idea of abstracting not only the behaviors, I will try to work on that, I really think it is an excellent idea |
Also horizontal only and vertical only axis constraints would fit inside the same framework. As well as constraining the knob movement in a circular area rather than square. |
I had a quick play at refactoring axis directions and joystick behaviors into singleton structs using traits. Its just an experiment, the trait methods should probably be modified (minimum refactor to get working): https://github.com/clinuxrulz/virtual_joystick/tree/externalize-behaviors It looks like dynamic dispatch for behaviors would have to be used top-level instead of static dispatch. Otherwise the plugin will need to be registered multiple times for each joystick with different behavior. Also handling joystick events get duplicated if behaviors are static-dispatch top level. (Put Behavior in a Box<> in |
We can change it to your example event trait methods above. Another example. A user might want to make a joystick behave like a manual gear stick for a car. We need to make sure knob movements can be customised. |
Another option which I think is more simple. Is to make the behaviours just a component that goes in the same entity as the main joystick node. The user can add a system for that component to control the joystick background and knob themselves. This library would still provide components for the current behaviours. Because for maximum flexibility you ultimately end up with:
But that would just be the same as the end user adding their own system. Will think about it some more. |
I had a good run on this branch: All the behaviors are just ECS components, that can be mixed and matched. Each behavior has its own system, and the user can create their own components and systems to customize behavior (or complete change it) Invisible from systems.rs:
Axis constraint from systems.rs:
If the end user wants to implement their own diagonal axis constraint for example, they can just make a component and a system and throw it in just in their code (no need for extra code in lib). Your change Tint color on press should be easy too.
For usage, have a look at the examples for that branch. |
Hello, I was carefully reviewing the implementations that you shared and I am afraid that I am looking for a way to implement it more as a variable of the joystick itself than as a component, it does not make much sense to me that it is a component cmd.spawn(
VirtualJoystickBundle::new(VirtualJoystickNode {
// Idea
action: ClickColor(Color::WHITE.with_a(0.5)),
})
) |
That is fair enough. Thank you for having a look. |
Here we go, attempt number 4: Behaviors are now a variable that goes into VirtualJoystickNode. See what you think. |
Oooooh, your implementation is very similar to something I was working on, I'm still seeing things I like, like the autoimplementation macro, today I'll be upgrading to bevy 0.13, there I will share any details or implementations I can think of |
That's all cool. We'll go with yours. I noticed when dealing direct with Anyway. Looking forward to seeing your implementation. I think this externalizing behaviors idea is good. Finally, if a end user needs a missing feature, then they can create a solution themselves without requesting more features of this library. |
@clinuxrulz bro, I was with very little time and trying to integrate it, I have not succeeded, do you dare to make a PR with one of your solutions? I would like to have something like that. pub trait VirtualJoystickAction<I> {
fn on_start_drag(
&self,
_id: I,
_axis: VirtualJoystickAxis,
_data: VirtualJoystickData,
_world: &mut World,
_entity: Entity,
) {
}
fn on_drag(
&self,
_id: I,
_axis: VirtualJoystickAxis,
_data: VirtualJoystickData,
_world: &mut World,
_entity: Entity,
) {
}
fn on_end_drag(
&self,
_id: I,
_axis: VirtualJoystickAxis,
_data: VirtualJoystickData,
_world: &mut World,
_entity: Entity,
) {
}
} The idea is that this only abstracts the behaviors related to joystick but with the game, internal joystick behaviors like movements and that, I would like it to be different. I was already too late with the upgrade to Bevy 0.13 |
There is no rush. Lets take time to think about it some more. |
I think it is a very good idea and thank you very much for your comments, even so I would like this feature to be an implementation of yours since I have seen that you have many different implementations for this solution. |
I made a pull request and got as close as I can to your It has two types of externalization now, one for joystick behavior ( I somehow broke my cargo, so I was unable to test it:
Maybe you can test it for me. |
You're the best, I will look the PR
No problem, I will test |
@clinuxrulz about your problem with cargo, please try removing the |
It's all good. The problem resolved itself somehow when I closed and opened the terminal window. |
The PR #27 was merged, do you consider that this issue can be closed? |
There will be some fine tuning we can do down the road. But yes we can close this. |
This is a feature that I would like to implement, the idea would be to achieve something like this
The idea is actually that there are actions already defined by default by the plugin but the user can also create their own actions like this
The trait should be something like this
The text was updated successfully, but these errors were encountered: