Refactor more stuff (Audio mostly)

This commit is contained in:
2025-03-10 20:52:39 -07:00
parent 23049b3231
commit a1c26ed7fb
45 changed files with 861 additions and 846 deletions

View File

@@ -0,0 +1,35 @@
namespace Zennysoft.Ma.Adapter;
public partial class InGameAudioLogic
{
public static class Output
{
#region BGM
public readonly record struct PlayOverworldMusic;
public readonly record struct PlayDungeonThemeAMusic;
#endregion
#region SFX
public readonly record struct PlayPlayerAttackSound;
public readonly record struct PlayPlayerAttackWallSound;
public readonly record struct PlayMenuScrollSound;
public readonly record struct PlayEquipSound;
public readonly record struct PlayInventorySortedSound;
public readonly record struct PlayMenuBackSound;
public readonly record struct PlayHealingItemSound;
public readonly record struct PlayTeleportSound;
#endregion
public readonly record struct PlayGameMusic;
public readonly record struct StopGameMusic;
}
}

View File

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

View File

@@ -0,0 +1,12 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace Zennysoft.Ma.Adapter;
public partial class InGameAudioLogic
{
[Meta]
public partial record State : StateLogic<State>
{
}
}

View File

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

View File

@@ -0,0 +1,13 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace Zennysoft.Ma.Adapter;
public interface IInGameAudioLogic : ILogicBlock<InGameAudioLogic.State>;
[Meta]
[LogicBlock(typeof(State))]
public partial class InGameAudioLogic :
LogicBlock<InGameAudioLogic.State>, IInGameAudioLogic
{
public override Transition GetInitialState() => To<Enabled>();
}

View File

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

View File

@@ -0,0 +1,11 @@
using Chickensoft.Introspection;
namespace Zennysoft.Ma.Adapter;
public partial class InGameAudioLogic
{
[Meta]
public partial record Disabled : State
{
}
}

View File

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

View File

@@ -0,0 +1,74 @@
using Chickensoft.Introspection;
using Zennysoft.Game.Abstractions;
namespace Zennysoft.Ma.Adapter;
public partial class InGameAudioLogic
{
[Meta]
public partial record Enabled : State
{
public Enabled()
{
OnAttach(() =>
{
var player = Get<IPlayer>();
OnOverworldEntered();
var gameEventDepot = Get<IGameEventDepot>();
var gameRepo = Get<IGameRepo>();
gameEventDepot.OverworldEntered += OnOverworldEntered;
gameEventDepot.DungeonAThemeAreaEntered += OnDungeonAThemeEntered;
gameEventDepot.MenuScrolled += OnMenuScrolled;
gameEventDepot.MenuBackedOut += OnMenuBackedOut;
player.EquippedWeapon.Changed += OnEquippedItem;
player.EquippedArmor.Changed += OnEquippedItem;
player.EquippedAccessory.Changed += OnEquippedItem;
gameEventDepot.InventorySorted += OnInventorySorted;
gameEventDepot.HealingItemConsumed += OnHealingItemConsumed;
gameEventDepot.RestorativePickedUp += OnRestorativePickedUp;
gameEventDepot.TeleportEntered += OnTeleportEntered;
gameRepo.PlayerAttack += OnPlayerAttack;
gameRepo.PlayerAttackedWall += OnPlayerAttackWall;
});
OnDetach(() =>
{
var gameEventDepot = Get<IGameEventDepot>();
var player = Get<IPlayer>();
var gameRepo = Get<IGameRepo>();
gameEventDepot.OverworldEntered -= OnOverworldEntered;
gameEventDepot.DungeonAThemeAreaEntered -= OnDungeonAThemeEntered;
gameEventDepot.MenuScrolled -= OnMenuScrolled;
gameEventDepot.MenuBackedOut -= OnMenuBackedOut;
player.EquippedWeapon.Changed -= OnEquippedItem;
player.EquippedArmor.Changed -= OnEquippedItem;
player.EquippedAccessory.Changed -= OnEquippedItem;
gameEventDepot.InventorySorted -= OnInventorySorted;
gameEventDepot.TeleportEntered -= OnTeleportEntered;
gameRepo.PlayerAttack -= OnPlayerAttack;
gameRepo.PlayerAttackedWall -= OnPlayerAttackWall;
});
}
private void OnPlayerAttack() => Output(new Output.PlayPlayerAttackSound());
private void OnPlayerAttackWall() => Output(new Output.PlayPlayerAttackWallSound());
private void OnRestorativePickedUp(IHealthPack restorative) => Output(new Output.PlayHealingItemSound());
private void OnMenuBackedOut() => Output(new Output.PlayMenuBackSound());
private void OnHealingItemConsumed(InventoryItem stats) => Output(new Output.PlayHealingItemSound());
private void OnInventorySorted() => Output(new Output.PlayInventorySortedSound());
private void OnEquippedItem(InventoryItem equipableItem) => Output(new Output.PlayEquipSound());
private void OnOverworldEntered() => Output(new Output.PlayOverworldMusic());
private void OnDungeonAThemeEntered() => Output(new Output.PlayDungeonThemeAMusic());
private void OnMenuScrolled() => Output(new Output.PlayMenuScrollSound());
private void OnTeleportEntered() => Output(new Output.PlayTeleportSound());
}
}

