Quantcast

Initial broker suport. WARNING: Code crashes client, use with care.

F16Gaming [09-02-12 - 12:22]
Initial broker suport. WARNING: Code crashes client, use with care.
Filename
.gitignore
.pkgmeta
Broker.lua
KillTrack.lua
KillTrack.toc
icon.tga
libs/LibDataBroker-1-1/LibDataBroker-1.1.lua
libs/LibDataBroker-1-1/README.textile
diff --git a/.gitignore b/.gitignore
index e3c621e..9f5fe64 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
-
-/libs/AceGUI-3.0
 /libs/LibStub
+/libs/CallbackHandler-1.0
+/libs/AceGUI-3.0
diff --git a/.pkgmeta b/.pkgmeta
index c5f0f02..a0c22ff 100644
--- a/.pkgmeta
+++ b/.pkgmeta
@@ -1,11 +1,17 @@
 package-as: KillTrack

 externals:
-    libs/AceGUI-3.0:
-        url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceGUI-3.0
-        tag: latest
     libs/LibStub:
         url: svn://svn.wowace.com/wow/libstub/mainline/trunk
         tag: latest
+    libs/CallbackHandler-1.0:
+        url: svn://svn.wowace.com/wow/callbackhandler/mainline/trunk/CallbackHandler-1.0
+        tag: latest
+    libs/AceGUI-3.0:
+        url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceGUI-3.0
+        tag: latest
+
+tools-used:
+    - libdatabroker-1-1

 license-output: COPYING
diff --git a/Broker.lua b/Broker.lua
new file mode 100644
index 0000000..97d8b9d
--- /dev/null
+++ b/Broker.lua
@@ -0,0 +1,67 @@
+--[[
+	* Copyright (c) 2011 by Adam Hellberg.
+	*
+	* This file is part of KillTrack.
+	*
+	* KillTrack is free software: you can redistribute it and/or modify
+	* it under the terms of the GNU General Public License as published by
+	* the Free Software Foundation, either version 3 of the License, or
+	* (at your option) any later version.
+	*
+	* KillTrack is distributed in the hope that it will be useful,
+	* but WITHOUT ANY WARRANTY; without even the implied warranty of
+	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	* GNU General Public License for more details.
+	*
+	* You should have received a copy of the GNU General Public License
+	* along with KillTrack. If not, see <http://www.gnu.org/licenses/>.
+--]]
+
+local KT = KillTrack
+
+KT.Broker = {
+	Text = {
+		Short = "KPM: %f",
+		Long = "Kills Per Minute: %f",
+	}
+}
+
+local KTB = KT.Broker
+
+local UPDATE = 1
+local t = 0
+
+local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
+
+local data = {
+	type = "data source",
+	label = "KillTrack |cff00FF00(" .. KT.Version .. ")|r",
+	icon = "Interface\\AddOns\\KillTrack\\icon.tga"
+}
+
+local obj = ldb:NewDataObject("Broker_KillTrack", data)
+
+function KTB:UpdateText()
+	local text = KT.Global.BROKER.SHORT_TEXT and self.Text.Short or self.Text.Long
+	obj.text = text:format(KT:GetKPM())
+end
+
+function KTB:OnUpdate(frame, elapsed)
+	t = t + elapsed
+	if t >= UPDATE then
+		self:UpdateText()
+		t = 0
+	end
+end
+
+function KTB:ToggleTextMode()
+	if type(KT.Global.BROKER) ~= "table" then KT.Global.BROKER = {} end
+	KT.Global.BROKER.SHORT_TEXT = not KT.Global.BROKER.SHORT_TEXT
+	self:UpdateText()
+end
+
+local frame = CreateFrame("Frame")
+
+frame:SetScript("OnUpdate", function(self, elapsed) KTB:OnUpdate(self, elapsed) end)
+
+KTB:UpdateText()
diff --git a/KillTrack.lua b/KillTrack.lua
index a6944da..c9fda7e 100644
--- a/KillTrack.lua
+++ b/KillTrack.lua
@@ -33,6 +33,10 @@ KillTrack = {
 		AlphaA = 5,
 		IdDesc = 6,
 		IdAsc = 7
+	},
+	Session = {
+		Count = 0,
+		Kills = {}
 	}
 }

