Implement Equip/Unequip SFX

This commit is contained in:
2025-03-11 16:51:22 -07:00
parent 294c52dc40
commit 29af9062b5
12 changed files with 135 additions and 67 deletions

View File

@@ -21,6 +21,8 @@ public partial class InGameAudioLogic
public readonly record struct PlayEquipSound; public readonly record struct PlayEquipSound;
public readonly record struct PlayUnequipSound;
public readonly record struct PlayInventorySortedSound; public readonly record struct PlayInventorySortedSound;
public readonly record struct PlayMenuBackSound; public readonly record struct PlayMenuBackSound;

View File

@@ -20,9 +20,8 @@ public partial class InGameAudioLogic
gameEventDepot.DungeonAThemeAreaEntered += OnDungeonAThemeEntered; gameEventDepot.DungeonAThemeAreaEntered += OnDungeonAThemeEntered;
gameEventDepot.MenuScrolled += OnMenuScrolled; gameEventDepot.MenuScrolled += OnMenuScrolled;
gameEventDepot.MenuBackedOut += OnMenuBackedOut; gameEventDepot.MenuBackedOut += OnMenuBackedOut;
player.EquippedWeapon.Changed += OnEquippedItem; gameRepo.EquippedItem += OnEquippedItem;
player.EquippedArmor.Changed += OnEquippedItem; gameRepo.UnequippedItem += OnUnequippedItem;
player.EquippedAccessory.Changed += OnEquippedItem;
gameEventDepot.InventorySorted += OnInventorySorted; gameEventDepot.InventorySorted += OnInventorySorted;
gameEventDepot.HealingItemConsumed += OnHealingItemConsumed; gameEventDepot.HealingItemConsumed += OnHealingItemConsumed;
gameEventDepot.RestorativePickedUp += OnRestorativePickedUp; gameEventDepot.RestorativePickedUp += OnRestorativePickedUp;
@@ -39,9 +38,8 @@ public partial class InGameAudioLogic
gameEventDepot.DungeonAThemeAreaEntered -= OnDungeonAThemeEntered; gameEventDepot.DungeonAThemeAreaEntered -= OnDungeonAThemeEntered;
gameEventDepot.MenuScrolled -= OnMenuScrolled; gameEventDepot.MenuScrolled -= OnMenuScrolled;
gameEventDepot.MenuBackedOut -= OnMenuBackedOut; gameEventDepot.MenuBackedOut -= OnMenuBackedOut;
player.EquippedWeapon.Changed -= OnEquippedItem; gameRepo.EquippedItem -= OnEquippedItem;
player.EquippedArmor.Changed -= OnEquippedItem; gameRepo.UnequippedItem -= OnUnequippedItem;
player.EquippedAccessory.Changed -= OnEquippedItem;
gameEventDepot.InventorySorted -= OnInventorySorted; gameEventDepot.InventorySorted -= OnInventorySorted;
gameEventDepot.TeleportEntered -= OnTeleportEntered; gameEventDepot.TeleportEntered -= OnTeleportEntered;
gameRepo.PlayerAttack -= OnPlayerAttack; gameRepo.PlayerAttack -= OnPlayerAttack;
@@ -63,6 +61,8 @@ public partial class InGameAudioLogic
private void OnEquippedItem(InventoryItem equipableItem) => Output(new Output.PlayEquipSound()); private void OnEquippedItem(InventoryItem equipableItem) => Output(new Output.PlayEquipSound());
private void OnUnequippedItem(InventoryItem equipableItem) => Output(new Output.PlayUnequipSound());
private void OnOverworldEntered() => Output(new Output.PlayOverworldMusic()); private void OnOverworldEntered() => Output(new Output.PlayOverworldMusic());
private void OnDungeonAThemeEntered() => Output(new Output.PlayDungeonThemeAMusic()); private void OnDungeonAThemeEntered() => Output(new Output.PlayDungeonThemeAMusic());

View File

