Fixed issue in transitions and updated simulate module

This commit is contained in:
Ryan Ward 2023-12-22 02:29:11 -05:00
parent 6cbd09a460
commit 004d5b9ca4
2 changed files with 40 additions and 47 deletions

View File

@ -15,16 +15,6 @@ end
proc = gui:getProcessor() proc = gui:getProcessor()
local simulate = {} local simulate = {}
local cursor = false
local smooth = false
function simulate:moveCursor(bool)
cursor = bool
end
function simulate:smoothMovement(bool)
smooth = bool
end
function simulate:Press(button, x, y, istouch) function simulate:Press(button, x, y, istouch)
if self then if self then
@ -32,9 +22,7 @@ function simulate:Press(button, x, y, istouch)
elseif x == nil or y == nil then elseif x == nil or y == nil then
x, y = love.mouse.getPosition() x, y = love.mouse.getPosition()
end end
if cursor then love.mouse.setPosition(x, y)
love.mouse.setPosition(x, y)
end
gui.Events.OnMousePressed:Fire(x, y, button or gui.MOUSE_PRIMARY, istouch or false) gui.Events.OnMousePressed:Fire(x, y, button or gui.MOUSE_PRIMARY, istouch or false)
end end
@ -44,9 +32,7 @@ function simulate:Release(button, x, y, istouch)
elseif x == nil or y == nil then elseif x == nil or y == nil then
x, y = love.mouse.getPosition() x, y = love.mouse.getPosition()
end end
if cursor then love.mouse.setPosition(x, y)
love.mouse.setPosition(x, y)
end
gui.Events.OnMouseReleased:Fire(x, y, button or gui.MOUSE_PRIMARY, istouch or false) gui.Events.OnMouseReleased:Fire(x, y, button or gui.MOUSE_PRIMARY, istouch or false)
end end
@ -56,9 +42,7 @@ simulate.Click = proc:newFunction(function(self, button, x, y, istouch)
elseif x == nil or y == nil then elseif x == nil or y == nil then
x, y = love.mouse.getPosition() x, y = love.mouse.getPosition()
end end
if cursor then love.mouse.setPosition(x, y)
love.mouse.setPosition(x, y)
end
gui.Events.OnMousePressed:Fire(x, y, button or gui.MOUSE_PRIMARY, istouch or false) gui.Events.OnMousePressed:Fire(x, y, button or gui.MOUSE_PRIMARY, istouch or false)
thread.skip(1) thread.skip(1)
gui.Events.OnMouseReleased:Fire(x, y, button or gui.MOUSE_PRIMARY, istouch or false) gui.Events.OnMouseReleased:Fire(x, y, button or gui.MOUSE_PRIMARY, istouch or false)
@ -72,37 +56,37 @@ simulate.Move = proc:newFunction(function(self, dx, dy, x, y, istouch)
elseif x == nil or y == nil then elseif x == nil or y == nil then
x, y = love.mouse.getPosition() x, y = love.mouse.getPosition()
end end
if dx == 0 and dy == 0 then
_x, _y = love.mouse.getPosition()
if x == _x and y == _y then
return
end
local dx, dy = 0, 0
dx = x - _x
dy = y - _y
return simulate.Move(nil, dx, dy)
end
gui.Events.OnMouseMoved:Fire(x, y, 0, 0, istouch or false) gui.Events.OnMouseMoved:Fire(x, y, 0, 0, istouch or false)
thread.skip(1) thread.skip(1)
if smooth then local gx = transition.glide(0, dx, .25)
local gx = transition.glide(0, dx, .25) local gy = transition.glide(0, dy, .25)
local gy = transition.glide(0, dy, .25) local xx = gx()
local xx = gx() xx.OnStep(function(p)
xx.OnStep(function(p) _x, _y = love.mouse.getPosition()
_x, _y = love.mouse.getPosition() love.mouse.setPosition(x + p, _y)
if cursor then end)
love.mouse.setPosition(x + p, _y) local yy = gy()
else yy.OnStep(function(p)
gui.Events.OnMouseMoved:Fire(x + p, _y, 0, 0, istouch or false) _x, _y = love.mouse.getPosition()
end love.mouse.setPosition(_x, y + p)
end) end)
local yy = gy() if not(dx==0 and dy == 0) then
yy.OnStep(function(p) print("Holding...")
_x, _y = love.mouse.getPosition()
if cursor then
love.mouse.setPosition(_x, y + p)
else
gui.Events.OnMouseMoved:Fire(_x, y + p, 0, 0, istouch or false)
end
end)
thread.hold(xx.OnStop * yy.OnStop) thread.hold(xx.OnStop * yy.OnStop)
gui.Events.OnMouseMoved:Fire(x + dx, y + dy, 0, 0, istouch or false)
else
if cursor then
love.mouse.setPosition(x + dx, y + dy)
end
gui.Events.OnMouseMoved:Fire(x + dx, y + dy, 0, 0, istouch or false)
end end
print("Done")
gui.Events.OnMouseMoved:Fire(x + dx, y + dy, 0, 0, istouch or false)
end, true) end, true)
return simulate return simulate

View File

@ -15,7 +15,16 @@ transition.__call = function(t, start, stop, time, ...)
local args = {...} local args = {...}
return function() return function()
if not start or not stop then return multi.error("start and stop must be supplied") end if not start or not stop then return multi.error("start and stop must be supplied") end
if start == stop then multi.print("start and stop cannot be the same!") return {OnStep = function() end, OnStop = function() end} end if start == stop then
local temp = {
OnStep = function() end,
OnStop = multi:newConnection()
}
proc:newTask(function()
temp.OnStop:Fire()
end)
return temp
end
local handle = t.func(t, start, stop, time or 1, unpack(args)) local handle = t.func(t, start, stop, time or 1, unpack(args))
return { return {
OnStep = handle.OnStatus, OnStep = handle.OnStatus,