Advertisement
Guest User

TomTom

a guest
May 17th, 2014
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.63 KB | None | 0 0
  1. local function usage()
  2.     ChatFrame1:AddMessage(L["|cffffff78TomTom |r/way |cffffff78Usage:|r"])
  3.     ChatFrame1:AddMessage(L["|cffffff78/way <x> <y> [desc]|r - Adds a waypoint at x,y with descrtiption desc"])
  4.     ChatFrame1:AddMessage(L["|cffffff78/way <zone> <x> <y> [desc]|r - Adds a waypoint at x,y in zone with description desc"])
  5.     ChatFrame1:AddMessage(L["|cffffff78/way reset all|r - Resets all waypoints"])
  6.     ChatFrame1:AddMessage(L["|cffffff78/way reset <zone>|r - Resets all waypoints in zone"])
  7. end
  8.  
  9. SLASH_TOMTOM_WAY1 = "/way"
  10. SLASH_TOMTOM_WAY2 = "/tway"
  11. SLASH_TOMTOM_WAY3 = "/tomtomway"
  12. SlashCmdList["TOMTOM_WAY"] = function(msg)
  13.     local tokens = {}
  14.     for token in msg:gmatch("%S+") do table.insert(tokens, token) end
  15.  
  16.     -- Lower the first token
  17.     if tokens[1] then
  18.         tokens[1] = tokens[1]:lower()
  19.     end
  20.  
  21.     if tokens[1] == "reset" then
  22.         if tokens[2] == "all" then
  23.             if TomTom.db.profile.general.confirmremoveall then
  24.                 StaticPopup_Show("TOMTOM_REMOVE_ALL_CONFIRM")
  25.             else
  26.                 StaticPopupDialogs["TOMTOM_REMOVE_ALL_CONFIRM"].OnAccept()
  27.                 return
  28.             end
  29.  
  30.         elseif tokens[2] then
  31.             -- Reset the named zone
  32.             local zone = table.concat(tokens, " ", 2)
  33.  
  34.             -- Find a fuzzy match for the zone
  35.             local matches = {}
  36.             zone = zone:lower():gsub("[%L]", "")
  37.  
  38.             for z,entry in pairs(zlist) do
  39.                 if z:match(zone) then
  40.                     table.insert(matches, entry)
  41.                 end
  42.             end
  43.  
  44.             if #matches > 5 then
  45.                 local msg = string.format(L["Found %d possible matches for zone %s.  Please be more specific"], #matches, tokens[2])
  46.                 ChatFrame1:AddMessage(msg)
  47.                 return
  48.             elseif #matches > 1 then
  49.                 local poss = {}
  50.                 for k,v in pairs(matches) do
  51.                     table.insert(poss, v[3])
  52.                 end
  53.                 table.sort(poss)
  54.  
  55.                 ChatFrame1:AddMessage(string.format(L["Found multiple matches for zone '%s'.  Did you mean: %s"], tokens[2], table.concat(poss, ", ")))
  56.                 return
  57.             end
  58.  
  59.             local c,z,name = unpack(matches[1])
  60.             local zone = TomTom:GetMapFile(c, z)
  61.             if waypoints[zone] then
  62.                 for uid in pairs(waypoints[zone]) do
  63.                     TomTom:RemoveWaypoint(uid)
  64.                 end
  65.             else
  66.                 ChatFrame1:AddMessage(L["There were no waypoints to remove in %s"]:format(name))
  67.             end
  68.         end
  69.     elseif tokens[1] and not tonumber(tokens[1]) then
  70.         -- Find the first numeric token
  71.         local zoneEnd = 1
  72.         for idx,token in ipairs(tokens) do
  73.             if tonumber(token) then
  74.                 zoneEnd = idx - 1
  75.                 break
  76.             end
  77.         end
  78.  
  79.         -- This is a waypoint set, with a zone before the coords
  80.         local zone = table.concat(tokens, " ", 1, zoneEnd)
  81.         local x,y,desc = select(zoneEnd + 1, unpack(tokens))
  82.  
  83.         if desc then desc = table.concat(tokens, " ", zoneEnd + 3) end
  84.  
  85.         -- Find a fuzzy match for the zone
  86.         local matches = {}
  87.         zone = zone:lower():gsub("[%L]", "")
  88.  
  89.         for z,entry in pairs(zlist) do
  90.             if z:match(zone) then
  91.                 table.insert(matches, entry)
  92.             end
  93.         end
  94.  
  95.         if #matches ~= 1 then
  96.                 local msg = string.format(L["Found %d possible matches for zone %s.  Please be more specific"], #matches, tokens[1])
  97.                 ChatFrame1:AddMessage(msg)
  98.             return
  99.         end
  100.  
  101.         local c,z,name = unpack(matches[1])
  102.  
  103.         if not x or not tonumber(x) then
  104.             return usage()
  105.         elseif not y or not tonumber(y) then
  106.             return usage()
  107.         end
  108.  
  109.         x = tonumber(x)
  110.         y = tonumber(y)
  111.         TomTom:AddZWaypoint(c, z, x, y, desc)
  112.     elseif tonumber(tokens[1]) then
  113.         -- A vanilla set command
  114.         local x,y,desc = unpack(tokens)
  115.         if not x or not tonumber(x) then
  116.             return usage()
  117.         elseif not y or not tonumber(y) then
  118.             return usage()
  119.         end
  120.         if desc then
  121.             desc = table.concat(tokens, " ", 3)
  122.         end
  123.  
  124.         x = tonumber(x)
  125.         y = tonumber(y)
  126.         TomTom:AddWaypoint(x, y, desc)
  127.     else
  128.         return usage()
  129.     end
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement