View Single Post
12-11-14, 10:07 AM   #2
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
Just took a glance at your code. I noticed that you can easily optimize by reusing similar code.

For instance, create health and power bar code just once and insert it for each unit.

You could do this with using a "Shared" function, that contains code used for every unit and/or by creating single functions. Somewhat like this:

Code:
local createPower = function(self) 	-- Power bar

.......

end
and insert it into each unit that you want to have a power bar, like:

Code:
UnitSpecific.player = function(self, ...)
	Shared(self, ...)                    -- only if you use a shared function, obviously
	createPower(self)                 

end
You can also do this with textures, like borders, background and so on ... Basically if you reuse code at least once on another frame, it makes sense to do it this way.



€: Just to add to the confusion, let's say you create a "createPower" function; you don't want to put the SetPoint stuff in there. Unless every unit you use is exactly the same, ofc. Only put the CreateFrame, background, PostUpdate, color and stuff like that in there.

Set your Points for each unit, after you inserted the createPower(self) function.

like

Code:
	UnitSpecific.player = function(self, ...)
		createPower(self)
		self.Power:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT", 38, 20)

		createRaidIcon(self)
		self.RaidIcon:SetPoint("TOPLEFT", self, "TOPLEFT", 4, 0)		
	end

	UnitSpecific.target = function(self, ...)
		createPower(self)
		self.Power:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", -38, 20)

		createRaidIcon(self)
		self.RaidIcon:SetPoint("TOPRIGHT", self, "TOPRIGHT", -4, 0)		
	end
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."


Last edited by Dawn : 12-11-14 at 10:14 AM.
  Reply With Quote