2024-10-09 06:35:54 +02:00

30 lines
551 B
Lua

local Prop = {}
Prop.__index = Prop
function Prop:getState(element)
return element[self:getId()]
end
function Prop:setState(element, state)
element[self:getId()] = state
end
function Prop:getId()
return self.uid
end
function Prop.attach(elementType, prop, defaultState)
prop:setState(elementType, defaultState or prop.defaultState)
return prop:with(elementType)
end
function Prop:new(o)
if o.uid == nil then
error("Property must carry a unique identifier")
end
setmetatable(o, Prop)
o.__index = o
return o
end
return Prop