changeset 39:ce4ddefb68c2

Fail early when a wow object cannot be created. Default to empty slots rather than empty wow objects.
author madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09
date Thu, 25 Apr 2013 18:16:03 +0000
parents d12a5a7d2be5
children 67ad1101ee10
files RatPageModel.lua WowObjects.lua
diffstat 2 files changed, 49 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/RatPageModel.lua	Thu Apr 25 18:15:57 2013 +0000
+++ b/RatPageModel.lua	Thu Apr 25 18:16:03 2013 +0000
@@ -76,13 +76,12 @@
 	if data then
 		for mode=1,RAT7.MODES do
 			for button=1,RAT7.BUTTONS do
-				if self.data[mode][button] then
-					local object = CyborgMMO_CreateWowObject(self.data[mode][button].type, self.data[mode][button].detail, self.data[mode][button].subdetail)
+				local data = self.data[mode][button]
+				if data and data.type then
+					local object = CyborgMMO_CreateWowObject(data.type, data.detail, data.subdetail)
 					self:SetObjectOnButtonNoUpdate(button, mode, object)
 				else
-					local object = CyborgMMO_CreateWowObject()
-					self:SetObjectOnButtonNoUpdate(button, mode, object)
-					self.data[mode][button] = object
+					self:SetObjectOnButtonNoUpdate(button, mode, nil)
 				end
 			end
 		end
@@ -128,12 +127,14 @@
 			slot:SetNormalTexture(object.texture)
 		end
 	else
-		CyborgMMO_DPrint("clearing "..button)
 		CyborgMMO_ClearBinding(CyborgMMO_ProfileKeyBindings[((mode-1)*RAT7.BUTTONS)+button])
 	end
 end
 
 function RatPageModel_methods:SetObjectOnButton(button, mode, object)
+	if not object then
+		CyborgMMO_DPrint("clearing "..button)
+	end
 	self:SetObjectOnButtonNoUpdate(button, mode, object)
 	self:UpdateObservers()
 end
--- a/WowObjects.lua	Thu Apr 25 18:15:57 2013 +0000
+++ b/WowObjects.lua	Thu Apr 25 18:16:03 2013 +0000
@@ -110,10 +110,15 @@
 local WowItem_mt = {__index=WowItem_methods}
 
 local function WowItem(itemID)
+	local texture = select(10, GetItemInfo(itemID)) -- :FIXME: this may fail too early in the session (like when loading saved data)
+	if not texture then
+		return nil
+	end
+
 	local self = WowObject("item", itemID)
 
 	self.itemID = itemID
-	self.texture = select(10, GetItemInfo(itemID)) -- :FIXME: this may fail too early in the session (like when loading saved data)
+	self.texture = texture
 
 	setmetatable(self, WowItem_mt)
 
@@ -138,10 +143,15 @@
 local WowSpell_mt = {__index=WowSpell_methods}
 
 local function WowSpell(spellID)
+	local texture = GetSpellTexture(spellID)
+	if not texture then
+		return nil
+	end
+
 	local self = WowObject("spell", spellID)
 
 	self.spellID = spellID
-	self.texture = GetSpellTexture(spellID)
+	self.texture = texture
 
 	setmetatable(self, WowSpell_mt)
 
@@ -173,10 +183,15 @@
 local WowMacro_mt = {__index=WowMacro_methods}
 
 local function WowMacro(name)
+	local texture = select(2, GetMacroInfo(name))
+	if not texture then
+		return nil
+	end
+
 	local self = WowObject("macro", name)
 
 	self.name = name
-	self.texture = select(2, GetMacroInfo(name))
+	self.texture = texture
 
 	setmetatable(self, WowMacro_mt)
 
@@ -204,11 +219,16 @@
 local WowCompanion_mt = {__index=WowCompanion_methods}
 
 local function WowCompanion(spellID)
+	local texture = select(3, GetSpellInfo(spellID))
+	if not texture then
+		return nil
+	end
+
 	local self = WowObject("companion", spellID)
 	CyborgMMO_DPrint("creating companion binding:", type, spellID)
 
 	self.spellID = spellID
-	self.texture = select(3, GetSpellInfo(spellID))
+	self.texture = texture
 
 	setmetatable(self, WowCompanion_mt)
 
@@ -255,10 +275,14 @@
 local WowEquipmentSet_mt = {__index=WowEquipmentSet_methods}
 
 local function WowEquipmentSet(name)
+	local texture = GetEquipmentSetInfoByName(name)
+	if not texture then
+		return nil
+	end
+
 	local self = WowObject("equipmentset", name)
 
 	self.name = name
-	local texture = GetEquipmentSetInfoByName(name)
 	self.texture = "Interface\\Icons\\"..texture
 
 	setmetatable(self, WowEquipmentSet_mt)
@@ -288,11 +312,16 @@
 local WowBattlePet_mt = {__index=WowBattlePet_methods}
 
 local function WowBattlePet(petID)
+	local texture = select(9, C_PetJournal.GetPetInfoByPetID(petID)) -- :FIXME: this may fail too early in the session (like when loading saved data)
+	if not texture then
+		return nil
+	end
+
 	local self = WowObject("battlepet", petID)
 	CyborgMMO_DPrint("creating battle pet binding:", petID)
 
 	self.petID = petID
-	self.texture = select(9, C_PetJournal.GetPetInfoByPetID(petID)) -- :FIXME: this may fail too early in the session (like when loading saved data)
+	self.texture = texture
 
 	setmetatable(self, WowBattlePet_mt)
 
@@ -373,16 +402,10 @@
 ------------------------------------------------------------------------------
 
 function CyborgMMO_CreateWowObject(type, ...)
-	local object
+	local object,unsupported
 
 	if type == "item" then
-		-- :KLUDGE: if the item is not in the cache, return an empty WowObject
-		local id = ...
-		if not GetItemInfo(id) then
-			object = WowObject()
-		else
-			object = WowItem(...)
-		end
+		object = WowItem(...)
 	elseif type == "macro" then
 		object = WowMacro(...)
 	elseif type == "spell" then
@@ -396,7 +419,11 @@
 	elseif type == "callback" then
 		object = WowCallback(...)
 	else
-		object = WowObject(type, ...)
+		CyborgMMO_DPrint("unsupported wow object:", type, ...)
+		unsupported = true
+	end
+	if not object and not unsupported then
+		CyborgMMO_DPrint("creating "..tostring(type).." object failed:", type, ...)
 	end
 
 	return object