Big refactor in place: Organize nodes in line with dependency injection expectations, use state machine flow more
This commit is contained in:
58
src/audio/DimmableAudioStreamPlayer.cs
Normal file
58
src/audio/DimmableAudioStreamPlayer.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
namespace GameJamDungeon;
|
||||
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Godot;
|
||||
|
||||
public interface IDimmableAudioStreamPlayer : IAudioStreamPlayer
|
||||
{
|
||||
/// <summary>Fade this dimmable audio stream track in.</summary>
|
||||
public void FadeIn();
|
||||
/// <summary>Fade this dimmable audio stream track out.</summary>
|
||||
public void FadeOut();
|
||||
}
|
||||
|
||||
public partial class DimmableAudioStreamPlayer :
|
||||
AudioStreamPlayer, IDimmableAudioStreamPlayer
|
||||
{
|
||||
#region Constants
|
||||
// -60 to -80 is considered inaudible for decibels.
|
||||
public const float VOLUME_DB_INAUDIBLE = -80f;
|
||||
public const double FADE_DURATION = 3d; // seconds
|
||||
#endregion Constants
|
||||
|
||||
public ITween? FadeTween { get; set; }
|
||||
|
||||
public float InitialVolumeDb;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
InitialVolumeDb = VolumeDb;
|
||||
VolumeDb = VOLUME_DB_INAUDIBLE;
|
||||
}
|
||||
|
||||
public void FadeIn()
|
||||
{
|
||||
SetupFade(InitialVolumeDb, Tween.EaseType.Out);
|
||||
Play();
|
||||
}
|
||||
|
||||
public void FadeOut()
|
||||
{
|
||||
SetupFade(VOLUME_DB_INAUDIBLE, Tween.EaseType.In);
|
||||
FadeTween!.TweenCallback(Callable.From(Stop));
|
||||
}
|
||||
|
||||
public void SetupFade(float volumeDb, Tween.EaseType ease)
|
||||
{
|
||||
FadeTween?.Kill();
|
||||
|
||||
FadeTween = GodotInterfaces.Adapt<ITween>(CreateTween());
|
||||
|
||||
FadeTween.TweenProperty(
|
||||
this,
|
||||
"volume_db",
|
||||
volumeDb,
|
||||
FADE_DURATION
|
||||
).SetTrans(Tween.TransitionType.Circ).SetEase(ease);
|
||||
}
|
||||
}
|
||||
21
src/audio/InGameAudio.cs
Normal file
21
src/audio/InGameAudio.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
|
||||
namespace GameJamDungeon;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class InGameAudio : Node
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
#region BGM Nodes
|
||||
[Node] public IDimmableAudioStreamPlayer MenuBGM { get; set; } = default!;
|
||||
[Node] public IDimmableAudioStreamPlayer OverworldBGM { get; set; } = default!;
|
||||
#endregion
|
||||
|
||||
#region SFX Nodes
|
||||
[Node] public IAudioStreamPlayer PlayerAttackSFX { get; set; } = default!;
|
||||
#endregion
|
||||
}
|
||||
19
src/audio/InGameAudio.tscn
Normal file
19
src/audio/InGameAudio.tscn
Normal file
@@ -0,0 +1,19 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://b16ejcwanod72"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/audio/InGameAudio.cs" id="1_gpmcr"]
|
||||
[ext_resource type="Script" path="res://src/audio/DimmableAudioStreamPlayer.cs" id="2_857rw"]
|
||||
|
||||
[node name="InGameAudio" type="Node"]
|
||||
process_mode = 3
|
||||
script = ExtResource("1_gpmcr")
|
||||
|
||||
[node name="MenuBGM" type="AudioStreamPlayer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("2_857rw")
|
||||
|
||||
[node name="OverworldBGM" type="AudioStreamPlayer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("2_857rw")
|
||||
|
||||
[node name="PlayerAttackSFX" type="AudioStreamPlayer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
BIN
src/audio/music/crossing-the-gate.mp3
Normal file
BIN
src/audio/music/crossing-the-gate.mp3
Normal file
Binary file not shown.
19
src/audio/music/crossing-the-gate.mp3.import
Normal file
19
src/audio/music/crossing-the-gate.mp3.import
Normal file
@@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="mp3"
|
||||
type="AudioStreamMP3"
|
||||
uid="uid://d2jrktp06xsba"
|
||||
path="res://.godot/imported/crossing-the-gate.mp3-f062dfcb3f59739ce7e55970f8091d25.mp3str"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://src/audio/music/crossing-the-gate.mp3"
|
||||
dest_files=["res://.godot/imported/crossing-the-gate.mp3-f062dfcb3f59739ce7e55970f8091d25.mp3str"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
BIN
src/audio/music/droney.mp3
Normal file
BIN
src/audio/music/droney.mp3
Normal file
Binary file not shown.
19
src/audio/music/droney.mp3.import
Normal file
19
src/audio/music/droney.mp3.import
Normal file
@@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="mp3"
|
||||
type="AudioStreamMP3"
|
||||
uid="uid://dfu0fksb6slhx"
|
||||
path="res://.godot/imported/droney.mp3-a35fe85a5df08f09cd4cf965e60dc611.mp3str"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://src/audio/music/droney.mp3"
|
||||
dest_files=["res://.godot/imported/droney.mp3-a35fe85a5df08f09cd4cf965e60dc611.mp3str"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
BIN
src/audio/music/tar-winds.mp3
Normal file
BIN
src/audio/music/tar-winds.mp3
Normal file
Binary file not shown.
19
src/audio/music/tar-winds.mp3.import
Normal file
19
src/audio/music/tar-winds.mp3.import
Normal file
@@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="mp3"
|
||||
type="AudioStreamMP3"
|
||||
uid="uid://dn2e2hqujlia1"
|
||||
path="res://.godot/imported/tar-winds.mp3-7ac6ab80e2c96dfbcd5e5c27c1154ff2.mp3str"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://src/audio/music/tar-winds.mp3"
|
||||
dest_files=["res://.godot/imported/tar-winds.mp3-7ac6ab80e2c96dfbcd5e5c27c1154ff2.mp3str"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
BIN
src/audio/music/useless immune system.wav
Normal file
BIN
src/audio/music/useless immune system.wav
Normal file
Binary file not shown.
24
src/audio/music/useless immune system.wav.import
Normal file
24
src/audio/music/useless immune system.wav.import
Normal file
@@ -0,0 +1,24 @@
|
||||
[remap]
|
||||
|
||||
importer="wav"
|
||||
type="AudioStreamWAV"
|
||||
uid="uid://6002a12ecfo5"
|
||||
path="res://.godot/imported/useless immune system.wav-90ff2c5c12784f54b1b15c7a7e4603b8.sample"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://src/audio/music/useless immune system.wav"
|
||||
dest_files=["res://.godot/imported/useless immune system.wav-90ff2c5c12784f54b1b15c7a7e4603b8.sample"]
|
||||
|
||||
[params]
|
||||
|
||||
force/8_bit=false
|
||||
force/mono=false
|
||||
force/max_rate=false
|
||||
force/max_rate_hz=44100
|
||||
edit/trim=false
|
||||
edit/normalize=false
|
||||
edit/loop_mode=0
|
||||
edit/loop_begin=0
|
||||
edit/loop_end=-1
|
||||
compress/mode=0
|
||||
Reference in New Issue
Block a user