| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- --[[
- ECS Component class
- @author : Eiyeron Fulmincendii
- A component is a data container for entities. It determines also which systems the holder entity
- will be processed on.
- ]]--
- local class = require("class")
- local object = require("object")
- local __cid = 0
- local component = class(object)
- local function eq(a, b) return a.__cid == b.__cid end
- local function le(a, b) return a.__cid <= b.__cid end
- local function lt(a, b) return a.__cid < b.__cid end
- local function make_component(...)
- local c = class(component, ...)
- __cid = __cid + 1
- -- Component unique ID. If you don't want to break everything, avoid touching this.
- c.__cid = __cid
- -- Override this variable at class creation to have a more explicit tostring result.
- c.__name = "Component"
- -- Used in SystemFilters
- c.__lt = lt
- c.__le = le
- c.__eq = eq
- local mt = getmetatable(c)
- -- Used in SystemFilters
- mt.__lt = lt
- mt.__le = le
- mt.__eq = eq
- -- Class type functions.
- mt.__tostring = function(a) return string.format("{Component class %s (id:%d)}", a.__name, a.__cid) end
- return c
- end
- return make_component
|