diff --git a/Game/Behaviours/IDisplayableShape.cs b/Game/Abstract/IDisplayableShape.cs similarity index 70% rename from Game/Behaviours/IDisplayableShape.cs rename to Game/Abstract/IDisplayableShape.cs index 0949f13..a75374a 100644 --- a/Game/Behaviours/IDisplayableShape.cs +++ b/Game/Abstract/IDisplayableShape.cs @@ -1,6 +1,6 @@ using Apos.Shapes; -namespace Pong.Behaviours; +namespace Syntriax.Engine.Core.Abstract; public interface IDisplayableShape { diff --git a/Game/Graphics/TwoDimensional/Abstract/IDisplayable.cs b/Game/Abstract/IDisplayableSprite.cs similarity index 78% rename from Game/Graphics/TwoDimensional/Abstract/IDisplayable.cs rename to Game/Abstract/IDisplayableSprite.cs index d27a812..076c7b1 100644 --- a/Game/Graphics/TwoDimensional/Abstract/IDisplayable.cs +++ b/Game/Abstract/IDisplayableSprite.cs @@ -2,7 +2,7 @@ using Microsoft.Xna.Framework.Graphics; namespace Syntriax.Engine.Core.Abstract; -public interface IDisplayable +public interface IDisplayableSprite { public void Draw(SpriteBatch spriteBatch); } diff --git a/Game/Behaviours/TextBehaviour.cs b/Game/Behaviours/TextBehaviour.cs index da97b6a..df1ee66 100644 --- a/Game/Behaviours/TextBehaviour.cs +++ b/Game/Behaviours/TextBehaviour.cs @@ -6,7 +6,7 @@ using Syntriax.Engine.Core.Abstract; namespace Pong.Behaviours; -public class TextBehaviour : BehaviourOverride, IDisplayable +public class TextBehaviour : BehaviourOverride, IDisplayableSprite { public TextBehaviour() { } public TextBehaviour(SpriteFont font) => Font = font; diff --git a/Game/GamePong.cs b/Game/GamePong.cs index dac0c3f..2e8cf71 100644 --- a/Game/GamePong.cs +++ b/Game/GamePong.cs @@ -22,7 +22,7 @@ public class GamePong : Game private ShapeBatch shapeBatch = null!; private GameManager gameManager = null!; - private BehaviourCacher displayableCacher = null!; + private BehaviourCacher displayableCacher = null!; private BehaviourCacher displayableShapeCacher = null!; private MonoGameCameraBehaviour cameraBehaviour = null!; diff --git a/Game/Graphics/Abstract/Assignable/IAssignableSprite.cs b/Game/Graphics/Abstract/Assignable/IAssignableSprite.cs deleted file mode 100644 index 8f05c68..0000000 --- a/Game/Graphics/Abstract/Assignable/IAssignableSprite.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; - -namespace Syntriax.Engine.Core.Abstract; - -/// -/// Indicates the object is an with an assignable field. -/// -public interface IAssignableSprite : IAssignable -{ - /// - /// Callback triggered when the value has has been assigned a new value. - /// - Action? OnSpriteAssigned { get; set; } - - /// - ISprite Sprite { get; } - - /// - /// Assign a value to the field of this object - /// - /// New to assign. - /// - /// , if the value given assigned successfully assigned, if not. - /// - bool Assign(ISprite sprite); -} diff --git a/Game/Graphics/Abstract/ISprite.cs b/Game/Graphics/Abstract/ISprite.cs deleted file mode 100644 index feb19e8..0000000 --- a/Game/Graphics/Abstract/ISprite.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -using Microsoft.Xna.Framework.Graphics; - -namespace Syntriax.Engine.Core.Abstract; - -// TODO Probably gonna have to rethink this -public interface ISprite -{ - Action? OnTextureChanged { get; set; } - - Texture2D Texture2D { get; set; } -} diff --git a/Game/Graphics/Sprite.cs b/Game/Graphics/Sprite.cs deleted file mode 100644 index 5adcdd3..0000000 --- a/Game/Graphics/Sprite.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; - -using Microsoft.Xna.Framework.Graphics; - -using Syntriax.Engine.Core.Abstract; - -namespace Syntriax.Engine.Core; - -public class Sprite : ISprite -{ - public Action? OnTextureChanged { get; set; } - - private Texture2D _texture = null!; - - public Texture2D Texture2D - { - get => _texture; - set - { - if (_texture == value) - return; - - _texture = value; - OnTextureChanged?.Invoke(this); - } - } -} diff --git a/Game/Graphics/TwoDimensional/Abstract/IDisplayableSprite.cs b/Game/Graphics/TwoDimensional/Abstract/IDisplayableSprite.cs deleted file mode 100644 index 83b8215..0000000 --- a/Game/Graphics/TwoDimensional/Abstract/IDisplayableSprite.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -using Syntriax.Engine.Core.Abstract; - -namespace Syntriax.Engine.Graphics.TwoDimensional.Abstract; -public interface IDisplayableSprite : IDisplayable, IAssignableSprite -{ - Action? OnSpriteEffectsChanged { get; set; } - Action? OnOriginChanged { get; set; } - Action? OnColorChanged { get; set; } - Action? OnDepthChanged { get; set; } - - SpriteEffects SpriteEffects { get; set; } - Vector2 Origin { get; set; } - Color Color { get; set; } - float Depth { get; set; } -} diff --git a/Game/Graphics/TwoDimensional/DisplayableSpriteBehaviour.cs b/Game/Graphics/TwoDimensional/DisplayableSpriteBehaviour.cs deleted file mode 100644 index 05b2d0d..0000000 --- a/Game/Graphics/TwoDimensional/DisplayableSpriteBehaviour.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System; - -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -using Syntriax.Engine.Core; -using Syntriax.Engine.Core.Abstract; -using Syntriax.Engine.Graphics.TwoDimensional.Abstract; - -namespace Syntriax.Engine.Graphics.TwoDimensional; - -public class DisplayableSpriteBehaviour : Behaviour, IDisplayableSprite, IAssignableSprite -{ - public Action? OnSpriteAssigned { get; set; } = null; - public Action? OnSpriteEffectsChanged { get; set; } = null; - public Action? OnOriginChanged { get; set; } = null; - public Action? OnColorChanged { get; set; } = null; - public Action? OnDepthChanged { get; set; } = null; - - private ISprite _sprite = null!; - private Color _color = Color.White; - private float _depth = 0f; - private SpriteEffects _spriteEffects = SpriteEffects.None; - private Vector2 _origin = Vector2.One * .5f; - - - public ISprite Sprite => _sprite; - - public SpriteEffects SpriteEffects - { - get => _spriteEffects; - set - { - if (_spriteEffects == value) - return; - - _spriteEffects = value; - OnSpriteEffectsChanged?.Invoke(this); - } - } - - public Vector2 Origin - { - get => _origin; - set - { - if (_origin == value) - return; - - _origin = value; - OnOriginChanged?.Invoke(this); - } - } - - public Color Color - { - get => _color; - set - { - if (_color == value) - return; - - _color = value; - OnColorChanged?.Invoke(this); - } - } - - public float Depth - { - get => _depth; - set - { - if (_depth == value) - return; - - _depth = value; - OnDepthChanged?.Invoke(this); - } - } - - public void Draw(SpriteBatch spriteBatch) - { - if (!BehaviourController.GameObject.StateEnable.Enabled || !StateEnable.Enabled) - return; - - ITransform transform = BehaviourController.GameObject.Transform; - Vector2D position = transform.Position; - Vector2D scale = transform.Scale; - - Rectangle rectangle = new((int)position.X, -(int)position.Y, (int)(Sprite.Texture2D.Width * scale.X), (int)(Sprite.Texture2D.Height * scale.Y)); - - spriteBatch.Draw(Sprite.Texture2D, rectangle, null, Color, transform.Rotation, new Vector2(Sprite.Texture2D.Width, Sprite.Texture2D.Height) * Origin, SpriteEffects, Depth); - } - - public bool Assign(ISprite sprite) - { - _sprite = sprite; - OnSpriteAssigned?.Invoke(this); - return true; - } - - public DisplayableSpriteBehaviour() => OnUnassigned += OnUnassign; - public DisplayableSpriteBehaviour( - Color? color = null, - float? depth = null, - SpriteEffects? spriteEffects = null, - Vector2? origin = null) - { - OnUnassigned += OnUnassign; - - _color = color ?? _color; - _depth = depth ?? _depth; - _spriteEffects = spriteEffects ?? _spriteEffects; - _origin = origin ?? _origin; - } - private void OnUnassign(IAssignable assignable) => _sprite = null!; -}