annotate Classes/ItemData.class.lua @ 176:26c750a10b14

Renamed Inventorium debug channel to IMDebug (so it?s easier to recognize only IM changes, not from other addons), write /im d to register this new channel. Implemented stock alerts. Added ?don?t alert at characters? option which allows you to track groups at characters without being bothered about low stock. You can change the speed of the stock alert at the extra config tab.
author Zerotorescue
date Sun, 30 Jan 2011 15:39:18 +0100
parents 3bec0ea44607
children
rev   line source
Zerotorescue@74 1 local addon = select(2, ...);
Zerotorescue@74 2
Zerotorescue@74 3 -- Define the class
Zerotorescue@74 4
Zerotorescue@74 5 addon.ItemData = {};
Zerotorescue@74 6 addon.ItemData.__index = addon.ItemData;
Zerotorescue@74 7
Zerotorescue@74 8 -- Construct
Zerotorescue@74 9 function addon.ItemData:New(itemId)
Zerotorescue@74 10 local self = {};
Zerotorescue@74 11
Zerotorescue@74 12 setmetatable(self, addon.ItemData);
Zerotorescue@74 13
Zerotorescue@74 14 local itemName, itemLink, itemRarity, _, _, _, _, _, _, itemTexture = GetItemInfo(itemId);
Zerotorescue@74 15
Zerotorescue@74 16 -- Standard info everything needs
Zerotorescue@74 17 self.id = itemId;
Zerotorescue@74 18 self.name = itemName;
Zerotorescue@74 19 self.link = itemLink;
Zerotorescue@74 20 self.rarity = itemRarity;
Zerotorescue@74 21 self.icon = itemTexture;
Zerotorescue@74 22
Zerotorescue@74 23 -- Detailed stuff
Zerotorescue@74 24 self.value = -3;
Zerotorescue@74 25 self.globalCount = -3;
Zerotorescue@74 26 self.localCount = -3;
Zerotorescue@74 27 self.set = {};
Zerotorescue@74 28
Zerotorescue@74 29 return self;
Zerotorescue@74 30 end
Zerotorescue@76 31
Zerotorescue@76 32 function addon.ItemData:AddToGroup(groupName)
Zerotorescue@76 33 if self:InGroup() then
Zerotorescue@76 34 return false;
Zerotorescue@76 35 end
Zerotorescue@76 36
Zerotorescue@76 37 if not addon.db.profile.groups[groupName].items then
Zerotorescue@76 38 addon.db.profile.groups[groupName].items = {};
Zerotorescue@76 39 end
Zerotorescue@76 40
Zerotorescue@76 41 -- Set this item
Zerotorescue@76 42 addon.db.profile.groups[groupName].items[self.id] = true;
Zerotorescue@76 43
Zerotorescue@76 44 return true;
Zerotorescue@76 45 end
Zerotorescue@76 46
Zerotorescue@76 47 -- To remove an item without groupname just do RemoveFromGroup(InGroup()), although providing the group name is a nice sanity check
Zerotorescue@76 48 function addon.ItemData:RemoveFromGroup(groupName)
Zerotorescue@76 49 if self:InGroup() ~= groupName then
Zerotorescue@76 50 return false;
Zerotorescue@76 51 end
Zerotorescue@76 52
Zerotorescue@76 53 -- Unset this item
Zerotorescue@76 54 addon.db.profile.groups[groupName].items[self.id] = nil;
Zerotorescue@76 55
Zerotorescue@76 56 return true;
Zerotorescue@76 57 end
Zerotorescue@76 58
Zerotorescue@76 59 function addon.ItemData:InGroup()
Zerotorescue@76 60 -- Go through all groups to see if this item is already somewhere
Zerotorescue@76 61 for groupName, values in pairs(addon.db.profile.groups) do
Zerotorescue@76 62 if values.items and values.items[self.id] then
Zerotorescue@76 63 return groupName;
Zerotorescue@76 64 end
Zerotorescue@76 65 end
Zerotorescue@76 66
Zerotorescue@76 67 return;
Zerotorescue@76 68 end