From 51854a3e59d9c6ec44bb810eea1a61bd0b3a9a3b Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sun, 13 Apr 2025 13:18:35 +0300 Subject: [PATCH] chore: updated engine --- Engine | 2 +- Shared/Behaviours/BallBehaviour.cs | 10 ++-------- Shared/Behaviours/CameraController.cs | 7 ++----- Shared/Behaviours/MovementBallBehaviour.cs | 11 +++-------- Shared/Behaviours/PaddleBehaviour.cs | 2 +- Shared/Behaviours/PongManagerBehaviour.cs | 2 +- 6 files changed, 10 insertions(+), 24 deletions(-) diff --git a/Engine b/Engine index c135035..9e4c74e 160000 --- a/Engine +++ b/Engine @@ -1 +1 @@ -Subproject commit c135035d5b72730a71665de3c9f27611880f32c8 +Subproject commit 9e4c74ed1d73eac40ed29fbdb1e5103c121844a9 diff --git a/Shared/Behaviours/BallBehaviour.cs b/Shared/Behaviours/BallBehaviour.cs index 68dfa4e..20a6e2f 100644 --- a/Shared/Behaviours/BallBehaviour.cs +++ b/Shared/Behaviours/BallBehaviour.cs @@ -17,14 +17,8 @@ public class BallBehaviour : Behaviour2D protected override void OnFirstActiveFrame() { - if (!BehaviourController.TryGetBehaviour(out IRigidBody2D? foundRigidBody)) - throw new Exception($"{nameof(IRigidBody2D)} is missing on {HierarchyObject.Name}."); - if (!BehaviourController.TryGetBehaviour(out ICollider2D? foundCollider)) - throw new Exception($"{nameof(ICollider2D)} is missing on {HierarchyObject.Name}."); - - foundCollider.OnCollisionDetected += OnCollisionDetected; - - rigidBody = foundRigidBody; + BehaviourController.GetRequiredBehaviour().OnCollisionDetected += OnCollisionDetected; + rigidBody = BehaviourController.GetRequiredBehaviour(); if (HierarchyObject.GameManager.TryFindBehaviour(out PongManagerBehaviour? pongManager)) { diff --git a/Shared/Behaviours/CameraController.cs b/Shared/Behaviours/CameraController.cs index c2f2123..53fae45 100644 --- a/Shared/Behaviours/CameraController.cs +++ b/Shared/Behaviours/CameraController.cs @@ -14,12 +14,9 @@ public class CameraController : Behaviour protected override void OnFirstActiveFrame() { - if (BehaviourController.TryGetBehaviour(out MonoGameCamera2DBehaviour? foundCameraBehaviour)) - cameraBehaviour = foundCameraBehaviour; + cameraBehaviour ??= BehaviourController.GetRequiredBehaviour(); + buttonInputs = GameManager.FindRequiredBehaviour>(); - cameraBehaviour ??= BehaviourController.AddBehaviour(); - - buttonInputs = GameManager.FindBehaviour>() ?? throw new("Unable to find inputs"); buttonInputs.RegisterOnPress(Keys.F, SwitchToFullScreen); buttonInputs.RegisterOnPress(Keys.R, ResetCamera); } diff --git a/Shared/Behaviours/MovementBallBehaviour.cs b/Shared/Behaviours/MovementBallBehaviour.cs index 80d28b7..2849ae0 100644 --- a/Shared/Behaviours/MovementBallBehaviour.cs +++ b/Shared/Behaviours/MovementBallBehaviour.cs @@ -16,15 +16,10 @@ public class MovementBallBehaviour : Behaviour2D protected override void OnFirstActiveFrame() { - if (!BehaviourController.TryGetBehaviour(out IRigidBody2D? foundRigidBody)) - throw new Exception($"{nameof(IRigidBody2D)} is missing on {HierarchyObject.Name}."); - if (!BehaviourController.TryGetBehaviour(out ICollider2D? foundCollider)) - throw new Exception($"{nameof(ICollider2D)} is missing on {HierarchyObject.Name}."); + rigidBody = BehaviourController.GetRequiredBehaviour(); - foundRigidBody.Velocity = StartDirection * Speed; - foundCollider.OnCollisionDetected += OnCollisionDetected; - - rigidBody = foundRigidBody; + rigidBody.Velocity = StartDirection * Speed; + BehaviourController.GetRequiredBehaviour().OnCollisionDetected += OnCollisionDetected; } protected override void OnUpdate() diff --git a/Shared/Behaviours/PaddleBehaviour.cs b/Shared/Behaviours/PaddleBehaviour.cs index fe243c4..82f2a31 100644 --- a/Shared/Behaviours/PaddleBehaviour.cs +++ b/Shared/Behaviours/PaddleBehaviour.cs @@ -35,7 +35,7 @@ public class PaddleBehaviour(Keys Up, Keys Down, float High, float Low, float Sp protected override void OnFirstActiveFrame() { - inputs = GameManager.FindBehaviour>() ?? throw new("Unable to find inputs"); + inputs = GameManager.FindRequiredBehaviour>(); inputs.RegisterOnPress(Up, OnUpPressed); inputs.RegisterOnRelease(Up, OnUpReleased); diff --git a/Shared/Behaviours/PongManagerBehaviour.cs b/Shared/Behaviours/PongManagerBehaviour.cs index 52c23ab..d90d29c 100644 --- a/Shared/Behaviours/PongManagerBehaviour.cs +++ b/Shared/Behaviours/PongManagerBehaviour.cs @@ -24,7 +24,7 @@ public class PongManagerBehaviour : Behaviour protected override void OnFirstActiveFrame() { - var buttonInputs = GameManager.FindBehaviour>() ?? throw new("Unable to find inputs"); + var buttonInputs = GameManager.FindRequiredBehaviour>(); buttonInputs.RegisterOnRelease(Keys.Space, (_, _1) => Reset()); }