<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile: rnmc_labwork_base.xml,v $
$Revision: 980 $

last change: $Date: 2009-02-20 11:48:39 +0300 (Пт, 20 фев 2009) $
             $Author: faja $

  Lacerta Project
  version 1.0.0.1
  Copyright (C) 2007-2009 RNMC
-->
<composition name="rnmc_labwork_base" class="rnmc_stdMediaGroup" x="0" y="0">
<script><![CDATA[
  this.type = "";
  this.allowMultipleSounds = null;
//  показывать панель результатов
  this.resultPanelVisible = RESULT_PANEL_VISIBLE_UNDEFINED;
  this.localStepIndicatorVisible = RESULT_PANEL_VISIBLE_UNDEFINED;
  
// массивы с действиями к соответствующим событиям
// при входе в шаг
  this.stepEnterActions = null;
// при выполнении задания
  this.stepCompleteActions = null;
  
  this.stepResult   = 0;
  this.stepErrors   = 0;
  this.stepHelps    = 0;
  this.stepAttempts = 0;
  
  function loadStep(srcNode){
    var properties = parent.getGlobalProperty(this.id.toString()+"_prop");
    if (properties)
      this.propertysList = properties;

    var xmlNode = srcNode.firstChild;
    while(xmlNode){
      if(xmlNode.nodeName == "properties" && !this.propertysList){
        parsePropertiesNode(xmlNode);
        break;
      }
      xmlNode = xmlNode.nextSibling;
    }
    return true;
  };
  
  function parseSettingsNode(xmlNode){
    if(xmlNode.nodeName != "settings")
      return false;
    
    var xmlAttributeMap = null;
    var xmlAttribute    = null;

    var settingNode = xmlNode.firstChild;
    while(settingNode){
      if(settingNode.nodeName == "sound"){
        xmlAttributeMap = settingNode.attributes;
        if (xmlAttributeMap){
          xmlAttribute = xmlAttributeMap.getNamedItem("allowMultiple");
          if (xmlAttribute != null && xmlAttribute.specified){
            if(xmlAttribute.value.toLowerCase() == "true")
              this.allowMultipleSounds = true;
            else
              this.allowMultipleSounds = false;
          }
        }
      } else if(settingNode.nodeName == "resultpanel"){
//trace("rnmc_labwork_base: parsing resultPanel");
        xmlAttributeMap = settingNode.attributes;
        if(xmlAttributeMap){
          xmlAttribute = xmlAttributeMap.getNamedItem("visible");
          if(xmlAttribute != null && xmlAttribute.specified){
            if (xmlAttribute.value == "true"){
              this.resultPanelVisible = RESULT_PANEL_VISIBLE_TRUE;
            } else if(xmlAttribute.value == "false"){
              this.resultPanelVisible = RESULT_PANEL_VISIBLE_FALSE;
            }
          } 
        }
      }  else if(settingNode.nodeName == "stepname"){
        xmlAttributeMap = settingNode.attributes;
        if(xmlAttributeMap){
          xmlAttribute = xmlAttributeMap.getNamedItem("visible");
          if(xmlAttribute != null && xmlAttribute.specified){
            if (xmlAttribute.value == "true")
              this.stepNameVisible = true;
            else
              this.stepNameVisible = false;
          } 
          xmlAttribute = xmlAttributeMap.getNamedItem("style");
          if(xmlAttribute != null && xmlAttribute.specified){
            this.stepNameStyle = xmlAttribute.value;
          } 
          xmlAttribute = xmlAttributeMap.getNamedItem("x");
          if(xmlAttribute != null && xmlAttribute.specified){
            this.stepNameX = parseInt(xmlAttribute.value);
          } 
          xmlAttribute = xmlAttributeMap.getNamedItem("y");
          if(xmlAttribute != null && xmlAttribute.specified){
            this.stepNameY = parseInt(xmlAttribute.value);
          } 
          xmlAttribute = xmlAttributeMap.getNamedItem("width");
          if(xmlAttribute != null && xmlAttribute.specified){
            this.stepNameWidth = parseInt(xmlAttribute.value);
          } 
          xmlAttribute = xmlAttributeMap.getNamedItem("height");
          if(xmlAttribute != null && xmlAttribute.specified){
            this.stepNameHeight = parseInt(xmlAttribute.value);
          } 
          xmlAttribute = xmlAttributeMap.getNamedItem("format");
          if(xmlAttribute != null && xmlAttribute.specified){
            this.stepNameFormat = xmlAttribute.value;
          }
        }
      } else if(settingNode.nodeName == "localindicator"){
        xmlAttributeMap = settingNode.attributes;
        if(xmlAttributeMap){
          xmlAttribute = xmlAttributeMap.getNamedItem("visible");
          if(xmlAttribute != null && xmlAttribute.specified){
            if ((xmlAttribute.value).toLowerCase() == "true"){
              this.localStepIndicatorVisible = STEP_INDICATOR_VISIBLE_TRUE;
            } else if((xmlAttribute.value).toLowerCase() == "false"){
              this.localStepIndicatorVisible = STEP_INDICATOR_VISIBLE_FALSE;
            }
          } 
        }
      } else if(settingNode.nodeName.toLowerCase() == "resultof"){
        this.parseCountingResults(settingNode);
	  }
      settingNode = settingNode.nextSibling;
    }
  }
  
  function parseActionsNode(xmlNode){
    this.stepEnterActions = scene.Utils.parseActionsNode(xmlNode, "onStartStep");
    this.stepFinishActions = scene.Utils.parseActionsNode(xmlNode, "onFinishStep");
	rnmc_stdMediaObject_parseActionsNode(xmlNode);
  }
  
  //  Пока не отличается от такой же в базовом классе
  /*
  function loadChildsObject(srcNode){
    return rnmc_stdMediaGroup_loadChildsObject(srcNode);
  }
  */
  
  function startStep(){
    this.stepResult = 0;
    this.lastStepResult = 0;
    this.stepErrors = 0;
    this.lastStepErrors = 0;
    this.stepHelps = 0;
    this.lastStepHelps = 0;
    this.stepAttempts = 0;
    this.lastStepAttempts = 0;
    
    resetResult();

    this.parent.setStepNameParams(this.stepNameStyle, this.stepNameX, this.stepNameY,
      this.stepNameWidth, this.stepNameHeight, this.stepNameFormat, this.stepNameVisible)

    if (this.childObjects){
      for(var i = 0; i < this.childObjects.length; i++){
        if(this.childObjects[i].visibility == OBJECT_VISIBILITY_TRUE){
          this.childObjects[i].showObject();
        }
      }
    }

    if(this.stepEnterActions){
      for(var i = 0; i < this.stepEnterActions.length; i++){
        this.dispatchAction(this.stepEnterActions[i]);
      }
    }
  }

  function exitStep(){
    parent.setGlobalProperty(this.id.toString()+"_prop", this.propertysList);

    if(this.stepCompleteActions){
      for(var i = 0; i < this.stepCompleteActions.length; i++){
        this.dispatchAction(this.stepEnterActions[i]);
      }
    }

    if (this.childObjects)
    {
      for(var i = 0; i < this.childObjects.length; i++){
        this.childObjects[i].effectsEnabled = false;
        
        if ("hideObject" in this.childObjects[i]){
          this.childObjects[i].hideObject();
        }
      }
    }
  }
  
  function getObjectProperty(objectId, propertyName){
    if (this.propertysList)
      if (this.propertysList[propertyName] != undefined){
        return this.propertysList[propertyName];
      }

    return rnmc_stdMediaGroup_getObjectProperty(objectId, propertyName);
  }
  
  function setObjectProperty(objectId, propertyName, propertyValue){
//trace("objectId == "+objectId);
    if (!objectId){
      if (!this.propertysList)
        this.propertysList = new Array();
        this.propertysList[propertyName] = propertyValue
    }
  }
  
  function updateStatistics(){
    var newStepResult = -1;
    var newStepErrors = -1;
    var newStepHelps = -1;
    if(this.lastStepResult != this.stepResult){
      newStepResult = this.stepResult;
      this.lastStepResult = this.stepResult;
    }
    if(this.lastStepErrors != this.stepErrors){
      newStepErrors = this.stepErrors;
      this.lastStepErrors = this.stepErrors;
    }
    if(this.lastStepHelps != this.stepHelps){
      newStepHelps = this.stepHelps;
      this.lastStepHelps = this.stepHelps;
    }
    if(this.lastStepAttempts != this.stepAttempts){
      newStepAttempts = this.stepAttempts;
      this.lastStepAttempts = this.stepAttempts;
    }
    parent.resultManager.updateStatistics(newStepResult, newStepErrors, newStepHelps);
  }

  function dispatchAction(singleAction){
    if(singleAction[1] && 
       (singleAction[1].slice(0,8) == "LABWORK." || 
        singleAction[1].slice(0,8) == "LABWORK")){
      //  если написано ключевое слово LABWORK - значит целевой 
      //  объект - глобальный отправляем на обработку в Loader
      singleAction = singleAction.slice(0);    
      singleAction[1] = singleAction[1].slice(8);
      scene.Labwork.doAction(singleAction);
    }
    this.doAction(singleAction);
  }
  
  function doAction(singleAction){
    switch(singleAction[0]){
    case "disableScene":
      parent.disableScene();
      break;
    case "setCurrentStepResult":
      this.stepResult = parseInt(singleAction[1]);
      break;
    case "increaseErrors":
      var errIncrement = 1;
      if(singleAction[1] && (parseInt(singleAction[1])) > 1)
        errIncrement = (parseInt(singleAction[1]));
      parent.resultManager.addErrors(errIncrement);
      break;
    case "decreaseErrors":
      var errIncrement = -1;
      if(singleAction[1] && (parseInt(singleAction[1])) > 1)
        errIncrement = -(parseInt(singleAction[1]));
      parent.resultManager.addErrors(errIncrement);
      break;
    case "increaseHelps":
      var helpsIncrement = 1;
      if(singleAction[1] && (parseInt(singleAction[1])) > 1)
        helpsIncrement = (parseInt(singleAction[1]));
      parent.resultManager.addHelps(helpsIncrement);
      break;
    case "decreaseHelps":
      var helpsIncrement = -1;
      if(singleAction[1] && (parseInt(singleAction[1])) > 1)
        helpsIncrement = -(parseInt(singleAction[1]));
      parent.resultManager.addHelps(helpsIncrement);
      break;
    case "goToStep":
      parent.startStep(parseInt(singleAction[1]));
      break;
    case "goToStepWithId":
      parent.startStepID(singleAction[1]);
      break;
    case "goPreviousStep":
      parent.startPreviousStep();
      break;
    case "goNextStep":
      parent.startNextStep();
      break;
    case "goFirstStep":
      parent.startFirstStep();
      break;
    case "goLastStep":
      parent.startLastStep();
      break;
    case "goToSummary":
      parent.startSummaryStep();
      break;
    case "setProperty":
      var param = singleAction[1].split(",");
      setObjectProperty(param[0], param[1], param[2]);
      break;
    case "saveResultToFile":
      scene.Labwork.resultManager.saveResultsToFile();
      break;
    default:
      rnmc_stdMediaGroup_doAction(singleAction);  
      break;
    }
  }
  
  function resetResult(){
    this.objectResult = 0;
    this.objectErrors = 0;
    this.objectHelps  = 0;  
  }  

  function getStepResult(resultsArray){
    //  getResult определена в stdMediaGroup
    this.getResult(resultsArray);
  }
  
  function getStepErrors(){
    this.stepErrors = this.getErrors();
    return this.stepErrors;
  }
  
//  virtual
  function getStepTotalAnswers(){
trace("#FF0000virtual rnmc_labwork_base.getStepTotalAnswers()");
  }

  function getStepHelps(){
//    this.stepHelps = this.getHelps();
    return this.stepHelps;
  }
  
  function getStepAttempts(){
    return this.stepAttempts;
  }
]]> </script>
</composition>
</rmml>