Implement core game functionality with AppRoot, SaveClient, PlayerRepository, and LevelRepository classes

This commit is contained in:
2025-08-15 02:46:02 +02:00
parent 173f0e5703
commit 406036504a
38 changed files with 422 additions and 213 deletions

34
common/AppRoot.cs Normal file
View File

@@ -0,0 +1,34 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Godot;
using Mr.BrickAdventures.data;
using Mr.BrickAdventures.game.repositories;
using Mr.BrickAdventures.game.services;
namespace Mr.BrickAdventures.common;
[Meta(typeof(IAutoNode))]
public partial class AppRoot : Node2D, IProvide<PlayerRepository>, IProvide<LevelRepository>, IProvide<SaveClient>, IProvide<SaveService>
{
public override void _Notification(int what) => this.Notify(what);
private readonly SaveClient _save = new("user://savegame.save", version: 2);
private readonly PlayerRepository _players = new();
private readonly LevelRepository _levels = new();
private SaveService _saveService = null!;
PlayerRepository IProvide<PlayerRepository>.Value() => _players;
LevelRepository IProvide<LevelRepository>.Value() => _levels;
SaveClient IProvide<SaveClient>.Value() => _save;
SaveService IProvide<SaveService>.Value() => _saveService;
public void OnReady()
{
_saveService = new SaveService(_players, _levels, _save);
_saveService.TryLoad();
this.Provide();
}
}