Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function usage()
- ChatFrame1:AddMessage(L["|cffffff78TomTom |r/way |cffffff78Usage:|r"])
- ChatFrame1:AddMessage(L["|cffffff78/way <x> <y> [desc]|r - Adds a waypoint at x,y with descrtiption desc"])
- ChatFrame1:AddMessage(L["|cffffff78/way <zone> <x> <y> [desc]|r - Adds a waypoint at x,y in zone with description desc"])
- ChatFrame1:AddMessage(L["|cffffff78/way reset all|r - Resets all waypoints"])
- ChatFrame1:AddMessage(L["|cffffff78/way reset <zone>|r - Resets all waypoints in zone"])
- end
- SLASH_TOMTOM_WAY1 = "/way"
- SLASH_TOMTOM_WAY2 = "/tway"
- SLASH_TOMTOM_WAY3 = "/tomtomway"
- SlashCmdList["TOMTOM_WAY"] = function(msg)
- local tokens = {}
- for token in msg:gmatch("%S+") do table.insert(tokens, token) end
- -- Lower the first token
- if tokens[1] then
- tokens[1] = tokens[1]:lower()
- end
- if tokens[1] == "reset" then
- if tokens[2] == "all" then
- if TomTom.db.profile.general.confirmremoveall then
- StaticPopup_Show("TOMTOM_REMOVE_ALL_CONFIRM")
- else
- StaticPopupDialogs["TOMTOM_REMOVE_ALL_CONFIRM"].OnAccept()
- return
- end
- elseif tokens[2] then
- -- Reset the named zone
- local zone = table.concat(tokens, " ", 2)
- -- Find a fuzzy match for the zone
- local matches = {}
- zone = zone:lower():gsub("[%L]", "")
- for z,entry in pairs(zlist) do
- if z:match(zone) then
- table.insert(matches, entry)
- end
- end
- if #matches > 5 then
- local msg = string.format(L["Found %d possible matches for zone %s. Please be more specific"], #matches, tokens[2])
- ChatFrame1:AddMessage(msg)
- return
- elseif #matches > 1 then
- local poss = {}
- for k,v in pairs(matches) do
- table.insert(poss, v[3])
- end
- table.sort(poss)
- ChatFrame1:AddMessage(string.format(L["Found multiple matches for zone '%s'. Did you mean: %s"], tokens[2], table.concat(poss, ", ")))
- return
- end
- local c,z,name = unpack(matches[1])
- local zone = TomTom:GetMapFile(c, z)
- if waypoints[zone] then
- for uid in pairs(waypoints[zone]) do
- TomTom:RemoveWaypoint(uid)
- end
- else
- ChatFrame1:AddMessage(L["There were no waypoints to remove in %s"]:format(name))
- end
- end
- elseif tokens[1] and not tonumber(tokens[1]) then
- -- Find the first numeric token
- local zoneEnd = 1
- for idx,token in ipairs(tokens) do
- if tonumber(token) then
- zoneEnd = idx - 1
- break
- end
- end
- -- This is a waypoint set, with a zone before the coords
- local zone = table.concat(tokens, " ", 1, zoneEnd)
- local x,y,desc = select(zoneEnd + 1, unpack(tokens))
- if desc then desc = table.concat(tokens, " ", zoneEnd + 3) end
- -- Find a fuzzy match for the zone
- local matches = {}
- zone = zone:lower():gsub("[%L]", "")
- for z,entry in pairs(zlist) do
- if z:match(zone) then
- table.insert(matches, entry)
- end
- end
- if #matches ~= 1 then
- local msg = string.format(L["Found %d possible matches for zone %s. Please be more specific"], #matches, tokens[1])
- ChatFrame1:AddMessage(msg)
- return
- end
- local c,z,name = unpack(matches[1])
- if not x or not tonumber(x) then
- return usage()
- elseif not y or not tonumber(y) then
- return usage()
- end
- x = tonumber(x)
- y = tonumber(y)
- TomTom:AddZWaypoint(c, z, x, y, 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 usage()
- elseif not y or not tonumber(y) then
- return usage()
- end
- if desc then
- desc = table.concat(tokens, " ", 3)
- end
- x = tonumber(x)
- y = tonumber(y)
- TomTom:AddWaypoint(x, y, desc)
- else
- return usage()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement