import mwpy_gameobject

MWPYGameObject = mwpy_gameobject.MWPYGameObject
MWPYGameObjectType = mwpy_gameobject.MWPYGameObjectType
MWPYGameObjectState = mwpy_gameobject.MWPYGameObjectState


class MWPYButton(MWPYGameObject):
	def __init__(self, gameObjectType = MWPYGameObjectType['MWGOT_BUTTON']):
		MWPYGameObject.__init__(self, gameObjectType)
		self.state = MWPYGameObjectState['AS_CLOSE']
		self.is_pushed = False
		self.push_time = 0.0
		self.object_type = 'MWGOT_FOUNTAIN'
		self.object_id = 0
		self.object_method_on = 'enable'
		self.object_method_off = 'enable'               
		

	def push(self, world_dict):
		self.state = MWPYGameObjectState['AS_OPEN']
		self.is_pushed = True
		self.push_time = 0.0
		for obj in world_dict[MWPYGameObjectType[self.object_type]]:
			if obj.id == self.object_id and obj.id != 0 and obj.gameObjectType == MWPYGameObjectType[self.object_type]:
				obj.switchon()
				#eval('obj.' + self.object_method_on + '()')

	def do_update(self, delta, currenttime, world_dict):
		if self.is_pushed:
		      self.push_time += delta
		      if self.push_time > 0.5:
			      self.is_pushed = False
			      self.state = MWPYGameObjectState['AS_CLOSE']
			      self.push_time = 0.0
			      for obj in world_dict[MWPYGameObjectType[self.object_type]]:
				      if obj.id == self.object_id and obj.id != 0 and obj.gameObjectType == MWPYGameObjectType[self.object_type]:
					      obj.switchoff()
					      #eval('obj.' + self.object_method_off + '()')

		return None

