Created
July 22, 2020 19:01
-
-
Save Meorawr/c08360f60e5b99c5edf9b6274d5cdd7d to your computer and use it in GitHub Desktop.
User Waypoint Position Skeleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local distances = {}; -- Array of 4 distances to TL, TR, BR, BL. | |
local function GetPointToQuery(index) | |
local mapID = C_Map.GetBestMapForUnit("player"); | |
local x, y; | |
if index == 1 then | |
x, y = 0, 0; | |
elseif index == 2 then | |
x, y = 1, 0; | |
elseif index == 3 then | |
x, y = 1, 1; | |
else | |
x, y = 0, 1; | |
end | |
return UiMapPoint.CreateFromCoordinates(mapID, x, y); | |
end | |
local function QueryNextPoint() | |
local point = GetPointToQuery(#distances + 1); | |
C_Map.SetUserWaypoint(point); | |
end | |
local function BeginPositionQuery() | |
wipe(distances); | |
QueryNextPoint(); | |
end | |
local function OnPositionQueryFinished() | |
-- Do your math magic here with the four distance values | |
-- to the top-left, top-right, bottom-right, and bottom-left | |
-- corners in the `distances` array. | |
end | |
local function OnSuperTrackingChanged() | |
table.insert(distances, C_Navigation.GetDistance()); | |
C_SuperTrack.SetSuperTrackedUserWaypoint(false); | |
if #distances == 4 then | |
OnPositionQueryFinished(); | |
else | |
QueryNextPoint(); | |
end | |
end | |
local function OnUserWaypointUpdated() | |
C_SuperTrack.SetSuperTrackedUserWaypoint(true); | |
end | |
local function OnEvent(_, event) | |
if event == "USER_WAYPOINT_UPDATED" then | |
OnUserWaypointUpdated(); | |
elseif event == "SUPER_TRACKING_CHANGED" then | |
OnSuperTrackingChanged(); | |
end | |
end | |
local frame = CreateFrame("Frame"); | |
frame:RegisterEvent("SUPER_TRACKING_CHANGED"); | |
frame:RegisterEvent("USER_WAYPOINT_UPDATED"); | |
frame:SetScript("OnEvent", OnEvent); | |
C_Timer.NewTicker(2, function() | |
BeginPositionQuery(); | |
end); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment