diff --git a/Awperative/Kernel/Scripting/Component/Core.cs b/Awperative/Kernel/Behavior/Core.cs similarity index 78% rename from Awperative/Kernel/Scripting/Component/Core.cs rename to Awperative/Kernel/Behavior/Core.cs index 9861bcb..4502ce7 100644 --- a/Awperative/Kernel/Scripting/Component/Core.cs +++ b/Awperative/Kernel/Behavior/Core.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using Microsoft.Xna.Framework; @@ -11,16 +12,19 @@ namespace Awperative; /// Anything that inherits Component is built to work in any DockerEntity, which leads to generic /// Assumptions. If you want to make a body specific or scene specific component both classes are available. /// -public abstract partial class Component : DockerEntity +public abstract partial class Behavior : Docker { - internal DockerEntity Docker; + internal Docker Docker; + + public Scene Scene; + public List Parents { get; private set; } + + //todo tags order and singleton - - - internal virtual void Initiate(DockerEntity __docker) { - Docker = __docker; + internal virtual void Initiate(Docker docker) { + Docker = docker; Create(); } diff --git a/Awperative/Kernel/Docker/Addition.cs b/Awperative/Kernel/Docker/Addition.cs new file mode 100644 index 0000000..a4f0737 --- /dev/null +++ b/Awperative/Kernel/Docker/Addition.cs @@ -0,0 +1,23 @@ +using System; + +namespace Awperative; + +public abstract partial class Docker +{ + + public Behavior Add() where Generic : Behavior => Add([]); + public Behavior Add(object[] __args) where Generic : Behavior { + if(typeof(Generic).GetConstructor((Type[]) __args) == null) { Debug.LogError("Component does not contain a valid constructor"); return null; }; + + try { + Behavior behavior = (Generic)Activator.CreateInstance(typeof(Generic), __args); + + if(behavior == null) { Debug.LogError("Failed to create component"); return null; } + + _components.Add(behavior); + behavior.Initiate(this); + return behavior; + + }catch { Debug.LogError("Failed to create component"); return null; } + } +} \ No newline at end of file diff --git a/Awperative/Kernel/Entities/DockerEntity/Core.cs b/Awperative/Kernel/Docker/Core.cs similarity index 66% rename from Awperative/Kernel/Entities/DockerEntity/Core.cs rename to Awperative/Kernel/Docker/Core.cs index f355ce1..c47293e 100644 --- a/Awperative/Kernel/Entities/DockerEntity/Core.cs +++ b/Awperative/Kernel/Docker/Core.cs @@ -8,9 +8,7 @@ namespace Awperative; /// /// Base class for all Awperative entities, manages components as a requirement because that is the job of all entities. /// -public abstract partial class DockerEntity +public abstract partial class Docker { - public Scene Scene; - - internal HashSet _components; + internal HashSet _components; } \ No newline at end of file diff --git a/Awperative/Kernel/Entities/DockerEntity/Location.cs b/Awperative/Kernel/Docker/Location.cs similarity index 50% rename from Awperative/Kernel/Entities/DockerEntity/Location.cs rename to Awperative/Kernel/Docker/Location.cs index d16b56a..1f22553 100644 --- a/Awperative/Kernel/Entities/DockerEntity/Location.cs +++ b/Awperative/Kernel/Docker/Location.cs @@ -3,13 +3,13 @@ using System.Collections.Generic; namespace Awperative; -public abstract partial class DockerEntity +public abstract partial class Docker { - public Component GetComponent() where Generic : Component => GetComponents()[0]; - public Component[] GetComponents() where Generic : Component { + public Behavior Get() where Generic : Behavior => GetAll()[0]; + public Behavior[] GetAll() where Generic : Behavior { - List returnValue = []; - foreach (Component component in _components) + List returnValue = []; + foreach (Behavior component in _components) if (component is Generic) returnValue.Add(component); if(returnValue.Count == 0) { Debug.LogWarning("Scene has no components of this type"); return null; } diff --git a/Awperative/Kernel/Docker/Removal.cs b/Awperative/Kernel/Docker/Removal.cs new file mode 100644 index 0000000..14d9129 --- /dev/null +++ b/Awperative/Kernel/Docker/Removal.cs @@ -0,0 +1,31 @@ +namespace Awperative; + +public abstract partial class Docker +{ + public void Remove(Behavior behavior) { + + if(!_components.Contains(behavior)) { Debug.LogError("Body does not have a component of this type"); return; } + + behavior.End(); + _components.Remove(behavior); + } + + public void Remove() where Generic : Behavior { + try + { + Behavior foundBehavior = Get(); + + foundBehavior.End(); + _components.Remove(foundBehavior); + }catch { Debug.LogError("Removal failed"); } + } + + public void RemoveAll() where Generic : Behavior { + try { + foreach (Behavior component in GetAll()) { + component.End(); + _components.Remove(component); + } + }catch { Debug.LogError("Removal failed"); } + } +} \ No newline at end of file diff --git a/Awperative/Kernel/Docker/Time.cs b/Awperative/Kernel/Docker/Time.cs new file mode 100644 index 0000000..8d16496 --- /dev/null +++ b/Awperative/Kernel/Docker/Time.cs @@ -0,0 +1,19 @@ +using Microsoft.Xna.Framework; + +namespace Awperative; + +public abstract partial class Docker +{ + internal virtual void ChainUnload() { foreach (Behavior component in _components) component.Unload(); } + internal virtual void ChainLoad() { foreach (Behavior component in _components) { component.Load(); } } + + + + internal virtual void ChainUpdate(GameTime __gameTime) { foreach (Behavior component in _components) { component.Update(__gameTime); } } + internal virtual void ChainDraw(GameTime __gameTime) { foreach (Behavior component in _components) { component.Draw(__gameTime); } } + + + + internal virtual void ChainDestroy() { foreach(Behavior component in _components) component.Destroy(); } + internal virtual void ChainCreate() { foreach (Behavior component in _components) component.Create(); } +} \ No newline at end of file diff --git a/Awperative/Kernel/Entities/Bodies/Core.cs b/Awperative/Kernel/Entities/Bodies/Core.cs deleted file mode 100644 index 92c0a08..0000000 --- a/Awperative/Kernel/Entities/Bodies/Core.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Xna.Framework; - - -namespace Awperative; - -public sealed partial class Body : DockerEntity -{ - - - /// - /// Current scene the body exists in - /// - public Scene Scene { get; internal set; } - - - - - - /// - /// All components attached to the body - /// - public List Components => _components.ToList(); - internal HashSet _components { get; private set; } = []; - - - - - - /// - /// All tags attached to the body - /// - public List Tags => _tags.ToList(); - internal HashSet _tags { get; private set; }= []; - - - - - - /// - /// Position of the body - /// - public Transform transform { get; internal set; } = new(); - - - - - - //Prevents outside construction - internal Body() {} - - - - - - /// - /// Creates a body in the given scene - /// - /// - internal Body(Scene __scene) { - Scene = __scene; - } - - - - - - /// - /// Creates a body with a scene and transform - /// - /// - /// - internal Body(Scene __scene, Transform __transform) { - Scene = __scene; - transform = __transform; - } - - - - - - internal void Unload() { foreach (Component component in _components) component.Unload(); } - internal void Load() { foreach (Component component in _components) { component.Load(); } } - - - - internal void Update(GameTime __gameTime) { foreach (Component component in _components) { component.Update(__gameTime); } } - internal void Draw(GameTime __gameTime) { foreach (Component component in _components) { component.Draw(__gameTime); } } - - - - internal void Destroy() { foreach(Component component in _components) component.Destroy(); } - internal void Create() { foreach (Component component in _components) component.Create(); } -} \ No newline at end of file diff --git a/Awperative/Kernel/Entities/DockerEntity/Addition.cs b/Awperative/Kernel/Entities/DockerEntity/Addition.cs deleted file mode 100644 index 44f23e8..0000000 --- a/Awperative/Kernel/Entities/DockerEntity/Addition.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace Awperative; - -public abstract partial class DockerEntity -{ - - public Component AddComponent() where Generic : Component => AddComponent([]); - public Component AddComponent(object[] __args) where Generic : Component { - if(typeof(Generic).GetConstructor((Type[]) __args) == null) { Debug.LogError("Component does not contain a valid constructor"); return null; }; - - try { - Component component = (Generic)Activator.CreateInstance(typeof(Generic), __args); - - if(component == null) { Debug.LogError("Failed to create component"); return null; } - - _components.Add(component); - component.Initiate(this); - return component; - - }catch { Debug.LogError("Failed to create component"); return null; } - } -} \ No newline at end of file diff --git a/Awperative/Kernel/Entities/DockerEntity/Removal.cs b/Awperative/Kernel/Entities/DockerEntity/Removal.cs deleted file mode 100644 index d817f3f..0000000 --- a/Awperative/Kernel/Entities/DockerEntity/Removal.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace Awperative; - -public abstract partial class DockerEntity -{ - public void RemoveComponent(Component __component) { - - if(!_components.Contains(__component)) { Debug.LogError("Body does not have a component of this type"); return; } - - __component.End(); - _components.Remove(__component); - } - - public void RemoveComponent() where Generic : Component { - try - { - Component foundComponent = GetComponent(); - - foundComponent.End(); - _components.Remove(foundComponent); - }catch { Debug.LogError("Removal failed"); } - } - - public void RemoveComponents() where Generic : Component { - try { - foreach (Component component in GetComponents()) { - component.End(); - _components.Remove(component); - } - }catch { Debug.LogError("Removal failed"); } - } -} \ No newline at end of file diff --git a/Awperative/Kernel/Entities/Scenes/Bodies.cs b/Awperative/Kernel/Entities/Scenes/Bodies.cs deleted file mode 100644 index 505539a..0000000 --- a/Awperative/Kernel/Entities/Scenes/Bodies.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.Collections.Generic; - - -namespace Awperative; - - -public sealed partial class Scene : DockerEntity -{ - public Body AddBody(Transform __transform) { - Body body = new Body(this, __transform); - bodies.Add(body); - body.Create(); - - BodyCreatedEvent?.Invoke(this, new BodyCreateEvent(body, this)); - - return body; - } - - public Body AddBody() { - Body body = new Body(this, new Transform()); - bodies.Add(body); - body.Create(); - - BodyCreatedEvent?.Invoke(this, new BodyCreateEvent(body, this)); - - return body; - } - - public Body[] GetBodies(string tag) { - List _bodies = new List(); - - foreach (Body body in bodies) - if (body._tags.Contains(tag)) - _bodies.Add(body); - - - if(_bodies.Count == 0) - throw new Exception("No Bodies found with the tag " + tag); - - return _bodies.ToArray(); - } - - public Body GetBody(string tag) { - foreach (Body body in bodies) - if (body._tags.Contains(tag)) - return body; - - throw new Exception("No Body found with the tag " + tag); - } - - public void DestroyBody(Body __body) { - __body.Destroy(); - BodyDestroyedEvent?.Invoke(this, new BodyDestroyEvent(__body, this)); - if (!bodies.Remove(__body)) - throw new Exception("Removal Failed! Does the Body Exist?"); - } - - //todo: add destroying and creating bodies with tags - - - //TAG SYSTEM IN V4 - -} \ No newline at end of file diff --git a/Awperative/Kernel/Entities/Scenes/Core.cs b/Awperative/Kernel/Entities/Scenes/Core.cs deleted file mode 100644 index 27c1ca2..0000000 --- a/Awperative/Kernel/Entities/Scenes/Core.cs +++ /dev/null @@ -1,35 +0,0 @@ - - -using System.Collections.Generic; -using System.Linq; -using Microsoft.Xna.Framework; - -namespace Awperative; - -public sealed partial class Scene : DockerEntity -{ - - public List bodies { get; private set; } = []; - - public void Unload() { - foreach (Component component in _components) component.Unload(); - foreach (Body body in bodies.ToList()) body.Unload(); - } - - public void Load() { - foreach (Component component in _components) component.Load(); - foreach (Body body in bodies.ToList()) { body.Load(); } - } - - public void Update(GameTime __gameTime) { - foreach (Component component in _components) component.Update(__gameTime); - foreach (Body body in bodies.ToList()) { body.Update(__gameTime); } - } - - public void Draw(GameTime __gameTime) { - foreach (Component component in _components) component.Draw(__gameTime); - foreach (Body body in bodies.ToList()) { body.Draw(__gameTime); } - } - - //todo: add scene.destroy in v5 -} diff --git a/Awperative/Kernel/Entities/Scenes/Events.cs b/Awperative/Kernel/Entities/Scenes/Events.cs deleted file mode 100644 index 7e31ce9..0000000 --- a/Awperative/Kernel/Entities/Scenes/Events.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - - -namespace Awperative; - - -public sealed partial class Scene : DockerEntity -{ - - public event EventHandler BodyCreatedEvent; - public event EventHandler BodyDestroyedEvent; -} \ No newline at end of file diff --git a/Awperative/Kernel/Events/Bodies/BodyCreateEvent.cs b/Awperative/Kernel/Events/Bodies/BodyCreateEvent.cs deleted file mode 100644 index 75458b0..0000000 --- a/Awperative/Kernel/Events/Bodies/BodyCreateEvent.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Awperative; - -public sealed record BodyCreateEvent -{ - public readonly Body body; - public readonly Scene scene; - - internal BodyCreateEvent() {} - - internal BodyCreateEvent(Body __body, Scene __scene) - { - body = __body; - scene = __scene; - } -} \ No newline at end of file diff --git a/Awperative/Kernel/Events/Bodies/BodyDestroyEvent.cs b/Awperative/Kernel/Events/Bodies/BodyDestroyEvent.cs deleted file mode 100644 index 71e75c8..0000000 --- a/Awperative/Kernel/Events/Bodies/BodyDestroyEvent.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Awperative; - -public sealed record BodyDestroyEvent -{ - public readonly Body body; - public readonly Scene scene; - - internal BodyDestroyEvent() {} - - internal BodyDestroyEvent(Body __body, Scene __scene) - { - body = __body; - scene = __scene; - } -} \ No newline at end of file diff --git a/Awperative/Kernel/Events/Components/ComponentCreateEvent.cs b/Awperative/Kernel/Events/Components/ComponentCreateEvent.cs deleted file mode 100644 index 1bb1038..0000000 --- a/Awperative/Kernel/Events/Components/ComponentCreateEvent.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Awperative; - -public sealed record ComponentCreateEvent -{ - public readonly Component component; - public readonly Body body; - public readonly Scene scene; - - internal ComponentCreateEvent() {} - - internal ComponentCreateEvent(Component __component, Body __body, Scene __scene) - { - component = __component; - body = __body; - scene = __scene; - } -} \ No newline at end of file diff --git a/Awperative/Kernel/Events/Components/ComponentDestroyEvent.cs b/Awperative/Kernel/Events/Components/ComponentDestroyEvent.cs deleted file mode 100644 index 232247e..0000000 --- a/Awperative/Kernel/Events/Components/ComponentDestroyEvent.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Awperative; - -public sealed record ComponentDestroyEvent -{ - public readonly Component component; - public readonly Body body; - public readonly Scene scene; - - internal ComponentDestroyEvent() {} - - internal ComponentDestroyEvent(Component __component, Body __body, Scene __scene) - { - component = __component; - body = __body; - scene = __scene; - } -} \ No newline at end of file diff --git a/Awperative/Kernel/Events/Scenes/SceneCreateEvent.cs b/Awperative/Kernel/Events/Scenes/SceneCreateEvent.cs deleted file mode 100644 index 2e56bee..0000000 --- a/Awperative/Kernel/Events/Scenes/SceneCreateEvent.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Awperative; - - -public sealed record SceneCreateEvent -{ - public Scene scene; - - internal SceneCreateEvent() {} - - internal SceneCreateEvent(Scene __scene) - { - scene = __scene; - } -} \ No newline at end of file diff --git a/Awperative/Kernel/Events/Scenes/SceneDestroyEvent.cs b/Awperative/Kernel/Events/Scenes/SceneDestroyEvent.cs deleted file mode 100644 index 459aec0..0000000 --- a/Awperative/Kernel/Events/Scenes/SceneDestroyEvent.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Awperative; - - -public sealed record SceneDestroyEvent -{ - public Scene scene; - - internal SceneDestroyEvent() {} - - internal SceneDestroyEvent(Scene __scene) - { - scene = __scene; - } -} \ No newline at end of file diff --git a/Awperative/Kernel/Events/Transform/TransformModifyEvent.cs b/Awperative/Kernel/Events/Transform/TransformModifyEvent.cs deleted file mode 100644 index cabbc82..0000000 --- a/Awperative/Kernel/Events/Transform/TransformModifyEvent.cs +++ /dev/null @@ -1,60 +0,0 @@ -using Microsoft.Xna.Framework; - - -namespace Awperative; - -public sealed record TransformModifyEvent -{ - public readonly Transform before; - public readonly Transform after; - - internal TransformModifyEvent() {} - - internal TransformModifyEvent(Transform __before, Transform __after) - { - before = __before; - after = __after; - } - - internal static TransformModifyEvent FromTransforms(Transform __previous, Transform __after) - { - Transform before = __previous; - Transform after = new Transform(__after.Origin, __after.Position, __after.Depth, __after.Rotation, __after.Scale); - return new TransformModifyEvent(before, after); - } - - internal static TransformModifyEvent FromOrigin(Transform __previous, Vector2 __origin) - { - Transform before = __previous; - Transform after = new Transform(__origin, __previous.Position, __previous.Depth, __previous.Rotation, __previous.Scale); - return new TransformModifyEvent(before, after); - } - - internal static TransformModifyEvent FromPosition(Transform __previous, Vector2 __position) - { - Transform before = __previous; - Transform after = new Transform(__previous.Origin, __position, __previous.Depth, __previous.Rotation, __previous.Scale); - return new TransformModifyEvent(before, after); - } - - internal static TransformModifyEvent FromDepth(Transform __previous, float __depth) - { - Transform before = __previous; - Transform after = new Transform(__previous.Origin, __previous.Position, __depth, __previous.Rotation, __previous.Scale); - return new TransformModifyEvent(before, after); - } - - internal static TransformModifyEvent FromRotation(Transform __previous, float __rotation) - { - Transform before = __previous; - Transform after = new Transform(__previous.Origin, __previous.Position, __previous.Depth, __rotation, __previous.Scale); - return new TransformModifyEvent(before, after); - } - - internal static TransformModifyEvent FromScale(Transform __previous, Vector2 __scale) - { - Transform before = __previous; - Transform after = new Transform(__previous.Origin, __previous.Position, __previous.Depth, __previous.Rotation, __scale); - return new TransformModifyEvent(before, after); - } -} \ No newline at end of file diff --git a/Awperative/Kernel/Overhead/Base.cs b/Awperative/Kernel/Overhead/Base.cs index 254221b..ac2426b 100644 --- a/Awperative/Kernel/Overhead/Base.cs +++ b/Awperative/Kernel/Overhead/Base.cs @@ -46,7 +46,7 @@ public sealed class Base : Game /// It is recommended to load content during LoadContent() protected override void LoadContent() { foreach (AwperativeHook hook in Awperative.EventHooks.ToList()) hook.Load(); - foreach(Scene scene in Awperative.LoadedScenes.ToList()) scene.Load(); + foreach(Scene scene in Awperative.LoadedScenes.ToList()) scene.ChainLoad(); } @@ -58,7 +58,7 @@ public sealed class Base : Game /// /// Hooks are unable to receive both Update() and Draw() protected override void Update(GameTime __gameTime) { - foreach(Scene scene in Awperative.LoadedScenes.ToList()) scene.Update(__gameTime); + foreach(Scene scene in Awperative.LoadedScenes.ToList()) scene.ChainUpdate(__gameTime); base.Update(__gameTime); } @@ -71,7 +71,7 @@ public sealed class Base : Game /// /// Hooks are unable to receive both Update() and Draw() protected override void Draw(GameTime __gameTime) { - foreach(Scene scene in Awperative.LoadedScenes.ToList()) scene.Draw(__gameTime); + foreach(Scene scene in Awperative.LoadedScenes.ToList()) scene.ChainDraw(__gameTime); base.Draw(__gameTime); } @@ -85,7 +85,7 @@ public sealed class Base : Game /// This event may not trigger if the program is force closed. protected override void EndRun() { foreach (AwperativeHook hook in Awperative.EventHooks.ToList()) hook.Unload(); - foreach (Scene scene in Awperative.LoadedScenes.ToList()) scene.Unload(); + foreach (Scene scene in Awperative.LoadedScenes.ToList()) scene.ChainUnload(); } diff --git a/Awperative/Kernel/Scene/Core.cs b/Awperative/Kernel/Scene/Core.cs new file mode 100644 index 0000000..dd0077d --- /dev/null +++ b/Awperative/Kernel/Scene/Core.cs @@ -0,0 +1,12 @@ + + +using System.Collections.Generic; +using System.Linq; +using Microsoft.Xna.Framework; + +namespace Awperative; + +public sealed partial class Scene : Docker +{ + //todo: make useful lolol +} diff --git a/Awperative/Kernel/Scripting/BodyComponent.cs b/Awperative/Kernel/Scripting/BodyComponent.cs deleted file mode 100644 index c4d59f7..0000000 --- a/Awperative/Kernel/Scripting/BodyComponent.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Awperative; - - -public class BodyComponent : Component -{ - - - public Body Body; - - internal override void Initiate(DockerEntity __docker) { - Docker = __docker; - - Body = (Body)__docker; - Create(); - } - - public Transform Transform => Body.transform; - -} \ No newline at end of file diff --git a/Awperative/Kernel/Scripting/Component/Methods.cs b/Awperative/Kernel/Scripting/Component/Methods.cs deleted file mode 100644 index 9a47eeb..0000000 --- a/Awperative/Kernel/Scripting/Component/Methods.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace Awperative; - -public abstract partial class Component -{ - - protected Body AddBody() => Scene.AddBody(); - protected Body AddBody(Transform __transform) => Scene.AddBody(__transform); - - protected Body GetBody(string __tag) => Scene.GetBody(__tag); - protected Body[] GetBodies(string __tag) => Scene.GetBodies(__tag); - - protected void DestroyBody(Body __body) => Scene.DestroyBody(__body); - - - - - - public Component AddComponent() where Generic : Component => Docker.AddComponent(); - public Component AddComponent(object[] __args) where Generic : Component => Docker.AddComponent(__args); - - public Component GetComponent() where Generic : Component => Docker.GetComponent(); - public Component[] GetComponents() where Generic : Component => Docker.GetComponents(); - - public void RemoveComponent() where Generic : Component => Docker.RemoveComponent(); - -} \ No newline at end of file diff --git a/Awperative/Kernel/Scripting/SceneComponent.cs b/Awperative/Kernel/Scripting/SceneComponent.cs deleted file mode 100644 index 413e75e..0000000 --- a/Awperative/Kernel/Scripting/SceneComponent.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Awperative; - - -public class SceneComponent : Component -{ - -} \ No newline at end of file diff --git a/Awperative/Kernel/Types/Transform/Transform.cs b/Awperative/Kernel/Types/Transform/Transform.cs deleted file mode 100644 index dc3ed76..0000000 --- a/Awperative/Kernel/Types/Transform/Transform.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using Microsoft.Xna.Framework; - - -namespace Awperative; - -public sealed class Transform -{ - - public event EventHandler OnTransformChangedEvent; - - - public Vector2 Origin { - get => _origin; set { - if(!value.Equals(_origin)) - OnTransformChangedEvent?.Invoke(this, TransformModifyEvent.FromPosition(this, value)); _origin = value; - } - } - private Vector2 _origin = Vector2.Zero; - - public Vector2 Position { - get => _position; set { - if(!value.Equals(_position)) - OnTransformChangedEvent?.Invoke(this, TransformModifyEvent.FromPosition(this, value)); _position = value; - } - } - private Vector2 _position = Vector2.Zero; - - public float Depth { - get => _depth; set { - if(!value.Equals(_depth)) - OnTransformChangedEvent?.Invoke(this, TransformModifyEvent.FromDepth(this, value)); _depth = value; - } - } - private float _depth = 0f; - - public float Rotation { - get => _rotation; set { - if(!value.Equals(_rotation)) - OnTransformChangedEvent?.Invoke(this, TransformModifyEvent.FromRotation(this, value)); _rotation = value; - } - } - private float _rotation = 0f; - - public Vector2 Scale { - get => _scale; set { - if(!value.Equals(_scale)) - OnTransformChangedEvent?.Invoke(this, TransformModifyEvent.FromScale(this, value)); _scale = value; - } - } - private Vector2 _scale = Vector2.One; - - public void Set(Vector2 __origin, Vector2 __position, float __depth, float __rotation, Vector2 __scale) - { - //todo: rename to previous and check names` - var previous = Clone(); - bool changed = false; - - if (!_origin.Equals(_origin)) { _origin = __origin; changed = true; } - if (!_position.Equals(_position)) { _position = __position; changed = true; } - if (!_depth.Equals(_depth)) { _depth = __depth; changed = true; } - if (!_rotation.Equals(_rotation)) { _rotation = __rotation; changed = true; } - if (!_scale.Equals(_scale)) { _scale = __scale; changed = true; } - - if (changed) - OnTransformChangedEvent?.Invoke(this, TransformModifyEvent.FromTransforms(this, previous)); - } - - public Transform() {} - - public Transform(Vector2 __origin, Vector2 __position, float __depth, float __rotation, Vector2 __scale) { - Origin = __origin; Position = __position; Depth = __depth; Rotation = __rotation; Scale = __scale; - } - - - //todo: operators? - - public Transform Clone() - { - return new Transform(Origin, Position, Depth, Rotation, Scale); - } - - public Matrix ToMatrix() - { - return - Matrix.CreateTranslation(new Vector3(-Position, 0f)) * - Matrix.CreateTranslation(new Vector3(-Origin, 0f)) * - Matrix.CreateRotationZ(Rotation) * - Matrix.CreateScale(new Vector3(Scale, 1f)) * - Matrix.CreateTranslation(new Vector3(Origin, 0f)); - } -} \ No newline at end of file