Rework game over logic and game initialization

This commit is contained in:
2025-10-27 15:04:01 -07:00
parent 720696aed0
commit 7e6dca1c29
46 changed files with 653 additions and 610 deletions

View File

@@ -1,12 +1,10 @@
using Chickensoft.AutoInject;
using Chickensoft.Collections;
using Chickensoft.Introspection;
using Chickensoft.SaveFileBuilder;
using Godot;
using Godot.Collections;
using System;
using System.Linq;
using System.Threading.Tasks;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;
@@ -18,9 +16,6 @@ public partial class Map : Node3D, IMap
[Dependency]
public IGame Game => this.DependOn<IGame>();
[Dependency]
public IPlayer Player => this.DependOn<IPlayer>();
[Node]
public Node MapOrder { get; set; } = default!;
@@ -33,10 +28,11 @@ public partial class Map : Node3D, IMap
private readonly string _floorFilePath = @"res://src/map/dungeon/floors/";
public event Action<Transform3D> SpawnPointCreated;
public void OnResolved()
{
this.Provide();
InitializeMapData();
}
@@ -66,13 +62,20 @@ public partial class Map : Node3D, IMap
public async Task LoadFloor(string sceneName)
{
AnimationPlayer.CallDeferred(AnimationPlayer.MethodName.Play, "fade_out");
ClearCurrentMap();
ClearMap();
var newFloor = await LoadNewFloor(sceneName);
AddChild(newFloor);
InitializeFloor(newFloor);
AnimationPlayer.CallDeferred(AnimationPlayer.MethodName.Play, ("fade_in"));
}
public void ClearMap()
{
AnimationPlayer.CallDeferred(AnimationPlayer.MethodName.Play, "fade_out");
CurrentFloor?.CallDeferred(MethodName.QueueFree, []);
SpawnPointCreated?.Invoke(new Transform3D(Basis.Identity, new Vector3(-999, -999, -999)));
}
private void InitializeFloor(Node newFloor)
{
CurrentFloor = (IDungeonFloor)newFloor;
@@ -92,16 +95,10 @@ public partial class Map : Node3D, IMap
return result;
}
private void ClearCurrentMap()
{
CurrentFloor?.CallDeferred(MethodName.QueueFree, []);
Player.TeleportPlayer(new Transform3D(Basis.Identity, new Vector3(-999, -999, -999)));
}
private void SetupDungeonFloor()
{
CurrentFloor.InitializeDungeon();
var transform = GetPlayerSpawnPosition();
Player.TeleportPlayer(transform);
SpawnPointCreated?.Invoke(transform);
}
}