Repository navigation
Expand file tree
/
Copy pathBind.lua
More file actions
166 lines (149 loc) · 6.43 KB
/
Copy pathBind.lua
File metadata and controls
166 lines (149 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
local ADDON, ns = ...
-- The keys our buttons are pressed with.
--
-- === Why this is our concern at all ===
--
-- A player sets their bindings once and for the character's life: "1" is the
-- first slot of the main bar, "shift-3" the third on the bar below. A binding
-- belongs to the SLOT rather than to a button: the game presses its own
-- button, that looks into the slot, and the spell fires.
--
-- The game does not know our buttons. Do nothing and "1" will keep pressing
-- the game's button - hidden but alive - and everything will work. But
-- everything else will stop: the pressed highlight, the cooldown, the
-- unavailability feedback will all be on a button nobody can see.
--
-- So the binding is routed: the key that pressed the game's button starts
-- pressing ours. That routing is an override, not an edit of the player's
-- settings: switch the addon off and they get their bindings untouched.
--
-- === What is pure here ===
--
-- Names. What the game's action for this slot is called and what a click on
-- our button is called - two strings, both assembled by a rule that has a
-- right answer. A typo in them produces neither an error nor a trace in the
-- log: the key simply stops working, and the player finds out in combat.
local Bind = {}
ns.Bind = Bind
-- The game's action names for bar slots.
--
-- There are ten sets of twelve and they are not named alike: page one is
-- "ACTIONBUTTON1", page two "MULTIACTIONBAR1BUTTON1" and so on. The names are
-- the game's and live in the core's compatibility layer; only the prefix
-- arrives here, with the number appended to it.
--
-- A prefix per page rather than per bar: a binding belongs to a slot and a
-- slot to a page. A bar is a window, and a slot may have any number of windows.
local PREFIX = {
[1] = "ACTIONBUTTON",
[2] = "ACTIONBUTTON",
[3] = "MULTIACTIONBAR3BUTTON",
[4] = "MULTIACTIONBAR4BUTTON",
[5] = "MULTIACTIONBAR2BUTTON",
[6] = "MULTIACTIONBAR1BUTTON",
}
Bind.PREFIX = PREFIX
--- The game's action name for this bar slot.
--
-- Pure. Pages with no bindings of their own (seven and up - stances and forms)
-- answer with nothing: the game hands out no keys for them, because they use
-- the same keys as page one.
--
-- @param page any page number
-- @param index any button index on the page, from one
-- @return string|nil
function Bind.ActionName(page, index)
local number = tonumber(index)
if number == nil then return nil end
number = math.floor(number)
if number < 1 or number > 12 then return nil end
local prefix = PREFIX[tonumber(page) or 0]
if prefix == nil then return nil end
return prefix .. number
end
--- The name of a click on our button.
--
-- The engine can bind a key to a click on a named frame, and that is the only
-- way to press our button with a key without touching the player's settings.
-- That is what a button gets a name for - a nameless one cannot be pressed.
--
-- @param buttonName any the button frame's name
-- @param mouse string|nil which mouse button; left by default
-- @return string|nil
function Bind.ClickName(buttonName, mouse)
if type(buttonName) ~= "string" or buttonName == "" then return nil end
local which = type(mouse) == "string" and mouse ~= "" and mouse
or "LeftButton"
return "CLICK " .. buttonName .. ":" .. which
end
--- The name of our button's frame.
--
-- The name is assembled from the bar's key and the index, and assembled by ONE
-- place: the button's name is needed at creation and when binding a key, and
-- two spellings drifting apart would break the key silently.
--
-- @param bar any bar key
-- @param index any button index
-- @return string|nil
function Bind.ButtonName(bar, index)
if type(bar) ~= "string" or bar == "" then return nil end
local number = tonumber(index)
if number == nil then return nil end
return "RackBar_" .. bar .. "_" .. math.floor(number)
end
--- Whose button this is.
--
-- Asked of the button itself rather than of the bar settings: creation marks
-- the button (Build.Button) and the mark travels with it. Settings have to be
-- found by key, and a key is one more way to answer a question the button can
-- already answer.
--
-- Lives here rather than where it is asked: it is asked in three places -
-- tooltip, dragging and key binding - and three answers to one question would
-- drift at the first new bar.
--
-- @param button any
-- @return string|nil "pet", "stance" or "action"
function Bind.Kind(button)
if type(button) ~= "table" then return nil end
if button.rackPetIndex ~= nil then return "pet" end
if button.rackStanceIndex ~= nil then return "stance" end
if button.rackBar ~= nil then return "action" end
return nil
end
--- The game's action name for this button of this bar.
--
-- The one place where three counts meet: action bar slots, pet actions and
-- stances. They have to meet here rather than in two places separately: key
-- routing and the binding mode ask the same thing, and were their answers to
-- drift, the window would show one key while another pressed.
--
-- @param key any bar key
-- @param index any button index
-- @return string|nil
function Bind.For(key, index)
if type(key) ~= "string" then return nil end
if key == "pet" then return ns.Pet.ActionName(index) end
if key == "stance" then return ns.Stance.ActionName(index) end
-- The page the bindings are taken from. For a bar without paging that is
-- its own page; for the main bar it is page one: the stance pages use the
-- same keys as page one and have none of their own.
--
-- === The slot offset is NOT taken into account here, and that is a
-- decision ===
--
-- At offset six the bar's first button shows the seventh slot. The question
-- arises: does the key bound to the first slot press the first BUTTON, or
-- the one showing the first slot - that is, the seventh?
--
-- It presses the first button. The player's hand remembers a physical
-- place: "this key is the leftmost on this bar", and the slot offset is
-- about WHAT lies on it rather than about what presses it. A key that moved
-- with the slot would mean a content setting silently reshuffling the
-- player's whole muscle memory.
--
-- Bartender behaves the same way, and this is the rare case worth naming
-- the agreement for: the question is not obvious, and diverging here would
-- mean re-teaching anyone who came from there.
return Bind.ActionName(ns.Slots.FIRST_PAGE[key] or 1, index)
end