You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
191 lines
6.1 KiB
191 lines
6.1 KiB
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
|
-- Lua Library inline imports
|
|
local function __TS__ArraySort(self, compareFn)
|
|
if compareFn ~= nil then
|
|
table.sort(
|
|
self,
|
|
function(a, b) return compareFn(nil, a, b) < 0 end
|
|
)
|
|
else
|
|
table.sort(self)
|
|
end
|
|
return self
|
|
end
|
|
|
|
local function __TS__ObjectAssign(target, ...)
|
|
local sources = {...}
|
|
for i = 1, #sources do
|
|
local source = sources[i]
|
|
for key in pairs(source) do
|
|
target[key] = source[key]
|
|
end
|
|
end
|
|
return target
|
|
end
|
|
-- End of Lua Library inline imports
|
|
local ____exports = {}
|
|
local _, _Mekanome = ...
|
|
local Mekanome = _Mekanome
|
|
local actions = {}
|
|
local isInitialized = false
|
|
local isMouseoverSettingEnabled = false
|
|
--- Evaluates the actions load conditions to tell the ActionManager
|
|
-- wether or not this action should be loaded.
|
|
--
|
|
-- @param loadConditions ActionLoadConditions
|
|
-- @returns boolean
|
|
local function GetIsActionLoaded(loadConditions)
|
|
local matchesClass = true
|
|
local matchesSpec = true
|
|
local matchesCustom = true
|
|
if loadConditions.class ~= nil then
|
|
local ____, ____, classId = UnitClass("player")
|
|
matchesClass = loadConditions.class == classId
|
|
end
|
|
if (loadConditions and loadConditions.spec) ~= nil then
|
|
matchesSpec = loadConditions.spec == GetSpecialization()
|
|
end
|
|
if loadConditions.custom ~= nil then
|
|
matchesCustom = loadConditions:custom()
|
|
end
|
|
return matchesClass == true and matchesSpec == true and matchesCustom == true
|
|
end
|
|
--- Returns the actions map in array format, sorted by priority.
|
|
local function GetSortedActions()
|
|
local actionsArray = {}
|
|
for ____, action in pairs(actions) do
|
|
actionsArray[#actionsArray + 1] = action
|
|
end
|
|
return __TS__ArraySort(
|
|
actionsArray,
|
|
function(____, a, b)
|
|
return a.priority - b.priority
|
|
end
|
|
)
|
|
end
|
|
--- Adds an action to the manager to call inside its ticker if loaded.
|
|
--
|
|
-- @param name A unique name to identify the action.
|
|
-- @param action The function to call for the action.
|
|
-- @param options Options for the action to add.
|
|
local function Add(name, options)
|
|
if actions[name] ~= nil then
|
|
error(
|
|
Mekanome.Error(("Tried to add action " .. name) .. " but it already exists."),
|
|
0
|
|
)
|
|
end
|
|
local ____temp_2
|
|
if options.loadConditions ~= nil then
|
|
____temp_2 = GetIsActionLoaded(options.loadConditions)
|
|
else
|
|
____temp_2 = false
|
|
end
|
|
local loaded = ____temp_2
|
|
local priority = options.priority
|
|
if priority == nil then
|
|
local sortedActions = GetSortedActions()
|
|
if #sortedActions == 0 then
|
|
priority = 1
|
|
else
|
|
local lastAction = sortedActions[#sortedActions]
|
|
priority = lastAction.priority + 1
|
|
end
|
|
end
|
|
actions[name] = {
|
|
priority = priority,
|
|
run = options.run,
|
|
loadConditions = options.loadConditions,
|
|
loaded = loaded,
|
|
name = name
|
|
}
|
|
if loaded then
|
|
Mekanome.Print({text = name, prefix = "Module Loaded", level = "info"})
|
|
end
|
|
end
|
|
--- Removes the action from the list.
|
|
--
|
|
-- @param name The name of the action to remove.
|
|
local function Remove(name)
|
|
if actions[name] ~= nil then
|
|
actions[name] = nil
|
|
end
|
|
end
|
|
--- Calls the list of loaded actions, in order.
|
|
-- If an action returns a binding, that binding is run and the loop is terminted
|
|
-- for a tick.
|
|
local function CallActions()
|
|
local actionList = GetSortedActions()
|
|
for ____, action in ipairs(actionList) do
|
|
if action and action.loaded then
|
|
local castable = action.run()
|
|
if castable ~= nil then
|
|
Mekanome.Cast(castable)
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
--- In order to cast on targets that arent the active target, we need
|
|
-- to leverage mouse over casting. If the setting isnt enabled, Mekanome
|
|
-- will not be able to cast on mobs that aren't the current target.
|
|
local function CheckSettings()
|
|
local mouseoverSetting = C_CVar.GetCVar("enableMouseoverCast")
|
|
if mouseoverSetting ~= nil and mouseoverSetting ~= "0" then
|
|
isMouseoverSettingEnabled = true
|
|
else
|
|
isMouseoverSettingEnabled = false
|
|
error(
|
|
Mekanome.Error("Please enable mouseover casting in the settings menu."),
|
|
0
|
|
)
|
|
end
|
|
end
|
|
--- Initializes the action manager.
|
|
local function Init()
|
|
if isInitialized == false then
|
|
CheckSettings()
|
|
C_Timer.NewTicker(
|
|
0.15,
|
|
function()
|
|
if Mekanome.enabled and isMouseoverSettingEnabled then
|
|
Mekanome.MobManager.Refresh()
|
|
Mekanome.PlayerStateManager.Refresh()
|
|
CallActions()
|
|
end
|
|
end,
|
|
nil
|
|
)
|
|
Mekanome.EventManager.RegisterEventHandler(
|
|
"PLAYER_SPECIALIZATION_CHANGED",
|
|
function()
|
|
for name, action in pairs(actions) do
|
|
if action.loadConditions then
|
|
local loaded = GetIsActionLoaded(action.loadConditions)
|
|
if loaded ~= action.loaded then
|
|
actions[name] = __TS__ObjectAssign({}, action, {loaded = loaded})
|
|
Mekanome.Print({text = name, level = "info", prefix = loaded and "Loaded Module" or "Unloaded Module"})
|
|
end
|
|
end
|
|
end
|
|
end,
|
|
"am_spec_change"
|
|
)
|
|
Mekanome.EventManager.RegisterEventHandler(
|
|
"CVAR_UPDATE",
|
|
function(____, ____bindingPattern0)
|
|
local eventName
|
|
eventName = ____bindingPattern0[1]
|
|
if eventName == "enableMouseoverCast" then
|
|
CheckSettings()
|
|
end
|
|
end,
|
|
"am_cvar_update"
|
|
)
|
|
isInitialized = true
|
|
end
|
|
end
|
|
local _ActionManager = {Add = Add, Remove = Remove, Init = Init}
|
|
Mekanome.ActionManager = _ActionManager
|
|
____exports.default = {}
|
|
return ____exports
|
|
|