refactor: Removed Static GamePong Fields

This commit is contained in:
2024-01-30 20:13:56 +03:00
parent 753c0031cd
commit de2d5fb446
3 changed files with 21 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework.Input;
using Syntriax.Engine.Core;
using Syntriax.Engine.Input;
@@ -41,20 +42,20 @@ public class CameraController : BehaviourOverride
private void SwitchToFullScreen(IButtonInputs<Keys> inputs, Keys keys)
{
if (GamePong.graphics.IsFullScreen)
if (cameraBehaviour.Graphics.IsFullScreen)
return;
GamePong.graphics.PreferMultiSampling = false;
GamePong.graphics.PreferredBackBufferWidth = GamePong.graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Width;
GamePong.graphics.PreferredBackBufferHeight = GamePong.graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Height;
GamePong.graphics.IsFullScreen = true;
GamePong.graphics.ApplyChanges();
cameraBehaviour.Graphics.PreferMultiSampling = false;
cameraBehaviour.Graphics.PreferredBackBufferWidth = cameraBehaviour.Graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Width;
cameraBehaviour.Graphics.PreferredBackBufferHeight = cameraBehaviour.Graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Height;
cameraBehaviour.Graphics.IsFullScreen = true;
cameraBehaviour.Graphics.ApplyChanges();
float previousScreenSize = Math.Sqrt(Math.Sqr(cameraBehaviour.Viewport.Width) + Math.Sqr(cameraBehaviour.Viewport.Height));
float currentScreenSize = Math.Sqrt(Math.Sqr(GamePong.graphics.GraphicsDevice.Viewport.Width) + Math.Sqr(GamePong.graphics.GraphicsDevice.Viewport.Height));
float currentScreenSize = Math.Sqrt(Math.Sqr(cameraBehaviour.Graphics.GraphicsDevice.Viewport.Width) + Math.Sqr(cameraBehaviour.Graphics.GraphicsDevice.Viewport.Height));
defaultZoomLevel /= previousScreenSize / currentScreenSize;
cameraBehaviour.Zoom /= previousScreenSize / currentScreenSize;
cameraBehaviour.Viewport = GamePong.graphics.GraphicsDevice.Viewport;
cameraBehaviour.Viewport = cameraBehaviour.Graphics.GraphicsDevice.Viewport;
}
private void ResetCamera(IButtonInputs<Keys> inputs, Keys keys)

View File

@@ -3,7 +3,7 @@ using Microsoft.Xna.Framework.Graphics;
using Syntriax.Engine.Core;
namespace Pong.Behaviours;
public class MonoGameCameraBehaviour : BehaviourOverride
public class MonoGameCameraBehaviour(GraphicsDeviceManager Graphics) : BehaviourOverride
{
public System.Action<MonoGameCameraBehaviour>? OnMatrixTransformChanged { get; set; } = null;
public System.Action<MonoGameCameraBehaviour>? OnViewportChanged { get; set; } = null;
@@ -12,7 +12,7 @@ public class MonoGameCameraBehaviour : BehaviourOverride
private Matrix _matrixTransform = Matrix.Identity;
private Viewport _viewport = default;
public GraphicsDeviceManager Graphics { get; } = Graphics;
private float _zoom = 1f;
public Matrix MatrixTransform
@@ -69,7 +69,7 @@ public class MonoGameCameraBehaviour : BehaviourOverride
}
protected override void OnFirstActiveFrame()
=> Viewport = GamePong.graphics.GraphicsDevice.Viewport;
=> Viewport = Graphics.GraphicsDevice.Viewport;
protected override void OnPreDraw()
{