2024-08-07 16:45:56 +00:00
|
|
|
local world = require(script.Parent.world)
|
|
|
|
local handle = require(script.Parent.handle)
|
|
|
|
local refs = {}
|
|
|
|
|
2024-09-05 22:51:47 +00:00
|
|
|
local function fini(e, key)
|
|
|
|
return function()
|
|
|
|
refs[key] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function ref(key): (handle.Handle, (() -> ())?)
|
2024-08-07 16:45:56 +00:00
|
|
|
if not key then
|
|
|
|
return handle(world:entity())
|
|
|
|
end
|
|
|
|
local e = refs[key]
|
|
|
|
if not e then
|
|
|
|
e = world:entity()
|
|
|
|
refs[key] = e
|
|
|
|
end
|
|
|
|
-- Cannot cache handles because they will get invalidated
|
2024-09-05 22:51:47 +00:00
|
|
|
return handle(e), fini(e, key)
|
2024-08-07 16:45:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return ref
|