Entity.lua 939 B

1234567891011121314151617181920212223242526272829303132333435
  1. --[[
  2. ECS Entity class
  3. @author : Eiyeron Fulmincendii
  4. An entity is not much more than its own ID and a few helpers to manage its own components via the holder world.
  5. ]]--
  6. local class = require("class")
  7. local object = require("object")
  8. local utils = require("utils")
  9. Entity = class(object)
  10. function Entity:init(index, world)
  11. self.__destroyed = false
  12. self.__destroy_required = false
  13. self.__eid = index
  14. self.__world = world
  15. end
  16. function Entity:addComponent(component_type, ...)
  17. self.__world:attachComponentToEntity(self, component_type, ...)
  18. end
  19. function Entity:removeComponent(component_type)
  20. self.__world:detachComponentFromEntity(self, component_type)
  21. end
  22. function Entity:hasComponent(component_type)
  23. return self.__world:entityHasComponent(self, component_type)
  24. end
  25. function Entity:getComponent(component_type)
  26. return self.__world:entityGetComponent(self, component_type)
  27. end
  28. return Entity