view Classes/ItemData.class.lua @ 89:a12d22ef3f39

AceSerializer has been enabled again as it?s used when exporting/importing groups. All other unused libraries are now really removed. Adjusted debug function to format only when a debug channel is available. Fixed moving from guild banks, checking if items are locked is different then with banks. Now unregistering the item locking event so it doesn?t continue to try to move every time an item is switched after the automated cycle has finished. (geeezus, this description is a total overkill) Fixed item queueing. Queue all when there?s a group without any items inside no longer crashes. Removing cached container data after closing a container.
author Zerotorescue
date Fri, 07 Jan 2011 22:19:03 +0100
parents 3bec0ea44607
children
line wrap: on
line source
local addon = select(2, ...);

-- Define the class

addon.ItemData = {};
addon.ItemData.__index = addon.ItemData;

-- Construct
function addon.ItemData:New(itemId)
	local self = {};
	
	setmetatable(self, addon.ItemData);
	
	local itemName, itemLink, itemRarity, _, _, _, _, _, _, itemTexture = GetItemInfo(itemId);
	
	-- Standard info everything needs
	self.id = itemId;
	self.name = itemName;
	self.link = itemLink;
	self.rarity = itemRarity;
	self.icon = itemTexture;
	
	-- Detailed stuff
	self.value = -3;
	self.globalCount = -3;
	self.localCount = -3;
	self.set = {};
	
	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