Skip to content

Instantly share code, notes, and snippets.

@frostney
Created December 28, 2012 22:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frostney/4402499 to your computer and use it in GitHub Desktop.
Save frostney/4402499 to your computer and use it in GitHub Desktop.
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