View File

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

View File

@@ -0,0 +1,36 @@
using Zennysoft.Game.Abstractions;
namespace Zennysoft.Ma.Adapter;
public interface IGameEventDepot : IDisposable
{
event Action? OverworldEntered;
public void OnOverworldEntered();
event Action? DungeonAThemeAreaEntered;
public void OnDungeonAThemeAreaEntered();
event Action? DungeonBThemeAreaEntered;
public void OnDungeonBThemeAreaEntered();
event Action? DungeonCThemeAreaEntered;
public void OnDungeonCThemeAreaEntered();
event Action? TeleportEntered;
public void OnTeleportEntered();
event Action? MenuScrolled;
public void OnMenuScrolled();
event Action? MenuBackedOut;
public void OnMenuBackedOut();
event Action? InventorySorted;
public void OnInventorySorted();
event Action<InventoryItem>? HealingItemConsumed;
public void OnHealingItemConsumed(InventoryItem item);
event Action<IHealthPack>? RestorativePickedUp;
public void OnRestorativePickedUp(IHealthPack restorative);
}

View File

@@ -0,0 +1,13 @@
using Chickensoft.Introspection;
using Chickensoft.Serialization;
namespace Zennysoft.Ma.Adapter;
[Meta, Id("equipable_item")]
public abstract partial class EquipableItem : InventoryItem
{
public abstract ItemTag ItemTag { get; }
[Save("equipable_item_is_equipped")]
public bool IsEquipped { get; set; }
}

View File

@@ -12,7 +12,8 @@ public class Module
container.RegisterSingleton<IFileSystem, FileSystem>();
container.RegisterSingleton<ISaveFileManager<GameData>, SaveFileManager<GameData>>();
container.RegisterSingleton<IMaSaveFileManager<GameData>, MaSaveFileManager<GameData>>();
container.Register<IGameRepo, GameRepo>(Lifestyle.Singleton);
container.Register<IGameLogic, GameLogic>(Lifestyle.Singleton);
container.RegisterSingleton<IGameRepo, GameRepo>();
container.RegisterSingleton<IGameLogic, GameLogic>();
container.RegisterSingleton<IDimmableAudioStreamPlayer, DimmableAudioStreamPlayer>();
}
}

View File

@@ -0,0 +1,60 @@
using Chickensoft.Collections;
using Godot;
using Zennysoft.Game.Abstractions;
namespace Zennysoft.Ma.Adapter;
public interface IPlayer : IKillable
{
public void Attack();
public void PlayerPause();
public void TakeDamage(double damage, ElementType elementType = ElementType.None, bool isCriticalHit = false);
public void Knockback(float impulse);
public void GainExp(double expGained);
public void LevelUp();
public void Move(float delta);
public void TeleportPlayer(Transform3D newTransform);
public void HealHP(int amount);
public void RaiseHP(int amount);
public void HealVT(int amount);
public void RaiseVT(int amount);
public void ModifyBonusAttack(int amount);
public void ModifyBonusDefense(int amount);
public void ModifyMaximumHP(int amount);
public void ModifyMaximumVT(int amount);
public void ModifyBonusLuck(double amount);
public IInventory Inventory { get; }
public PlayerStatController Stats { get; }
public Vector3 CurrentPosition { get; }
public Basis CurrentBasis { get; }
public IAutoProp<EquipableItem> EquippedWeapon { get; }
public IAutoProp<EquipableItem> EquippedArmor { get; }
public IAutoProp<EquipableItem> EquippedAccessory { get; }
public void Equip(EquipableItem equipable);
public void Unequip(EquipableItem equipable);
}

