@piekasz/wow-mcp 0.0.0-stage → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/LICENSE +674 -0
  2. package/NOTICE +37 -0
  3. package/README.md +41 -2
  4. package/addon/WowMcp/AuctionTooltip.lua +106 -0
  5. package/addon/WowMcp/Commands.lua +259 -0
  6. package/addon/WowMcp/Compat.lua +167 -0
  7. package/addon/WowMcp/Core.lua +50 -0
  8. package/addon/WowMcp/Events.lua +62 -0
  9. package/addon/WowMcp/Items.lua +314 -0
  10. package/addon/WowMcp/Maps.lua +66 -0
  11. package/addon/WowMcp/MinimapButton.lua +114 -0
  12. package/addon/WowMcp/Options.lua +208 -0
  13. package/addon/WowMcp/Panel.lua +294 -0
  14. package/addon/WowMcp/QuestDb.lua +303 -0
  15. package/addon/WowMcp/QuestRewards.lua +137 -0
  16. package/addon/WowMcp/Sections/ActionBars.lua +54 -0
  17. package/addon/WowMcp/Sections/Auctions.lua +305 -0
  18. package/addon/WowMcp/Sections/Bank.lua +48 -0
  19. package/addon/WowMcp/Sections/Buyback.lua +47 -0
  20. package/addon/WowMcp/Sections/Character.lua +177 -0
  21. package/addon/WowMcp/Sections/Cooldowns.lua +76 -0
  22. package/addon/WowMcp/Sections/Currencies.lua +47 -0
  23. package/addon/WowMcp/Sections/Deaths.lua +43 -0
  24. package/addon/WowMcp/Sections/Dungeons.lua +117 -0
  25. package/addon/WowMcp/Sections/EquipmentSets.lua +83 -0
  26. package/addon/WowMcp/Sections/FlightPaths.lua +145 -0
  27. package/addon/WowMcp/Sections/Friends.lua +70 -0
  28. package/addon/WowMcp/Sections/Group.lua +101 -0
  29. package/addon/WowMcp/Sections/Guide.lua +317 -0
  30. package/addon/WowMcp/Sections/Guild.lua +131 -0
  31. package/addon/WowMcp/Sections/Inspect.lua +100 -0
  32. package/addon/WowMcp/Sections/Inventory.lua +64 -0
  33. package/addon/WowMcp/Sections/Legacy.lua +375 -0
  34. package/addon/WowMcp/Sections/Loot.lua +170 -0
  35. package/addon/WowMcp/Sections/Macros.lua +26 -0
  36. package/addon/WowMcp/Sections/Mail.lua +70 -0
  37. package/addon/WowMcp/Sections/Note.lua +38 -0
  38. package/addon/WowMcp/Sections/Pet.lua +127 -0
  39. package/addon/WowMcp/Sections/Played.lua +52 -0
  40. package/addon/WowMcp/Sections/Probe.lua +79 -0
  41. package/addon/WowMcp/Sections/Professions.lua +129 -0
  42. package/addon/WowMcp/Sections/Pvp.lua +45 -0
  43. package/addon/WowMcp/Sections/QuestDb.lua +106 -0
  44. package/addon/WowMcp/Sections/QuestGiver.lua +45 -0
  45. package/addon/WowMcp/Sections/Quests.lua +146 -0
  46. package/addon/WowMcp/Sections/Recipes.lua +195 -0
  47. package/addon/WowMcp/Sections/Reputation.lua +56 -0
  48. package/addon/WowMcp/Sections/Spells.lua +87 -0
  49. package/addon/WowMcp/Sections/Stable.lua +90 -0
  50. package/addon/WowMcp/Sections/Talents.lua +137 -0
  51. package/addon/WowMcp/Sections/Trainer.lua +58 -0
  52. package/addon/WowMcp/Sections/Vendor.lua +72 -0
  53. package/addon/WowMcp/Sections/XpGains.lua +258 -0
  54. package/addon/WowMcp/Snapshot.lua +412 -0
  55. package/addon/WowMcp/Store.lua +142 -0
  56. package/addon/WowMcp/TalentGrid.lua +171 -0
  57. package/addon/WowMcp/Timing.lua +61 -0
  58. package/addon/WowMcp/TraitTree.lua +158 -0
  59. package/addon/WowMcp/WowMcp.lua +24 -0
  60. package/addon/WowMcp/WowMcp.toc +72 -0
  61. package/bin/wow-mcp.js +248 -0
  62. package/package.json +41 -4
