Skip to content

Commit 8a6c9e0

Browse files
committed
add varargs isOver and isOverAll
slightly reduce huge if blocks in rare cases
1 parent bf62b3d commit 8a6c9e0

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

Themes/_fallback/Scripts/00 Utility.lua

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,38 @@ function getTrueY(element)
4848
end
4949

5050
--- Checks whether the mouse is over an actor
51-
-- @tparam actor element the actor
52-
-- @treturn bool true if the mouse is over the actor
53-
function isOver(element)
51+
-- @tparam actors the actors
52+
-- @treturn bool true if the mouse is over any given actor
53+
function isOver(...)
54+
local actors = {...}
55+
local mouse = getMousePosition()
56+
for i = 1, #actors do
57+
local actor = actors[i]
58+
if actor ~= nil and actor:IsOver(mouse.x, mouse.y) then
59+
return true
60+
end
61+
end
62+
return false
63+
end
64+
65+
--- Checks whether the mouse is over an actor
66+
-- @tparam actors the actors
67+
-- @treturn bool true if the mouse is over all given actors unless none are given
68+
function isOverAll(...)
69+
local actors = {...}
5470
local mouse = getMousePosition()
55-
return element:IsOver(mouse.x, mouse.y)
71+
local ret = false
72+
for i = 1, #actors do
73+
local actor = actors[i]
74+
if actor ~= nil then
75+
if not actor:IsOver(mouse.x, mouse.y) then
76+
return false
77+
else
78+
ret = true
79+
end
80+
end
81+
end
82+
return ret
5683
end
5784

5885
--- returns true if the table contains the key.

0 commit comments

Comments
 (0)