View File

@@ -0,0 +1,118 @@
namespace Zennysoft.Ma.Adapter;
using Chickensoft.Collections;
using Godot;
using Zennysoft.Game.Ma;
public class PlayerStatController
{
public void Init(PlayerStats playerStats)
{
_currentHP.OnNext(playerStats.CurrentHP);
_maximumHP.OnNext(playerStats.MaximumHP);
_currentVT.OnNext(playerStats.CurrentVT);
_maximumVT.OnNext(playerStats.MaximumVT);
_currentExp.OnNext(playerStats.CurrentExp);
_currentLevel.OnNext(playerStats.CurrentLevel);
_currentAttack.OnNext(playerStats.CurrentAttack);
_bonusAttack.OnNext(playerStats.BonusAttack);
_maxAttack.OnNext(playerStats.MaxAttack);
_currentDefense.OnNext(playerStats.CurrentDefense);
_bonusDefense.OnNext(playerStats.BonusDefense);
_maxDefense.OnNext(playerStats.MaxDefense);
_expToNextLevel.OnNext(playerStats.ExpToNextLevel);
_luck.OnNext(playerStats.Luck);
}
public IAutoProp<int> CurrentHP => _currentHP;
public IAutoProp<int> MaximumHP => _maximumHP;
public IAutoProp<int> CurrentVT => _currentVT;
public IAutoProp<int> MaximumVT => _maximumVT;
public IAutoProp<int> CurrentAttack => _currentAttack;
public IAutoProp<int> MaxAttack => _maxAttack;
public IAutoProp<int> BonusAttack => _bonusAttack;
public IAutoProp<int> CurrentDefense => _currentDefense;
public IAutoProp<int> MaxDefense => _maxDefense;
public IAutoProp<int> BonusDefense => _bonusDefense;
public IAutoProp<double> CurrentExp => _currentExp;
public IAutoProp<int> ExpToNextLevel => _expToNextLevel;
public IAutoProp<int> CurrentLevel => _currentLevel;
public IAutoProp<double> Luck => _luck;
public void SetCurrentHP(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaximumHP.Value);
_currentHP.OnNext(clampedValue);
}
public void SetMaximumHP(int newValue)
{
_maximumHP.OnNext(newValue);
}
public void SetCurrentVT(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaximumVT.Value);
_currentVT.OnNext(clampedValue);
}
public void SetMaximumVT(int newValue)
{
_maximumVT.OnNext(newValue);
}
public void SetCurrentExp(double newValue)
{
_currentExp.OnNext(newValue);
}
public void SetCurrentLevel(int newValue)
{
_currentLevel.OnNext(newValue);
}
public void SetCurrentAttack(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaxAttack.Value);
_currentAttack.OnNext(clampedValue);
}
public void SetBonusAttack(int newValue)
{
_bonusAttack.OnNext(newValue);
}
public void SetMaxAttack(int newValue)
{
_maxAttack.OnNext(newValue);
}
public void SetCurrentDefense(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaxDefense.Value);
_currentDefense.OnNext(clampedValue);
}
public void SetBonusDefense(int newValue)
{
_bonusDefense.OnNext(newValue);
}
public void SetMaxDefense(int newValue)
{
_maxDefense.OnNext(newValue);
}
public void SetExpToNextLevel(int newValue)
{
_expToNextLevel.OnNext(newValue);
}
public void SetLuck(double newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, 1.0);
_luck.OnNext(clampedValue);
}
private readonly AutoProp<int> _currentHP = new(-1);
private readonly AutoProp<int> _maximumHP = new(-1);
private readonly AutoProp<int> _currentVT = new(-1);
private readonly AutoProp<int> _maximumVT = new(-1);
private readonly AutoProp<double> _currentExp = new(-1);
private readonly AutoProp<int> _currentLevel = new(-1);
private readonly AutoProp<int> _currentAttack = new(-1);
private readonly AutoProp<int> _bonusAttack = new(-1);
private readonly AutoProp<int> _maxAttack = new(-1);
private readonly AutoProp<int> _currentDefense = new(-1);
private readonly AutoProp<int> _bonusDefense = new(-1);
private readonly AutoProp<int> _maxDefense = new(-1);
private readonly AutoProp<int> _expToNextLevel = new(-1);
private readonly AutoProp<double> _luck = new(-1);
}

