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

last change: $Date: 2008-09-15 14:44:27 +0400 (Пн, 15 сен 2008) $
             $Author: toha $

	Lacerta Project
	version 1.0.0.1
	Copyright (C) 2008 RNMC
-->

<composition name="rnmc_SoundManager">
<script><![CDATA[
	this.soundsArray = null;
	this.allowMultipleSounds = false;
	this.activeSoundsTotal = 0;
	this.currentActiveSound = -1;
		
	function onStartStep(allowMultSnd){
		this.activeSoundsTotal = 0;
		this.allowMultipleSounds = allowMultSnd;
	}
	
	function onFinishStep(){
		if (this.soundsArray != null){
			for(var i = 0; i < this.soundsArray.length; i++){
				this.soundsArray[i] = null;
			}
			this.soundsArray = null;
		}
	}
	
	function registerSound(newAudioObject){
		if(!this.soundsArray)
			this.soundsArray = new Array();
		this.soundsArray.push(newAudioObject);
		return (this.soundsArray.length - 1);
	}
	
	function notifyPlay(sndObjectId){
		if(!this.allowMultipleSounds){
			if(this.activeSoundsTotal > 0){
				// значит есть уже проигрываемые звуки, их надо остановить
				this.soundsArray[this.currentActiveSound].interruptBySoundManager();
				this.currentActiveSound = sndObjectId;
			} else {
				this.activeSoundsTotal++;
				this.currentActiveSound = sndObjectId;
			}
		} else {
			this.activeSoundsTotal++;
		}
		return true;
	}

	function notifyPause(sndObjectId){
		if(!this.allowMultipleSounds){
			if(this.currentActiveSound == sndObjectId){
				this.activeSoundsTotal--;
				this.currentActiveSound = -1;
			}
		} else {
			this.activeSoundsTotal--;
		}
		
		return true;
	}

	function notifyStopped(sndObjectId){
		if(!this.allowMultipleSounds){
			if(this.currentActiveSound == sndObjectId){
				this.activeSoundsTotal--;
				this.currentActiveSound = -1;
			}
		} else {
			this.activeSoundsTotal--;
		}
		
		return true;
	}

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