Skip to content

Commit

Permalink
Update game API compatibility #110
Browse files Browse the repository at this point in the history
  • Loading branch information
haggen committed Sep 5, 2023
1 parent 2d4c3c5 commit 6e893a0
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 146 deletions.
50 changes: 19 additions & 31 deletions src/Fastbind/API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,28 @@
-- The MIT License © 2017 Arthur Corenzan
-- More on https://github.com/haggen/wow

--- Add-on name constant.
--- @type "Fastbind"
---
-- Add-on name constant.
--
local FASTBIND = ...

--- @class API
---
-- Add-on table.
--
local api = select(2, ...)

--- Saved variables.
---
-- Saved variables.
--
FastbindSavedVars = {}

--- Default values.
---
-- Default values.
--
api.defaultSavedVars = {
debug = false,
minimapButtonPosition = 0,
}

--- Enforce schema by deleting unrecognized keys from
--- stored saved variables and setting new defaults.
--- @return nil
---
-- Enforce schema by deleting unrecognized keys from
-- stored saved variables and setting new defaults.
--
function api.MigrateSavedVars()
-- Remove keys with no default.
for key in pairs(FastbindSavedVars) do
Expand All @@ -42,27 +40,20 @@ function api.MigrateSavedVars()
end
end

--- Get saved variable.
--- @param name string
--- @return any
---
-- Get saved variable.
--
function api.GetSavedVar(name)
return FastbindSavedVars[name] or api.defaultSavedVars[name]
end

--- Set saved variable.
--- @param name string
--- @param value any
--- @return nil
---
-- Set saved variable.
--
function api.SetSavedVar(name, value)
FastbindSavedVars[name] = value
end

--- Dump variables, if debug is enabled.
--- @param ... any
--- @return nil
---
-- Dump variables, if debug is enabled.
--
function api.Dump(...)
if not api.GetSavedVar("debug") then
return
Expand All @@ -75,11 +66,8 @@ function api.Dump(...)
DevTools_Dump({ FASTBIND, ... })
end

--- Print formatted message, if debug is enabled.
--- @param message string
--- @param ... any
--- @return nil
---
-- Print formatted message, if debug is enabled.
--
function api.Printf(message, ...)
if not api.GetSavedVar("debug") then
return
Expand Down
51 changes: 23 additions & 28 deletions src/Fastbind/Fastbind.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@
-- The MIT License © 2017 Arthur Corenzan
-- More on https://github.com/haggen/wow

--- Add-on name constant.
--- @type "Fastbind"
---
-- Add-on name constant.
--
local FASTBIND = ...

--- @class API
---
-- Add-on table.
--
local api = select(2, ...)

--- Slash command.
---
-- Slash command.
--
SLASH_FASTBIND1 = "/fastbind"

--- Keybinding sets.
---
-- Keybinding sets.
--
local KEYBINDINGS = {
DEFAULT = 0,
ACCOUNT = 1,
CHARACTER = 2
}

--- Modifiers and keys that we shouldn't bind to.
---
-- Modifiers and keys that we shouldn't bind to.
--
local EXCLUDED_KEYS = {
"LSHIFT",
"RSHIFT",
Expand All @@ -38,8 +37,8 @@ local EXCLUDED_KEYS = {
"RightButton"
}

--- Prefixes for action bars.
---
-- Prefixes for action bars.
--
local ACTIONBAR_PREFIXES = {
"MultiBarBottomLeftButton",
"MultiBarBottomRightButton",
Expand All @@ -52,16 +51,12 @@ local ACTIONBAR_PREFIXES = {
"PetActionButton"
}

--- FastbindFrameMixin declaration.
--- @class FastbindFrameMixin: Frame
--- @field isActive boolean
--- @field button Button
--- @field command string
---
-- Fastbind frame mixin.
--
FastbindFrameMixin = {}

--- Initialize frame.
---
-- Initialize frame.
--
function FastbindFrameMixin:OnLoad()
StaticPopupDialogs[FASTBIND] = {
text =
Expand Down Expand Up @@ -174,8 +169,8 @@ function FastbindFrameMixin:Update()
end

function FastbindFrameMixin:ClearButton()
self.button = nil
self.command = nil
self.button = nil

self:Hide()

Expand All @@ -187,7 +182,7 @@ function FastbindFrameMixin:SetButton(button)
local type = GetActionInfo(button.action)

-- We wouldn't want to bind the flyout button, only the spells inside it.
if (type == "flyout") then
if type == "flyout" then
return
end
end
Expand Down Expand Up @@ -238,7 +233,7 @@ function FastbindFrameMixin:SetButton(button)
command = self.command,
})

if (self.command) then
if self.command then
self.button = button
self:ClearAllPoints()
self:SetAllPoints(button)
Expand All @@ -254,17 +249,17 @@ function FastbindFrameMixin:ClearButtonBindings()
end

function FastbindFrameMixin:SetBinding(key)
if (not self.button) then
if not self.button then
api.Printf("No button is set.")
return
end

if (key == "RightButton") then
if key == "RightButton" then
self:ClearButtonBindings()
end

for i = 1, #EXCLUDED_KEYS do
if (key == EXCLUDED_KEYS[i]) then
if key == EXCLUDED_KEYS[i] then
api.Printf("Can't bind excluded key '%s'", key)
return
end
Expand Down Expand Up @@ -316,7 +311,7 @@ function FastbindFrameMixin:HookButton(name)
end

function FastbindFrameMixin:HookBindables()
for _, prefix in ipairs(ACTIONBAR_PREFIXES) do
for _, prefix in ipairs(ACTIONBAR_PREFIXES) do
local index = 1
while self:HookButton(prefix .. index) do
index = index + 1
Expand Down
Loading

0 comments on commit 6e893a0

Please sign in to comment.