From 3a913bde1f5a90a032c0cef9c2d5e8c4c0c109a7 Mon Sep 17 00:00:00 2001 From: James Whitehead II Date: Mon, 10 Jan 2011 23:19:46 +0000 Subject: [PATCH] Add a source for archaeology dig sites --- sources/ArchaeologyDigSites.lua | 99 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/sources/ArchaeologyDigSites.lua b/sources/ArchaeologyDigSites.lua index e69de29..2c7d90a 100644 --- a/sources/ArchaeologyDigSites.lua +++ b/sources/ArchaeologyDigSites.lua @@ -0,0 +1,99 @@ +local addonName, addon = ... +local L = addon.L + +--[[------------------------------------------------------------------- +-- Archaeology Dig Sitemodule for TomTomLite, example reference module +-------------------------------------------------------------------]]-- + +do + local desc = L["This source provides waypoints for archaeology dig sites"] + addon:RegisterSource("archaeodig", L["Archaeology Dig Sites"], desc) +end + +local eventFrame = CreateFrame("Frame") +eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD") +eventFrame:RegisterEvent("ARTIFACT_HISTORY_READY") +eventFrame:RegisterEvent("ARTIFACT_COMPLETE") +eventFrame:RegisterEvent("ARTIFACT_DIG_SITE_UPDATED") + +-- Creates waypoints for each of the dig sites that can be found +-- on the current continent + +local waypoints = {} +local function UpdateDigSites() + if not addon.db.profile.archaeologyDigSitesSource then + return + end + + local omap, ofloor = GetCurrentMapAreaID() + + -- Flip the map to our current zone, then zoom out to the continent + SetMapToCurrentZone() + local map, floor = GetCurrentMapAreaID() + + local continent = addon:GetMapContinentMap(map) + if continent then + SetMapByID(continent) + end + + local sites = {} + for idx = 1, GetNumMapLandmarks() do + local name, desc, textureIdx, px, py = GetMapLandmarkInfo(idx) + if textureIdx == 177 then + local key = string.format("%s:%f:%f:", name, px, py) + if not waypoints[key] then + local waypoint = addon:AddWaypoint(continent, nil, px, py, { + title = string.format(L["Dig site: %s"], name), + priority = 0, + }) + sites[key] = waypoint + else + sites[key] = waypoints[key] + end + end + end + + for key, waypoint in pairs(sites) do + waypoints[key] = nil + end + + for key, waypoint in pairs(waypoints) do + addon:RemoveWaypoint(waypoint) + end + + waypoints = sites +end + +eventFrame:SetScript("OnEvent", function(self, event, ...) + UpdateDigSites() +end) + +local throttle = 2.0 +eventFrame:SetScript("OnUpdate", function(self, elapsed) + local min = math.huge + local closest + for key, waypoint in pairs(waypoints) do + local distance, angle = addon:GetVectorFromCurrent(unpack(waypoint)) + if distance and distance < min then + min = distance + closest = waypoint + end + end + + if self.closest == closest then + -- Nothing changed, return + return + end + + for key, waypoint in pairs(waypoints) do + if waypoint ~= closest then + waypoint.priority = 0 + else + waypoint.priority = 5 + end + end + + self.closest = closest + + addon:FireMessage("TOMTOMLITE_WAYPOINTS_CHANGED") +end) -- 1.7.9.5