made the initial inventory loadout into a resource to initialize the injected dependency with
This commit is contained in:
@@ -13,33 +13,36 @@ using Movementtests.systems;
|
||||
public partial class MainSceneTemplate : Node3D, IProvide<InventoryManager>
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Node("PlayerFellRespawn")] private Marker3D? PlayerRespawnMarker { get; set; }
|
||||
private AnimationPlayer? _animationPlayer;
|
||||
private Node3D? _respawnabble;
|
||||
|
||||
private Area3D? _playerFellPlane;
|
||||
private Area3D? _deathPlane;
|
||||
#region Nodes
|
||||
|
||||
[Node("PlayerFellRespawn")] public required Marker3D PlayerRespawnMarker { get; set; }
|
||||
[Node("AnimationPlayer")] public required AnimationPlayer AnimationPlayer { get; set; }
|
||||
[Node("PlayerFellTP")] public required Area3D PlayerFellPlane { get; set; }
|
||||
[Node("DeathPlane")] public required Area3D DeathPlane { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
private Node3D? Respawnabble { get; set; }
|
||||
|
||||
#region Exports
|
||||
|
||||
[Export] public WeaponInventory? InitialWeaponInventory { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public required InventoryManager InventoryManager { get; set; }
|
||||
InventoryManager IProvide<InventoryManager>.Value() => InventoryManager;
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
_animationPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
|
||||
|
||||
_playerFellPlane = GetNode<Area3D>("PlayerFellTP");
|
||||
_deathPlane = GetNode<Area3D>("DeathPlane");
|
||||
|
||||
if (PlayerRespawnMarker == null) throw new Exception("Player respawn marker is null");
|
||||
if (_animationPlayer == null) throw new Exception("Animation player is null");
|
||||
if (_playerFellPlane == null) throw new Exception("Player reset plane is null");
|
||||
if (_deathPlane == null) throw new Exception("Enemy death plane is null");
|
||||
|
||||
_playerFellPlane.BodyEntered += StartResetPlayerAnimation;
|
||||
_deathPlane.BodyEntered += KillEnemy;
|
||||
PlayerFellPlane.BodyEntered += StartResetPlayerAnimation;
|
||||
DeathPlane.BodyEntered += KillEnemy;
|
||||
|
||||
InventoryManager = new InventoryManager();
|
||||
if (InitialWeaponInventory != null)
|
||||
InventoryManager.InitializeFromResource(InitialWeaponInventory);
|
||||
|
||||
AddChild(InventoryManager);
|
||||
this.Provide();
|
||||
}
|
||||
@@ -53,8 +56,8 @@ public partial class MainSceneTemplate : Node3D, IProvide<InventoryManager>
|
||||
|
||||
public void ResetPlayerPosition()
|
||||
{
|
||||
if (_respawnabble == null || PlayerRespawnMarker == null) throw new Exception("Player or respawn marker is null");
|
||||
_respawnabble.GlobalPosition = PlayerRespawnMarker.GlobalPosition;
|
||||
if (Respawnabble == null || PlayerRespawnMarker == null) throw new Exception("Player or respawn marker is null");
|
||||
Respawnabble.GlobalPosition = PlayerRespawnMarker.GlobalPosition;
|
||||
}
|
||||
|
||||
public void StartResetPlayerAnimation(Node3D body)
|
||||
@@ -66,23 +69,19 @@ public partial class MainSceneTemplate : Node3D, IProvide<InventoryManager>
|
||||
weapon.SetLinearVelocity(Vector3.Down);
|
||||
return;
|
||||
}
|
||||
_respawnabble = body as PlayerController;
|
||||
if (_respawnabble == null || _animationPlayer == null) throw new Exception("Player or anim player is null");
|
||||
_animationPlayer.Play("player_fell");
|
||||
Respawnabble = body as PlayerController;
|
||||
if (Respawnabble == null || AnimationPlayer == null) throw new Exception("Player or anim player is null");
|
||||
AnimationPlayer.Play("player_fell");
|
||||
}
|
||||
|
||||
public void KillEnemy(Node3D body)
|
||||
{
|
||||
if (body is not IKillable killable)
|
||||
{
|
||||
body.QueueFree();
|
||||
return;
|
||||
}
|
||||
if (killable is not IHealthable healthable)
|
||||
if (body is not (IKillable killable and IHealthable healthable))
|
||||
{
|
||||
body.QueueFree();
|
||||
return;
|
||||
}
|
||||
|
||||
killable.Kill(healthable);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user