diff ItemData.class.lua @ 76:958aba5f3297

Moved the group functions to the item data class. Added a new subgroup under the general config group called ?extra? which will provide features such as database character removal and perhaps guild selecting. Added a new custom .Print function to the addon object which takes two parameters: (string)text, (Color)color. The latter can be retrieved from the addon.Colors var (e.g. addon.Colors.Red). The ItemId parameter of the ItemData class constructor is now optional.
author Zerotorescue
date Sat, 25 Dec 2010 22:07:07 +0100
parents 8d11fc88ecab
children
line wrap: on
line diff
--- a/ItemData.class.lua	Sat Dec 25 15:33:40 2010 +0100
+++ b/ItemData.class.lua	Sat Dec 25 22:07:07 2010 +0100
@@ -28,3 +28,41 @@
 	
 	return self;
 end
+
+function addon.ItemData:AddToGroup(groupName)
+	if self:InGroup() then
+		return false;
+	end
+	
+	if not addon.db.profile.groups[groupName].items then
+		addon.db.profile.groups[groupName].items = {};
+	end
+	
+	-- Set this item
+	addon.db.profile.groups[groupName].items[self.id] = true;
+	
+	return true;
+end
+
+-- To remove an item without groupname just do RemoveFromGroup(InGroup()), although providing the group name is a nice sanity check
+function addon.ItemData:RemoveFromGroup(groupName)
+	if self:InGroup() ~= groupName then
+		return false;
+	end
+	
+	-- Unset this item
+	addon.db.profile.groups[groupName].items[self.id] = nil;
+	
+	return true;
+end
+
+function addon.ItemData:InGroup()
+	-- Go through all groups to see if this item is already somewhere
+	for groupName, values in pairs(addon.db.profile.groups) do
+		if values.items and values.items[self.id] then
+			return groupName;
+		end
+	end
+	
+	return;
+end