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

New Widget Style & Properties, Overall Refactor/Restructure #3

Merged
merged 37 commits into from Jul 22, 2017
Merged

New Widget Style & Properties, Overall Refactor/Restructure #3

merged 37 commits into from Jul 22, 2017

Conversation

Enteleform
Copy link
Contributor

@Enteleform Enteleform commented Jul 21, 2017

Demo

Changes:

  • Restructured component files

  • Assigned calculations to variables/properties

  • Extracted large functions into sub-functions

  • Removed rectangle background

  • Added circle size, background color, outline color, & outline width:

    • 2 circles @ joystick base
    • 1 circle @ joystick pad
    • sizes of the 3 circles are relative, based on percentage for automatic scaling
    • _total_diameter is set to min(*self.size), so the joystick will fill whatever space it is actually given automatically
  • Added 'sticky' property

    • if enabled, pad does not rebound to center @ on_touch_up
  • Removed pad_callback. Callbacks should be added with joystick.bind(pad=callback)

  • Moved radians & angle out of move_pad and into their own properties, as they were not reliant on the local calculations & can be calculated @ point of use

  • changed touch.ud['pad'] to self.is_active (should allow multiple pads to work simultaneously on multi-touch devices?)

  • I had to remove all of the documentation for readability while editing to make sure I got everything working correctly. I added it back in afterwards, while also allowing the increased use of named variables & sub-functions to speak for themselves. IMO if everything is broken down into named variables/functions - the code will be mostly self-documenting. (IE: Robert Martin's 'Clean Code' philosophy).

  • My original code wasn't pep8-ed (not a fan of pep8...), tried my best to pep8 the right way in order to pass the checker.

  • Updated README. Added GIF example & links to documentation/examples. (already linked @ master, so they'll show up as dead links in my repo but should be fine once merged)

Notes:

  • Magnitude doesn't seem right? It kind of jumps from around 0.6 or so straight to 1. I'm not too great at math stuff, so can't really verify everything 100%, but I added a coordinate readout to the demo so you should be able to see what's going on pretty easily.

  • Some improved collision detection is required. Not sure if the original had the same issue or if it's due to the way I setup up auto-sizing or something else, but clicking outside of the actual joystick area still activates it (since it's technically still part of the joystick widget):

  • Maybe you have some better names for some of the calculation variables? I tried to make them as relevant as possible, but like I said - math isn't really my thing. _update_coordinates_a & _update_coordinates_b definitely need some context-providing names, I just wasn't sure of what the condition relative_distance > self._radius_difference mean's exactly. Collision Demo

  • Mentioned self.is_active. Haven't built to mobile yet so can't really test to see if it works for multiple joysticks, each with their own lifecycle for [touch_down, touch_move, touch_up]

  • Let me know if there are any problems with the PR. It's kind of massive, changewise, but I had already drafted most of it so didn't know how to go about doing it incrementally.

  • Also let me know once everything is sorted out, and I'll update the GIF to include the few new styles & coordinate readout.

@Narcolapser
Copy link
Member

I'll have to take a look at this when I get home to night.

I can tell you right now though that self.is_active won't work. Imagine this scenario: Player 1 touches his controller, p1.is_active = true. player 2 touches his controller, p2.is_active is now true. p2 moves his finger, p1 is active so it responds. We'll have to bind the movement to the touch itself, so touch.ud will be necessary.

we could use _update_coordinates_external and _update_coordinates_internal for a and b respectively. The names hopefully suggest their purposes. update ext: Update coordinates for a point outside the controller. update int: update coordinates for a point inside the controller. It makes sense in my mind, does that make sense to you?

Thanks for all the polish!

@Enteleform
Copy link
Contributor Author

Enteleform commented Jul 21, 2017

we could use _update_coordinates_external and _update_coordinates_internal for a and b respectively

This helped, I managed to fix a few of the issues mentioned in the PR detail based on that. Updated resolved issues with strikethroughs.

 

touch.ud re-implementation & improved collision detection:

@ move_pad

@ _update_coordinates

@ on_touch

@ TouchData.py

 

Magnitude Fix:

relative_distance / self._total_radius
>>>
relative_distance / (self._total_radius - self.ids.pad._radius)

@KeyWeeUsr
Copy link
Member

@Enteleform please use proper commit messages and git client :)

@Enteleform
Copy link
Contributor Author

@KeyWeeUsr
True, didn't foresee the troubleshooting & figured this would just be a one-shot. Def gotta step up my Git workflow, usually avoid it for smaller projects cuz I'm not a fan of CLI (prefer command palette + scripts) & haven't written any automation scripts yet. Just started messing with pygithub though, so should be set up soon.

@Narcolapser
Copy link
Member

This looks good. I'll merge it and if I run into anything else I'll fix it. Thanks again for all the polish!

@Narcolapser Narcolapser merged commit 3fb213c into kivy-garden:master Jul 22, 2017
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.

None yet

3 participants