diff WowObjects.lua @ 13:6cb9a2936580

Miscellanous Lua code consistency improvements: - no semicolon except between statements on same line - use of implicit cast to bool in if/while conditions, instead of various eq/neq against true, false or nil - no parenthesis around if/while conditions (C-ism) - avoid long function calls in if conditions - removed space in comma-separated expressions lists in multiple assignments - added spaces between arguments of functions calls - use tabs for indentation (in Lua files only) - don't reverse == in if conditions, like "if 42==foo then" (C-ism) - removed some extra parenthesis in complex expressions (C-ism) - added spaces around operators in most expressions for ease of reading - added comma after last element of table initializers - removed space after # operator - moved comment prefix of disabled code into tab (to keep disabled code aligned)
author madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09
date Thu, 25 Apr 2013 01:29:45 +0000
parents d186f8cd5000
children 9f2d838d4f8e
line wrap: on
line diff
--- a/WowObjects.lua	Tue Apr 16 15:19:23 2013 +0000
+++ b/WowObjects.lua	Thu Apr 25 01:29:45 2013 +0000
@@ -1,4 +1,4 @@
---~ Warcraft Plugin for Cyborg MMO7 
+--~ Warcraft Plugin for Cyborg MMO7
 --~ Filename: WowObjects.lua
 --~ Description: Warcraft in game object models
 --~ Copyright (C) 2012 Mad Catz Inc.