View File

@@ -37,116 +37,3 @@ public partial record PlayerStats
[Save("luck")]
public double Luck { get; init; }
}
public class PlayerStatController
{
public void Init(PlayerStats playerStats)
{
_currentHP.OnNext(playerStats.CurrentHP);
_maximumHP.OnNext(playerStats.MaximumHP);
_currentVT.OnNext(playerStats.CurrentVT);
_maximumVT.OnNext(playerStats.MaximumVT);
_currentExp.OnNext(playerStats.CurrentExp);
_currentLevel.OnNext(playerStats.CurrentLevel);
_currentAttack.OnNext(playerStats.CurrentAttack);
_bonusAttack.OnNext(playerStats.BonusAttack);
_maxAttack.OnNext(playerStats.MaxAttack);
_currentDefense.OnNext(playerStats.CurrentDefense);
_bonusDefense.OnNext(playerStats.BonusDefense);
_maxDefense.OnNext(playerStats.MaxDefense);
_expToNextLevel.OnNext(playerStats.ExpToNextLevel);
_luck.OnNext(playerStats.Luck);
}
public IAutoProp<int> CurrentHP => _currentHP;
public IAutoProp<int> MaximumHP => _maximumHP;
public IAutoProp<int> CurrentVT => _currentVT;
public IAutoProp<int> MaximumVT => _maximumVT;
public IAutoProp<int> CurrentAttack => _currentAttack;
public IAutoProp<int> MaxAttack => _maxAttack;
public IAutoProp<int> BonusAttack => _bonusAttack;
public IAutoProp<int> CurrentDefense => _currentDefense;
public IAutoProp<int> MaxDefense => _maxDefense;
public IAutoProp<int> BonusDefense => _bonusDefense;
public IAutoProp<double> CurrentExp => _currentExp;
public IAutoProp<int> ExpToNextLevel => _expToNextLevel;
public IAutoProp<int> CurrentLevel => _currentLevel;
public IAutoProp<double> Luck => _luck;
public void SetCurrentHP(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaximumHP.Value);
_currentHP.OnNext(clampedValue);
}
public void SetMaximumHP(int newValue)
{
_maximumHP.OnNext(newValue);
}
public void SetCurrentVT(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaximumVT.Value);
_currentVT.OnNext(clampedValue);
}
public void SetMaximumVT(int newValue)
{
_maximumVT.OnNext(newValue);
}
public void SetCurrentExp(double newValue)
{
_currentExp.OnNext(newValue);
}
public void SetCurrentLevel(int newValue)
{
_currentLevel.OnNext(newValue);
}
public void SetCurrentAttack(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaxAttack.Value);
_currentAttack.OnNext(clampedValue);
}
public void SetBonusAttack(int newValue)
{
_bonusAttack.OnNext(newValue);
}
public void SetMaxAttack(int newValue)
{
_maxAttack.OnNext(newValue);
}
public void SetCurrentDefense(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaxDefense.Value);
_currentDefense.OnNext(clampedValue);
}
public void SetBonusDefense(int newValue)
{
_bonusDefense.OnNext(newValue);
}
public void SetMaxDefense(int newValue)
{
_maxDefense.OnNext(newValue);
}
public void SetExpToNextLevel(int newValue)
{
_expToNextLevel.OnNext(newValue);
}
public void SetLuck(double newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, 1.0);
_luck.OnNext(clampedValue);
}
private readonly AutoProp<int> _currentHP = new(-1);
private readonly AutoProp<int> _maximumHP = new(-1);
private readonly AutoProp<int> _currentVT = new(-1);
private readonly AutoProp<int> _maximumVT = new(-1);
private readonly AutoProp<double> _currentExp = new(-1);
private readonly AutoProp<int> _currentLevel = new(-1);
private readonly AutoProp<int> _currentAttack = new(-1);
private readonly AutoProp<int> _bonusAttack = new(-1);
private readonly AutoProp<int> _maxAttack = new(-1);
private readonly AutoProp<int> _currentDefense = new(-1);
private readonly AutoProp<int> _bonusDefense = new(-1);
private readonly AutoProp<int> _maxDefense = new(-1);
private readonly AutoProp<int> _expToNextLevel = new(-1);
private readonly AutoProp<double> _luck = new(-1);
}