Skip to content

Commit

Permalink
Support multiple entries for various triggers & load condition
Browse files Browse the repository at this point in the history
Also:
* Slightly improve the look of the trigger/load pages by hiding
disabled controls and using multiline controls for input boxes that can
get full.

* Add some titles to the Load options page, making it a bit more
  structured

* Reverted the "Never" load option to the old place, giving people what
  they want.

fixes #4403
  • Loading branch information
mrbuds authored and InfusOnWoW committed Sep 10, 2023
1 parent 9f0c3d9 commit 7a16831
Show file tree
Hide file tree
Showing 9 changed files with 2,195 additions and 902 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ globals = {

-- misc custom
"AceGUIWeakAurasMultiLineEditBoxInsertLink",
"AceGUIWeakAurasMultiLineEditBoxWithEnterInsertLink",
"AceGUIWidgetLSMlists",
"CUSTOM_CLASS_COLORS",
"LibStub",
Expand Down
6 changes: 3 additions & 3 deletions WeakAuras/BossMods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ Private.event_prototypes["DBM Timer"] = {
return ret:format(
trigger.use_count and trigger.count or "",
trigger.use_id and trigger.id or "",
trigger.use_spellId and trigger.spellId or "",
trigger.use_spellId and tostring(trigger.spellId) or "",
trigger.use_message and trigger.message or "",
trigger.use_message and trigger.message_operator or "",
trigger.use_cloneId and "true" or "false",
Expand Down Expand Up @@ -1220,7 +1220,7 @@ Private.event_prototypes["BigWigs Timer"] = {
]=]
return ret:format(
trigger.use_count and trigger.count or "",
trigger.use_spellId and trigger.spellId or "",
trigger.use_spellId and tostring(trigger.spellId) or "",
trigger.use_text and trigger.text or "",
trigger.use_text and trigger.text_operator or "",
trigger.use_cloneId and "true" or "false",
Expand Down Expand Up @@ -1609,7 +1609,7 @@ Private.event_prototypes["Boss Mod Timer"] = {

return ret:format(
trigger.use_count and trigger.count or "",
trigger.use_spellId and trigger.spellId or "",
trigger.use_spellId and tostring(trigger.spellId) or "",
trigger.use_message and trigger.message or "",
trigger.use_message and trigger.message_operator or "",
trigger.use_cloneId and "true" or "false",
Expand Down
132 changes: 98 additions & 34 deletions WeakAuras/GenericTrigger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -202,47 +202,98 @@ function TestForMultiSelect(trigger, arg)
return test;
end

function ConstructTest(trigger, arg)
local function singleTest(arg, trigger, name, value, operator, use_exact)
local number = tonumber(value)
if(arg.type == "tristate") then
return TestForTriState(trigger, arg);
elseif(arg.type == "multiselect") then
return TestForMultiSelect(trigger, arg);
elseif(arg.type == "toggle") then
return TestForToggle(trigger, arg);
elseif (arg.type == "spell" or arg.type == "item") then
if arg.test then
if arg.showExactOption then
return "("..arg.test:format(value, tostring(use_exact) or "false") ..")";
else
return "("..arg.test:format(value)..")";
end
else
return "(".. name .." and "..name.."==" ..(number or ("\""..(tostring(value) or "").."\""))..")";
end
elseif(arg.test) then
return "("..arg.test:format(tostring(value) or "")..")";
elseif(arg.type == "longstring" and operator) then
return TestForLongString(trigger, arg);
elseif (arg.type == "string" or arg.type == "select") then
return "(".. name .." and "..name.."==" ..(number or ("\""..(tostring(value) or "").."\""))..")";
elseif (arg.type == "number") then
return "(".. name .." and "..name..(operator or "==")..(number or 0) ..")";
else
-- Should be unused
return "(".. name .." and "..name..(operator or "==")..(number or ("\""..(tostring(value) or 0).."\""))..")";
end
end

function ConstructTest(trigger, arg, testGroups, preambleGroups)
local test
local preamble
local name = arg.name;
if(arg.hidden or arg.type == "tristate" or arg.type == "toggle" or (arg.type == "multiselect" and trigger["use_"..name] ~= nil) or ((trigger["use_"..name] or arg.required) and trigger[name])) then
local number = tonumber(trigger[name]);
if(arg.type == "tristate") then
test = TestForTriState(trigger, arg);
elseif(arg.type == "multiselect") then
test = TestForMultiSelect(trigger, arg);
elseif(arg.type == "toggle") then
test = TestForToggle(trigger, arg);
elseif (arg.type == "spell" or arg.type == "item") then
if arg.test then
if arg.showExactOption then
test = "("..arg.test:format(trigger[name], tostring(trigger["use_exact_" .. name]) or "false") ..")";

if arg.preamble then
if not arg.preambleGroup or not preambleGroups[arg.preambleGroup] then
preamble = arg.preamble:format(trigger[name] or "")
end
if arg.preambleGroup then
preambleGroups[arg.preambleGroup] = true
end
end

if arg.hidden
or arg.type == "tristate"
or arg.type == "toggle"
or (arg.type == "multiselect" and trigger["use_"..name] ~= nil)
or ((trigger["use_"..name] or arg.required) and trigger[name])
then
if arg.multiEntry then
if type(trigger[name]) == "table" and #trigger[name] > 0 then
test = ""
for i, value in ipairs(trigger[name]) do
local operator = name and type(trigger[name.."_operator"]) == "table" and trigger[name.."_operator"][i]
local use_exact = name and type(trigger["use_exact_" .. name]) == "table" and trigger["use_exact_" .. name][i]

if arg.multiEntry.operator == "preamble" then
preamble = preamble and (preamble .. "\n") or ""
preamble = preamble .. arg.multiEntry.preambleAdd:format(value)
else
local single = singleTest(arg, trigger, name, value, operator, use_exact)
if single then
if test ~= "" then
test = test .. arg.multiEntry.operator
end
test = test .. single
end
end
end

if arg.multiEntry.operator == "preamble" then
test = arg.test
end

if test == "" then
test = nil
else
test = "("..arg.test:format(trigger[name])..")";
test = "(" .. test .. ")"
end
else
test = "(".. name .." and "..name.."==" ..(number or ("\""..(trigger[name] or "").."\""))..")";
end
elseif(arg.test) then
test = "("..arg.test:format(tostring(trigger[name]) or "")..")";
elseif(arg.type == "longstring" and trigger[name.."_operator"]) then
test = TestForLongString(trigger, arg);
elseif (arg.type == "string" or arg.type == "select") then
test = "(".. name .." and "..name.."==" ..(number or ("\""..(trigger[name] or "").."\""))..")";
elseif (arg.type == "number") then
test = "(".. name .." and "..name..(trigger[name.."_operator"] or "==")..(number or 0) ..")";
end
else
-- Should be unused
test = "(".. name .." and "..name..(trigger[name.."_operator"] or "==")..(number or ("\""..(trigger[name] or 0).."\""))..")";
local value = trigger[name]
local operator = name and trigger[name.."_operator"]
local use_exact = name and trigger["use_exact_" .. name]
test = singleTest(arg, trigger, name, value, operator, use_exact)
end
end

if arg.preamble then
preamble = arg.preamble:format(trigger[name] or "")
end

if (test == "(true)") then
if not test or test == "(true)" or arg.testGroup and testGroups[arg.testGroup] then
return nil, preamble
end

Expand Down Expand Up @@ -275,6 +326,9 @@ function ConstructFunction(prototype, trigger)
local store = {};
local init;
local preambles = "\n"
local orConjunctionGroups = {}
local preambleGroups = {}
local testGroups = {}
if(prototype.init) then
init = prototype.init(trigger);
else
Expand All @@ -300,12 +354,17 @@ function ConstructFunction(prototype, trigger)
if (arg.store) then
tinsert(store, name);
end
local test, preamble = ConstructTest(trigger, arg);
local test, preamble = ConstructTest(trigger, arg, testGroups, preambleGroups);
if (test) then
if(arg.required) then
tinsert(required, test);
else
tinsert(tests, test);
if arg.orConjunctionGroup then
orConjunctionGroups[arg.orConjunctionGroup] = orConjunctionGroups[arg.orConjunctionGroup] or {}
tinsert(orConjunctionGroups[arg.orConjunctionGroup], test)
else
tinsert(tests, test);
end
end
if(arg.debug) then
tinsert(debug, arg.debug:format(trigger[name]));
Expand All @@ -317,6 +376,11 @@ function ConstructFunction(prototype, trigger)
end
end
end

for _, orConjunctionGroup in pairs(orConjunctionGroups) do
tinsert(tests, "("..table.concat(orConjunctionGroup, " or ")..")")
end

local ret = preambles .. "return function("..tconcat(input, ", ")..")\n";
ret = ret..(init or "");

Expand Down
Loading

0 comments on commit 7a16831

Please sign in to comment.