2023-05-25 18:34:26 -04:00
|
|
|
package funkin.audio;
|
|
|
|
|
2023-12-06 15:04:24 -05:00
|
|
|
import funkin.audio.FunkinSound;
|
2023-05-25 18:34:26 -04:00
|
|
|
import flixel.group.FlxGroup.FlxTypedGroup;
|
|
|
|
|
|
|
|
class VoicesGroup extends SoundGroup
|
|
|
|
{
|
2023-12-06 15:04:24 -05:00
|
|
|
var playerVoices:FlxTypedGroup<FunkinSound>;
|
|
|
|
var opponentVoices:FlxTypedGroup<FunkinSound>;
|
2023-05-25 18:34:26 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Control the volume of only the sounds in the player group.
|
|
|
|
*/
|
2023-12-05 02:44:57 -05:00
|
|
|
public var playerVolume(default, set):Float = 1.0;
|
2023-05-25 18:34:26 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Control the volume of only the sounds in the opponent group.
|
|
|
|
*/
|
2023-12-05 02:44:57 -05:00
|
|
|
public var opponentVolume(default, set):Float = 1.0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the time offset for the player's vocal track.
|
|
|
|
*/
|
|
|
|
public var playerVoicesOffset(default, set):Float = 0.0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the time offset for the opponent's vocal track.
|
|
|
|
*/
|
|
|
|
public var opponentVoicesOffset(default, set):Float = 0.0;
|
2023-05-25 18:34:26 -04:00
|
|
|
|
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
2023-12-06 15:04:24 -05:00
|
|
|
playerVoices = new FlxTypedGroup<FunkinSound>();
|
|
|
|
opponentVoices = new FlxTypedGroup<FunkinSound>();
|
2023-05-25 18:34:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a voice to the player group.
|
|
|
|
*/
|
2023-12-06 15:04:24 -05:00
|
|
|
public function addPlayerVoice(sound:FunkinSound):Void
|
2023-05-25 18:34:26 -04:00
|
|
|
{
|
|
|
|
super.add(sound);
|
|
|
|
playerVoices.add(sound);
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_playerVolume(volume:Float):Float
|
|
|
|
{
|
2023-12-06 15:04:24 -05:00
|
|
|
playerVoices.forEachAlive(function(voice:FunkinSound) {
|
2023-05-25 18:34:26 -04:00
|
|
|
voice.volume = volume;
|
|
|
|
});
|
|
|
|
return playerVolume = volume;
|
|
|
|
}
|
|
|
|
|
2023-12-05 02:44:57 -05:00
|
|
|
override function set_time(time:Float):Float
|
|
|
|
{
|
|
|
|
forEachAlive(function(snd) {
|
|
|
|
// account for different offsets per sound?
|
|
|
|
snd.time = time;
|
|
|
|
});
|
|
|
|
|
2023-12-06 15:04:24 -05:00
|
|
|
playerVoices.forEachAlive(function(voice:FunkinSound) {
|
2023-12-05 02:44:57 -05:00
|
|
|
voice.time -= playerVoicesOffset;
|
|
|
|
});
|
2023-12-06 15:04:24 -05:00
|
|
|
opponentVoices.forEachAlive(function(voice:FunkinSound) {
|
2023-12-05 02:44:57 -05:00
|
|
|
voice.time -= opponentVoicesOffset;
|
|
|
|
});
|
|
|
|
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_playerVoicesOffset(offset:Float):Float
|
|
|
|
{
|
2023-12-06 15:04:24 -05:00
|
|
|
playerVoices.forEachAlive(function(voice:FunkinSound) {
|
2023-12-05 02:44:57 -05:00
|
|
|
voice.time += playerVoicesOffset;
|
|
|
|
voice.time -= offset;
|
|
|
|
});
|
|
|
|
return playerVoicesOffset = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_opponentVoicesOffset(offset:Float):Float
|
|
|
|
{
|
2023-12-06 15:04:24 -05:00
|
|
|
opponentVoices.forEachAlive(function(voice:FunkinSound) {
|
2023-12-05 02:44:57 -05:00
|
|
|
voice.time += opponentVoicesOffset;
|
|
|
|
voice.time -= offset;
|
|
|
|
});
|
|
|
|
return opponentVoicesOffset = offset;
|
|
|
|
}
|
|
|
|
|
2023-05-25 18:34:26 -04:00
|
|
|
/**
|
|
|
|
* Add a voice to the opponent group.
|
|
|
|
*/
|
2023-12-06 15:04:24 -05:00
|
|
|
public function addOpponentVoice(sound:FunkinSound):Void
|
2023-05-25 18:34:26 -04:00
|
|
|
{
|
|
|
|
super.add(sound);
|
|
|
|
opponentVoices.add(sound);
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_opponentVolume(volume:Float):Float
|
|
|
|
{
|
2023-12-06 15:04:24 -05:00
|
|
|
opponentVoices.forEachAlive(function(voice:FunkinSound) {
|
2023-05-25 18:34:26 -04:00
|
|
|
voice.volume = volume;
|
|
|
|
});
|
|
|
|
return opponentVolume = volume;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override function clear():Void
|
|
|
|
{
|
|
|
|
playerVoices.clear();
|
|
|
|
opponentVoices.clear();
|
|
|
|
super.clear();
|
|
|
|
}
|
2023-07-13 20:27:45 -04:00
|
|
|
|
|
|
|
public override function destroy():Void
|
|
|
|
{
|
|
|
|
playerVoices.destroy();
|
|
|
|
opponentVoices.destroy();
|
|
|
|
super.destroy();
|
|
|
|
}
|
2023-05-25 18:34:26 -04:00
|
|
|
}
|