adam@0: local _, AskMrRobot = ... adam@0: adam@0: local unresolvedItemIds = {} adam@0: adam@0: -- Create a new class that inherits from a base class adam@0: function AskMrRobot.inheritsFrom( baseClass ) adam@0: adam@0: -- The following lines are equivalent to the SimpleClass example: adam@0: adam@0: -- Create the table and metatable representing the class. yellowfive@11: local new_class = { } adam@0: adam@0: -- Note that this function uses class_mt as an upvalue, so every instance adam@0: -- of the class will share the same metatable. adam@0: -- adam@0: -- function new_class:create(o) adam@0: -- o = o or {} adam@0: -- setmetatable( o, class_mt ) adam@0: -- return o adam@0: -- end adam@0: adam@0: -- The following is the key to implementing inheritance: adam@0: adam@0: -- The __index member of the new class's metatable references the adam@0: -- base class. This implies that all methods of the base class will adam@0: -- be exposed to the sub-class, and that the sub-class can override adam@0: -- any of these methods. adam@0: -- adam@0: if baseClass then adam@0: setmetatable( new_class, { __index = baseClass } ) adam@0: end adam@0: adam@0: return new_class adam@0: end adam@0: adam@0: local itemInfoFrame = nil; adam@0: adam@0: local function onGetItemInfoReceived(arg1, arg2, arg3) adam@0: -- since wow is awesome, it doesn't tell us *which* item id was just resolved, so we have to look at them all adam@0: for itemId, callbacks in pairs(unresolvedItemIds) do adam@0: -- attempt to get the item info AGAIN adam@0: local a, b, c, d, e, f, g, h, i, j, k = GetItemInfo(itemId) adam@0: -- if we got item info... adam@0: if a then adam@0: -- remove the callbacks from the list adam@0: unresolvedItemIds[itemId] = nil adam@0: adam@0: -- call each callback adam@0: for i = 1, #callbacks do adam@0: callbacks[i](a, b, c, d, e, f, g, h, i, j, k) adam@0: end adam@0: end adam@0: end adam@0: end adam@0: adam@0: adam@0: function AskMrRobot.RegisterItemInfoCallback(itemId, callback) adam@0: if not itemId then adam@0: return adam@0: end adam@0: adam@0: if not itemInfoFrame then adam@0: waitFrame = CreateFrame("Frame","WaitFrame", UIParent); adam@0: waitFrame:RegisterEvent("GET_ITEM_INFO_RECEIVED") adam@0: waitFrame:SetScript("OnEvent", onGetItemInfoReceived); adam@0: end adam@0: adam@0: adam@0: -- get the list of registered callbacks for this particular item adam@0: local list = unresolvedItemIds[itemId] adam@0: -- if there was a list, then just add the callback to the list adam@0: if list then adam@0: tinsert(list, callback) adam@0: else adam@0: -- there wasn't a list, so make a new one with this callback adam@0: unresolvedItemIds[itemId] = { callback } adam@0: end adam@0: end adam@0: adam@0: function AskMrRobot.getItemIdFromLink(item) adam@0: if not item then return 0 end adam@0: local id = tonumber (item:match ("item:(%d+):%d+:%d+:%d+:%d+:%d+:%-?%d+:%-?%d+:%d+:%d+")) adam@0: return (id and id ~= 0 and id or 0) adam@0: end adam@0: adam@0: -- initialize the Frame class (inherit from a dummy frame) adam@0: AskMrRobot.Frame = AskMrRobot.inheritsFrom(CreateFrame("Frame")) adam@0: adam@0: -- Frame contructor adam@0: function AskMrRobot.Frame:new(name, parentFrame, inheritsFrame) adam@0: -- create a new frame (if one isn't supplied) adam@0: local o = CreateFrame("Frame", name, parentFrame, inheritsFrame) adam@0: adam@0: -- use the Frame class adam@0: setmetatable(o, { __index = AskMrRobot.Frame }) adam@0: adam@0: -- return the instance of the Frame adam@0: return o adam@0: end adam@0: adam@0: local MAINHAND = nil adam@0: local OFFHAND = nil adam@0: adam@0: AskMrRobot.slotNames = {"HeadSlot", "NeckSlot", "ShoulderSlot", "BackSlot", "ChestSlot", "ShirtSlot", "TabardSlot", "WristSlot", "HandsSlot", "WaistSlot", "LegsSlot", "FeetSlot", "Finger0Slot", "Finger1Slot", "Trinket0Slot", "Trinket1Slot", "MainHandSlot", "SecondaryHandSlot", "AmmoSlot" }; adam@0: AskMrRobot.OptimizationSlots = {} adam@0: AskMrRobot.slotIdToSlotNum = {} adam@0: AskMrRobot.slotIds = {}; adam@0: for slotNum = 1, #AskMrRobot.slotNames do adam@0: local slotId = GetInventorySlotInfo(AskMrRobot.slotNames[slotNum]) adam@0: AskMrRobot.slotIds[slotNum] = slotId adam@0: AskMrRobot.slotIdToSlotNum[slotId] = slotNum adam@0: local slotName = AskMrRobot.slotNames[slotNum] adam@0: if slotName == "MainHandSlot" then adam@0: MAINHAND = slotNum adam@0: end adam@0: if slotName == "SecondaryHandSlot" then adam@0: OFFHAND = slotNum adam@0: end adam@0: if slotName ~= "TabardSlot" and slotName ~= "AmmoSlot" and slotName ~= "ShirtSlot" then adam@0: AskMrRobot.OptimizationSlots[slotNum] = true adam@0: end adam@0: adam@0: end adam@0: adam@0: AskMrRobot.sortedSlots = {[MAINHAND] = 1, [OFFHAND] = 2} adam@0: adam@0: local i = 3 adam@0: for slotNum = 1, #AskMrRobot.slotNames do adam@0: if slotNum ~= MAINHAND and slotNum ~= OFFHAND then adam@0: AskMrRobot.sortedSlots[slotNum] = i adam@0: i = i + 1 adam@0: end yellowfive@11: end