Adaptive music and music 👍

This commit is contained in:
Rendo 2025-07-21 14:28:40 +05:00
commit dcffb97a3d
48 changed files with 603 additions and 24 deletions

View file

@ -0,0 +1,24 @@
using Godot;
using Newlon.Components.Level;
public partial class ChooseYourSeedsMusic : AudioStreamPlayer
{
public override void _Ready()
{
RuntimeLevelData.Instance.OnLevelStateChanged += OnLevelStateChanged;
}
private void OnLevelStateChanged(RuntimeLevelData.LevelStates state)
{
if (state == RuntimeLevelData.LevelStates.ChooseYourSeeds)
{
Play();
}
else
{
var tween = CreateTween();
tween.TweenProperty(this, "volume_linear", 0, 1);
tween.TweenCallback(Callable.From(Stop));
}
}
}

View file

@ -0,0 +1 @@
uid://b4ysi1iutmju3

View file

@ -0,0 +1,41 @@
using Godot;
using Newlon.Components.Level;
using System;
public partial class MusicTransitioner : AudioStreamPlayer
{
private AudioStreamPlaybackInteractive playback;
private Timer timer;
public override void _Ready()
{
RuntimeLevelData.Instance.OnLevelStateChanged += OnLevelStateChanged;
timer = GetNode<Timer>("Timer");
}
private void OnLevelStateChanged(RuntimeLevelData.LevelStates state)
{
if (state == RuntimeLevelData.LevelStates.Game)
{
Play();
playback = (AudioStreamPlaybackInteractive)GetStreamPlayback();
VolumeLinear = 1;
}
else
{
var tween = CreateTween();
tween.TweenProperty(this, "volume_linear", 0, 1);
tween.TweenCallback(Callable.From(Stop));
}
}
public void OnHugeWaveApproaching()
{
playback.SwitchToClip(1);
timer.Start();
}
public void OnTimerTimeout()
{
playback.SwitchToClip(0);
}
}

View file

@ -0,0 +1 @@
uid://bnj5tlcpmep2o

View file

@ -63,8 +63,8 @@ public partial class SaveSerializer : Node
Settings.Music = parsed.MusicVolume;
Settings.Splash = parsed.SplashSeen;
AudioServer.SetBusVolumeDb(1, Mathf.LinearToDb((float)Settings.SFX));
AudioServer.SetBusVolumeDb(2, Mathf.LinearToDb((float)Settings.Music));
AudioServer.SetBusVolumeDb(2, Mathf.LinearToDb(Mathf.Exp((float)Settings.SFX) - 1));
AudioServer.SetBusVolumeDb(1, Mathf.LinearToDb(Mathf.Exp((float)Settings.Music) - 1));
var playerProgress = PlayerProgress.Instance;
playerProgress.MaxSeedpackets = parsed.SeedpacketSlots;

View file

@ -0,0 +1,12 @@
using Godot;
using System;
public partial class ScalableAudioPlayer : AudioStreamPlayer
{
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
if(PitchScale != (float)Engine.TimeScale)
PitchScale = (float)Engine.TimeScale * (float)Engine.TimeScale;
}
}

View file

@ -0,0 +1 @@
uid://wfjsgbg3fekl

View file

@ -12,7 +12,7 @@ public partial class AudioSlider : HSlider
[Export] private TYPE affects;
public override void _Ready()
{
DragEnded += OnDragEnded;
ValueChanged += OnValueChanged;
if (affects == TYPE.SFX)
{
SetValueNoSignal(Settings.SFX);
@ -23,20 +23,19 @@ public partial class AudioSlider : HSlider
}
}
private void OnDragEnded(bool hasChanged)
private void OnValueChanged(double value)
{
if (hasChanged)
if (affects == TYPE.SFX)
{
if (affects == TYPE.SFX)
{
Settings.SFX = Value;
AudioServer.SetBusVolumeDb(2, Mathf.LinearToDb((float)Value));
}
else
{
Settings.Music = Value;
AudioServer.SetBusVolumeDb(1, Mathf.LinearToDb((float)Value));
}
var volume = Mathf.LinearToDb(Mathf.Exp((float)value) - 1); ;
Settings.SFX = value;
AudioServer.SetBusVolumeDb(2, volume);
}
else
{
var volume = Mathf.LinearToDb(Mathf.Exp((float)value) - 1); ;
Settings.Music = value;
AudioServer.SetBusVolumeDb(1, volume);
}
}

View file

@ -53,5 +53,6 @@ public partial class FastForwardButton : Button
}
Engine.TimeScale = speed;
}
}

View file

@ -2,7 +2,7 @@ extends Node
func _on_play_button_pressed() -> void:
LevelController.call("StartLevel",preload("uid://dd3yegl1xo44m"),preload("uid://ds2js2vylygvy"))
LevelController.call("StartLevel",preload("uid://dd3yegl1xo44m"),preload("uid://ctbue7dex4umy"))
$ChannelPlayer.call("Play")

View file

@ -19,6 +19,7 @@ public partial class LevelRunner : Node
[Export] private float approachNotificationTime;
[Export] private AnimationPlayer player;
[Export] private Node rewardParent;
[Export] private AudioStream firstWaveSound;
[Signal] public delegate void ResourceChangedEventHandler(AdventureLevelResource resource);
[Signal] public delegate void WaveChangedEventHandler(int to);
[Signal] public delegate void HugeWaveApproachingCallbackEventHandler();
@ -68,6 +69,10 @@ public partial class LevelRunner : Node
EmitSignal(SignalName.FinalWaveInitiated);
return;
}
if (waveIndex == 0)
{
AudioSequencer.Play("fl_wave",firstWaveSound);
}
waveTimer.WaitTime = resource.waves[waveIndex].customWaveDelay > 0 ? resource.waves[waveIndex].customWaveDelay : resource.standardWaveDelay;
waveTimer.Start();