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

push:toGame return value #26

Closed
GrunHausler opened this issue Jun 16, 2019 · 1 comment
Closed

push:toGame return value #26

GrunHausler opened this issue Jun 16, 2019 · 1 comment

Comments

@GrunHausler
Copy link

Thank you for the code, it really saved time!

However I don't like getting nil back with push:toGame, so I added an alternate calculation. If method is true It should return 0 or the respective max game width/height instead.
Maybe you care to implement it?

function push:toGame(x, y, method)
  x, y = x - self._OFFSET.x, y - self._OFFSET.y
  local normalX, normalY = x / self._GWIDTH, y / self._GHEIGHT
  
  if method then
-- new version
    x = ( (x < 0 and 0 ) or 
        ( (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH ) or
            (x >=self._WWIDTH * self._SCALE.x and self._WWIDTH ) )
    y = ( (y < 0 and 0 ) or 
        ( (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT ) or
            (y >=self._WHEIGHT * self._SCALE.y and self._WHEIGHT ) )
  else
-- old code
    x = (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH or nil
    y = (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT or nil
  end
  
  return x, y
end
@Ulydev
Copy link
Owner

Ulydev commented Jun 16, 2019

Hello @GrunHausler, thanks for opening an issue!
I really appreciate the kind words and the effort you made to try to improve the library! push:toGame returning nil values is a design choice, though, that allows the user to know when the mouse is out of the screen. Returning 0 in such cases would be misleading in my opinion, but I am glad you've found a workaround for your own use case.
Thank you for using push, I'm going to close the issue now but I absolutely encourage you to keep contributing and open a pull request next time, whenever you feel like it!
Cheers :-)

@Ulydev Ulydev closed this as completed Jun 16, 2019
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

No branches or pull requests

2 participants