-
Notifications
You must be signed in to change notification settings - Fork 4
/
WayHandler.lua
175 lines (156 loc) · 6.5 KB
/
WayHandler.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
TomTomWayHandler = {}
TomTomWayHandler.tomtom = nil
function TomTomWayHandler:Register(tomtom)
self.tomtom = tomtom
SLASH_TOMTOM_WAY1 = "/way"
SLASH_TOMTOM_WAY2 = "/tway"
SLASH_TOMTOM_WAY3 = "/tomtomway"
SlashCmdList["TOMTOM_WAY"] = function(msg) self:ChatHandler(msg) end
SLASH_TOMTOM_CLOSEST_WAYPOINT1 = "/cway"
SLASH_TOMTOM_CLOSEST_WAYPOINT2 = "/closestway"
SlashCmdList["TOMTOM_CLOSEST_WAYPOINT"] = function(msg) self.tomtom:SetClosestWaypoint() end
SLASH_TOMTOM_WAYBACK1 = "/wayb"
SLASH_TOMTOM_WAYBACK2 = "/wayback"
SlashCmdList["TOMTOM_WAYBACK"] = function(msg) self:AddWayBack() end
end
--[[
/way <x> <y> [desc] - Adds a waypoint at x,y with description desc
/way <zone> <x> <y> [desc] - Adds a waypoint at x,y in zone with descript desc
/way reset all - Resets all waypoints
/way reset <zone> - Resets all waypoints in zone
/way list - Lists active waypoints
]]
function TomTomWayHandler:Usage()
ChatFrame1:AddMessage("|cffffff78TomTom |r/way |cffffff78Usage:|r")
ChatFrame1:AddMessage("|cffffff78/way <x> <y> [desc]|r - Adds a waypoint at x,y with descrtiption desc")
ChatFrame1:AddMessage("|cffffff78/way <zone> <x> <y> [desc]|r - Adds a waypoint at x,y in zone with description desc")
ChatFrame1:AddMessage("|cffffff78/way reset|r - Resets waypoints in current zone")
ChatFrame1:AddMessage("|cffffff78/way reset all|r - Resets all waypoints")
ChatFrame1:AddMessage("|cffffff78/way reset <zone>|r - Resets all waypoints in zone")
ChatFrame1:AddMessage("|cffffff78/way list|r - Lists active waypoints in current zone")
ChatFrame1:AddMessage("|cffffff78/way list all|r - Lists all active waypoints")
ChatFrame1:AddMessage("|cffffff78/way list <zone>|r - Lists active waypoints in zone")
end
function TomTomWayHandler:AddWayBack()
local backc,backz,backx,backy = TomTom:GetCurrentPlayerPosition()
TomTom:AddMFWaypoint(backc, backz, backx, backy, {
title = "Wayback",
})
end
function TomTomWayHandler:ChatHandler(msg)
msg = msg or ""
local wrongseparator = "(%d)" .. (tonumber("1.1") and "," or ".") .. "(%d)"
local rightseparator = "%1" .. (tonumber("1.1") and "." or ",") .. "%2"
msg = string.gsub(string.gsub(msg, "(%d)[%.,] (%d)", "%1 %2"), wrongseparator, rightseparator)
local tokens = {}
string.gsub(msg, "(%S+)", function(c) table.insert(tokens, c) end)
-- Lower the first token
local ltoken = tokens[1] and string.lower(tokens[1])
if ltoken == "list" then
local ltoken2 = tokens[2] and string.lower(tokens[2])
if ltoken2 ~= nil and ltoken2 ~= "all" then
ltoken2 = TomTom:CleanZoneName(table.concat(tokens, " ", 2))
end
TomTom:DebugListWaypoints(ltoken2)
return
elseif ltoken == "reset" or ltoken == "remove" or ltoken == "clear" or ltoken == "clean" or ltoken == "del" or ltoken == "delete" then
local ltoken2 = tokens[2] and string.lower(tokens[2])
if ltoken2 == "all" then
if TomTom.db.profile.general.confirmremoveall then
StaticPopup_Show("TOMTOM_REMOVE_ALL_CONFIRM")
else
StaticPopupDialogs["TOMTOM_REMOVE_ALL_CONFIRM"].OnAccept()
return
end
else
local cont, zoneid
if not ltoken2 then
cont, zoneid = TomTom:GetCurrentPlayerPosition()
else
local zone = table.concat(tokens, " ", 2)
cont, zoneid = TomTom:GetZoneInfo(lowergsub(zone))
end
if cont == nil then
local msg = string.format("Could not find any matches for zone %s.", zone)
ChatFrame1:AddMessage(msg)
return
end
local _, _, zoneName = TomTom:GetZoneInfo(zoneid, cont)
local numRemoved = 0
local waypoints = TomTom:GetWaypoints(cont, zoneid)
if waypoints and table.getn(waypoints) > 0 then
for key, uid in pairs(waypoints) do
TomTom:RemoveWaypoint(uid, true)
numRemoved = numRemoved + 1
end
ChatFrame1:AddMessage(string.format("Removed %d waypoints from %s", numRemoved, zoneName))
else
ChatFrame1:AddMessage(string.format("There were no waypoints to remove in %s", zoneName))
end
end
elseif tokens[1] and not tonumber(tokens[1]) then
-- Example: /way Elwynn Forest 34.2 50.7 Party in the forest!
-- tokens[1] = Elwynn
-- tokens[2] = Forest
-- tokens[3] = 34.2
-- tokens[4] = 50.7
-- tokens[5] = Party
-- ...
--
-- Find the first numeric token
local zoneEnd
for idx = 1, table.getn(tokens) do
local token = tokens[idx]
if tonumber(token) then
-- We've encountered a number, so the zone name must have
-- ended at the prior token
zoneEnd = idx - 1
break
end
end
if not zoneEnd then
self:Usage()
return
end
-- This is a waypoint set, with a zone before the coords
local zone = table.concat(tokens, " ", 1, zoneEnd)
local x, y, desc = tokens[zoneEnd + 1], tokens[zoneEnd + 2], tokens[zoneEnd + 3]
if desc then desc = table.concat(tokens, " ", zoneEnd + 3) end
local cont, zoneid = TomTom:GetZoneInfo(TomTom:CleanZoneName(zone))
if cont == nil then
local msg = string.format("Could not find any matches for zone %s.", zone)
ChatFrame1:AddMessage(msg)
return
end
--self.tomtom:log(string.format("%s %s %s %s", lowergsub(zone), x or "nil", y or "nil", desc or "nil"))
x = x and tonumber(x)
y = y and tonumber(y)
if not x or not y then
return self:Usage()
end
self.tomtom:AddMFWaypoint(cont, zoneid, x/100, y/100, {
title = desc,
})
elseif tonumber(tokens[1]) then
-- A vanilla set command
local x,y,desc = unpack(tokens)
if not x or not tonumber(x) then
return self:Usage()
elseif not y or not tonumber(y) then
return self:Usage()
end
if desc then
desc = table.concat(tokens, " ", 3)
end
x = tonumber(x)
y = tonumber(y)
local cont, zone = TomTom:GetCurrentPlayerPosition()
if cont and zone and x and y then
self.tomtom:AddMFWaypoint(cont, zone, x/100, y/100, {
title = desc
})
end
else
return self:Usage()
end
end