Permalink
Browse files

Adds Footprints file, moves past position tracking to Footprints.lua

Adds Coords Queue-Array for handling remembered coordinates
  • Loading branch information...
1 parent 28a45e8 commit 469272893a6cc853005129bbcab6031a1a4eae72 @Jiyambi committed Apr 16, 2012
Showing with 86 additions and 34 deletions.
  1. +71 −0 Footprints.lua
  2. +13 −33 Footsteps.lua
  3. +2 −1 Footsteps.toc
View
@@ -0,0 +1,71 @@
+-------------------------------------------------------------------------------------
+-- Footprints.lua Footprints module tracks where you've been
+-- Project Footsteps - an addon that tracks where you're going and
+-- where you've been.
+-- Authors Jiyambi, Taellis, Phaedra
+-- Version 0.1
+-- Licesnse Creative Commons Attribution-NonCommercial-NoDerivs 3.0
+-- Unported License
+-------------------------------------------------------------------------------------
+
+-------------------------------------------------------------------------------------
+-- Initialization
+-------------------------------------------------------------------------------------
+Footsteps.Footprints = {} -- Table for holding footprint related values
+local F = Footsteps.Footprints -- Localize this section for easy access
+F.Rate = 5 -- Number of seconds between footprint drops
+F.Remembered = 5 -- Number of footprints the addon will remember
+F.Coords = {} -- Array to hold footprints
+F.Frames = {} -- Array to hold texture for footprints
+F.Timer = F.Rate -- Timer for footprint drop
+
+-------------------------------------------------------------------------------------
+-- Coords Queue-Array
+-------------------------------------------------------------------------------------
+local C = F.Coords -- Localize Coords for easy access
+C.Size = 0 -- Size of Queue
+C.First = 1 -- Index of first item in Queue
+C.Last = 0 -- Index of last item in Queue
+function C:Push(value)
+ local last = C.Last
+ C.Last = last + 1
+ C[last] = value
+end
+function C:Pop()
+ local first = C.First
+ if first > C.Last then error("Coordinate queue empty") end
+ local value = C[first]
+ C[first] = nil
+ C.First = first + 1
+ return value
+end
+
+-------------------------------------------------------------------------------------
+-- DrawFootprints() Adds a footprint to the array and bumps old ones out
+-- Arguments elapsed - time since last called
+-- Returns nil
+-------------------------------------------------------------------------------------
+function F:DropFootprints(elapsed)
+ -- Add the timesince last update to the timer
+ F.Timer = F.Timer + elapsed
+
+ -- If the timer value is greater than our rate, it's time to print.
+ if F.Timer >= F.Rate then
+ -- Reset timer
+ F.Timer = 0
+
+ -- Create coordinate object
+ local coord = {}
+ coord.zone = GetZoneText()
+ coord.x, coord.y = GetPlayerMapPosition("player")
+ F.Coords.Push(coord)
+
+ -- Remove old coordinate object if necessary
+ if F.Coords.Size > F.Remembered then F.Coords.Pop() end
+
+ -- TODO: Remove
+ -- Print the current coordinates to the chat window
+ DEFAULT_CHAT_FRAME:AddMessage(format("( %s ) %d,%d", coord.zone,coord.x*100,coord.y*100))
+ end
+end
+Footsteps.Listener:SetScript("OnUpdate", F.DropFootprints)
View
@@ -1,5 +1,5 @@
-------------------------------------------------------------------------------------
--- Footsteps.lua Main addon setup
+-- Footsteps.lua Main addon setup
-- Project Footsteps - an addon that tracks where you're going and
-- where you've been.
-- Authors Jiyambi, Taellis, Phaedra
@@ -9,43 +9,23 @@
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
--- Global Variable Initialization
+-- Initialization
-------------------------------------------------------------------------------------
-Footsteps = {} -- Table to hold all addon data
-Footsteps.version = -- The addon version defined in the ToC page
+
+-- General --
+Footsteps = {} -- Table to hold all addon data
+Footsteps.Version = -- The addon version defined in the ToC page
GetAddOnMetadata("Footsteps", "Version")
-Footsteps.rate = 1 -- Number of seconds between footprint drops
-------------------------------------------------------------------------------------
--- CreateDebugFrame() Sets up a debugging frame for interaction with the addon
--- during testing.
--- Arguments nil
--- Returns nil
+-- CreateListenerFrame() Sets up a listener frame for event handling.
+-- Arguments nil
+-- Returns nil
-------------------------------------------------------------------------------------
-function Footsteps:CreateDebugFrame()
+function Footsteps:CreateListener()
- -- Create debug frame
- -- For now, we don't really want it to be visible so we don't specify a size
- -- or background.
- local frame = CreateFrame("Button", "Footsteps.DebugFrame", UIParent)
- Footsteps.DebugFrame = frame
+ -- Create Listener
+ Footsteps.Listener = CreateFrame("Button", "Footsteps.Listener", UIParent)
- -- Set up OnUpdate script
- -- This is called every time the game redraws it's graphics
- local timer = 0 -- Timer for footprint drop based on Footsteps.rate
- local function OnUpdate(self, elapsed)
- -- Add the timesince last update to the timer
- timer = timer + elapsed
-
- -- If the timer value is greater than our rate, it's time to print.
- if timer > Footsteps.rate then
- -- Reset timer
- timer = 0
- -- Print the current coordinates to the chat window
- local px,py=GetPlayerMapPosition("player")
- DEFAULT_CHAT_FRAME:AddMessage(format("( %s ) %i,%i", GetZoneText(),px *100,py *100))
- end
- end
- Footsteps.DebugFrame:SetScript("OnUpdate", OnUpdate)
end
-Footsteps:CreateDebugFrame()
+Footsteps:CreateListener()
View
@@ -5,4 +5,5 @@
## SavedVariables: FootstepsDB
## Version: 0.1
-Footsteps.lua
+Footsteps.lua
+Footprints.lua

0 comments on commit 4692728

Please sign in to comment.