@@ -25,6 +25,10 @@ public interface IGameRepo : IDisposable
event Action? PlayerAttackedEnemy; event Action? PlayerAttackedEnemy;
event Action<EquipableItem>? EquippedItem;
event Action<EquipableItem>? UnequippedItem;
void Pause(); void Pause();
void Resume(); void Resume();
@@ -51,6 +55,10 @@ public interface IGameRepo : IDisposable
public void GameEnded(); public void GameEnded();
public void OnEquippedItem(EquipableItem item);
public void OnUnequippedItem(EquipableItem item);
public double ExpRate { get; } public double ExpRate { get; }
} }
@@ -66,6 +74,8 @@ public class GameRepo : IGameRepo
public event Action? PlayerAttack; public event Action? PlayerAttack;
public event Action? PlayerAttackedWall; public event Action? PlayerAttackedWall;
public event Action? PlayerAttackedEnemy; public event Action? PlayerAttackedEnemy;
public event Action<EquipableItem>? EquippedItem;
public event Action<EquipableItem>? UnequippedItem;
public IAutoProp<bool> IsPaused => _isPaused; public IAutoProp<bool> IsPaused => _isPaused;
private readonly AutoProp<bool> _isPaused; private readonly AutoProp<bool> _isPaused;
@@ -141,6 +151,10 @@ public class GameRepo : IGameRepo
CloseInventoryEvent?.Invoke(); CloseInventoryEvent?.Invoke();
} }
public void OnEquippedItem(EquipableItem item) => EquippedItem?.Invoke(item);
public void OnUnequippedItem(EquipableItem item) => UnequippedItem?.Invoke(item);
public void GameEnded() public void GameEnded()
{ {
Pause(); Pause();

View File

@@ -43,6 +43,8 @@ public partial class InGameAudio : Node
[Node] public IAudioStreamPlayer EquipSFX { get; set; } = default!; [Node] public IAudioStreamPlayer EquipSFX { get; set; } = default!;
[Node] public IAudioStreamPlayer UnequipSFX { get; set; } = default!;
[Node] public IAudioStreamPlayer MenuBackSFX { get; set; } = default!; [Node] public IAudioStreamPlayer MenuBackSFX { get; set; } = default!;
[Node] public IAudioStreamPlayer InventorySortedSFX { get; set; } = default!; [Node] public IAudioStreamPlayer InventorySortedSFX { get; set; } = default!;
@@ -57,86 +59,93 @@ public partial class InGameAudio : Node
public void Setup() public void Setup()
{ {
InGameAudioLogic = new InGameAudioLogic(); InGameAudioLogic = new InGameAudioLogic();
} }
public void OnResolved() public void OnResolved()
{ {
InGameAudioLogic.Set(AppRepo); InGameAudioLogic.Set(AppRepo);
InGameAudioLogic.Set(GameEventDepot); InGameAudioLogic.Set(GameEventDepot);
InGameAudioLogic.Set(Player); InGameAudioLogic.Set(Player);
InGameAudioLogic.Set(GameRepo); InGameAudioLogic.Set(GameRepo);
InGameAudioBinding = InGameAudioLogic.Bind(); InGameAudioBinding = InGameAudioLogic.Bind();
InGameAudioBinding InGameAudioBinding
.Handle((in InGameAudioLogic.Output.PlayOverworldMusic _) => StartOverworldMusic()) .Handle((in InGameAudioLogic.Output.PlayOverworldMusic _) => StartOverworldMusic())
.Handle((in InGameAudioLogic.Output.PlayDungeonThemeAMusic _) => StartDungeonThemeA()) .Handle((in InGameAudioLogic.Output.PlayDungeonThemeAMusic _) => StartDungeonThemeA())
.Handle((in InGameAudioLogic.Output.PlayMenuScrollSound _) => PlayMenuScrollSound()) .Handle((in InGameAudioLogic.Output.PlayMenuScrollSound _) => PlayMenuScrollSound())
.Handle((in InGameAudioLogic.Output.PlayEquipSound _) => PlayEquipSound()) .Handle((in InGameAudioLogic.Output.PlayEquipSound _) => PlayEquipSound())
.Handle((in InGameAudioLogic.Output.PlayMenuBackSound _) => PlayMenuBackSound()) .Handle((in InGameAudioLogic.Output.PlayUnequipSound _) => PlayUnequipSound())
.Handle((in InGameAudioLogic.Output.PlayInventorySortedSound _) => PlayInventorySortedSound()) .Handle((in InGameAudioLogic.Output.PlayMenuBackSound _) => PlayMenuBackSound())
.Handle((in InGameAudioLogic.Output.PlayHealingItemSound _) => PlayHealingItemSound()) .Handle((in InGameAudioLogic.Output.PlayInventorySortedSound _) => PlayInventorySortedSound())
.Handle((in InGameAudioLogic.Output.PlayTeleportSound _) => PlayTeleportSound()) .Handle((in InGameAudioLogic.Output.PlayHealingItemSound _) => PlayHealingItemSound())
.Handle((in InGameAudioLogic.Output.PlayPlayerAttackSound _) => { PlayerAttackSFX.Stop(); PlayerAttackSFX.Play(); }) .Handle((in InGameAudioLogic.Output.PlayTeleportSound _) => PlayTeleportSound())
.Handle((in InGameAudioLogic.Output.PlayPlayerAttackWallSound _) => { PlayerAttackWallSFX.Stop(); PlayerAttackWallSFX.Play(); }) .Handle((in InGameAudioLogic.Output.PlayPlayerAttackSound _) => { PlayerAttackSFX.Stop(); PlayerAttackSFX.Play(); })
.Handle((in InGameAudioLogic.Output.PlayPlayerAttackEnemySound _) => { PlayerAttackEnemySFX.Stop(); PlayerAttackEnemySFX.Play(); }); .Handle((in InGameAudioLogic.Output.PlayPlayerAttackWallSound _) => { PlayerAttackWallSFX.Stop(); PlayerAttackWallSFX.Play(); })
.Handle((in InGameAudioLogic.Output.PlayPlayerAttackEnemySound _) => { PlayerAttackEnemySFX.Stop(); PlayerAttackEnemySFX.Play(); });
InGameAudioLogic.Start(); InGameAudioLogic.Start();
} }
public void OnExitTree() public void OnExitTree()
{ {
InGameAudioLogic.Stop(); InGameAudioLogic.Stop();
InGameAudioBinding.Dispose(); InGameAudioBinding.Dispose();
} }
private void StartOverworldMusic() private void StartOverworldMusic()
{ {
OverworldBgm.Stop(); OverworldBgm.Stop();
OverworldBgm.FadeIn(); OverworldBgm.FadeIn();
} }
private void StartDungeonThemeA() private void StartDungeonThemeA()
{ {
OverworldBgm.FadeOut(); OverworldBgm.FadeOut();
DungeonThemeABgm.Stop(); DungeonThemeABgm.Stop();
DungeonThemeABgm.FadeIn(); DungeonThemeABgm.FadeIn();
} }
private void PlayMenuScrollSound() private void PlayMenuScrollSound()
{ {
MenuScrollSFX.Stop(); MenuScrollSFX.Stop();
MenuScrollSFX.Play(); MenuScrollSFX.Play();
} }
private void PlayEquipSound() private void PlayEquipSound()
{ {
EquipSFX.Stop(); EquipSFX.Stop();
EquipSFX.Play(); EquipSFX.Play();
}
private void PlayUnequipSound()
{
UnequipSFX.Stop();
UnequipSFX.Play();
} }
private void PlayMenuBackSound() private void PlayMenuBackSound()
{ {
MenuBackSFX.Stop(); MenuBackSFX.Stop();
MenuBackSFX.Play(); MenuBackSFX.Play();
} }
private void PlayInventorySortedSound() private void PlayInventorySortedSound()
{ {
InventorySortedSFX.Stop(); InventorySortedSFX.Stop();
InventorySortedSFX.Play(); InventorySortedSFX.Play();
} }
private void PlayHealingItemSound() private void PlayHealingItemSound()
{ {
HealingItemSFX.Stop(); HealingItemSFX.Stop();
HealingItemSFX.Play(); HealingItemSFX.Play();
} }
private void PlayTeleportSound() private void PlayTeleportSound()
{ {
TeleportSFX.Stop(); TeleportSFX.Stop();
TeleportSFX.Play(); TeleportSFX.Play();
} }
} }

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=16 format=3 uid="uid://b16ejcwanod72"] [gd_scene load_steps=17 format=3 uid="uid://b16ejcwanod72"]
[ext_resource type="Script" uid="uid://2mnouyn1jcqs" path="res://src/audio/InGameAudio.cs" id="1_gpmcr"] [ext_resource type="Script" uid="uid://2mnouyn1jcqs" path="res://src/audio/InGameAudio.cs" id="1_gpmcr"]
[ext_resource type="AudioStream" uid="uid://dfu0fksb6slhx" path="res://src/audio/music/droney.mp3" id="2_8hfyr"] [ext_resource type="AudioStream" uid="uid://dfu0fksb6slhx" path="res://src/audio/music/droney.mp3" id="2_8hfyr"]
@@ -10,11 +10,12 @@
[ext_resource type="AudioStream" uid="uid://dor0in0x2fg48" path="res://src/audio/sfx/MenuScrollSFX.ogg" id="7_777nl"] [ext_resource type="AudioStream" uid="uid://dor0in0x2fg48" path="res://src/audio/sfx/MenuScrollSFX.ogg" id="7_777nl"]
[ext_resource type="AudioStream" uid="uid://d1mlduwauechv" path="res://src/audio/sfx/PlayerAttackSFX.wav" id="7_wtvpb"] [ext_resource type="AudioStream" uid="uid://d1mlduwauechv" path="res://src/audio/sfx/PlayerAttackSFX.wav" id="7_wtvpb"]
[ext_resource type="AudioStream" uid="uid://r1tryiit38i8" path="res://src/audio/sfx/MenuBackSFX.ogg" id="8_1xcgo"] [ext_resource type="AudioStream" uid="uid://r1tryiit38i8" path="res://src/audio/sfx/MenuBackSFX.ogg" id="8_1xcgo"]
[ext_resource type="AudioStream" uid="uid://bjj61s8q2gwb8" path="res://src/audio/sfx/EquipSFX.ogg" id="8_kwybb"]
[ext_resource type="AudioStream" uid="uid://4u8f1tpgs08b" path="res://src/audio/sfx/PlayerHitEnemySFX.wav" id="9_hertr"] [ext_resource type="AudioStream" uid="uid://4u8f1tpgs08b" path="res://src/audio/sfx/PlayerHitEnemySFX.wav" id="9_hertr"]
[ext_resource type="AudioStream" uid="uid://myx4s8lmarc2" path="res://src/audio/sfx/HealSFX.ogg" id="10_3lcw5"] [ext_resource type="AudioStream" uid="uid://myx4s8lmarc2" path="res://src/audio/sfx/HealSFX.ogg" id="10_3lcw5"]
[ext_resource type="AudioStream" uid="uid://dci08kmwsu6k1" path="res://src/audio/sfx/ExitSFX.ogg" id="11_offhc"] [ext_resource type="AudioStream" uid="uid://dci08kmwsu6k1" path="res://src/audio/sfx/ExitSFX.ogg" id="11_offhc"]
[ext_resource type="AudioStream" uid="uid://d0wd6xgjoadbc" path="res://src/audio/sfx/EquipSFX.wav" id="12_hertr"]
[ext_resource type="AudioStream" uid="uid://d3sn7c614uj2n" path="res://src/audio/sfx/SortSFX.ogg" id="12_wprjr"] [ext_resource type="AudioStream" uid="uid://d3sn7c614uj2n" path="res://src/audio/sfx/SortSFX.ogg" id="12_wprjr"]
[ext_resource type="AudioStream" uid="uid://f5agx4ewe04d" path="res://src/audio/sfx/UnequipSFX.wav" id="13_y7w0c"]
[node name="InGameAudio" type="Node"] [node name="InGameAudio" type="Node"]
process_mode = 3 process_mode = 3
@@ -88,8 +89,11 @@ volume_db = -10.0
[node name="EquipSFX" type="AudioStreamPlayer" parent="SFX"] [node name="EquipSFX" type="AudioStreamPlayer" parent="SFX"]
unique_name_in_owner = true unique_name_in_owner = true
stream = ExtResource("8_kwybb") stream = ExtResource("12_hertr")
volume_db = -10.0
[node name="UnequipSFX" type="AudioStreamPlayer" parent="SFX"]
unique_name_in_owner = true
stream = ExtResource("13_y7w0c")
[node name="HealSFX" type="AudioStreamPlayer" parent="SFX"] [node name="HealSFX" type="AudioStreamPlayer" parent="SFX"]
unique_name_in_owner = true unique_name_in_owner = true

