From da9dd31f504d30f33922cdf362a7c01673a6b927 Mon Sep 17 00:00:00 2001 From: Alexander M Pickering Date: Sun, 19 Jan 2025 15:23:06 -0600 Subject: Last commit before theme release --- src/ecs.moon | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/ecs.moon') diff --git a/src/ecs.moon b/src/ecs.moon index 4fdecc9..d20984a 100644 --- a/src/ecs.moon +++ b/src/ecs.moon @@ -29,7 +29,7 @@ class Entity --Entity is responsible for the component -> entity link @components = componenets or {} - for name, component in pairs(components) + for name, component in pairs(@components) component.entity = @ @c_by_type[component.__class] = @c_by_type[component.__class] or {} @c_by_type[component.__class][name] = component @@ -43,12 +43,15 @@ class Entity cid += 1 assert(@components[cid] == nil, "Already had a component with id" .. tostring(cid)) @components[cid] = component + @c_by_type[component.__class][cid] = component @ remove: (cid) => component = @components[cid] component.entity = nil component\leave(@) component + @components[cid] = nil + @c_by_type[component.__class][cid] = nil get: (cid) => @components[cid] @@ -74,7 +77,23 @@ class PredictedComponent extends Component class GraphicsComponent extends Component new: (name, properties) => - assert(properties.node , "Failed to find node for graphics component") + assert(properties and properties.node , "Failed to find node for graphics component") + super(name, properties) + static: () => + @@static + buffer_size: () => + error("Subclasses of GraphicsComponent must implement a buffer_size() method") + populate_buffer: (buffer, offset) => + error("Subclasses of GraphicsComponent must implement a populate_buffer() method") + +class PhysicsComponent extends Component + new: (name, properties) => + assert(properties and properties.shape, "Failed to find a shape for physics component") + super(name, properties) + +class ScriptComponent extends Component + new: (name, properties) => + assert(properties and properties.script, "Failed to find script name for script component") super(name, properties) { @@ -83,6 +102,6 @@ class GraphicsComponent extends Component NetworkedComponent: NetworkedComponent PredictedComponent: PredictedComponent GraphicsComponent: GraphicsComponent -} - + PhysicsComponent: PhysicsComponent + ScriptComponent: ScriptComponent } -- cgit v1.2.3-70-g09d2