add support for 'button' conditional (#3)

* add support for 'button' conditional

* Route [button] through Multi, add [nobutton], register as static

- [button] now reads conditionals.button via Multi(...) instead of indexing
  _groups.button[1].values[1] directly, so OR/AND lists and repeated groups
  behave like every other argument conditional. [button:1/2] now matches left
  or right; previously only the first value was ever checked and the rest were
  silently dropped. This also removes the unguarded _groups reach-in, which
  Multi itself defends against (it checks _groups is present and falls back to
  _operators).

- Adds [nobutton:N] via NegatedMulti, following the convention that every
  conditional ships its negation (nomod, nostance, nokeydown, ...).

- Bare [button] / [nobutton] now mean "any / no mapped mouse button held",
  mirroring bare [mod]. Bare [nobutton] doubles as an "activated by a keybind
  rather than a click" test.

- Registers button/nobutton in STATIC_CONDITIONALS next to mod and keydown, so
  they are checked once up front rather than re-evaluated for every candidate
  unit during multiscan target scanning.

Still open: IsMouseButtonDown reports live physical state, so a keybound macro
has no button held and [button:N] is false for it, and whether the button still
reads down at macro-execution time depends on whether the action button fires on
mouse-down or mouse-up. Needs in-game verification.

---------

Co-authored-by: Brues <5278969+brues-code@users.noreply.github.com>
This commit is contained in:
2026-09-09 10:51:51 +03:00
committed by GitHub
parent 269c6ba67e
commit 0ef4fe1818
2 changed files with 43 additions and 0 deletions
+25
View File
@@ -5422,6 +5422,30 @@ end
-- A list of Conditionals and their functions to validate them
CleveRoids.Keywords = {
-- [button:N] — true while mouse button N is held (1=Left, 2=Right, 3=Middle,
-- 4/5=extra). Routed through Multi so OR/AND lists and repeated groups behave
-- like every other argument conditional ([button:1/2] = left or right).
-- [button] with no argument — true if any mapped mouse button is held.
button = function(conditionals)
if type(conditionals.button) ~= "table" then
return CleveRoids.AnyMouseButtonDown()
end
return Multi(conditionals.button, function(button)
local name = CleveRoids.buttons[button]
return name and IsMouseButtonDown(name) or false
end, conditionals, "button")
end,
nobutton = function(conditionals)
if type(conditionals.nobutton) ~= "table" then
return not CleveRoids.AnyMouseButtonDown()
end
return NegatedMulti(conditionals.nobutton, function(button)
local name = CleveRoids.buttons[button]
return not (name and IsMouseButtonDown(name))
end, conditionals, "nobutton")
end,
exists = function(conditionals)
return UnitExists(conditionals.target)
end,
@@ -9330,6 +9354,7 @@ CleveRoids.STATIC_CONDITIONALS = {
inbag = true, noinbag = true,
mod = true, nomod = true,
keydown = true, nokeydown = true,
button = true, nobutton = true,
swimming = true, noswimming = true, swim = true, noswim = true,
indoors = true, noindoors = true, outdoors = true, nooutdoors = true,
rooted = true, norooted = true,
+18
View File
@@ -656,6 +656,24 @@ function CleveRoids.PrintT(t, depth)
end
end
CleveRoids.buttons = {
['1'] = 'LeftButton',
['2'] = 'RightButton',
['3'] = 'MiddleButton',
['4'] = 'Button4',
['5'] = 'Button5',
}
-- True while any mapped mouse button is held. Backs the argument-less [button] /
-- [nobutton], mirroring how a bare [mod] means "any modifier". Bare [nobutton] is
-- the practical "activated by a keybind, not a click" test.
function CleveRoids.AnyMouseButtonDown()
for _, name in pairs(CleveRoids.buttons) do
if IsMouseButtonDown(name) then return true end
end
return false
end
CleveRoids.kmods = {
ctrl = IsControlKeyDown,
lctrl = IsLeftControlKeyDown,