@@ -80,6 +84,7 @@ function KT.Events.ADDON_LOADED(self, ...)
 		self.CharGlobal.MOBS = {}
 	end
 	self:Msg("AddOn Loaded!")
+	self.Session.Start = time()
 end

 function KT.Events.COMBAT_LOG_EVENT_UNFILTERED(self, ...)
@@ -172,6 +177,7 @@ function KT:AddKill(id, name)
 	if self.Global.PRINTKILLS then
 		self:Msg(("Updated %q, new kill count: %d. Kill count on this character: %d"):format(name, self.Global.MOBS[id].Kills, self.CharGlobal.MOBS[id].Kills))
 	end
+	self:AddSessionKill(name, self.Global.MOBS[id].Kills)
 	if type(self.Global.MOBS[id].AchievCount) ~= "number" then
 		self.Global.MOBS[id].AchievCount = floor(self.Global.MOBS[id].Kills / self.Global.ACHIEV_THRESHOLD)
 		if self.Global.MOBS[id].AchievCount >= 1 then
@@ -186,6 +192,21 @@ function KT:AddKill(id, name)
 	end
 end

+function KT:AddSessionKill(name, kills)
+	self.Session.Kills[name] = kills
+	table.sort(self.Session.Kills, function(a, b) return a > b end)
+	-- Trim table to only contain 3 entries
+	local trimmed = {}
+	local i = 0
+	for k,v in pairs(self.Session.Kills) do
+		trimmed[k] = v
+		i = i + 1
+		if i >= 3 then break end
+	end
+	self.Session.Kills = trimmed
+	self.Session.Count = self.Session.Count + 1
+end
+
 function KT:GetKills(id)
 	local gKills, cKills = 0, 0
 	for k,v in pairs(self.Global.MOBS) do
@@ -199,6 +220,11 @@ function KT:GetKills(id)
 	return gKills, cKills
 end

+function GetKPM()
+	if not self.Session.Start then return 0 end
+	return self.Session.Count / (time() - self.Session.Start)
+end
+
 function KT:PrintKills(identifier)
 	local found = false
 	local name = "<No Name>"
diff --git a/KillTrack.toc b/KillTrack.toc
index 4ad14fc..5af85e6 100644
--- a/KillTrack.toc
+++ b/KillTrack.toc
@@ -8,8 +8,10 @@

 #@no-lib-strip@
 libs\LibStub\LibStub.lua
+libs\CallbackHandler-1.0\CallbackHandler-1.0.xml
 libs\AceGUI-3.0\AceGUI-3.0.xml
 #@end-no-lib-strip@
+libs\LibDataBroker-1-1\LibDataBroker-1.1.lua

 Tools.lua
 KillTrack.lua
@@ -19,3 +21,4 @@ MobList.lua
 Timer.lua
 TimerFrame.lua
 TimerFrame.xml