View File

@@ -1,19 +0,0 @@
[remap]
importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://bjj61s8q2gwb8"
path="res://.godot/imported/EquipSFX.ogg-6a8dd8843f1eb38662d6d370e4b2f930.oggvorbisstr"
[deps]
source_file="res://src/audio/sfx/EquipSFX.ogg"
dest_files=["res://.godot/imported/EquipSFX.ogg-6a8dd8843f1eb38662d6d370e4b2f930.oggvorbisstr"]
[params]
loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4

Binary file not shown.

View File

@@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://d0wd6xgjoadbc"
path="res://.godot/imported/EquipSFX.wav-ec813b83f09b5b1011f86476dc0f2aba.sample"
[deps]
source_file="res://src/audio/sfx/EquipSFX.wav"
dest_files=["res://.godot/imported/EquipSFX.wav-ec813b83f09b5b1011f86476dc0f2aba.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=2

Binary file not shown.

View File

@@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://f5agx4ewe04d"
path="res://.godot/imported/UnequipSFX.wav-b40e3365fde607f5fc81ee5c782ed02e.sample"
[deps]
source_file="res://src/audio/sfx/UnequipSFX.wav"
dest_files=["res://.godot/imported/UnequipSFX.wav-b40e3365fde607f5fc81ee5c782ed02e.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=2

View File

@@ -384,6 +384,9 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<ISaveChunk<Play
public void Equip(EquipableItem equipable) public void Equip(EquipableItem equipable)
{ {
if (string.IsNullOrEmpty(equipable.ItemName))
return;
if (equipable is Weapon weapon) if (equipable is Weapon weapon)
{ {
Unequip(_equippedWeapon.Value); Unequip(_equippedWeapon.Value);
@@ -404,10 +407,15 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<ISaveChunk<Play
} }
else else
throw new NotImplementedException("Item type is not supported."); throw new NotImplementedException("Item type is not supported.");
_gameRepo.OnEquippedItem(equipable);
} }
public void Unequip(EquipableItem equipable) public void Unequip(EquipableItem equipable)
{ {
if (string.IsNullOrEmpty(equipable.ItemName))
return;
if (equipable is Weapon weapon) if (equipable is Weapon weapon)
{ {
weapon.IsEquipped = false; weapon.IsEquipped = false;
@@ -435,6 +443,8 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<ISaveChunk<Play
if (equipable.ItemTag == ItemTag.BreaksOnChange) if (equipable.ItemTag == ItemTag.BreaksOnChange)
Inventory.Remove(equipable); Inventory.Remove(equipable);
_gameRepo.OnUnequippedItem(equipable);
} }
private static Vector3 GlobalInputVector private static Vector3 GlobalInputVector