mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-19 09:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
@@ -0,0 +1,374 @@
|
||||
package com.sbi.corelib.audio
|
||||
{
|
||||
import flash.media.SoundTransform;
|
||||
import flash.net.SharedObject;
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
public class SBAudio
|
||||
{
|
||||
|
||||
private static var _isMusicMuted:Boolean = false;
|
||||
|
||||
private static var _areSoundsMuted:Boolean = false;
|
||||
|
||||
private static var _isInitialized:Boolean = false;
|
||||
|
||||
private static var _volume:Number = 1;
|
||||
|
||||
private static var _cachedSounds:Dictionary;
|
||||
|
||||
private static var _sharedObj:SharedObject;
|
||||
|
||||
private static var _muteCallback:Function;
|
||||
|
||||
private static var _guiManager:Object;
|
||||
|
||||
private static var _sounds:Array = [];
|
||||
|
||||
private static var _music:Array = [];
|
||||
|
||||
public function SBAudio()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init(param1:Object, param2:Function, param3:Object) : void
|
||||
{
|
||||
var _loc4_:Object = null;
|
||||
_guiManager = param3;
|
||||
_cachedSounds = new Dictionary();
|
||||
for(var _loc5_:String in param1)
|
||||
{
|
||||
_loc4_ = param1[_loc5_];
|
||||
addCachedSound(_loc5_,_loc4_.className,_loc4_.volume);
|
||||
}
|
||||
_muteCallback = param2;
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
public static function setupSharedObject(param1:SharedObject) : void
|
||||
{
|
||||
if(_sharedObj == null && param1 != null)
|
||||
{
|
||||
_sharedObj = param1;
|
||||
if(_sharedObj.data.volume)
|
||||
{
|
||||
setVolumeAll(_sharedObj.data.volume);
|
||||
}
|
||||
if(_sharedObj.data.isMusicMuted)
|
||||
{
|
||||
muteMusic();
|
||||
}
|
||||
if(_sharedObj.data.areSoundsMuted)
|
||||
{
|
||||
muteSounds();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function addCachedSound(param1:String, param2:Class, param3:Number = 0.3) : void
|
||||
{
|
||||
_cachedSounds[param1] = new SBSound(param2,false,param3 * _volume);
|
||||
}
|
||||
|
||||
public static function get isMusicMuted() : Boolean
|
||||
{
|
||||
return _isMusicMuted;
|
||||
}
|
||||
|
||||
public static function get areSoundsMuted() : Boolean
|
||||
{
|
||||
return _areSoundsMuted;
|
||||
}
|
||||
|
||||
public static function get isInitialized() : Boolean
|
||||
{
|
||||
return _isInitialized;
|
||||
}
|
||||
|
||||
public static function get currentVolume() : Number
|
||||
{
|
||||
return _volume;
|
||||
}
|
||||
|
||||
public static function addSound(param1:SBSound) : void
|
||||
{
|
||||
_sounds.push(param1);
|
||||
}
|
||||
|
||||
public static function removeSound(param1:SBSound) : void
|
||||
{
|
||||
_sounds.splice(_sounds.indexOf(param1),1);
|
||||
}
|
||||
|
||||
public static function addMusic(param1:Object) : void
|
||||
{
|
||||
_music.push(param1);
|
||||
}
|
||||
|
||||
public static function removeMusic(param1:Object) : void
|
||||
{
|
||||
_music.splice(_music.indexOf(param1),1);
|
||||
}
|
||||
|
||||
public static function playCachedSound(param1:String, param2:int = 1) : void
|
||||
{
|
||||
if(_isMusicMuted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var _loc3_:SBSound = _cachedSounds[param1];
|
||||
if(!_loc3_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_loc3_.play(0,param2,new SoundTransform(_volume));
|
||||
}
|
||||
|
||||
public static function stopCachedSound(param1:String) : void
|
||||
{
|
||||
var _loc2_:SBSound = _cachedSounds[param1];
|
||||
if(!_loc2_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_loc2_.stop();
|
||||
}
|
||||
|
||||
public static function setVolumeAll(param1:Number) : void
|
||||
{
|
||||
setVolumeSounds(param1);
|
||||
setVolumeMusic(param1);
|
||||
_volume = param1;
|
||||
}
|
||||
|
||||
public static function setVolumeSounds(param1:Number) : void
|
||||
{
|
||||
for each(var _loc2_:SBSound in _sounds)
|
||||
{
|
||||
_loc2_.volume = param1;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getVolumeMusic() : Number
|
||||
{
|
||||
var _loc1_:Number = NaN;
|
||||
for each(var _loc2_:Object in _music)
|
||||
{
|
||||
_loc1_ = Number(_loc2_.volume);
|
||||
}
|
||||
return _loc1_;
|
||||
}
|
||||
|
||||
public static function setVolumeMusic(param1:Number) : void
|
||||
{
|
||||
for each(var _loc2_:Object in _music)
|
||||
{
|
||||
_loc2_.volume = param1;
|
||||
}
|
||||
}
|
||||
|
||||
private static function setSharedObjMusicMuted(param1:Boolean) : void
|
||||
{
|
||||
if(_sharedObj != null && _sharedObj.data.isMusicMuted != param1)
|
||||
{
|
||||
_sharedObj.data.isMusicMuted = param1;
|
||||
try
|
||||
{
|
||||
_sharedObj.flush();
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function setSharedObjSoundsMuted(param1:Boolean) : void
|
||||
{
|
||||
if(_sharedObj != null && _sharedObj.data.areSoundsMuted != param1)
|
||||
{
|
||||
_sharedObj.data.areSoundsMuted = param1;
|
||||
try
|
||||
{
|
||||
_sharedObj.flush();
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function toggleMuteAll() : void
|
||||
{
|
||||
toggleMuteSounds();
|
||||
toggleMuteMusic();
|
||||
_muteCallback(_isMusicMuted);
|
||||
if(_guiManager != null)
|
||||
{
|
||||
if(_isMusicMuted)
|
||||
{
|
||||
_guiManager.mainHud.soundBtn.upToDownState();
|
||||
}
|
||||
else
|
||||
{
|
||||
_guiManager.mainHud.soundBtn.downToUpState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function muteAll() : void
|
||||
{
|
||||
muteSounds();
|
||||
muteMusic();
|
||||
}
|
||||
|
||||
public static function unmuteAll() : void
|
||||
{
|
||||
unmuteSounds();
|
||||
unmuteMusic();
|
||||
}
|
||||
|
||||
public static function toggleMuteSounds() : void
|
||||
{
|
||||
_areSoundsMuted = !_areSoundsMuted;
|
||||
setSharedObjSoundsMuted(_areSoundsMuted);
|
||||
}
|
||||
|
||||
public static function muteSounds() : void
|
||||
{
|
||||
_areSoundsMuted = true;
|
||||
setSharedObjSoundsMuted(true);
|
||||
}
|
||||
|
||||
public static function unmuteSounds() : void
|
||||
{
|
||||
_areSoundsMuted = false;
|
||||
setSharedObjSoundsMuted(false);
|
||||
}
|
||||
|
||||
public static function toggleMuteMusic() : void
|
||||
{
|
||||
for each(var _loc1_:Object in _music)
|
||||
{
|
||||
_loc1_.toggleMute();
|
||||
}
|
||||
_isMusicMuted = !_isMusicMuted;
|
||||
setSharedObjMusicMuted(_isMusicMuted);
|
||||
}
|
||||
|
||||
public static function muteMusic(param1:Boolean = true) : void
|
||||
{
|
||||
for each(var _loc2_:Object in _music)
|
||||
{
|
||||
_loc2_.mute();
|
||||
}
|
||||
if(param1)
|
||||
{
|
||||
_isMusicMuted = true;
|
||||
setSharedObjMusicMuted(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static function unmuteMusic(param1:Boolean = true) : void
|
||||
{
|
||||
for each(var _loc2_:Object in _music)
|
||||
{
|
||||
_loc2_.unmute();
|
||||
}
|
||||
if(param1)
|
||||
{
|
||||
_isMusicMuted = false;
|
||||
setSharedObjMusicMuted(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static function togglePauseAll() : void
|
||||
{
|
||||
togglePauseSounds();
|
||||
togglePauseMusic();
|
||||
}
|
||||
|
||||
public static function pauseAll() : void
|
||||
{
|
||||
pauseSounds();
|
||||
pauseMusic();
|
||||
}
|
||||
|
||||
public static function unpauseAll() : void
|
||||
{
|
||||
unpauseSounds();
|
||||
unpauseMusic();
|
||||
}
|
||||
|
||||
public static function togglePauseSounds() : void
|
||||
{
|
||||
for each(var _loc1_:SBSound in _sounds)
|
||||
{
|
||||
_loc1_.togglePause();
|
||||
}
|
||||
}
|
||||
|
||||
public static function pauseSounds() : void
|
||||
{
|
||||
for each(var _loc1_:SBSound in _sounds)
|
||||
{
|
||||
_loc1_.pause();
|
||||
}
|
||||
}
|
||||
|
||||
public static function unpauseSounds() : void
|
||||
{
|
||||
for each(var _loc1_:SBSound in _sounds)
|
||||
{
|
||||
_loc1_.unpause();
|
||||
}
|
||||
}
|
||||
|
||||
public static function togglePauseMusic() : void
|
||||
{
|
||||
for each(var _loc1_:Object in _music)
|
||||
{
|
||||
_loc1_.togglePause();
|
||||
}
|
||||
}
|
||||
|
||||
public static function pauseMusic() : void
|
||||
{
|
||||
for each(var _loc1_:Object in _music)
|
||||
{
|
||||
_loc1_.pause();
|
||||
}
|
||||
}
|
||||
|
||||
public static function unpauseMusic() : void
|
||||
{
|
||||
for each(var _loc1_:Object in _music)
|
||||
{
|
||||
_loc1_.unpause();
|
||||
}
|
||||
}
|
||||
|
||||
public static function stopAll() : void
|
||||
{
|
||||
stopSounds();
|
||||
stopMusic();
|
||||
}
|
||||
|
||||
public static function stopSounds() : void
|
||||
{
|
||||
for each(var _loc1_:SBSound in _sounds)
|
||||
{
|
||||
_loc1_.stop();
|
||||
}
|
||||
}
|
||||
|
||||
public static function stopMusic() : void
|
||||
{
|
||||
for each(var _loc1_:Object in _music)
|
||||
{
|
||||
_loc1_.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
package com.sbi.corelib.audio
|
||||
{
|
||||
import com.sbi.loader.LoaderCache;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.media.Sound;
|
||||
import flash.media.SoundChannel;
|
||||
import flash.media.SoundLoaderContext;
|
||||
import flash.media.SoundTransform;
|
||||
import flash.net.URLRequest;
|
||||
|
||||
public class SBMusic
|
||||
{
|
||||
|
||||
private var _hashKey:String;
|
||||
|
||||
private var _previouslyPlayedFilename:String;
|
||||
|
||||
private var _currFilename:String;
|
||||
|
||||
private var _previousVolume:Number;
|
||||
|
||||
private var _currVolume:Number;
|
||||
|
||||
public var paused:Boolean = false;
|
||||
|
||||
public var muted:Boolean = false;
|
||||
|
||||
public var mutedVolume:Number = 1;
|
||||
|
||||
public var playVolume:Number = 1;
|
||||
|
||||
public var s:Sound;
|
||||
|
||||
public var sc:SoundChannel;
|
||||
|
||||
public var position:Number;
|
||||
|
||||
public function SBMusic(param1:String, param2:Boolean = true, param3:Number = 1, param4:Number = 1000, param5:Boolean = true)
|
||||
{
|
||||
super();
|
||||
playNewMusic(param1,param2,param3,param4,param5);
|
||||
SBAudio.addMusic(this);
|
||||
}
|
||||
|
||||
public function playNewMusic(param1:String, param2:Boolean = true, param3:Number = 1, param4:Number = 1000, param5:Boolean = true) : void
|
||||
{
|
||||
_previouslyPlayedFilename = _currFilename;
|
||||
_currFilename = param1;
|
||||
_previousVolume = _currVolume;
|
||||
_currVolume = param3 * SBAudio.currentVolume;
|
||||
var _loc6_:URLRequest = LoaderCache.fetchCDNURLRequest("audio/" + param1);
|
||||
if(s)
|
||||
{
|
||||
s.removeEventListener("ioError",handleIOError);
|
||||
s = null;
|
||||
}
|
||||
if(sc)
|
||||
{
|
||||
sc.stop();
|
||||
sc = null;
|
||||
}
|
||||
s = new Sound(_loc6_,new SoundLoaderContext(param4,param5));
|
||||
volume = _currVolume;
|
||||
if(param2)
|
||||
{
|
||||
play();
|
||||
}
|
||||
else
|
||||
{
|
||||
stop();
|
||||
}
|
||||
s.addEventListener("ioError",handleIOError,false,0,true);
|
||||
}
|
||||
|
||||
public function play(param1:Number = 0, param2:int = 2147483647, param3:SoundTransform = null) : void
|
||||
{
|
||||
if(s == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
sc = s.play(param1,param2,param3);
|
||||
if(sc == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
setTransformVolume(playVolume);
|
||||
}
|
||||
|
||||
public function get volume() : Number
|
||||
{
|
||||
return sc ? sc.soundTransform.volume : -1;
|
||||
}
|
||||
|
||||
public function set volume(param1:Number) : void
|
||||
{
|
||||
if(muted)
|
||||
{
|
||||
mutedVolume = param1;
|
||||
}
|
||||
else
|
||||
{
|
||||
playVolume = param1;
|
||||
}
|
||||
if(sc)
|
||||
{
|
||||
setTransformVolume(param1);
|
||||
}
|
||||
}
|
||||
|
||||
public function toggleMute() : void
|
||||
{
|
||||
if(muted)
|
||||
{
|
||||
unmute();
|
||||
}
|
||||
else
|
||||
{
|
||||
mute();
|
||||
}
|
||||
}
|
||||
|
||||
public function mute() : void
|
||||
{
|
||||
if(!muted)
|
||||
{
|
||||
mutedVolume = volume;
|
||||
volume = 0;
|
||||
muted = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function unmute() : void
|
||||
{
|
||||
if(muted)
|
||||
{
|
||||
volume = mutedVolume;
|
||||
muted = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function togglePause() : void
|
||||
{
|
||||
if(paused)
|
||||
{
|
||||
unpause();
|
||||
}
|
||||
else
|
||||
{
|
||||
pause();
|
||||
}
|
||||
}
|
||||
|
||||
public function pause() : void
|
||||
{
|
||||
if(s && sc && !paused)
|
||||
{
|
||||
position = sc.position;
|
||||
sc.stop();
|
||||
paused = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function unpause() : void
|
||||
{
|
||||
if(s && sc && paused)
|
||||
{
|
||||
sc = s.play(position);
|
||||
setTransformVolume(playVolume);
|
||||
paused = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function stop() : void
|
||||
{
|
||||
if(sc)
|
||||
{
|
||||
sc.stop();
|
||||
}
|
||||
paused = false;
|
||||
muted = false;
|
||||
}
|
||||
|
||||
public function get previouslyPlayedFilename() : String
|
||||
{
|
||||
return _previouslyPlayedFilename;
|
||||
}
|
||||
|
||||
public function get previousVolume() : Number
|
||||
{
|
||||
return _previousVolume;
|
||||
}
|
||||
|
||||
public function get currFilename() : String
|
||||
{
|
||||
return _currFilename;
|
||||
}
|
||||
|
||||
public function get currVolume() : Number
|
||||
{
|
||||
return _currVolume;
|
||||
}
|
||||
|
||||
private function setTransformVolume(param1:Number) : void
|
||||
{
|
||||
var _loc2_:SoundTransform = sc.soundTransform;
|
||||
_loc2_.volume = param1;
|
||||
sc.soundTransform = _loc2_;
|
||||
}
|
||||
|
||||
private function handleIOError(param1:IOErrorEvent) : void
|
||||
{
|
||||
if(s)
|
||||
{
|
||||
trace("WARNING - IOError while attempting to load music:" + s.url);
|
||||
s = null;
|
||||
}
|
||||
if(sc)
|
||||
{
|
||||
sc.stop();
|
||||
sc = null;
|
||||
}
|
||||
SBAudio.removeMusic(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
package com.sbi.corelib.audio
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.media.Sound;
|
||||
import flash.media.SoundChannel;
|
||||
import flash.media.SoundTransform;
|
||||
|
||||
public class SBSound
|
||||
{
|
||||
|
||||
public var paused:Boolean = false;
|
||||
|
||||
public var playVolume:Number = 1;
|
||||
|
||||
public var s:Sound;
|
||||
|
||||
public var sc:SoundChannel;
|
||||
|
||||
private var _soundPlaying:Boolean;
|
||||
|
||||
private var _onSoundComplete:Function;
|
||||
|
||||
public function SBSound(param1:Class, param2:Boolean = true, param3:Number = 1)
|
||||
{
|
||||
super();
|
||||
s = new param1();
|
||||
volume = param3;
|
||||
if(param2)
|
||||
{
|
||||
play();
|
||||
}
|
||||
else
|
||||
{
|
||||
stop();
|
||||
}
|
||||
SBAudio.addSound(this);
|
||||
}
|
||||
|
||||
public function play(param1:Number = 0, param2:int = 0, param3:SoundTransform = null, param4:Function = null) : void
|
||||
{
|
||||
if(param2 == -1)
|
||||
{
|
||||
param2 = 2147483647;
|
||||
}
|
||||
if(s == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
sc = s.play(param1,param2,param3);
|
||||
if(sc == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_soundPlaying = true;
|
||||
_onSoundComplete = param4;
|
||||
sc.addEventListener("soundComplete",soundStoppedHandler,false,0,true);
|
||||
setTransformVolume(playVolume);
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
stop();
|
||||
sc = null;
|
||||
s = null;
|
||||
SBAudio.removeSound(this);
|
||||
}
|
||||
|
||||
public function get volume() : Number
|
||||
{
|
||||
return sc ? sc.soundTransform.volume : -1;
|
||||
}
|
||||
|
||||
public function set volume(param1:Number) : void
|
||||
{
|
||||
playVolume = param1;
|
||||
if(sc)
|
||||
{
|
||||
setTransformVolume(param1);
|
||||
}
|
||||
}
|
||||
|
||||
public function get isPlaying() : Boolean
|
||||
{
|
||||
return _soundPlaying;
|
||||
}
|
||||
|
||||
public function togglePause() : void
|
||||
{
|
||||
if(paused)
|
||||
{
|
||||
unpause();
|
||||
}
|
||||
else
|
||||
{
|
||||
pause();
|
||||
}
|
||||
}
|
||||
|
||||
public function pause() : void
|
||||
{
|
||||
if(sc && !paused)
|
||||
{
|
||||
sc.stop();
|
||||
paused = true;
|
||||
_soundPlaying = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function unpause() : void
|
||||
{
|
||||
if(s && sc && paused)
|
||||
{
|
||||
sc = s.play(sc.position);
|
||||
if(sc == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_soundPlaying = true;
|
||||
sc.addEventListener("soundComplete",soundStoppedHandler,false,0,true);
|
||||
setTransformVolume(playVolume);
|
||||
paused = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function stop() : void
|
||||
{
|
||||
if(sc)
|
||||
{
|
||||
sc.stop();
|
||||
}
|
||||
paused = false;
|
||||
_soundPlaying = false;
|
||||
}
|
||||
|
||||
private function setTransformVolume(param1:Number) : void
|
||||
{
|
||||
var _loc2_:SoundTransform = sc.soundTransform;
|
||||
if(SBAudio.isMusicMuted)
|
||||
{
|
||||
_loc2_.volume = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc2_.volume = param1;
|
||||
}
|
||||
sc.soundTransform = _loc2_;
|
||||
}
|
||||
|
||||
private function soundStoppedHandler(param1:Event) : void
|
||||
{
|
||||
_soundPlaying = false;
|
||||
if(_onSoundComplete != null)
|
||||
{
|
||||
_onSoundComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user