Browse Source

Update for LÖVE 0.10.0;

bjorn 9 years ago
parent
commit
e1ae0d4e53
2 changed files with 14 additions and 10 deletions
  1. 5 9
      dragAndDrop.lua
  2. 9 1
      rx-love.lua

+ 5 - 9
dragAndDrop.lua

@@ -5,7 +5,7 @@ require 'rx-love'
 local object = rx.BehaviorSubject.create(400, 300)
 local object = rx.BehaviorSubject.create(400, 300)
 
 
 local radius = 30
 local radius = 30
-local isLeft = function(x, y, button) return button == 'l' end
+local isLeft = function(x, y, button) return button == 1 end
 
 
 -- Set up observables for clicking and releasing the left mouse button.
 -- Set up observables for clicking and releasing the left mouse button.
 local leftPressed = love.mousepressed:filter(isLeft)
 local leftPressed = love.mousepressed:filter(isLeft)
@@ -13,21 +13,17 @@ local leftReleased = love.mousereleased:filter(isLeft)
 
 
 -- Run some operations on the mousepressed and mousereleased observables:
 -- Run some operations on the mousepressed and mousereleased observables:
 --  * filter out any mouse presses that aren't within the radius of the circle.
 --  * filter out any mouse presses that aren't within the radius of the circle.
---  * map over the mouse presses and return an observable from the love.mousemoved event, which
---    produces the coordinates of the mouse as it moves.
---  * takeUntil to stop moving the circle when the mouse is released.
---  * flatten it to convert the observable of observables into an observable that just contains the
---    mouse coordinates.
---  * subscribe to them and set the circle's position.
+--  * flatMap the mousepresses to start producing values from the love.mousemoved event.  takeUntil
+--    ensures that the dragging stops when the mouse button is released.
+--  * subscribe to the mouse positions and set the circle's position accordingly.
 local drag = leftPressed
 local drag = leftPressed
   :filter(function(x, y)
   :filter(function(x, y)
     local ox, oy = object:getValue()
     local ox, oy = object:getValue()
     return (x - ox) ^ 2 + (y - oy) ^ 2 < radius ^ 2
     return (x - ox) ^ 2 + (y - oy) ^ 2 < radius ^ 2
   end)
   end)
-  :map(function()
+  :flatMap(function()
     return love.mousemoved:takeUntil(leftReleased)
     return love.mousemoved:takeUntil(leftReleased)
   end)
   end)
-  :flatten()
   :subscribe(function(x, y)
   :subscribe(function(x, y)
     object:onNext(x, y)
     object:onNext(x, y)
   end)
   end)

+ 9 - 1
rx-love.lua

@@ -5,20 +5,28 @@
 local rx = require 'rx'
 local rx = require 'rx'
 
 
 local events = {
 local events = {
+  'directorydropped',
   'draw',
   'draw',
+  'filedropped',
   'focus',
   'focus',
   'keypressed',
   'keypressed',
   'keyreleased',
   'keyreleased',
+  'lowmemory',
   'mousefocus',
   'mousefocus',
   'mousemoved',
   'mousemoved',
   'mousepressed',
   'mousepressed',
   'mousereleased',
   'mousereleased',
   'quit',
   'quit',
   'resize',
   'resize',
+  'textedited',
   'textinput',
   'textinput',
+  'touchmoved',
+  'touchpressed',
+  'touchreleased',
   'threaderror',
   'threaderror',
   'update',
   'update',
-  'visible'
+  'visible',
+  'wheelmoved'
 }
 }
 
 
 for _, event in pairs(events) do
 for _, event in pairs(events) do