import mwpy_group

MWPYGroup = mwpy_group.MWPYGroup
MWPYGameObjectType = mwpy_group.MWPYGameObjectType
MWPYGameObjectState = mwpy_group.MWPYGameObjectState



class MWPYPipelineGroup(MWPYGroup):
	def __init__(self, gameObjectType = MWPYGameObjectType['MWGOT_PIPELINEGROUP']):
		MWPYGroup.__init__(self, gameObjectType)
		self.out_actor_status = "AS_LEFT"
		self.round_status = "AS_LEFT"
		
	def update_sprites_state(self, state, offset_x, offset_y):
		pos_x = round( (self.x + offset_x) * mwpy_group.mwpy_gameobject.ScrW) / mwpy_group.mwpy_gameobject.ScrW
		pos_y = round( (self.y + offset_y) * mwpy_group.mwpy_gameobject.ScrH) / mwpy_group.mwpy_gameobject.ScrH
		x012 = round(0.12  * mwpy_group.mwpy_gameobject.ScrW) / mwpy_group.mwpy_gameobject.ScrW
		x004 = round(0.04  * mwpy_group.mwpy_gameobject.ScrW) / mwpy_group.mwpy_gameobject.ScrW
		y002 = round(0.02  * mwpy_group.mwpy_gameobject.ScrH) / mwpy_group.mwpy_gameobject.ScrH
		y008 = round(0.08  * mwpy_group.mwpy_gameobject.ScrH) / mwpy_group.mwpy_gameobject.ScrH
		x008 = round(0.08  * mwpy_group.mwpy_gameobject.ScrW) / mwpy_group.mwpy_gameobject.ScrW
		width = round(self.w * 2 * mwpy_group.mwpy_gameobject.ScrW) / mwpy_group.mwpy_gameobject.ScrW
		height = round(self.h * 2 * mwpy_group.mwpy_gameobject.ScrH) / mwpy_group.mwpy_gameobject.ScrH
		watersprite = None
		waterendsprite = None
		waterbrinksprite = None
		waterdownsprite = None
		onLeft = self.round_status == "AS_LEFT"
		moveToLeft = self.out_actor_status == "AS_LEFT"
		if(state in self.states_info):
			sprite_list = self.states_info[state]
			for si in sprite_list:
				if(si.name == "WaterSprite"):
					watersprite = si
				elif(si.name == "WaterEndSprite"):
					waterendsprite = si
				elif(si.name == "WaterBrinkSprite"):
					waterbrinksprite = si
				elif(si.name == "WaterDownSprite"):
					waterdownsprite = si
			if(None != watersprite):
				if(width < 0.12):
					watersprite.enable = False
				else:
					if(onLeft == True):
						watersprite.posx = pos_x + x012
						watersprite.flip_h = True
						if(moveToLeft == True):
							watersprite.anim_inv = True
						
					else:
						watersprite.posx = pos_x
						if(moveToLeft == False):
							watersprite.anim_inv = True
					watersprite.posy = pos_y - y002
					watersprite.width = width - x012
					watersprite.height = y002
					lenw = watersprite.width / 0.08
					watersprite.tex_w = round(lenw, 0) + 1.0
					watersprite.tex_x = watersprite.tex_w - lenw
			if(None != waterendsprite):
				if(width < 0.04):
					waterendsprite.enable = False
				else:
					if(onLeft == True):
						#round to the left
						waterendsprite.posx = pos_x + x004
						waterendsprite.flip_h = True
						if(width < 0.12):
							waterendsprite.tex_x = waterendsprite.width / 0.08
						if(moveToLeft == True):
							waterendsprite.anim_inv = True
					else:
						waterendsprite.tex_w = waterendsprite.width / 0.08
						#round to the right
						waterendsprite.posx = pos_x + width - x012
						#move to the left
						if(moveToLeft == False):
							waterendsprite.anim_inv = True
					waterendsprite.posy = pos_y - y002
					waterendsprite.width = min(x008, width - x004)
					waterendsprite.height = y002

			if(None != waterbrinksprite):
				waterbrinksprite.posy = pos_y - y002
				waterbrinksprite.flip_h = False
				if(onLeft == True):
					waterbrinksprite.posx =  pos_x - x004
					waterbrinksprite.flip_h = True
				       
				else:
					waterbrinksprite.posx =  pos_x + width - x004

			if(None != waterdownsprite):
				waterdownsprite.posy = pos_y + y008
				waterdownsprite.height = 1.0 - waterdownsprite.posy
				waterdownsprite.tex_h = waterdownsprite.height / 0.08
				if(onLeft == True):
					waterdownsprite.posx =  pos_x - x004
					waterdownsprite.flip_h = True
				else:
					waterdownsprite.posx =  pos_x + width - x004
				 
			return sprite_list
		return []
