Entity.lua 908 B

12345678910111213141516171819202122232425262728293031323334
  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. Entity = class(object)
  9. function Entity:init(index, world)
  10. self.__destroyed = false
  11. self.__destroy_required = false
  12. self.__eid = index
  13. self.__world = world
  14. end
  15. function Entity:addComponent(component_type, ...)
  16. self.__world:attachComponentToEntity(self, component_type, ...)
  17. end
  18. function Entity:removeComponent(component_type)
  19. self.__world:detachComponentFromEntity(self, component_type)
  20. end
  21. function Entity:hasComponent(component_type)
  22. return self.__world:entityHasComponent(self, component_type)
  23. end
  24. function Entity:getComponent(component_type)
  25. return self.__world:entityGetComponent(self, component_type)
  26. end
  27. return Entity