Add serialization and deserialization functions to component, entity, world

This commit is contained in:
Tjakka5 2020-01-04 13:26:26 +01:00
parent c217183cb9
commit 6cd66e6737
6 changed files with 214 additions and 33 deletions

View file

@ -20,12 +20,22 @@ function Components.register(name, componentClass)
end
if (rawget(Components, name)) then
error("bad argument #2 to 'Components.register' (ComponentClass with name '"..name.."' was already registerd)", 3)
error("bad argument #2 to 'Components.register' (ComponentClass with name '"..name.."' was already registerd)", 3) -- luacheck: ignore
end
Components[name] = componentClass
componentClass.__name = name
end
function Components.has(name)
return Components[name] and true or false
end
function Components.get(name)
return Components[name]
end
return setmetatable(Components, {
__index = function(_, name)
error("Attempt to index ComponentClass '"..tostring(name).."' that does not exist / was not registered", 2)