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.
325 lines
10 KiB
325 lines
10 KiB
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
|
-- Lua Library inline imports
|
|
local function __TS__Class(self)
|
|
local c = {prototype = {}}
|
|
c.prototype.__index = c.prototype
|
|
c.prototype.constructor = c
|
|
return c
|
|
end
|
|
|
|
local __TS__Symbol, Symbol
|
|
do
|
|
local symbolMetatable = {__tostring = function(self)
|
|
return ("Symbol(" .. (self.description or "")) .. ")"
|
|
end}
|
|
function __TS__Symbol(description)
|
|
return setmetatable({description = description}, symbolMetatable)
|
|
end
|
|
Symbol = {
|
|
asyncDispose = __TS__Symbol("Symbol.asyncDispose"),
|
|
dispose = __TS__Symbol("Symbol.dispose"),
|
|
iterator = __TS__Symbol("Symbol.iterator"),
|
|
hasInstance = __TS__Symbol("Symbol.hasInstance"),
|
|
species = __TS__Symbol("Symbol.species"),
|
|
toStringTag = __TS__Symbol("Symbol.toStringTag")
|
|
}
|
|
end
|
|
|
|
local __TS__Iterator
|
|
do
|
|
local function iteratorGeneratorStep(self)
|
|
local co = self.____coroutine
|
|
local status, value = coroutine.resume(co)
|
|
if not status then
|
|
error(value, 0)
|
|
end
|
|
if coroutine.status(co) == "dead" then
|
|
return
|
|
end
|
|
return true, value
|
|
end
|
|
local function iteratorIteratorStep(self)
|
|
local result = self:next()
|
|
if result.done then
|
|
return
|
|
end
|
|
return true, result.value
|
|
end
|
|
local function iteratorStringStep(self, index)
|
|
index = index + 1
|
|
if index > #self then
|
|
return
|
|
end
|
|
return index, string.sub(self, index, index)
|
|
end
|
|
function __TS__Iterator(iterable)
|
|
if type(iterable) == "string" then
|
|
return iteratorStringStep, iterable, 0
|
|
elseif iterable.____coroutine ~= nil then
|
|
return iteratorGeneratorStep, iterable
|
|
elseif iterable[Symbol.iterator] then
|
|
local iterator = iterable[Symbol.iterator](iterable)
|
|
return iteratorIteratorStep, iterator
|
|
else
|
|
return ipairs(iterable)
|
|
end
|
|
end
|
|
end
|
|
|
|
local Map
|
|
do
|
|
Map = __TS__Class()
|
|
Map.name = "Map"
|
|
function Map.prototype.____constructor(self, entries)
|
|
self[Symbol.toStringTag] = "Map"
|
|
self.items = {}
|
|
self.size = 0
|
|
self.nextKey = {}
|
|
self.previousKey = {}
|
|
if entries == nil then
|
|
return
|
|
end
|
|
local iterable = entries
|
|
if iterable[Symbol.iterator] then
|
|
local iterator = iterable[Symbol.iterator](iterable)
|
|
while true do
|
|
local result = iterator:next()
|
|
if result.done then
|
|
break
|
|
end
|
|
local value = result.value
|
|
self:set(value[1], value[2])
|
|
end
|
|
else
|
|
local array = entries
|
|
for ____, kvp in ipairs(array) do
|
|
self:set(kvp[1], kvp[2])
|
|
end
|
|
end
|
|
end
|
|
function Map.prototype.clear(self)
|
|
self.items = {}
|
|
self.nextKey = {}
|
|
self.previousKey = {}
|
|
self.firstKey = nil
|
|
self.lastKey = nil
|
|
self.size = 0
|
|
end
|
|
function Map.prototype.delete(self, key)
|
|
local contains = self:has(key)
|
|
if contains then
|
|
self.size = self.size - 1
|
|
local next = self.nextKey[key]
|
|
local previous = self.previousKey[key]
|
|
if next ~= nil and previous ~= nil then
|
|
self.nextKey[previous] = next
|
|
self.previousKey[next] = previous
|
|
elseif next ~= nil then
|
|
self.firstKey = next
|
|
self.previousKey[next] = nil
|
|
elseif previous ~= nil then
|
|
self.lastKey = previous
|
|
self.nextKey[previous] = nil
|
|
else
|
|
self.firstKey = nil
|
|
self.lastKey = nil
|
|
end
|
|
self.nextKey[key] = nil
|
|
self.previousKey[key] = nil
|
|
end
|
|
self.items[key] = nil
|
|
return contains
|
|
end
|
|
function Map.prototype.forEach(self, callback)
|
|
for ____, key in __TS__Iterator(self:keys()) do
|
|
callback(nil, self.items[key], key, self)
|
|
end
|
|
end
|
|
function Map.prototype.get(self, key)
|
|
return self.items[key]
|
|
end
|
|
function Map.prototype.has(self, key)
|
|
return self.nextKey[key] ~= nil or self.lastKey == key
|
|
end
|
|
function Map.prototype.set(self, key, value)
|
|
local isNewValue = not self:has(key)
|
|
if isNewValue then
|
|
self.size = self.size + 1
|
|
end
|
|
self.items[key] = value
|
|
if self.firstKey == nil then
|
|
self.firstKey = key
|
|
self.lastKey = key
|
|
elseif isNewValue then
|
|
self.nextKey[self.lastKey] = key
|
|
self.previousKey[key] = self.lastKey
|
|
self.lastKey = key
|
|
end
|
|
return self
|
|
end
|
|
Map.prototype[Symbol.iterator] = function(self)
|
|
return self:entries()
|
|
end
|
|
function Map.prototype.entries(self)
|
|
local items = self.items
|
|
local nextKey = self.nextKey
|
|
local key = self.firstKey
|
|
return {
|
|
[Symbol.iterator] = function(self)
|
|
return self
|
|
end,
|
|
next = function(self)
|
|
local result = {done = not key, value = {key, items[key]}}
|
|
key = nextKey[key]
|
|
return result
|
|
end
|
|
}
|
|
end
|
|
function Map.prototype.keys(self)
|
|
local nextKey = self.nextKey
|
|
local key = self.firstKey
|
|
return {
|
|
[Symbol.iterator] = function(self)
|
|
return self
|
|
end,
|
|
next = function(self)
|
|
local result = {done = not key, value = key}
|
|
key = nextKey[key]
|
|
return result
|
|
end
|
|
}
|
|
end
|
|
function Map.prototype.values(self)
|
|
local items = self.items
|
|
local nextKey = self.nextKey
|
|
local key = self.firstKey
|
|
return {
|
|
[Symbol.iterator] = function(self)
|
|
return self
|
|
end,
|
|
next = function(self)
|
|
local result = {done = not key, value = items[key]}
|
|
key = nextKey[key]
|
|
return result
|
|
end
|
|
}
|
|
end
|
|
Map[Symbol.species] = Map
|
|
end
|
|
|
|
local function __TS__New(target, ...)
|
|
local instance = setmetatable({}, target.prototype)
|
|
instance:____constructor(...)
|
|
return instance
|
|
end
|
|
-- End of Lua Library inline imports
|
|
local ____exports = {}
|
|
local _, _Mekanome = ...
|
|
local Mekanome = _Mekanome
|
|
local ActionBarButtonNames = {
|
|
"ActionButton",
|
|
"MultiBarBottomLeftButton",
|
|
"MultiBarBottomRightButton",
|
|
"MultiBarLeftButton",
|
|
"MultiBarRightButton",
|
|
"MultiBar5Button",
|
|
"MultiBar6Button",
|
|
"MultiBar7Button"
|
|
}
|
|
local BarMap = {
|
|
ActionButton = "ACTIONBUTTON",
|
|
MultiBarBottomLeftButton = "MULTIACTIONBAR1BUTTON",
|
|
MultiBarBottomRightButton = "MULTIACTIONBAR2BUTTON",
|
|
MultiBarRightButton = "MULTIACTIONBAR3BUTTON",
|
|
MultiBarLeftButton = "MULTIACTIONBAR4BUTTON",
|
|
MultiBar5Button = "MULTIACTIONBAR5BUTTON",
|
|
MultiBar6Button = "MULTIACTIONBAR6BUTTON"
|
|
}
|
|
local bindings = __TS__New(Map)
|
|
local isInitialized = false
|
|
--- Loops through all of the WoW action bar buttons, checks to see if there is a spell
|
|
-- or item on them, then stores that relationship for later use.
|
|
local function CheckBindings(self)
|
|
bindings:clear()
|
|
for ____, bar in ipairs(ActionBarButtonNames) do
|
|
for i = 1, 12 do
|
|
local actionButton = bar .. tostring(i)
|
|
local button = _G[actionButton]
|
|
if button ~= nil and type(button) == "table" and button.action ~= nil then
|
|
local ____type, id = GetActionInfo(button.action)
|
|
if ____type == "spell" or ____type == "item" then
|
|
local barName = BarMap[bar]
|
|
local binding = tostring(barName) .. tostring(i)
|
|
bindings:set(button.action, {binding = binding, id = id, type = ____type})
|
|
end
|
|
end
|
|
end
|
|
end
|
|
Mekanome.Print({
|
|
text = tostring(bindings.size),
|
|
prefix = "Bindings Update",
|
|
level = "warn"
|
|
})
|
|
end
|
|
--- Returns the ActionButtons binding for a given spell.
|
|
--
|
|
-- @param spell
|
|
-- @returns ActionButtons
|
|
local function GetBindingForSpell(spell)
|
|
local binding = nil
|
|
for ____, ____value in __TS__Iterator(bindings) do
|
|
local bindingInfo = ____value[2]
|
|
if bindingInfo.id == spell.id then
|
|
binding = bindingInfo.binding
|
|
break
|
|
end
|
|
end
|
|
return binding
|
|
end
|
|
local function CallBinding(binding)
|
|
RunBinding(binding)
|
|
RunBinding(binding, "up")
|
|
end
|
|
--- Initializes the bindings manager.
|
|
local function Init()
|
|
if isInitialized == false then
|
|
CheckBindings(nil)
|
|
Mekanome.EventManager.RegisterEventHandler(
|
|
"ACTIONBAR_SLOT_CHANGED",
|
|
function(____, args)
|
|
local slot = args[1]
|
|
local binding = bindings:get(slot)
|
|
local ____type, id = GetActionInfo(slot)
|
|
if binding ~= nil then
|
|
if ____type ~= binding.type or id ~= binding.id then
|
|
CheckBindings(nil)
|
|
end
|
|
else
|
|
if ____type == "spell" or ____type == "item" then
|
|
CheckBindings(nil)
|
|
end
|
|
end
|
|
end,
|
|
"bm_action_bar_slot_changed"
|
|
)
|
|
Mekanome.EventManager.RegisterEventHandler(
|
|
"UPDATE_BONUS_ACTIONBAR",
|
|
function()
|
|
CheckBindings(nil)
|
|
end,
|
|
"bm_player_mount_display"
|
|
)
|
|
Mekanome.EventManager.RegisterEventHandler(
|
|
"PLAYER_SPECIALIZATION_CHANGED",
|
|
function()
|
|
CheckBindings(nil)
|
|
end,
|
|
"bm_spec_change"
|
|
)
|
|
isInitialized = true
|
|
end
|
|
end
|
|
local _BindingsManager = {Init = Init, GetBindingForSpell = GetBindingForSpell, CallBinding = CallBinding}
|
|
Mekanome.BindingsManager = _BindingsManager
|
|
____exports.default = {}
|
|
return ____exports
|
|
|