+Broker.lua
diff --git a/icon.tga b/icon.tga
new file mode 100644
index 0000000..8e43c71
Binary files /dev/null and b/icon.tga differ
diff --git a/libs/LibDataBroker-1-1/LibDataBroker-1.1.lua b/libs/LibDataBroker-1-1/LibDataBroker-1.1.lua
new file mode 100644
index 0000000..f47c0cd
--- /dev/null
+++ b/libs/LibDataBroker-1-1/LibDataBroker-1.1.lua
@@ -0,0 +1,90 @@
+
+assert(LibStub, "LibDataBroker-1.1 requires LibStub")
+assert(LibStub:GetLibrary("CallbackHandler-1.0", true), "LibDataBroker-1.1 requires CallbackHandler-1.0")
+
+local lib, oldminor = LibStub:NewLibrary("LibDataBroker-1.1", 4)
+if not lib then return end
+oldminor = oldminor or 0
+
+
+lib.callbacks = lib.callbacks or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib)
+lib.attributestorage, lib.namestorage, lib.proxystorage = lib.attributestorage or {}, lib.namestorage or {}, lib.proxystorage or {}
+local attributestorage, namestorage, callbacks = lib.attributestorage, lib.namestorage, lib.callbacks
+
+if oldminor < 2 then
+	lib.domt = {
+		__metatable = "access denied",
+		__index = function(self, key) return attributestorage[self] and attributestorage[self][key] end,
+	}
+end
+
+if oldminor < 3 then
+	lib.domt.__newindex = function(self, key, value)
+		if not attributestorage[self] then attributestorage[self] = {} end
+		if attributestorage[self][key] == value then return end
+		attributestorage[self][key] = value
+		local name = namestorage[self]
+		if not name then return end
+		callbacks:Fire("LibDataBroker_AttributeChanged", name, key, value, self)
+		callbacks:Fire("LibDataBroker_AttributeChanged_"..name, name, key, value, self)
+		callbacks:Fire("LibDataBroker_AttributeChanged_"..name.."_"..key, name, key, value, self)
+		callbacks:Fire("LibDataBroker_AttributeChanged__"..key, name, key, value, self)
+	end
+end
+
+if oldminor < 2 then
+	function lib:NewDataObject(name, dataobj)
+		if self.proxystorage[name] then return end
+
+		if dataobj then
+			assert(type(dataobj) == "table", "Invalid dataobj, must be nil or a table")
+			self.attributestorage[dataobj] = {}
+			for i,v in pairs(dataobj) do
+				self.attributestorage[dataobj][i] = v
+				dataobj[i] = nil
+			end
+		end
+		dataobj = setmetatable(dataobj or {}, self.domt)
+		self.proxystorage[name], self.namestorage[dataobj] = dataobj, name
+		self.callbacks:Fire("LibDataBroker_DataObjectCreated", name, dataobj)
+		return dataobj
+	end
+end
+
+if oldminor < 1 then
+	function lib:DataObjectIterator()
+		return pairs(self.proxystorage)
+	end
+
+	function lib:GetDataObjectByName(dataobjectname)
+		return self.proxystorage[dataobjectname]
+	end
+
+	function lib:GetNameByDataObject(dataobject)
+		return self.namestorage[dataobject]
+	end
+end
+
+if oldminor < 4 then
+	local next = pairs(attributestorage)
+	function lib:pairs(dataobject_or_name)
+		local t = type(dataobject_or_name)
+		assert(t == "string" or t == "table", "Usage: ldb:pairs('dataobjectname') or ldb:pairs(dataobject)")
+
+		local dataobj = self.proxystorage[dataobject_or_name] or dataobject_or_name
+		assert(attributestorage[dataobj], "Data object not found")
+
+		return next, attributestorage[dataobj], nil
+	end
+
+	local ipairs_iter = ipairs(attributestorage)
+	function lib:ipairs(dataobject_or_name)
+		local t = type(dataobject_or_name)
+		assert(t == "string" or t == "table", "Usage: ldb:ipairs('dataobjectname') or ldb:ipairs(dataobject)")
+
+		local dataobj = self.proxystorage[dataobject_or_name] or dataobject_or_name
+		assert(attributestorage[dataobj], "Data object not found")
+
+		return ipairs_iter, attributestorage[dataobj], 0
+	end
+end
diff --git a/libs/LibDataBroker-1-1/README.textile b/libs/LibDataBroker-1-1/README.textile
new file mode 100644
index 0000000..ef16fed
--- /dev/null
+++ b/libs/LibDataBroker-1-1/README.textile
@@ -0,0 +1,13 @@
+LibDataBroker is a small WoW addon library designed to provide a "MVC":http://en.wikipedia.org/wiki/Model-view-controller interface for use in various addons.
+LDB's primary goal is to "detach" plugins for TitanPanel and FuBar from the display addon.
+Plugins can provide data into a simple table, and display addons can receive callbacks to refresh their display of this data.
+LDB also provides a place for addons to register "quicklaunch" functions, removing the need for authors to embed many large libraries to create minimap buttons.
+Users who do not wish to be "plagued" by these buttons simply do not install an addon to render them.
+
+Due to it's simple generic design, LDB can be used for any design where you wish to have an addon notified of changes to a table.
+
+h2. Links
+
+* "API documentation":http://github.com/tekkub/libdatabroker-1-1/wikis/api
+* "Data specifications":http://github.com/tekkub/libdatabroker-1-1/wikis/data-specifications
+* "Addons using LDB":http://github.com/tekkub/libdatabroker-1-1/wikis/addons-using-ldb