-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommands.lua
More file actions
211 lines (193 loc) · 6.31 KB
/
Copy pathCommands.lua
File metadata and controls
211 lines (193 loc) · 6.31 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
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
if _G.LibTaxiData_CommandsRegistered then return end
local API = _G.LibTaxiData_API
if not API then return end
local L = API.LOCALIZATION
if not L then return end
_G.LibTaxiData_CommandsRegistered = true
local PREFIX = "|cff4db3ffLibTaxiData:|r "
local function Print(message)
if DEFAULT_CHAT_FRAME and DEFAULT_CHAT_FRAME.AddMessage then
DEFAULT_CHAT_FRAME:AddMessage(PREFIX .. message)
else
print("LibTaxiData: " .. message)
end
end
local function Words(message)
local words = {}
for word in (message or ""):gmatch("%S+") do
table.insert(words, word)
end
return words
end
local function Coordinate(value)
value = tonumber(value)
if value and value > 1 and value <= 100 then
return value / 100
end
return value
end
local function State(value)
if value == nil then
return L["STATE_UNKNOWN"]
end
return value and L["STATE_YES"] or L["STATE_NO"]
end
local function PrintHelp()
Print(L["COMMAND_HELP_NAME"])
Print(L["COMMAND_HELP_NODE"])
Print(L["COMMAND_HELP_NEAREST_PLAYER"])
Print(L["COMMAND_HELP_NEAREST_MAP"])
Print(L["COMMAND_HELP_NEAREST_WORLD"])
Print(L["COMMAND_HELP_WAYPOINT"])
end
local function PrintNode(nodeID, uiMapID)
local details = API.GetNodeDetails(nodeID, uiMapID)
if not details then
Print(string.format(L["UNKNOWN_NODE_ID"], tostring(nodeID)))
return
end
Print(string.format(L["NODE_HEADER"], details.name or L["UNKNOWN_NAME"], nodeID))
Print(string.format(
L["NODE_WORLD_POSITION"],
details.worldPosition.instanceID,
details.worldPosition.x,
details.worldPosition.y,
details.worldPosition.z,
details.aprWorldPosition.x,
details.aprWorldPosition.y
))
if details.mapPosition then
Print(string.format(
L["NODE_MAP_POSITION"],
details.mapPosition.mapID,
details.mapPosition.x,
details.mapPosition.y,
details.mapPosition.x * 100,
details.mapPosition.y * 100
))
end
Print(string.format(
L["NODE_CONDITIONS"],
State(details.availability),
State(details.visibility),
details.conditionID or 0,
details.visibilityConditionID or 0,
details.specialIconConditionID or 0,
details.flags or 0
))
Print(string.format(
L["NODE_MOUNTS"],
details.hordeMountCreatureID or 0,
details.allianceMountCreatureID or 0,
tostring(details.mountCreatureID or L["NONE"]),
details.characterBitNumber or 0
))
Print(string.format(
L["NODE_OFFSETS"],
details.mapOffsetX or 0,
details.mapOffsetY or 0,
details.flightMapOffsetX or 0,
details.flightMapOffsetY or 0,
details.uiTextureKitID or 0,
details.minimapAtlasMemberID or 0,
details.facing or 0
))
end
local waypointErrorKeys = {
["unknown-node"] = "ERROR_UNKNOWN_NODE",
["no-compatible-ui-map"] = "ERROR_NO_COMPATIBLE_UI_MAP",
["waypoint-api-unavailable"] = "ERROR_WAYPOINT_API_UNAVAILABLE",
["waypoint-rejected"] = "ERROR_WAYPOINT_REJECTED",
["invalid-coordinates"] = "ERROR_INVALID_COORDINATES",
["map-api-unavailable"] = "ERROR_MAP_API_UNAVAILABLE",
["vector-api-unavailable"] = "ERROR_VECTOR_API_UNAVAILABLE",
["map-not-convertible"] = "ERROR_MAP_NOT_CONVERTIBLE",
["outside-map"] = "ERROR_OUTSIDE_MAP",
["unit-position-unavailable"] = "ERROR_UNIT_POSITION_UNAVAILABLE",
["player-position-unavailable"] = "ERROR_PLAYER_POSITION_UNAVAILABLE",
}
local function LocalizeWaypointError(errorCode)
local localizationKey = waypointErrorKeys[errorCode]
if localizationKey then
return L[localizationKey]
end
return string.format(L["ERROR_UNKNOWN"], tostring(errorCode))
end
local function Waypoint(nodeID, uiMapID)
local success, positionOrError = API.SetWaypointToNode(nodeID, uiMapID)
if not success then
Print(string.format(L["CANNOT_SET_WAYPOINT"], LocalizeWaypointError(positionOrError)))
return
end
Print(string.format(
L["WAYPOINT_SET"],
API.GetNodeName(nodeID) or L["UNKNOWN_NAME"],
nodeID,
positionOrError.mapID,
positionOrError.x * 100,
positionOrError.y * 100
))
end
local function Nearest(words)
local result
local preferredMapID
if words[2] == "world" then
local instanceID = tonumber(words[3])
local worldX = tonumber(words[4])
local worldY = tonumber(words[5])
result = API.FindNearestNodeFromWorld(worldX, worldY, instanceID)
elseif words[2] then
preferredMapID = tonumber(words[2])
local mapX = Coordinate(words[3])
local mapY = Coordinate(words[4])
result = API.FindNearestNodeFromMap(preferredMapID, mapX, mapY)
else
preferredMapID = C_Map and C_Map.GetBestMapForUnit and C_Map.GetBestMapForUnit("player") or nil
result = API.FindNearestNodeToPlayer()
end
if not result then
Print(L["NO_MATCHING_TAXI"])
return
end
Print(string.format(
L["NEAREST_TAXI"],
result.name or L["UNKNOWN_NAME"],
result.nodeID,
result.distance
))
Waypoint(result.nodeID, preferredMapID)
end
local function HandleCommand(message)
local words = Words(message)
local command = words[1] and words[1]:lower() or "help"
if command == "name" then
local nodeID = tonumber(words[2])
local name = nodeID and API.GetNodeName(nodeID) or nil
if not name then
Print(string.format(L["UNKNOWN_NODE_ID"], tostring(words[2] or "")))
return
end
Print(string.format(L["NODE_HEADER"], name, nodeID))
elseif command == "node" or command == "details" then
local nodeID = tonumber(words[2])
if not nodeID then
PrintHelp()
return
end
PrintNode(nodeID, tonumber(words[3]))
elseif command == "nearest" then
Nearest(words)
elseif command == "waypoint" then
local nodeID = tonumber(words[2])
if not nodeID then
PrintHelp()
return
end
Waypoint(nodeID, tonumber(words[3]))
else
PrintHelp()
end
end
SLASH_LIBTAXIDATA1 = "/libtaxidata"
SLASH_LIBTAXIDATA2 = "/ltd"
SlashCmdList.LIBTAXIDATA = HandleCommand