public
Description: WoW Powerleveling addon
Homepage: http://www.tekkub.net/
Clone URL: git://github.com/tekkub/tourguide.git
Click here to lend your support to: tourguide and make a donation at www.pledgie.com !
tourguide / Mapping.lua
100644 80 lines (66 sloc) 2.259 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
local L = TourGuide.Locale
 
local zonei, zonec, zonenames = {}, {}, {}
for ci,c in pairs{GetMapContinents()} do
  zonenames[ci] = {GetMapZones(ci)}
  for zi,z in pairs(zonenames[ci]) do
    zonei[z], zonec[z] = zi, ci
  end
end
 
 
local cache = {}
local function MapPoint(zone, x, y, desc)
  TourGuide:DebugF(1, "Mapping %q - %s (%.2f, %.2f)", desc, zone, x, y)
  local zi, zc = zone and zonei[zone], zone and zonec[zone]
  if not zi then
    if zone then TourGuide:PrintF("Cannot find zone %q, using current zone.", zone)
    else TourGuide:Print("No zone provided, using current zone.") end
 
    zi, zc = GetCurrentMapZone(), GetCurrentMapContinent()
    zone = zonenames[zc][zi]
  end
 
  if TomTom then TomTom:AddZWaypoint(zc, zi, x, y, "[TG] "..desc) --AddZWaypoint(c,z,x,y,desc) select(z, GetMapZones(c))
  elseif Cartographer_Waypoints then
    local pt = NotePoint:new(zone, x/100, y/100, "[TG] "..desc)
    Cartographer_Waypoints:AddWaypoint(pt)
    table.insert(cache, pt.WaypointID)
  end
end
 
 
function TourGuide:ParseAndMapCoords(note, desc, zone)
  if TomTom then
    local Astrolabe = DongleStub("Astrolabe-0.4")
    local TomTom = TomTom
 
    if TomTom.m_points then
      for c,ctbl in pairs(TomTom.m_points) do
        for z,ztbl in pairs(ctbl) do
          for idx,entry in pairs(ztbl) do
            if type(entry) == "table" then
              if entry.label and string.sub(entry.label, 1, 5) == "[TG] " then
                self:DebugF(1, "Removing %q from Astrolabe", entry.label)
                Astrolabe:RemoveIconFromMinimap(entry.icon)
                entry:Hide()
                table.insert(TomTom.minimapIcons, entry.icon)
                ztbl[idx] = nil
              end
            end
          end
        end
      end
    end
 
    if TomTom.w_points then
      for k,wp in ipairs(TomTom.w_points) do
        if wp.icon.label and string.sub(wp.icon.label, 1, 5) == "[TG] " then
          self:DebugF(1, "Removing %q from TomTom", wp.icon.label)
          local icon = wp.icon
          icon:Hide()
          TomTom.w_points[k] = nil
          table.insert(TomTom.worldmapIcons, icon)
        end
      end
    end
  elseif Cartographer_Waypoints then
    while cache[1] do
      local pt = table.remove(cache)
      Cartographer_Waypoints:CancelWaypoint(pt)
    end
  end
 
  if not note then return end
 
  for x,y in note:gmatch(L.COORD_MATCH) do MapPoint(zone, tonumber(x), tonumber(y), desc) end
end