Add game scene and level catalog interfaces, and implement scene management in AppRoot
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.app;
|
||||
using Mr.BrickAdventures.game.repositories;
|
||||
using Mr.BrickAdventures.game.services;
|
||||
|
||||
@@ -20,10 +21,11 @@ public partial class MainMenu : Control
|
||||
[Export] public Label VersionLabel { get; set; } = null!;
|
||||
[Export] public Control SettingsControl { get; set; } = null!;
|
||||
[Export] public Control CreditsControl { get; set; } = null!;
|
||||
[Export] public PackedScene FirstLevelScene { get; set; } = null!;
|
||||
|
||||
[Dependency] public SaveService Save => this.DependOn<SaveService>();
|
||||
[Dependency] public LevelRepository Levels => this.DependOn<LevelRepository>();
|
||||
[Dependency] public IGameScenes Scenes => this.DependOn<IGameScenes>();
|
||||
[Dependency] public ILevelCatalog Catalog => this.DependOn<ILevelCatalog>();
|
||||
|
||||
public void OnReady() {
|
||||
VersionLabel.Text = $"v. {ProjectSettings.GetSetting("application/config/version")}";
|
||||
@@ -44,15 +46,13 @@ public partial class MainMenu : Control
|
||||
private void OnNewGamePressed() {
|
||||
Save.NewGame();
|
||||
Levels.SetCurrent(0);
|
||||
GetTree().ChangeSceneToPacked(FirstLevelScene);
|
||||
var first = Catalog.First;
|
||||
Scenes.Load(first);
|
||||
}
|
||||
|
||||
private void OnContinuePressed() {
|
||||
if (!Save.TryLoad()) {
|
||||
// Fallback: start new game
|
||||
OnNewGamePressed();
|
||||
return;
|
||||
}
|
||||
GetTree().ChangeSceneToPacked(FirstLevelScene);
|
||||
if (!Save.TryLoad()) { OnNewGamePressed(); return; }
|
||||
var scene = Catalog.Get(Levels.Current) ?? Catalog.First;
|
||||
Scenes.Load(scene);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user