Spawn markers in editor

This commit is contained in:
Marco 2025-09-22 16:33:10 +02:00
commit 479df3c7c4
8 changed files with 150 additions and 76 deletions

View file

@ -17,32 +17,31 @@ public partial class GameController : Node
private Hud _hud;
private IsoPlayerFSMProxy _player;
public IsoPlayerStateMachine Player => _player.PlayerFSM;
[Export] private Marker3D _cameraTarget;
public Vector3? PlayerPosition => _player?.GlobalPosition ?? null;
public Vector3? PlayerVelocity => _player?.Velocity ?? null;
[Export] public bool DebugDraw { get; set; }
[Signal]
public delegate void ManagerReadyEventHandler();
[Export] public MapResource MapResource { get; private set; }
[Export] public PackedScene PlayerTemplate { get; set; }
[Export] public Dictionary<int, NodePath> SpawnMarkers { get; private set; } = new();
[Export]
public int EggStartIndex = 0;
[Export] public int EggStartIndex = 0;
[Export] public Node3D PlayerParentNode { get; set; }
private InventoryManager _inventoryManager { get; set; }
private Vector3 _lastCheckPointPosition;
private GameState GameState => GameStateManager.Instance.GameState;
private GameState GameState => GameStateManager.Instance.GameState;
public Vector3 LastCheckPointPosition
{
get => _lastCheckPointPosition;
@ -57,7 +56,7 @@ public partial class GameController : Node
gsm.ProcessMode = ProcessModeEnum.Always;
this.AddChild(gsm);
gsm.Init(GameState.Playing);
RenderingServer.SetDefaultClearColor(Colors.Black);
if (GlobalState.Instance.SessionSettings.GameMode is GameMode.Roguelite)
{
@ -72,7 +71,7 @@ public partial class GameController : Node
GlobalState.Session.LevelNumber = MapResource.LevelId;
GlobalState.Session.MapId = MapResource.MapId;
}
GlobalState.Instance.ChangeCursor(false);
if (GlobalState.Instance.SessionSettings.AllowSaving)
@ -91,7 +90,7 @@ public partial class GameController : Node
_inventoryManager = GetNodeOrNull<InventoryManager>("InventoryManager");
if (_inventoryManager == null) GD.Print("No inventory manager in scene.");
//SpawnBulletsContainer();
if (_hud != null)
@ -118,7 +117,7 @@ public partial class GameController : Node
{
EmitSignalManagerReady();
}
private void DelayPlayerSpawn()
{
if (SpawnMarkers.Any())
@ -154,7 +153,7 @@ public partial class GameController : Node
// Wait before the player is fully initialized before spawning weapons on it
CallDeferred(MethodName.SpawnWeapons);
}
private void SpawnWeapons()
{
foreach (var startingItem in MapResource.StartData.StartingEquipment)
@ -167,14 +166,14 @@ public partial class GameController : Node
_inventoryManager.RemoveItem(item);
}
}
public void SpawnPlayer()
{
if (_player != null) return;
//_player = this.CreateChild<PlayerMovement>(PlayerTemplate, PlayerSpawnMarker.Position );
_player = PlayerTemplate.Instantiate<IsoPlayerFSMProxy>();
if (PlayerParentNode is not null)
{
PlayerParentNode.AddChild(_player);
@ -186,7 +185,7 @@ public partial class GameController : Node
this.AddChild(_player);
_player.Owner = this;
}
_player.GlobalPosition = GetStartPosition();
LastCheckPointPosition = _player.GlobalPosition;
@ -202,7 +201,7 @@ public partial class GameController : Node
// _cameraTarget.GlobalPosition = _player.Position;
// }
}
public void CameraTargetPlayer()
{
if (_player is null) return;
@ -219,9 +218,8 @@ public partial class GameController : Node
{
_cameraTarget.Position += offset.Value;
}
}
private Vector3 GetStartPosition()
{
var spawners = GetTree().GetNodesInGroup("SpawnMarkers").Cast<PlayerStartMarker3D>().ToList();