@@ -0,0 +1,62 @@
1
+ -- SPDX-License-Identifier: GPL-3.0-or-later
2
+ -- Copyright (C) 2026 Piekasz (GitHub: Piekario). Author attribution must be kept: see NOTICE.
3
+
4
+ -- Game events: one frame and an event -> handlers table.
5
+ -- Modules register through Events.on instead of knowing one shared table.
6
+ --
7
+ -- Each handler runs in pcall: an error in one (e.g. the vendor's) does not stop the next
8
+ -- ones for the same event (e.g. the buyback list). Errors go to Events.errors(),
9
+ -- and the dump appends them to the errors field so they are visible without the Lua error popup.
10
+
11
+ local _, ns = ...
12
+
13
+ local Events = {}
14
+ ns.Events = Events
15
+
16
+ local MAX_ERRORS = 10
17
+
18
+ local handlersByEvent = {}
19
+ local registration = {} -- event -> whether the client accepted RegisterEvent
20
+ local handlerErrors = {} -- "event: error" strings from this session (no repeats), at most MAX_ERRORS
21
+ local seenErrors = {}
22
+ local frame = CreateFrame("Frame")
23
+
24
+ local function rememberError(event, err)
25
+ local text = "event " .. tostring(event) .. ": " .. tostring(err)
26
+ if seenErrors[text] or #handlerErrors >= MAX_ERRORS then return end
27
+ seenErrors[text] = true
28
+ handlerErrors[#handlerErrors + 1] = text
29
+ end
30
+
31
+ frame:SetScript("OnEvent", function(_, event, ...)
32
+ local handlers = handlersByEvent[event]
33
+ if not handlers then return end
34
+ for _, handler in ipairs(handlers) do
35
+ local ok, err = pcall(handler, ...)
36
+ if not ok then rememberError(event, err) end
37
+ end
38
+ end)
39
+
40
+ function Events.on(event, handler)
41
+ if not handlersByEvent[event] then
42
+ handlersByEvent[event] = {}
43
+ -- An unknown event name raises an error in new clients, hence pcall.
44
+ registration[event] = pcall(frame.RegisterEvent, frame, event) and true or false
45
+ end
46
+ local handlers = handlersByEvent[event]
47
+ handlers[#handlers + 1] = handler
48
+ end
49
+
50
+ -- Copy of each addon event's registration result (true = the client accepted it); for /mcp probe.
51
+ function Events.registrationResults()
52
+ local copy = {}
53
+ for event, accepted in pairs(registration) do copy[event] = accepted end
54
+ return copy
55
+ end
56
+
57
+ -- Copy of event handler errors from this session (since login or /reload).
58
+ function Events.errors()
59
+ local copy = {}
60
+ for i, text in ipairs(handlerErrors) do copy[i] = text end
61
+ return copy
62
+ end
@@ -0,0 +1,314 @@
1
+ -- SPDX-License-Identifier: GPL-3.0-or-later
2
+ -- Copyright (C) 2026 Piekasz (GitHub: Piekario). Author attribution must be kept: see NOTICE.
3
+
4
+ -- Items: hyperlink parsing, item details and container contents.
5
+ -- Shared by bags, equipment, bank, vendor, mail, auctions and Inspect.
6
+
7
+ local _, ns = ...
8
+ local plain, callFirst, firstValue = ns.Compat.plain, ns.Compat.callFirst, ns.Compat.firstValue
9
+ local round1 = ns.round1
10
+
11
+ local Items = {}
12
+ ns.Items = Items
13
+
14
+ -- Equipment slot names by API slot number.
15
+ Items.EQUIPMENT_SLOTS = {
16
+ [0] = "ammo", [1] = "head", [2] = "neck", [3] = "shoulder", [4] = "shirt", [5] = "chest",
17
+ [6] = "waist", [7] = "legs", [8] = "feet", [9] = "wrist", [10] = "hands",
18
+ [11] = "finger1", [12] = "finger2", [13] = "trinket1", [14] = "trinket2",
19
+ [15] = "back", [16] = "mainHand", [17] = "offHand", [18] = "ranged", [19] = "tabard",
20
+ }
21
+
22
+ -- They can be equipped, but are not gear to compare against equipment.
23
+ local NOT_GEAR = { INVTYPE_BAG = true, INVTYPE_QUIVER = true, INVTYPE_AMMO = true }
24
+
25
+ -- Item name from a hyperlink: "...|h[Name]|h..." -> "Name"
26
+ function Items.nameFromLink(link)
27
+ if type(link) ~= "string" then return nil end
28
+ return link:match("%[(.-)%]")
29
+ end
30
+
31
+ -- Item ID from a hyperlink: "|Hitem:12345:..." -> 12345
32
+ function Items.idFromLink(link)
33
+ if type(link) ~= "string" then return nil end
34
+ local id = link:match("item:(%d+)")
35
+ return id and tonumber(id) or nil
36
+ end
37
+
38
+ -- Numeric identifiers that are the same in every client language (Enum.ItemClass, the item subclass, Enum.ItemBind):
39
+ -- the server classifies items by them, and the type/subType text is only for reading.
40
+ local function addClassIDs(item, info, link)
41
+ item.classID = plain(info[12])
42
+ item.subclassID = plain(info[13])
43
+ item.bindType = plain(info[14])
44
+ if item.classID == nil then
45
+ -- GetItemInfoInstant: itemID, type, subType, equipLoc, icon, classID, subclassID (no server query).
46
+ local instant = callFirst({ "C_Item.GetItemInfoInstant", "GetItemInfoInstant" }, link)
47
+ if instant then
48
+ item.classID = plain(instant[6])
49
+ item.subclassID = plain(instant[7])
50
+ end
51
+ end
52
+ if type(item.classID) ~= "number" then item.classID, item.subclassID = nil, nil end
53
+ if type(item.bindType) ~= "number" then item.bindType = nil end
54
+ end
55
+
56
+ local function addItemInfo(item, link)
57
+ local info = callFirst({ "C_Item.GetItemInfo", "GetItemInfo" }, link)
58
+ if not (info and info[1]) then return end
59
+ if item.quality == nil then item.quality = plain(info[3]) end
60
+ addClassIDs(item, info, link)
61
+ item.itemLevel = plain(info[4])
62
+ item.requiredLevel = plain(info[5])
63
+ item.type = plain(info[6])
64
+ item.subType = plain(info[7])
65
+ local equipLoc = plain(info[9])
66
+ -- INVTYPE_NON_EQUIP_IGNORE means "cannot be equipped", i.e. the same as no field.
67
+ if type(equipLoc) == "string" and equipLoc ~= "" and equipLoc ~= "INVTYPE_NON_EQUIP_IGNORE" then
68
+ item.equipLoc = equipLoc
69
+ end
70
+ item.sellPrice = plain(info[11])
71
+ end
72
+
73
+ local function addItemStats(item, link)
74
+ local stats = callFirst({ "C_Item.GetItemStats", "GetItemStats" }, link)
75
+ if not (stats and type(stats[1]) == "table") then return end
76
+ local out, tokens, any = {}, {}, false
77
+ for key, amount in pairs(stats[1]) do
78
+ if type(key) == "string" and type(plain(amount)) == "number" then
79
+ -- Keys like ITEM_MOD_AGILITY_SHORT have readable names in global variables (in the client's language);
80
+ -- statTokens keeps the keys themselves, which are the same in every language.
81
+ local label = _G[key]
82
+ out[type(label) == "string" and label or key] = round1(amount)
83
+ tokens[key] = round1(amount)
84
+ any = true
85
+ end
86
+ end
87
+ if any then item.stats, item.statTokens = out, tokens end
88
+ end
89
+
90
+ -- Adds type, level, sell price and stats to the item.
91
+ function Items.addDetails(item, link)
92
+ if type(link) ~= "string" then return end
93
+ addItemInfo(item, link)
94
+ addItemStats(item, link)
95
+ end
96
+
97
+ -- Weapon DPS from the stat tokens (no tooltip needed): GetItemStats gives ITEM_MOD_DAMAGE_PER_SECOND_SHORT for weapons.
98
+ local function addStatDps(item)
99
+ local dps = item.statTokens and item.statTokens.ITEM_MOD_DAMAGE_PER_SECOND_SHORT
100
+ if type(dps) == "number" then item.dps = round1(dps) end
101
+ end
102
+
103
+ -- What GetItemInfoInstant knows from the item ID alone (it reads the client's static tables and never queries the server).
104
+ local function addInstantInfo(item, itemID)
105
+ local instant = callFirst({ "C_Item.GetItemInfoInstant", "GetItemInfoInstant" }, itemID)
106
+ if not instant then return end
107
+ item.type = plain(instant[2])
108
+ item.subType = plain(instant[3])
109
+ local equipLoc = plain(instant[4])
110
+ if type(equipLoc) == "string" and equipLoc ~= "" and equipLoc ~= "INVTYPE_NON_EQUIP_IGNORE" then
111
+ item.equipLoc = equipLoc
112
+ end
113
+ item.classID = plain(instant[6])
114
+ item.subclassID = plain(instant[7])
115
+ if type(item.classID) ~= "number" then item.classID, item.subclassID = nil, nil end
116
+ end
117
+
118
+ -- Whether the client already holds the item's data. IsItemDataCachedByID only looks in the local cache (no request);
119
+ -- when the client lacks the function we cannot tell, so we treat the data as not cached.
120
+ local function isItemDataCached(itemID)
121
+ local result = callFirst({ "C_Item.IsItemDataCachedByID", "IsItemDataCachedByID" }, itemID)
122
+ return result ~= nil and plain(result[1]) == true
123
+ end
124
+
125
+ -- Details of an item known only by ID (auction results), taken ONLY from what the client already holds. GetItemInfo and
126
+ -- GetItemStats on an uncached item may ask the server to load it, so they run only after IsItemDataCachedByID says the data
127
+ -- is local. Without cached data only the static GetItemInfoInstant fields are filled; never a request, an event wait or a
128
+ -- tooltip. No tooltip text, so weapon DPS comes from the stat tokens and there is no speed or damage range.
129
+ -- gearOnly: stop after the static fields when the item is not gear (keeps a bounded section small).
130
+ function Items.addCachedDetails(item, itemID, gearOnly)
131
+ if type(itemID) ~= "number" then return end
132
+ local itemString = "item:" .. itemID
133
+ pcall(addInstantInfo, item, itemID)
134
+ if gearOnly and not Items.isGear(item) then
135
+ item.type, item.subType, item.classID, item.subclassID = nil, nil, nil, nil
136
+ return
137
+ end
138
+ if not isItemDataCached(itemID) then return end
139
+ pcall(addItemInfo, item, itemString)
140
+ pcall(addItemStats, item, itemString)
141
+ addStatDps(item)
142
+ end
143
+
144
+ -- Weapon numbers (0.10.0): damage range, speed and DPS as numbers, so the server does not read English tooltip text.
145
+ -- Damage and DPS lines are found with the client's own format strings (DAMAGE_TEMPLATE "%s - %s Damage",
146
+ -- DPS_TEMPLATE "(%s damage per second)"); speed is the right-hand part of the damage line (where the client puts it,
147
+ -- in every language) or, when it stands alone, the number after the client's WEAPON_SPEED label.
148
+ local NUMBER = "([%d]+[%.,]?%d*)"
149
+
150
+ -- "1.60" or "1,60" (a decimal comma) -> 1.6; the first number in the text.
151
+ local function parseNumber(text)
152
+ local digits = type(text) == "string" and text:match("%d+[%.,]?%d*")
153
+ if not digits then return nil end
154
+ return tonumber((digits:gsub(",", ".")))
155
+ end
156
+
157
+ -- Lua pattern from a game format string: each %s, %d or %1$s becomes a number capture (not anchored).
158
+ local function numberPattern(format)
159
+ local marked = format:gsub("%%%d?%$?[sd]", "\1")
160
+ local escaped = marked:gsub("[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%0")
161
+ return (escaped:gsub("\1", function() return NUMBER end))
162
+ end
163
+
164
+ local function findDamage(lines)
165
+ local template = _G.DAMAGE_TEMPLATE
166
+ if type(template) ~= "string" then return nil end
167
+ local pattern = numberPattern(template)
168
+ for _, line in ipairs(lines) do
169
+ if type(line) == "string" then
170
+ local low, high = line:match(pattern)
171
+ low, high = parseNumber(low), parseNumber(high)
172
+ if low and high and high > 0 then return low, high, line end
173
+ end
174
+ end
175
+ return nil
176
+ end
177
+
178
+ local function findSpeed(lines, damageLine)
179
+ local right = damageLine:match(" | (.+)$")
180
+ local speed = parseNumber(right)
181
+ local label = _G.WEAPON_SPEED
182
+ if not speed and type(label) == "string" and label ~= "" then
183
+ for _, line in ipairs(lines) do
184
+ local at = type(line) == "string" and line:find(label, 1, true)
185
+ if at then speed = parseNumber(line:sub(at + #label)) end
186
+ if speed then break end
187
+ end
188
+ end
189
+ if speed and speed >= 0.3 and speed <= 10 then return speed end
190
+ return nil
191
+ end
192
+
193
+ local function findTooltipDps(lines)
194
+ local template = _G.DPS_TEMPLATE
195
+ if type(template) ~= "string" then return nil end
196
+ local pattern = numberPattern(template)
197
+ for _, line in ipairs(lines) do
198
+ local dps = type(line) == "string" and parseNumber(line:match(pattern))
199
+ if dps then return dps end
200
+ end
201
+ return nil
202
+ end
203
+
204
+ local function addWeaponNumbers(item)
205
+ local lines = item.tooltip
206
+ if type(lines) ~= "table" then return end
207
+ local low, high, damageLine = findDamage(lines)
208
+ if not low then return end
209
+ local speed = findSpeed(lines, damageLine)
210
+ item.damageMin, item.damageMax = low, high
211
+ item.speed = speed and (math.floor(speed * 100 + 0.5) / 100) or nil
212
+ local dps = item.statTokens and item.statTokens.ITEM_MOD_DAMAGE_PER_SECOND_SHORT
213
+ dps = dps or findTooltipDps(lines) or (speed and (low + high) / 2 / speed)
214
+ item.dps = round1(dps)
215
+ end
216
+
217
+ -- Sets the tooltip lines and, for weapons, the numbers read from them (speed, dps, damageMin, damageMax).
218
+ function Items.attachTooltip(item, lines)
219
+ item.tooltip = lines
220
+ if lines then pcall(addWeaponNumbers, item) end
221
+ end
222
+
223
+ -- Whether the item (after addDetails) is gear to compare against equipment.
224
+ function Items.isGear(item)
225
+ return item.equipLoc ~= nil and not NOT_GEAR[item.equipLoc]
226
+ end
227
+
228
+ -- Details of an item known only by ID or link (e.g. a quest reward): type, level,
229
+ -- stats, and for gear the tooltip. readTooltip supplies the tooltip from a window; without it the tooltip is read by ID.
230
+ function Items.describe(item, link, readTooltip)
231
+ item.id = item.id or Items.idFromLink(link)
232
+ item.name = item.name or Items.nameFromLink(link)
233
+ local itemString = link or (item.id and ("item:" .. item.id))
234
+ pcall(Items.addDetails, item, itemString)
235
+ if Items.isGear(item) then
236
+ Items.attachTooltip(item, (readTooltip and readTooltip()) or (item.id and ns.Compat.tooltipFor("GetItemByID", item.id)))
237
+ end
238
+ return item
239
+ end
240
+
241
+ -- Number of the last equipped bag (0 is the backpack).
242
+ function Items.lastEquippedBag()
243
+ return NUM_TOTAL_EQUIPPED_BAG_SLOTS or 5
244
+ end
245
+
246
+ -- Number of slots in a container; 0 if the container does not exist.
247
+ function Items.containerSlotCount(bag)
248
+ local sizeResult = callFirst({ "C_Container.GetContainerNumSlots", "GetContainerNumSlots" }, bag)
249
+ local size = sizeResult and plain(sizeResult[1]) or 0
250
+ return type(size) == "number" and size or 0
251
+ end
252
+
253
+ -- Item in a container slot: itemID, count, quality, link, isBound (nil when the client does not say).
254
+ local function containerItem(bag, slot)
255
+ if C_Container and C_Container.GetContainerItemInfo then
256
+ local info = C_Container.GetContainerItemInfo(bag, slot)
257
+ if type(info) == "table" then
258
+ return plain(info.itemID), plain(info.stackCount), plain(info.quality), plain(info.hyperlink), plain(info.isBound)
259
+ end
260
+ elseif GetContainerItemInfo then
261
+ local _, count, _, quality, _, _, link, _, _, itemID, isBound = GetContainerItemInfo(bag, slot)
262
+ return plain(itemID), plain(count), plain(quality), plain(link), plain(isBound)
263
+ end
264
+ return nil
265
+ end
266
+
267
+ -- Quest data of a container item: isQuestItem and the ID of the quest the item begins (questID).
268
+ -- C_Container.GetContainerItemQuestInfo returns a table, the classic GetContainerItemQuestInfo several values.
269
+ local function addQuestInfo(item, bag, slot)
270
+ local result = callFirst({ "C_Container.GetContainerItemQuestInfo", "GetContainerItemQuestInfo" }, bag, slot)
271
+ if not result then return end
272
+ local isQuestItem, questID
273
+ if type(result[1]) == "table" then
274
+ isQuestItem, questID = plain(result[1].isQuestItem), plain(result[1].questID)
275
+ else
276
+ isQuestItem, questID = plain(result[1]), plain(result[2])
277
+ end
278
+ if isQuestItem == true then item.isQuestItem = true end
279
+ if type(questID) == "number" and questID > 0 then item.questID = questID end
280
+ end
281
+
282
+ -- Contents of one container (a bag or a bank tab).
283
+ function Items.scanContainer(bag)
284
+ local size = Items.containerSlotCount(bag)
285
+ if size <= 0 then return nil end
286
+
287
+ local container = { index = bag, size = size, items = {} }
288
+ container.name = firstValue({ "C_Container.GetBagName", "GetBagName" }, bag)
289
+ local used = 0
290
+ for slot = 1, size do
291
+ local itemID, count, quality, link, isBound = containerItem(bag, slot)
292
+ if itemID or link then
293
+ used = used + 1
294
+ local item = {
295
+ slot = slot,
296
+ id = itemID or Items.idFromLink(link),
297
+ name = Items.nameFromLink(link),
298
+ count = count or 1,
299
+ quality = quality,
300
+ }
301
+ isBound = plain(isBound)
302
+ if type(isBound) == "boolean" then item.isBound = isBound end
303
+ pcall(addQuestInfo, item, bag, slot)
304
+ pcall(Items.addDetails, item, link)
305
+ -- Full description only for equippable things, so they can be compared against equipment.
306
+ if Items.isGear(item) then
307
+ Items.attachTooltip(item, ns.Compat.tooltipFor("GetBagItem", bag, slot))
308
+ end
309
+ container.items[#container.items + 1] = item
310
+ end
311
+ end
312
+ container.free = size - used
313
+ return container
314
+ end
@@ -0,0 +1,66 @@
1
+ -- SPDX-License-Identifier: GPL-3.0-or-later
2
+ -- Copyright (C) 2026 Piekasz (GitHub: Piekario). Author attribution must be kept: see NOTICE.
3
+
4
+ -- Maps: zone map IDs (UiMapID) by zone name, so the dump carries a number that is the same in every client language
5
+ -- (quest log headers and flight points only have the translated zone name). Only reads map data (C_Map).
6
+
7
+ local _, ns = ...
8
+ local plain = ns.Compat.plain
9
+
10
+ local Maps = {}
11
+ ns.Maps = Maps
12
+
13
+ local CONTINENT_MAP_TYPE = 2 -- Enum.UIMapType.Continent
14
+ local ZONE_MAP_TYPE = 3 -- Enum.UIMapType.Zone
15
+ local MAX_PARENT_STEPS = 10
16
+
17
+ function Maps.mapType(name, default)
18
+ local types = Enum and Enum.UIMapType
19
+ return (types and types[name]) or default
20
+ end
21
+
22
+ -- Continent the character is on (the player's map and its parents); nil when the client does not supply it.
23
+ function Maps.playerContinent()
24
+ if not (C_Map and C_Map.GetBestMapForUnit and C_Map.GetMapInfo) then return nil end
25
+ local mapID = plain(C_Map.GetBestMapForUnit("player"))
26
+ for _ = 1, MAX_PARENT_STEPS do
27
+ if not mapID then return nil end
28
+ local ok, info = pcall(C_Map.GetMapInfo, mapID)
29
+ if not (ok and type(info) == "table") then return nil end
30
+ if plain(info.mapType) == Maps.mapType("Continent", CONTINENT_MAP_TYPE) then return mapID end
31
+ mapID = plain(info.parentMapID)
32
+ end
33
+ return nil
34
+ end
35
+
36
+ -- Children of a map of the given type (all descendants); an empty list when the client has none.
37
+ local function children(mapID, typeName, default)
38
+ if not (mapID and C_Map and C_Map.GetMapChildrenInfo) then return {} end
39
+ local ok, list = pcall(C_Map.GetMapChildrenInfo, mapID, Maps.mapType(typeName, default), true)
40
+ return (ok and type(list) == "table") and list or {}
41
+ end
42
+
43
+ local function addZones(names, mapID)
44
+ for _, zone in ipairs(children(mapID, "Zone", ZONE_MAP_TYPE)) do
45
+ local id, name = plain(zone.mapID), plain(zone.name)
46
+ if id and type(name) == "string" and name ~= "" and names[name] == nil then names[name] = id end
47
+ end
48
+ end
49
+
50
+ -- Zone name -> map ID for the zones of the world map's continents and of the player's continent. Built on demand
51
+ -- (a few C_Map calls) and returned as a plain table; empty when the client has no map API.
52
+ function Maps.zoneIDsByName()
53
+ local names = {}
54
+ local ok, worldID = pcall(function() return C_Map and C_Map.GetFallbackWorldMapID and plain(C_Map.GetFallbackWorldMapID()) end)
55
+ local continents = {}
56
+ if ok and worldID then
57
+ for _, continent in ipairs(children(worldID, "Continent", CONTINENT_MAP_TYPE)) do
58
+ continents[#continents + 1] = plain(continent.mapID)
59
+ end
60
+ end
61
+ local own = Maps.playerContinent()
62
+ if own then continents[#continents + 1] = own end
63
+ for _, continentID in ipairs(continents) do addZones(names, continentID) end
64
+ return names
65
+ end
66
+
@@ -0,0 +1,114 @@
1
+ -- SPDX-License-Identifier: GPL-3.0-or-later
2
+ -- Copyright (C) 2026 Piekasz (GitHub: Piekario). Author attribution must be kept: see NOTICE.
3
+
4
+ -- Minimap button: left click shows or hides the panel (the same as /mcp panel).
5
+ -- Saves and reloads nothing; right click does nothing. The player can drag it
6
+ -- around the minimap. Disabled by /mcp minimap off (setting minimap = false).
7
+ -- Created in pcall: when that fails (another client, no minimap), there is simply no button.
8
+
9
+ local _, ns = ...
10
+ local Store, Panel = ns.Store, ns.Panel
11
+
12
+ local MinimapButton = {}
13
+ ns.MinimapButton = MinimapButton
14
+
15
+ local RADIUS = 80
16
+ local DEFAULT_ANGLE = 225 -- degrees, bottom-left corner of the minimap
17
+ local button
18
+
19
+ local function angleSetting()
20
+ local angle = tonumber(Store.settings().minimapAngle)
21
+ return angle or DEFAULT_ANGLE
22
+ end
23
+
24
+ local function place(angleDegrees)
25
+ local radians = math.rad(angleDegrees)
26
+ button:ClearAllPoints()
27
+ button:SetPoint("CENTER", Minimap, "CENTER", math.cos(radians) * RADIUS, math.sin(radians) * RADIUS)
28
+ end
29
+
30
+ -- Angle from the minimap center to the cursor (degrees). Only reads the mouse position.
31
+ local function cursorAngle()
32
+ local centerX, centerY = Minimap:GetCenter()
33
+ local cursorX, cursorY = GetCursorPosition()
34
+ local scale = Minimap:GetEffectiveScale()
35
+ if not (centerX and cursorX and scale and scale > 0) then return nil end
36
+ local atan2 = math.atan2 or math.atan
37
+ return math.deg(atan2(cursorY / scale - centerY, cursorX / scale - centerX))
38
+ end
39
+
40
+ local function startDrag(self)
41
+ self:SetScript("OnUpdate", function()
42
+ local angle = cursorAngle()
43
+ if angle then
44
+ Store.settings().minimapAngle = angle
45
+ place(angle)
46
+ end
47
+ end)
48
+ end
49
+
50
+ local function stopDrag(self)
51
+ self:SetScript("OnUpdate", nil)
52
+ end
53
+
54
+ local function showTooltip(self)
55
+ if not GameTooltip then return end
56
+ GameTooltip:SetOwner(self, "ANCHOR_LEFT")
57
+ GameTooltip:SetText("WowMcp")
58
+ GameTooltip:AddLine("Left click: show or hide the panel", 1, 1, 1)
59
+ GameTooltip:AddLine("Only the Save button on the panel saves", 0.7, 0.7, 0.7)
60
+ GameTooltip:Show()
61
+ end
62
+
63
+ local function build()
64
+ local b = CreateFrame("Button", "WowMcpMinimapButton", Minimap)
65
+ b:SetSize(28, 28)
66
+ b:SetFrameStrata("MEDIUM")
67
+ b:SetFrameLevel(8)
68
+ local icon = b:CreateTexture(nil, "ARTWORK")
69
+ icon:SetTexture("Interface\\Icons\\INV_Misc_Book_09")
70
+ icon:SetSize(18, 18)
71
+ icon:SetPoint("CENTER", b, "CENTER", 0, 0)
72
+ local ring = b:CreateTexture(nil, "OVERLAY")
73
+ ring:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
74
+ ring:SetSize(52, 52)
75
+ ring:SetPoint("TOPLEFT", b, "TOPLEFT", 0, 0)
76
+ b:RegisterForClicks("LeftButtonUp", "RightButtonUp")
77
+ b:RegisterForDrag("LeftButton")
78
+ b:SetScript("OnClick", function(_, mouseButton)
79
+ if mouseButton == "LeftButton" then Panel.toggle() end
80
+ end)
81
+ b:SetScript("OnDragStart", startDrag)
82
+ b:SetScript("OnDragStop", stopDrag)
83
+ b:SetScript("OnEnter", showTooltip)
84
+ b:SetScript("OnLeave", function() if GameTooltip then GameTooltip:Hide() end end)
85
+ return b
86
+ end
87
+
88
+ -- Creates the button (once) or shows it; returns the frame or nil. Does nothing when minimap = false.
89
+ function MinimapButton.create()
90
+ if Store.settings().minimap == false then return nil end
91
+ if not (CreateFrame and Minimap) then return nil end
92
+ if not button then
93
+ button = build()
94
+ place(angleSetting())
95
+ end
96
+ button:Show()
97
+ return button
98
+ end
99
+
100
+ function MinimapButton.isEnabled()
101
+ return Store.settings().minimap ~= false
102
+ end
103
+
104
+ -- /mcp minimap on|off
105
+ function MinimapButton.setEnabled(enabled)
106
+ if enabled then
107
+ Store.settings().minimap = nil
108
+ local ok, created = pcall(MinimapButton.create)
109
+ return ok and created ~= nil
110
+ end
111
+ Store.settings().minimap = false
112
+ if button then button:Hide() end
113
+ return true
114
+ end