Finished docking
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Awperative;
|
||||
|
||||
public sealed partial class Body
|
||||
{
|
||||
|
||||
public Component AddComponent<Generic>() where Generic : Component => AddComponent<Generic>([]);
|
||||
public Component AddComponent<Generic>(object[] __args) where Generic : Component {
|
||||
|
||||
if (SingletonExists<Generic>()) { Debug.LogError("Cannot add component when singleton exists"); return null; }
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Awperative;
|
||||
|
||||
public sealed partial class Body
|
||||
{
|
||||
public Component GetComponent<Generic>() where Generic : Component => GetComponents<Generic>()[0];
|
||||
public Component[] GetComponents<Generic>() where Generic : Component {
|
||||
|
||||
List<Component> returnValue = [];
|
||||
foreach (Component 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; }
|
||||
|
||||
return returnValue.ToArray();
|
||||
}
|
||||
|
||||
public Component FindSingleton<Generic>() where Generic : Component {
|
||||
foreach (Component component in _components)
|
||||
if (component.GetType() == typeof(Generic))
|
||||
if(component.EnforceSingleton)
|
||||
return component;
|
||||
else {
|
||||
Debug.LogError("Component is not a singleton");
|
||||
return null;
|
||||
}
|
||||
|
||||
Debug.LogError("Scene does not contain a component of this type");
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SingletonExists<Generic>() where Generic : Component
|
||||
{
|
||||
foreach (Component __component in _components)
|
||||
if (__component.GetType() == typeof(Generic))
|
||||
if (__component.EnforceSingleton)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
namespace Awperative;
|
||||
|
||||
public sealed partial class Body
|
||||
{
|
||||
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<Generic>() where Generic : Component {
|
||||
try
|
||||
{
|
||||
Component foundComponent = GetComponent<Generic>();
|
||||
|
||||
foundComponent.End();
|
||||
_components.Remove(foundComponent);
|
||||
}catch { Debug.LogError("Removal failed"); }
|
||||
}
|
||||
|
||||
public void RemoveComponents<Generic>() where Generic : Component {
|
||||
try {
|
||||
foreach (Component component in GetComponents<Generic>()) {
|
||||
component.End();
|
||||
_components.Remove(component);
|
||||
}
|
||||
}catch { Debug.LogError("Removal failed"); }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
|
||||
namespace Awperative;
|
||||
|
||||
public sealed partial class Body
|
||||
public sealed partial class Body : DockerEntity
|
||||
{
|
||||
|
||||
|
||||
@@ -80,4 +81,16 @@ public sealed partial class Body
|
||||
|
||||
|
||||
|
||||
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(); }
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
|
||||
namespace Awperative;
|
||||
|
||||
|
||||
public sealed partial class Body
|
||||
{
|
||||
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(); }
|
||||
}
|
||||
Reference in New Issue
Block a user