You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
662 B

  1. local GameObject = {}
  2. function GameObject.extend(target)
  3. target.components_ = {}
  4. function target:checkComponent(name)
  5. return self.components_[name] ~= nil
  6. end
  7. function target:addComponent(component)
  8. self.components_[component:getName()] = component
  9. component:bind_(self)
  10. return component
  11. end
  12. function target:removeComponent(name)
  13. local component = self.components_[name]
  14. if component then component:unbind_() end
  15. self.components_[name] = nil
  16. end
  17. function target:getComponent(name)
  18. return self.components_[name]
  19. end
  20. return target
  21. end
  22. return GameObject