-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworldmap.lua
323 lines (275 loc) · 10.7 KB
/
worldmap.lua
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
--------------------------------------------------------------------------------
--[[ worldmap.lua - A collection of utilities for the World Map. ]]--
--
-- by erglo <[email protected]>
--
-- Copyright (C) 2024 Erwin D. Glockner (aka erglo)
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see http://www.gnu.org/licenses.
--
-- Further reading:
-- ================
-- REF.: <https://www.townlong-yak.com/framexml/live/Blizzard_APIDocumentationGenerated/MapConstantsDocumentation.lua>
-- REF.: <https://www.townlong-yak.com/framexml/live/Blizzard_APIDocumentationGenerated/MapDocumentation.lua>
-- REF.: <https://www.townlong-yak.com/framexml/live/Blizzard_SharedMapDataProviders/WaypointLocationDataProvider.lua>
-- REF.: <https://www.townlong-yak.com/framexml/live/Blizzard_WorldMap/Blizzard_WorldMapTemplates.lua>
-- REF.: <https://www.townlong-yak.com/framexml/live/Helix/GlobalColors.lua>
-- REF.: <https://www.townlong-yak.com/framexml/live/ObjectAPI/UiMapPoint.lua>
--
--------------------------------------------------------------------------------
local _, ns = ...
local utils = ns.utils or {}
ns.utils = utils
local LocalMapUtils = {}
utils.worldmap = LocalMapUtils
local C_Map = C_Map
local C_SuperTrack = C_SuperTrack
local UiMapPoint = UiMapPoint
----- Constants ----------------------------------------------------------------
-------------------------------------------------- Enum.UIMapType.Cosmic
LocalMapUtils.COSMIC_MAP_ID = 946
-------------------------------------------------- Enum.UIMapType.World
LocalMapUtils.AZEROTH_MAP_ID = 947
-------------------------------------------------- Enum.UIMapType.Continent
LocalMapUtils.KALIMDOR_MAP_ID = 12
LocalMapUtils.EASTERN_KINGDOMS_MAP_ID = 13
LocalMapUtils.OUTLAND_MAP_ID = 101
LocalMapUtils.NORTHREND_MAP_ID = 113
LocalMapUtils.PANDARIA_MAP_ID = 424
LocalMapUtils.DRAENOR_MAP_ID = 572
LocalMapUtils.BROKEN_ISLES_MAP_ID = 619
LocalMapUtils.ZANDALAR_MAP_ID = 875
LocalMapUtils.KUL_TIRAS_MAP_ID = 876
LocalMapUtils.ARGUS_MAP_ID = 905
LocalMapUtils.THE_MAELSTROM_MAP_ID = 948
LocalMapUtils.THE_SHADOWLANDS_MAP_ID = 1550
LocalMapUtils.DRAGON_ISLES_MAP_ID = 1978
-------------------------------------------------- Enum.UIMapType.Zone
----- Dragonflight -----
LocalMapUtils.THE_WAKING_SHORES_MAP_ID = 2022
LocalMapUtils.OHNAHRAN_PLAINS_MAP_ID = 2023
LocalMapUtils.THE_AZURE_SPAN_MAP_ID = 2024
LocalMapUtils.THALDRASZUS_MAP_ID = 2025
LocalMapUtils.THEFORBIDDEN_REACH_MAP_ID = 2118
LocalMapUtils.ZARALEK_CAVERN_MAP_ID = 2133
LocalMapUtils.THE_FORBIDDEN_REACH_MAP_ID = 2151
LocalMapUtils.EMERALD_DREAM_MAP_ID = 2200
LocalMapUtils.AMIRDRASSIL_MAP_ID = 2239
-- Thaldraszus
LocalMapUtils.VALDRAKKEN_MAP_ID = 2112
-- Zaralek Cavern
LocalMapUtils.THE_THROUGHWAY_MAP_ID = 2165
----- Shadowlands -----
LocalMapUtils.REVENDRETH_MAP_ID = 1525
LocalMapUtils.BASTION_MAP_ID = 1533
LocalMapUtils.MALDRAXXUS_MAP_ID = 1536
LocalMapUtils.THE_MAW_MAP_ID = 1543 -- alt: 1960
LocalMapUtils.ARDENWEALD_MAP_ID = 1565
LocalMapUtils.ZERETH_MORTIS_MAP_ID = 1970
-- The Maw
LocalMapUtils.KORTHIA_MAP_ID = 1961
-- Note: Some maps, ie. Oribos, etc. are NOT zones (mapType: 3).
----- Battle for Azeroth -----
-- Zandalar
LocalMapUtils.ZULDAZAR_MAP_ID = 862
LocalMapUtils.NAZMIR_MAP_ID = 863
LocalMapUtils.VOLDUN_MAP_ID = 864
-- Kul Tiras
LocalMapUtils.TIRAGARDE_SOUND_MAP_ID = 895
LocalMapUtils.DRUSTVAR_MAP_ID = 896
LocalMapUtils.STORMSONG_VALLEY_MAP_ID = 942
LocalMapUtils.TOL_DAGOR_MAP_ID = 1169
LocalMapUtils.MECHAGON_ISLAND_MAP_ID = 1462
-- Zuldazar
LocalMapUtils.DAZARALOR_MAP_ID = 1165
-- Nazmir
LocalMapUtils.THE_UNDERROT_MAP_ID = 1041
-- Tiragarde Sound
LocalMapUtils.BORALUS_MAP_ID = 1161
-- Azeroth
LocalMapUtils.NAZJATAR_MAP_ID = 1355
----- Legion -----
-- Broken Isles
LocalMapUtils.AZSUNA_MAP_ID = 630
LocalMapUtils.STORMHEIM_MAP_ID = 634
LocalMapUtils.VALSHARAH_MAP_ID = 641
LocalMapUtils.BROKEN_SHORE_MAP_ID = 646
LocalMapUtils.HIGHMOUNTAIN_MAP_ID = 650
LocalMapUtils.SURAMAR_MAP_ID = 680
LocalMapUtils.EYE_OF_AZSHARA_MAP_ID = 790
-- Argus
LocalMapUtils.KROKUUN_MAP_ID = 830
LocalMapUtils.EREDATH_MAP_ID = 882
LocalMapUtils.ANTORAN_WASTES_MAP_ID = 885
-- High Mountain
LocalMapUtils.TRUESHOT_LODGE_MAP_ID = 739
-- Note: Maps like Mardum, etc. are NOT zones (mapType: 3).
----- Warlords of Draenor -----
LocalMapUtils.FROSTFIRE_RIDGE_MAP_ID = 525
LocalMapUtils.TANAAN_JUNGLE_MAP_ID = 534
LocalMapUtils.TALADOR_MAP_ID = 535
LocalMapUtils.SHADOWMOON_VALLEY_MAP_ID = 539
LocalMapUtils.SPIRES_OF_ARAK_MAP_ID = 542
LocalMapUtils.GORGROND_MAP_ID = 543
LocalMapUtils.NAGRAND_MAP_ID = 550
LocalMapUtils.ASHRAN_MAP_ID = 588
--> TODO - Add more zones.
----- Wrapper ------------------------------------------------------------------
local mapInfoCache = {} --> { [uiMapID] = mapInfo, ...}
-- Return the map information for given map.
---@param uiMapID number
---@return UiMapDetails mapInfo
--
function LocalMapUtils:GetMapInfo(uiMapID)
if not mapInfoCache[uiMapID] then
mapInfoCache[uiMapID] = C_Map.GetMapInfo(uiMapID)
end
return mapInfoCache[uiMapID]
end
-- Get the map information for each child zone of given map.
---@param mapID number
---@param mapType number|Enum.UIMapType|nil
---@param allDescendants boolean|nil
---@return UiMapDetails[] mapChildrenInfos
--
function LocalMapUtils:GetMapChildrenInfo(mapID, mapType, allDescendants)
return C_Map.GetMapChildrenInfo(mapID, mapType, allDescendants)
end
-- Return map information for any child map at given position on the map.
-- Note: The argument `ignoreZoneMapPositionData` is optional.
---@param uiMapID number
---@param x number
---@param y number
---@param ignoreZoneMapPositionData boolean|nil
---@return UiMapDetails mapInfo
--
function LocalMapUtils:GetMapInfoAtPosition(uiMapID, x, y, ignoreZoneMapPositionData)
return C_Map.GetMapInfoAtPosition(uiMapID, x, y, ignoreZoneMapPositionData)
end
-- Returns the current uiMapID of the player's current location.
---@return number uiMapID
--
function LocalMapUtils:GetBestMapForPlayer()
return C_Map.GetBestMapForUnit("player") -- or C_Map.GetFallbackWorldMapID()
end
-- Returns the player's current map position.
---@return Vector2DMixin|nil playerMapPosition
--
function LocalMapUtils:GetPlayerPosition()
-- Note: "Only works for the player and party members."
return C_Map.GetPlayerMapPosition(self:GetBestMapForPlayer(), "player")
end
----- Convenience -----
-- Check whether the given map is a continent.
---@param uiMapID number
---@return boolean isContinent
--
function LocalMapUtils:IsMapTypeContinent(uiMapID)
local mapInfo = self:GetMapInfo(uiMapID)
return mapInfo.mapType == Enum.UIMapType.Continent
end
----- User Waypoints -----------------------------------------------------------
-- Set a user waypoint on given map at given position.
---@param uiMapID number
---@param posX number
---@param posY number
---@param setActive boolean|nil Defaults to `nil`.
---@param chatNotifyOnError boolean|nil Defaults to `nil`.
---@return UiMapPoint|nil mapPoint
--
function LocalMapUtils:SetUserWaypointXY(uiMapID, posX, posY, setActive, chatNotifyOnError)
if C_Map.CanSetUserWaypointOnMap(uiMapID) then
local uiMapPoint = UiMapPoint.CreateFromCoordinates(uiMapID, posX, posY)
C_Map.SetUserWaypoint(uiMapPoint)
local shouldSuperTrack = setActive and setActive or not C_SuperTrack.IsSuperTrackingUserWaypoint()
C_SuperTrack.SetSuperTrackedUserWaypoint(shouldSuperTrack)
if shouldSuperTrack then
PlaySound(SOUNDKIT.UI_MAP_WAYPOINT_SUPER_TRACK_ON)
else
PlaySound(SOUNDKIT.UI_MAP_WAYPOINT_SUPER_TRACK_OFF)
end
return uiMapPoint
else
-- Inform user
UIErrorsFrame:AddMessage(MAP_PIN_INVALID_MAP, RED_FONT_COLOR:GetRGBA())
if chatNotifyOnError then
print(RED_FONT_COLOR:WrapTextInColorCode(MAP_PIN_INVALID_MAP))
end
end
end
-- Get the UiMapPoint of a previously set user waypoint.
---@return UiMapPoint|nil mapPoint
--
function LocalMapUtils:GetUserWaypoint()
if not C_Map.HasUserWaypoint() then return end
return C_Map.GetUserWaypoint()
end
-- Remove a previously set user waypoint.
function LocalMapUtils:ClearUserWaypoint()
if not C_Map.HasUserWaypoint() then return end
C_Map.ClearUserWaypoint()
C_SuperTrack.SetSuperTrackedUserWaypoint(false)
PlaySound(SOUNDKIT.UI_MAP_WAYPOINT_REMOVE)
end
--[[--> TODO -----
local hyperlink = C_Map.GetUserWaypointHyperlink()
local uiMapPoint = C_Map.GetUserWaypointFromHyperlink(hyperlink)
local mapPosition = C_Map.GetUserWaypointPositionForMap(uiMapID)
UiMapPoint.CreateFromVector2D(mapID, position, z)
WorldMapFrame:TriggerEvent("SetAreaLabel", MAP_AREA_LABEL_TYPE.POI, self.name, self.description);
WorldMapFrame:TriggerEvent("ClearAreaLabel", MAP_AREA_LABEL_TYPE.POI);
-- Returns a map area/subzone name.
---@param areaID number
---@return string areaName
-- [Documentation](https://wowpedia.fandom.com/wiki/API_C_Map.GetAreaInfo),
-- [AreaTable.db2](https://wow.tools/dbc/?dbc=areatable)
--
function LocalMapUtils:GetAreaInfo(areaID)
return C_Map.GetAreaInfo(areaID)
end
-- Returns a table with POI IDs currently active on the world map.
---@param mapID number
---@return number[] areaPoiIDs
-- REF.: <FrameXML/Blizzard_SharedMapDataProviders/AreaPOIDataProvider.lua>
-- REF.: <FrameXML/Blizzard_SharedMapDataProviders/SharedMapPoiTemplates.lua>
-- REF.: <FrameXML/Blizzard_APIDocumentationGenerated/AreaPoiInfoDocumentation.lua>
-- REF.: <FrameXML/TableUtil.lua>
--
function LocalMapUtils:GetAreaPOIForMap(mapID)
local areaPOIs = GetAreaPOIsForPlayerByMapIDCached(mapID);
areaPOIs = TableIsEmpty(areaPOIs) and C_AreaPoiInfo.GetAreaPOIForMap(mapID) or areaPOIs;
return areaPOIs;
end
-- Main POI retrieval function; Gets all POIs of given map info.
---@param mapInfo table|UiMapDetails
---@param includeAreaName boolean|nil
---@return AreaPOIInfo[]|nil activeAreaPOIs
---@class AreaPOIInfo
--
function LocalMapUtils:GetAreaPOIForMapInfo(mapInfo, includeAreaName)
local areaPOIs = self:GetAreaPOIForMap(mapInfo.mapID);
if (areaPOIs and #areaPOIs > 0) then
local activeAreaPOIs = {};
for i, areaPoiID in ipairs(areaPOIs) do
local poiInfo = C_AreaPoiInfo.GetAreaPOIInfo(mapInfo.mapID, areaPoiID);
if not poiInfo then
ClearCachedAreaPOIsForPlayer();
break;
end
tinsert(activeAreaPOIs, poiInfo);
end
return activeAreaPOIs;
end
end
]]