@@ -20,37 +20,37 @@
 
 CyborgMMO_WowObject = {
 	new = function(type, detail, subdetail)
-		local self = {};
-		self.Texture = nil;
-		self.Name = "NoName";
-		self.Type = type;
-		self.Detail = detail;
-		self.Subdetail = subdetail;
-
+		local self = {}
+		self.Texture = nil
+		self.Name = "NoName"
+		self.Type = type
+		self.Detail = detail
+		self.Subdetail = subdetail
 
 		-- Methods --
 		self.DoAction = function()
-			msg("Nothing To Do");
+			msg("Nothing To Do")
 		end
 
 		self.Pickup = function()
-			msg("Pick up Item");
+			msg("Pick up Item")
 		end
 
 		self.SetBinding = function(key)
 		end
 
 		self.PlaySound = function()
-			PlaySound("igAbilityIconDrop");
+			PlaySound("igAbilityIconDrop")
 		end
 
-		return self;
+		return self
 	end,
 
 	ClearBinding = function(key)
-		local buttonFrame, parentFrame, name = CyborgMMO_CallbackFactory.Instance().AddCallback(CyborgMMO_WowObject.DoNothing);
-		if(1 ~= SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton")) then
-			msg("Failed to bind companion to button click");
+		local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory.Instance().AddCallback(CyborgMMO_WowObject.DoNothing)
+		local result = SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton")
+		if result ~= 1 then
+			msg("Failed to bind companion to button click")
 		end
 	end,
 
@@ -58,158 +58,155 @@
 	end,
 
 	Load = function(object)
-		if("item" == type) then
+		if type == "item" then
 			object = CyborgMMO_WowItem.Load(Object)
-		elseif("macro" == type) then
+		elseif type == "macro" then
 			object = CyborgMMO_WowMacro.Load(object)
-		elseif("spell" == type) then
+		elseif type == "spell" then
 			object = CyborgMMO_WowSpell.Load(object)
-		elseif("petaction" == type) then
+		elseif type == "petaction" then
 			object = CyborgMMO_WowSpell.Load(object)
-		--elseif("merchant"== type) then
-			--object = SlotMerchant.new(detail,subdetail)
-		elseif("companion" == type) then
+	--	elseif type == "merchant" then
+	--		object = SlotMerchant.new(detail, subdetail)
+		elseif type == "companion" then
 			object = CyborgMMO_WowCompanion.Load(object)
-		elseif("equipmentset" == type) then
+		elseif type == "equipmentset" then
 			object = CyborgMMO_WowEquipmentSet.Load(object)
 		else
-			object = CyborgMMO_WowObject.new(type,detail, subdetail)
+			object = CyborgMMO_WowObject.new(type, detail, subdetail)
 		end
-		return object;
+		return object
 	end,
 
 	-- Static Methods --
 	Create = function(objectType, detail, subdetail)
-		local object;
-		if("item" == objectType) then
-			object = CyborgMMO_WowItem.new(detail,subdetail)
-		elseif("macro" == objectType) then
+		local object
+		if objectType == "item" then
+			object = CyborgMMO_WowItem.new(detail, subdetail)
+		elseif objectType == "macro" then
 			object = CyborgMMO_WowMacro.new(detail)
-		elseif("spell" == objectType) then
-			object = CyborgMMO_WowSpell.new(objectType, detail,subdetail)
-		elseif("petaction" == objectType) then
-			object = CyborgMMO_WowSpell.new(objectType, detail,subdetail)
-		elseif("merchant"== objectType) then
-			object = CyborgMMO_SlotMerchant.new(detail,subdetail)
-		elseif("companion" == objectType) then
-			object = CyborgMMO_WowCompanion.new(detail,subdetail)
-		elseif("equipmentset" == objectType) then
-			object = CyborgMMO_WowEquipmentSet.new(objectType,detail,subdetail)
-		elseif("callback" == objectType) then
-			object = CyborgMMO_WowCallback.new(detail);
+		elseif objectType == "spell" then
+			object = CyborgMMO_WowSpell.new(objectType, detail, subdetail)
+		elseif objectType == "petaction" then
+			object = CyborgMMO_WowSpell.new(objectType, detail, subdetail)
+		elseif objectType == "merchant" then
+			object = CyborgMMO_SlotMerchant.new(detail, subdetail)
+		elseif objectType == "companion" then
+			object = CyborgMMO_WowCompanion.new(detail, subdetail)
+		elseif objectType == "equipmentset" then
+			object = CyborgMMO_WowEquipmentSet.new(objectType, detail, subdetail)
+		elseif objectType == "callback" then
+			object = CyborgMMO_WowCallback.new(detail)
 		else
-			object = CyborgMMO_WowObject.new(objectType,detail, subdetail)
+			object = CyborgMMO_WowObject.new(objectType, detail, subdetail)
 		end
 
-		return object;
-	end
+		return object
+	end,
 }
 
-local CallbackCursor = nil;
+local CallbackCursor = nil
 
 CyborgMMO_CallbackIcons = {
 	new = function(self)
-		self.point, self.relativeTo, self.relativePoint, self.xOfs, self.yOfs = self:GetPoint();
-		--self:SetPoint(self.point, self.relativeTo, self.relativePoint, self.xOfs, self.yOfs);
-		self.strata = self:GetFrameStrata();
+		self.point,
+		self.relativeTo,
+		self.relativePoint,
+		self.xOfs,
+		self.yOfs = self:GetPoint()
+	--	self:SetPoint(self.point, self.relativeTo, self.relativePoint, self.xOfs, self.yOfs)
+		self.strata = self:GetFrameStrata()
 		self.wowObject = CyborgMMO_WowCallback.new(string.gsub(self:GetName(), self:GetParent():GetName(), "",1))
-		self.wowObject.SetTextures(self);
+		self.wowObject.SetTextures(self)
 		self:RegisterForDrag("LeftButton","RightButton")
-		self:SetResizable(false);
-		
+		self:SetResizable(false)
+
 		self.OnClick = function()
-			self.wowObject.DoAction();
+			self.wowObject.DoAction()
 		end
-		
-		
+
 		self.DragStart = function()
-			self:SetMovable(true);
-			self:StartMoving();
-			self.isMoving = true;
+			self:SetMovable(true)
+			self:StartMoving()
+			self.isMoving = true
 			self:SetFrameStrata("TOOLTIP")
 		end
-		
+
 		self.DragStop = function()
-		
-			self:SetFrameStrata(self.strata);
-			self.isMoving = false;
-			self:SetMovable(false);
-			self:StopMovingOrSizing();
+			self:SetFrameStrata(self.strata)
+			self.isMoving = false
+			self:SetMovable(false)
+			self:StopMovingOrSizing()
 
-			self:ClearAllPoints();
-			self:SetPoint(self.point, self.relativeTo, self.relativePoint, self.xOfs, self.yOfs);
-			local x, y  = GetCursorPosition();
+			self:ClearAllPoints()
+			self:SetPoint(self.point, self.relativeTo, self.relativePoint, self.xOfs, self.yOfs)
+			local x,y = GetCursorPosition()
 			CyborgMMO_RatPageController.Instance().CallbackDropped(self)
 		end
-		
-		return self;
-	end
+
+		return self
+	end,
 }
 
 CyborgMMO_WowCallback = {
 	new = function(callbackName)
-		local self = CyborgMMO_WowObject.new("callback", callbackName, "");
-		self.CallbackName = callbackName;
+		local self = CyborgMMO_WowObject.new("callback", callbackName, "")
+		self.CallbackName = callbackName
 		self.Texture = "Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Unselected.tga"
-		
+
 		self.SetTextures = function(buttonFrame)
 			msg("TextureName = "..self.CallbackName)
 			buttonFrame:SetNormalTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Unselected.tga")
 			buttonFrame:SetPushedTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Down.tga")
 			buttonFrame:SetHighlightTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Over.tga")
 		end
-		
+
 		self.DoAction = function()
 			local action = CyborgMMO_CallbackFactory.Instance().GetCallback(self.CallbackName)
-			msg("calling callback:- "..self.CallbackName);
-			action();
-			
+			msg("calling callback:- "..self.CallbackName)
+			action()
 		end
-		
+
 		self.PickupCallback = function()
-			
-			local slot = nil;
-			local observers = CyborgMMO_RatPageModel.Instance().GetAllObservers();
-			for i = 1, (# observers) do
-				if(MouseIsOver(observers[i])) then
-					slot = observers[i];
-					break;
+			local slot = nil
+			local observers = CyborgMMO_RatPageModel.Instance().GetAllObservers()
+			for i=1,#observers do
+				if MouseIsOver(observers[i]) then
+					slot = observers[i]
+					break
 				end
 			end
 			slot:SetNormalTexture(slot.UnCheckedTexture)
 		end
 
-		
 		self.ClickHandler = function(self, button, down)
-			msg("click handler");
-			CallbackCursor:StopMoving();
-			CallbackCursor:Hide();
+			msg("click handler")
+			CallbackCursor:StopMoving()
+			CallbackCursor:Hide()
 		end
-		
+
 		self.Pickup = function()
 			self.PlaySound()
-			ClearCursor();
-			self.PickupCallback();
+			ClearCursor()
+			self.PickupCallback()
+		end
 
-		end
-		
-		
 		self.SetBinding = function(key)
-			local buttonFrame, parentFrame, name = CyborgMMO_CallbackFactory.Instance().AddCallback(self.DoAction);
-			if(1 ~= SetOverrideBindingClick(CyborgMMO_CallbackFactory.Instance().Frame, true, key, name, "LeftButton")) then
-				msg("Failed to Bind modeChange");
+			local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory.Instance().AddCallback(self.DoAction)
+			local result = SetOverrideBindingClick(CyborgMMO_CallbackFactory.Instance().Frame, true, key, name, "LeftButton")
+			if result ~= 1 then
+				msg("Failed to Bind modeChange")
 			end
 		end
-		
-		return self;
-	end
+
+		return self
+	end,
 }
 
 -- WowItem Class --
-
 CyborgMMO_WowItem = {
 	new = function(number, itemID)
-		local self = CyborgMMO_WowObject.new("item", number, itemID); -- base class
+		local self = CyborgMMO_WowObject.new("item", number, itemID) -- base class
 		-- Set all the item info. --
 		self.Name,
 		self.Link,
@@ -221,153 +218,153 @@
 		self.StackCount,
 		self.EquipLoc,
 		self.Texture,
-		self.SellPrice = GetItemInfo(itemID);
+		self.SellPrice = GetItemInfo(itemID)
 
 		-- override method --
 		self.DoAction = function()
-			msg("Use Item");
+			msg("Use Item")
 		end
 
 		-- override method --
 		self.Pickup = function()
 			self.PlaySound()
-			ClearCursor();
-			--SetCursor(self.Texture);
-			return PickupItem(self.Link);
+			ClearCursor()
+		--	SetCursor(self.Texture)
+			return PickupItem(self.Link)
 		end
 
 		self.SetBinding = function(key)
-			SetOverrideBinding(CyborgMMO_CallbackFactory.Instance().Frame, true, key, "ITEM "..self.Name);
+			SetOverrideBinding(CyborgMMO_CallbackFactory.Instance().Frame, true, key, "ITEM "..self.Name)
 		end
 
-		return self;
+		return self
 	end,
 }
 
 -- WowSpell Class --
-
 CyborgMMO_WowSpell = {
 	new = function(type, spellbookID, spellbook)
 		local self = CyborgMMO_WowObject.new(type, spellbookID, spellbook) -- base class
-		self.SpellbookID = spellbookID;
-		self.Spellbook = spellbook;
-		self.Name, self.Rank = GetSpellBookItemName(spellbookID, spellbook);
-		self.Texture = GetSpellBookItemTexture(spellbookID, spellbook);
-		self.Type = type;
+		self.SpellbookID = spellbookID
+		self.Spellbook = spellbook
+		self.Name,self.Rank = GetSpellBookItemName(spellbookID, spellbook)
+		self.Texture = GetSpellBookItemTexture(spellbookID, spellbook)
+		self.Type = type
 
 
 		-- override method --
 		self.DoAction = function()
-			msg("Cast Spell");
+			msg("Cast Spell")
 		end
 
 		-- override method --
 		self.Pickup = function()
 			self.PlaySound()
-			ClearCursor();
-			--SetCursor(self.Texture);
-			return PickupSpellBookItem(self.SpellbookID, self.Spellbook);
+			ClearCursor()
+		--	SetCursor(self.Texture)
+			return PickupSpellBookItem(self.SpellbookID, self.Spellbook)
 		end
 
 		self.SetBinding = function(key)
 			msg("Binding to key "..key)
 			self.Key = key
-			SetOverrideBinding(CyborgMMO_CallbackFactory.Instance().Frame, true, self.Key, self.Type.." "..self.Name);
+			SetOverrideBinding(CyborgMMO_CallbackFactory.Instance().Frame, true, self.Key, self.Type.." "..self.Name)
 		end
 
-    return self;
-
+		return self
 	end,
 
 	Load = function(object)
-		local o = WowSpell.new(object.Type, object.Detail, object.Subdetail);
-		o.Name = object.Name;
-		o.Texture = object.Texture;
-		return o;
-	end
+		local o = WowSpell.new(object.Type, object.Detail, object.Subdetail)
+		o.Name = object.Name
+		o.Texture = object.Texture
+		return o
+	end,
 }
 
 -- WowMacro Class --
-
 CyborgMMO_WowMacro = {
 	new = function(index)
-		local self = CyborgMMO_WowObject.new("macro", index, nil); -- base class
+		local self = CyborgMMO_WowObject.new("macro", index, nil) -- base class
 		-- Set all the item info. --
 		self.Name,
 		self.Texture,
 		self.Body,
-		self.isLocal = GetMacroInfo(index);
-		self.Index = index;
+		self.isLocal = GetMacroInfo(index)
+		self.Index = index
 
 		-- override method --
 		self.DoAction = function()
-			msg("Use Item");
+			msg("Use Item")
 		end
 
 		-- override method --
 		self.Pickup = function()
 			self.PlaySound()
-			ClearCursor();
-			--SetCursor(self.Texture);
-			return PickupMacro(self.Index);
+			ClearCursor()
+		--	SetCursor(self.Texture)
+			return PickupMacro(self.Index)
 		end
 
 		self.SetBinding = function(key)
-			self.Key = key;
-			SetOverrideBinding(CyborgMMO_CallbackFactory.Instance().Frame, true, key, "MACRO "..self.Index);
+			self.Key = key
+			SetOverrideBinding(CyborgMMO_CallbackFactory.Instance().Frame, true, key, "MACRO "..self.Index)
 		end
 
-    return self;
-  end,
+		return self
+	end,
 }
 
-
 -- WowCompanion Class --
-
 CyborgMMO_WowCompanion = {
 	new = function(index, SubType)
-		local self = CyborgMMO_WowObject.new("companion", index, SubType); -- base class
+		local self = CyborgMMO_WowObject.new("companion", index, SubType) -- base class
 		-- Set all the item info. --
-		self.Id, self.Name, self.SpellId, self.Texture,	self.isSummoned = GetCompanionInfo(SubType, index);
-		self.SubType = SubType;
-		self.index = index;
+		self.Id,
+		self.Name,
+		self.SpellId,
+		self.Texture,
+		self.isSummoned = GetCompanionInfo(SubType, index)
+		self.SubType = SubType
+		self.index = index
 		-- override method --
 		self.DoAction = function()
-			if((self.SubType == "MOUNT") and IsMounted()) then
-				Dismount();
+			if self.SubType == "MOUNT" and IsMounted() then
+				Dismount()
 			else
-				CallCompanion(self.SubType, self.index);
+				CallCompanion(self.SubType, self.index)
 			end
 		end
 
 		-- override method --
 		self.Pickup = function()
 			self.PlaySound()
-			return PickupCompanion(self.SubType, self.index);
+			return PickupCompanion(self.SubType, self.index)
 		end
 
 		self.SetBinding = function(key)
 			self.Key = key
-			local buttonFrame, parentFrame, name = CyborgMMO_CallbackFactory.Instance().AddCallback(self.DoAction);
-			if(1 ~= SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton")) then
-				msg("Failed to bind companion to button click");
+			local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory.Instance().AddCallback(self.DoAction)
+			local result = SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton")
+			if result ~= 1 then
+				msg("Failed to bind companion to button click")
 			end
-			--SetOverrideBinding(hiddenModeChanger, true, key, "MACRO "..self.Index);
+		--	SetOverrideBinding(hiddenModeChanger, true, key, "MACRO "..self.Index)
 		end
 
-		return self;
+		return self
 	end,
 
 	Load = function(object)
-		local o = WowCompanion.new(object.index, object.SubType);
-		return o;
-	end
+		local o = WowCompanion.new(object.index, object.SubType)
+		return o
+	end,
 }
 
 -- WowMerchant Class --
 CyborgMMO_WowMerchant = {
 	new = function(index)
-		local self = CyborgMMO_WowObject.new("macro", index, nil); -- base class
+		local self = CyborgMMO_WowObject.new("macro", index, nil) -- base class
 		-- Set all the item info. --
 		self.Name,
 		self.Texture,
@@ -375,65 +372,65 @@
 		self.Quantity,
 		self.NumAvailable,
 		self.IsUsable,
-		self.ExtendedCost = GetMerchantItemInfo(index);
-		self.Index = index;
+		self.ExtendedCost = GetMerchantItemInfo(index)
+		self.Index = index
 
 		-- override method --
 		self.DoAction = function()
-			msg("Use Item");
+			msg("Use Item")
 		end
 
 		-- override method --
 		self.Pickup = function()
 			self.PlaySound()
-			ClearCursor();
-			--SetCursor(self.Texture);
-			return PickupMerchantItem(self.Index);
+			ClearCursor()
+		--	SetCursor(self.Texture)
+			return PickupMerchantItem(self.Index)
 		end
 
 		self.SetBinding = function(key)
 			self.Key = key
-			SetOverrideBinding(CyborgMMO_CallbackFactory.Instance().Frame, true, key, "MERCHANT "..self.Index);
+			SetOverrideBinding(CyborgMMO_CallbackFactory.Instance().Frame, true, key, "MERCHANT "..self.Index)
 		end
 
-    return self;
-  end,
+		return self
+	end,
 }
 
 -- WowEquipmentSet Class --
 CyborgMMO_WowEquipmentSet = {
 	new = function(objectType, name, index)
-		local self = CyborgMMO_WowObject.new(objectType, name, index); -- base class
+		local self = CyborgMMO_WowObject.new(objectType, name, index) -- base class
 		-- Set all the item info. --
-		texture, lessIndex = GetEquipmentSetInfoByName(name);
-		self.Texture = "Interface\\Icons\\"..texture;
+		texture,lessIndex = GetEquipmentSetInfoByName(name)
+		self.Texture = "Interface\\Icons\\"..texture
 		self.Name = name
-		self.Index = lessIndex+1;
+		self.Index = lessIndex + 1
 
 		-- override method --
 		self.DoAction = function()
-			UseEquipmentSet(self.Name);
+			UseEquipmentSet(self.Name)
 		end
 
 		-- override method --
 		self.Pickup = function()
 			self.PlaySound()
-			ClearCursor();
-			--SetCursor(self.Texture);
-			return PickupEquipmentSetByName(self.Name);
+			ClearCursor()
+		--	SetCursor(self.Texture)
+			return PickupEquipmentSetByName(self.Name)
 		end
 
 		self.SetBinding = function(key)
 			self.Key = key
-			local buttonFrame, parentFrame, name = CyborgMMO_CallbackFactory.Instance().AddCallback(self.DoAction);
-			if(1 ~= SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton")) then
-				msg("Failed to bind companion to button click");
+			local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory.Instance().AddCallback(self.DoAction);
+			local result = SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton")
+			if result ~= 1 then
+				msg("Failed to bind companion to button click")
 			end
 		end
 
-    return self;
-  end,
+		return self
+	end,
 }
 
-
 -- End Of WowObjects --