Initial push
This commit is contained in:
commit
ee69c03334
31 changed files with 1578 additions and 0 deletions
27
lib/ref.luau
Normal file
27
lib/ref.luau
Normal file
|
@ -0,0 +1,27 @@
|
|||
--!strict
|
||||
--!optimize 2
|
||||
local handle = require("./handle")
|
||||
local world = require("./world").get()
|
||||
|
||||
local refs = {}
|
||||
|
||||
--- Gets an entity the given key references to.
|
||||
--- If the key is nil, an entirely new entity is created and returned.
|
||||
--- If the key doesn't reference an entity, a new entity is made for it to reference and returned.
|
||||
--- @param key any
|
||||
--- @return handle
|
||||
local function ref(key: any): handle.handle
|
||||
if not key then
|
||||
return handle.new(world:entity())
|
||||
end
|
||||
|
||||
local entity = refs[key]
|
||||
if not entity then
|
||||
entity = world:entity()
|
||||
refs[key] = entity
|
||||
end
|
||||
|
||||
return handle.new(entity)
|
||||
end
|
||||
|
||||
return ref
|
Loading…
Add table
Add a link
Reference in a new issue