Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rudimentary Entity-Component-model in CoffeeScript
class Entity
componentList = {}
constructor: (@name = @constructor.name) ->
get: (componentName) ->
if componentName
componentList[componentName]
else
Object.keys componentList
add: (component) ->
return @ unless component
unless componentList[component.name]
componentList[component.name] = component
component.register?()
@
remove: (componentName) ->
if componentList[componentName]
componentList[componentName].unregister?()
delete componentList[componentName]
@
render: ->
for key, value of componentList
value.render?()
null
update: (dt) ->
for key, value of componentList
value.update?(dt)
null
class Component
constructor: (@name = @constructor.name) ->
register: ->
unregister: ->
render: ->
update: (dt) ->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.