Add resources to world

- setResource(name, resource) to set a resource
- getResource(name) to retrieve it
This commit is contained in:
Jesse Viikari 2023-02-14 18:18:43 -03:00 committed by Pablo Mayobre
parent cb34513d21
commit bbcb49b6f9
No known key found for this signature in database
GPG key ID: 13A2F589D013E0E7

View file

@ -36,6 +36,8 @@ function World.new()
__events = {},
__emitSDepth = 0,
__resources = {},
__hash = {
state = -2^53,
generator = defaultGenerator,
@ -474,6 +476,22 @@ end
function World:onEntityRemoved(e) -- luacheck: ignore
end
--- Sets a named resource in the world
-- @string name Name of the resource
-- @tparam Any resource Resource to set
-- @treturn World self
function World:setResource(name, resource)
self.__resources[name] = resource
return self
end
--- Gets a named resource from the world
-- @string name Name of the resource
-- @treturn Any resource
function World:getResource(name)
return self.__resources[name]
end
return setmetatable(World, {
__call = function(_, ...)
---@diagnostic disable-next-line: redundant-parameter