summaryrefslogtreecommitdiff
path: root/src/ecs.moon
diff options
context:
space:
mode:
authorAlexander M Pickering <alex@cogarr.net>2025-01-19 15:23:06 -0600
committerAlexander M Pickering <alex@cogarr.net>2025-01-19 15:23:06 -0600
commitda9dd31f504d30f33922cdf362a7c01673a6b927 (patch)
tree6e3247dc8f57c16fd02d7ac07246d82c8ab65ccb /src/ecs.moon
parent90ee66a3a6aae10fd84f3f43844db55229933e37 (diff)
downloadggj25-da9dd31f504d30f33922cdf362a7c01673a6b927.tar.gz
ggj25-da9dd31f504d30f33922cdf362a7c01673a6b927.tar.bz2
ggj25-da9dd31f504d30f33922cdf362a7c01673a6b927.zip
Last commit before theme release
Diffstat (limited to 'src/ecs.moon')
-rw-r--r--src/ecs.moon27
1 files changed, 23 insertions, 4 deletions
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
}