<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile: rnmc_stdObject.xml $
$Revision: 983 $

last change: $Date: 2009-02-24 16:09:45 +0300 (Вт, 24 фев 2009) $
             $Author: faja $

	Lacerta Project
	version 1.0.0.1
	Copyright (C) 2007-2009 RNMC
-->
<composition name="rnmc_stdObject">
<script><![CDATA[
//	this.id = null;
//	this.type = "rnmc_stdObject";
	this.saveState = false;
//	массив для эффектов
	this.attachedEffects = null;
//	разрешены ли эффекты
	this.effectsEnabled = true;
//	целевой объект для эффектов
	this.effectsTarget = null;
//	количество эффектов в действии 
	this.effectsRunning = 0;
//	массив действий на события
	this.actionsList  = null;
	
	this.objectiveWeight = 1;
	this.objectivesList = null;
	
	//	OBJECTIVES
	this.onShowObjectives = false;
	this.onHideObjectives = false;
	this.onPressObjectives = false;
	this.onReleaseObjectives = false;
	this.onRollOverObjectives = false;
	this.onRollOutObjectives = false;
	//	END OBJECTIVES

	
//	virtual
	function initFromNode(srcNode){
		trace("#FF0000ERROR: вызван 'виртуальный' метод rnmc_stdObject.initFromNode().");
	}
//	virtual
	function showObject(){
		trace("#FF0000ERROR: вызван 'виртуальный' метод rnmc_stdObject.showObject().");
	}
//	virtual
	function hideObject(srcNode){
		trace("#FF0000ERROR: вызван 'виртуальный' метод rnmc_stdObject.hideObject().");
	}
//	virtual
	function loadObject(){
		trace("#FF0000ERROR: вызван 'виртуальный' метод rnmc_stdObject.loadObject().");
	}
//	virtual
	function unloadObject(srcNode){
		trace("#FF0000ERROR: вызван 'виртуальный' метод rnmc_stdObject.unloadObject().");
	}
//	virtual
	function buttonDispatcher(){
		trace("#FF0000ERROR: вызван 'виртуальный' метод rnmc_stdObject.buttonDispatcher().");
	}
//	virtual
	function resetObject(){
		trace("#FF0000ERROR: вызван 'виртуальный' метод rnmc_stdObject.resetObject().");
	}
//	virtual
	function checkObject(){
		trace("#FF0000ERROR: вызван 'виртуальный' метод rnmc_stdObject.checkObject().");
	}

//	virtual
	function disableObject(){
		this.disabled = true;
	}

//	virtual
	function enableObject(){
		this.disabled = false;
	}

//	virtual
	function frozenObject(){
		trace("#FF0000ERROR: вызван 'виртуальный' метод rnmc_stdObject.resetObject().");
	}
//	virtual
	function unfrozenObject(){
		trace("#FF0000ERROR: вызван 'виртуальный' метод rnmc_stdObject.checkObject().");
	}	

//	====================================== ЭФФЕКТЫ	=========================================	
//	разбор узла effects

	function parseEffectsNode(srcNode){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;

		if(srcNode.nodeName == "effects"){		
			xmlNode = srcNode.firstChild;
			while(xmlNode){	
				if(xmlNode.nodeName == "effect")
					this.parseEffectNode(xmlNode);
				xmlNode = xmlNode.nextSibling;
			}
		}	
	}

	
	//	вспомогательная функция проверяет, можно ли назначить
	//	эффект некоторго типа на опредлённое событие (если назначить
	//	два движения на одно событие - не понятно куда двигать)
	function checkEffectForEvent(effectType, applyEvent){
		var effectDefined = false;
		if(this.attachedEffects && this.attachedEffects[applyEvent] && this.attachedEffects[applyEvent].length > 0){
			for(var i = 0; i < this.attachedEffects[applyEvent].length; i++){
				if(this.attachedEffects[applyEvent][i].effectType == effectType)
					effectDefined = true;
			}
		}
		return effectDefined;
	}
	
	//	оставлена для совместимости
	
	function parseEffectNode(srcNode){
		var xmlAttributeMap = null;
		var xmlAttribute = null;

		if(srcNode.nodeName == "effect"){
			if(!this.attachedEffects)
				this.attachedEffects = new Array();
			var newEffect = scene.Utils.initEffectFromNode(srcNode, this);
			if (newEffect){
				if(newEffect.effectEvent == EVENT_ON_SHOW){
					if(!this.attachedEffects[EVENT_ON_SHOW])
						this.attachedEffects[EVENT_ON_SHOW] = new Array();
					this.attachedEffects[EVENT_ON_SHOW].push(newEffect);
				} else if(newEffect.effectEvent == EVENT_ON_HIDE){
					if(!this.attachedEffects[EVENT_ON_HIDE])
						this.attachedEffects[EVENT_ON_HIDE] = new Array();
					this.attachedEffects[EVENT_ON_HIDE].push(newEffect);
				} else if(newEffect.effectEvent == EVENT_ON_ROLLOVER){
					if(!this.attachedEffects[EVENT_ON_ROLLOVER])
						this.attachedEffects[EVENT_ON_ROLLOVER] = new Array();
					this.attachedEffects[EVENT_ON_ROLLOVER].push(newEffect);
				} else if(newEffect.effectEvent == EVENT_ON_ROLLOUT){
					if(!this.attachedEffects[EVENT_ON_ROLLOUT])
						this.attachedEffects[EVENT_ON_ROLLOUT] = new Array();
					this.attachedEffects[EVENT_ON_ROLLOUT].push(newEffect);
				} else if(newEffect.effectEvent == EVENT_ON_PRESS){
					if(!this.attachedEffects[EVENT_ON_PRESS])
						this.attachedEffects[EVENT_ON_PRESS] = new Array();
					this.attachedEffects[EVENT_ON_PRESS].push(newEffect);
				} else if(newEffect.effectEvent == EVENT_ON_RELEASE){
					if(!this.attachedEffects[EVENT_ON_RELEASE])
						this.attachedEffects[EVENT_ON_RELEASE] = new Array();
					this.attachedEffects[EVENT_ON_RELEASE].push(newEffect);
				} else {
					if(!this.attachedEffects[NO_EVENT])
						this.attachedEffects[NO_EVENT] = new Array();
					this.attachedEffects[NO_EVENT].push(newEffect);
				}
			}
		}
		return true;
	}
	
//	добавление эффекта
	function addEffect(effectEvent, effectString){
		if(effectEvent != null && effectString != null){
			if(!this.attachedEffects)
				this.attachedEffects = new Array();
			if(!this.attachedEffects[effectEvent])
				this.attachedEffects[effectEvent] = new Array();
			var newEffect = new Composition();
			newEffect._class = "rnmc_stdEffect";
			newEffect.parent = this;
			newEffect.initEffect(null, effectEvent, effectString);
			this.attachedEffects[effectEvent].push(newEffect);
		}
		return true;
	}

//	функция стартует все эффекты для некотого события
	function startEffects(currentEvent){
		if(!this.effectsTarget)
			return 0;
		this.stopEffects();
		this.effectsRunning = 0
		if(this.effectsEnabled && this.attachedEffects && this.attachedEffects[currentEvent]){
			var effectsStartedCount = 0;
			for(var i = 0; i < this.attachedEffects[currentEvent].length; i++){	
				this.attachedEffects[currentEvent][i].setCallBack(this, this.notifyEffectComplete);
				this.attachedEffects[currentEvent][i].setTargetObject(this.effectsTarget);
				this.attachedEffects[currentEvent][i].startEffect();
				this.effectsRunning++;
				effectsStartedCount++;
				if(this.actionsList && this.actionsList[EVENT_ON_START_EFFECT]){
					for(var j = 0; j < this.actionsList[EVENT_ON_START_EFFECT].length; j++){
						if(this.actionsList[EVENT_ON_START_EFFECT][j].eventParam
							&& this.actionsList[EVENT_ON_START_EFFECT][j].eventParam == this.attachedEffects[currentEvent][i].id){
							parent.dispatchAction(this.actionsList[EVENT_ON_START_EFFECT][j]);
						}
					}
				}				
			}
			return effectsStartedCount;
		} else {
			return 0;
		}
	}
	
	//	функция стартует все эффекты для некотого события
	function startEffectWithId(effectId){
		if(!this.effectsTarget)
			return 0;
		this.stopEffects();
		this.effectsRunning = 0;
		if(this.effectsEnabled && this.attachedEffects && this.attachedEffects[NO_EVENT]){
			var effectsStartedCount = 0;
			for(var i = 0; i < this.attachedEffects[NO_EVENT].length; i++){	
				if(this.attachedEffects[NO_EVENT][i].id == effectId){
					this.attachedEffects[NO_EVENT][i].setCallBack(this, this.notifyEffectComplete);
					this.attachedEffects[NO_EVENT][i].setTargetObject(this.effectsTarget);
					this.attachedEffects[NO_EVENT][i].startEffect();
					this.effectsRunning++;
					effectsStartedCount++;
					if(this.actionsList && this.actionsList[EVENT_ON_START_EFFECT]){
						for(var j = 0; j < this.actionsList[EVENT_ON_START_EFFECT].length; j++){
							if(this.actionsList[EVENT_ON_START_EFFECT][j].eventParam
								&& this.actionsList[EVENT_ON_START_EFFECT][j].eventParam == this.attachedEffects[NO_EVENT][i].id){
								parent.dispatchAction(this.actionsList[EVENT_ON_START_EFFECT][j]);
							}
						}
					}
				}
			}
			return effectsStartedCount;
		} else {
			return 0;
		}
	}

	
//	останавливает все приаттаченные эффекты
	function stopEffects(){
		if(this.attachedEffects){
			for(var i = 0; i < this.attachedEffects.length; i++){	
				if(this.attachedEffects[i]){
					for(var j = 0; j < this.attachedEffects[i].length; j++)
						this.attachedEffects[i][j].stopEffect();
				}
			}
		}
	}
	
	//	сообщение от эффекта
	function notifyEffectComplete(effectObject){
		if(this.actionsList && this.actionsList[EVENT_ON_COMPLETE_EFFECT] && effectObject){
			for(var i = 0; i < this.actionsList[EVENT_ON_COMPLETE_EFFECT].length; i++){
				if(this.actionsList[EVENT_ON_COMPLETE_EFFECT][i].eventParam
					&& this.actionsList[EVENT_ON_COMPLETE_EFFECT][i].eventParam == effectObject.id){
					parent.dispatchAction(this.actionsList[EVENT_ON_COMPLETE_EFFECT][i]);
				}
			}
		}
		effectObject.clearCallBack();
		this.effectsRunning--;
		if(effectObject.effectEvent == EVENT_ON_HIDE){
			if(this.effectsRunning == 0){
				this.unloadObject();
				//	если назначена функция обратного вызова
				if(this.hideCallBackFunction != null && this.hideCallBackObject != null)
					this.hideCallBackFunction.call(this.hideCallBackObject, this.id);
			}
		}
	}
	
	this.objectiveOptional = false;
	
	//	OBJECTIVES	=======================================================================
	function parseObjectivesNode(srcNode){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;
		
		if(srcNode.nodeName == "objectives"){
			if(!this.objectivesList)
				this.objectivesList = new Array();
			//	по умолчанию вес равен 1
			this.objectiveWeight = 1;
			xmlAttributeMap = srcNode.attributes;
			if (xmlAttributeMap){
				xmlAttribute =  xmlAttributeMap.getNamedItem("weight");
				if (xmlAttribute != null && xmlAttribute.specified){
					this.objectiveWeight = parseFloat(xmlAttribute.value);
				}
			}

			var objectiveNode = srcNode.firstChild;
			while(objectiveNode){
				if(objectiveNode.nodeName == "objective"){				
					//var newObjective = new String("onShow");				
					
					if(objectiveNode.textContent){
						newObjective = new String(objectiveNode.textContent);
						var objectiveParams = objectiveNode.textContent.split(":");
						var objectiveEvent = objectiveParams[0];
						this.addObjectiveDispatcher(objectiveEvent);
					}
					
					newObjective.complete = false;	
					xmlAttributeMap = objectiveNode.attributes;
				
					if (xmlAttributeMap){
						xmlAttribute =  xmlAttributeMap.getNamedItem("id");
						if (xmlAttribute != null && xmlAttribute.specified){
							newObjective.id = xmlAttribute.value;							
						}
						xmlAttribute =  xmlAttributeMap.getNamedItem("weight");
						if (xmlAttribute != null && xmlAttribute.specified){
							newObjective.weight = parseFloat(xmlAttribute.value);
						} else {
							newObjective.weight = 1; 
						}
						xmlAttribute =  xmlAttributeMap.getNamedItem("optional");
						if (xmlAttribute != null && xmlAttribute.specified){
							if (xmlAttribute != null && xmlAttribute.specified){
								if((xmlAttribute.value).toLowerCase() == "true"){
									newObjective.optional = true;
								} else {
									newObjective.optional = false;
								}
							}
						} else {
							newObjective.optional = false;
						}			
						
					}
					this.objectivesList.push(newObjective);
				}
				if(objectiveNode.nodeName == "objectiveWrong"){
				
					//var newObjective = new String("onShow");				
					this.objectiveWeight = 0;
					if(objectiveNode.textContent){
						newObjective = new String(objectiveNode.textContent);
						var objectiveParams = objectiveNode.textContent.split(":");
						var objectiveEvent = objectiveParams[0];
						this.addObjectiveDispatcher(objectiveEvent);
					}
					
					newObjective.complete = false;
					newObjective.wrongtarget = true;  //говорим, что цель ложная
					newObjective.optional = true;   //обязательной она быть вообще не может
					
					xmlAttributeMap = objectiveNode.attributes;
			
					if (xmlAttributeMap){
						xmlAttribute =  xmlAttributeMap.getNamedItem("id");
						if (xmlAttribute != null && xmlAttribute.specified){
							newObjective.id = xmlAttribute.value;							
						}
						xmlAttribute =  xmlAttributeMap.getNamedItem("weight");
						if (xmlAttribute != null && xmlAttribute.specified){
							newObjective.weight = parseFloat(xmlAttribute.value);
						} else {
							newObjective.weight = 0; 
						}										
						
					}
						
					this.objectivesList.push(newObjective);
				}
				objectiveNode = objectiveNode.nextSibling;
			}
		}
//trace(this.id+":  this.objectivesList = " + this.objectivesList+"  "+this.objectivesList[0].optional);
		return true;
	}
	
	function getResult(resultsArray){
		if(this.objectivesList && this.objectivesList.length > 0){
			var objectivesCopmplete = true;
			for(var i = 0; i < this.objectivesList.length; i++){
//trace("this.objectivesList[i] == "+this.objectivesList[i] + " : "+this.objectivesList[i].complete);
				if(!this.objectivesList[i].optional && !this.objectivesList[i].complete){
					objectivesCopmplete = false;
				}
			}
			if(objectivesCopmplete){
				var resultString = "100;" + this.objectiveWeight;
				resultsArray.push(resultString);
			} else {
				var resultString = "0;" + this.objectiveWeight;
				resultsArray.push(resultString);			
			}
		}
	}
	
//	устанавливает 
	function addObjectiveDispatcher(){
		trace("#FF0000ERROR: вызван 'виртуальный' метод rnmc_stdObject.addObjectiveDispatcher().");	
	}
	
	//	END OBJECTIVES	=======================================================================
	
	function setPosition(newX, newY, newWidth, newHeight, newDepth, newRatio){
	
	}
	
	function resetPosition(){
	
	}
	
	function getObjectProperty(propertyName){
		return null;
	}

	
]]></script>
</composition>
</rmml>
