dependency injection test
This commit is contained in:
@@ -1,47 +1,68 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Movementtests.interfaces;using Movementtests.managers;
|
||||
using Movementtests.systems;
|
||||
|
||||
public partial class MainSceneTemplate : Node3D
|
||||
[Meta(
|
||||
typeof(IAutoOn),
|
||||
typeof(IAutoConnect),
|
||||
typeof(IProvider)
|
||||
)]
|
||||
public partial class MainSceneTemplate : Node3D, IProvide<InventoryManager>
|
||||
{
|
||||
private Marker3D? _playerRespawnMarker;
|
||||
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;
|
||||
|
||||
public override void _Ready()
|
||||
public required InventoryManager InventoryManager { get; set; }
|
||||
InventoryManager IProvide<InventoryManager>.Value() => InventoryManager;
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
_playerRespawnMarker = GetNode<Marker3D>("PlayerFellRespawn");
|
||||
_animationPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
|
||||
|
||||
_playerFellPlane = GetNode<Area3D>("PlayerFellTP");
|
||||
_deathPlane = GetNode<Area3D>("DeathPlane");
|
||||
|
||||
if (_playerRespawnMarker == null) throw new Exception("Player respawn marker is null");
|
||||
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;
|
||||
|
||||
|
||||
InventoryManager = new InventoryManager();
|
||||
AddChild(InventoryManager);
|
||||
this.Provide();
|
||||
}
|
||||
|
||||
public void OnProvided()
|
||||
{
|
||||
// You can optionally implement this method. It gets called once you call
|
||||
// this.Provide() to inform AutoInject that the provided values are now
|
||||
// available.
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (body is WeaponSystem weapon)
|
||||
{
|
||||
if (_playerRespawnMarker == null) throw new Exception("Respawn marker is null");
|
||||
weapon.GlobalPosition = _playerRespawnMarker.GlobalPosition;
|
||||
if (PlayerRespawnMarker == null) throw new Exception("Respawn marker is null");
|
||||
weapon.GlobalPosition = PlayerRespawnMarker.GlobalPosition;
|
||||
weapon.SetLinearVelocity(Vector3.Down);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user