mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 01:20:04 +00:00
51 lines
1.3 KiB
Text
51 lines
1.3 KiB
Text
|
local jecs = require("@jecs")
|
||
|
local ECS_GENERATION = jecs.ECS_GENERATION
|
||
|
local ECS_ID = jecs.ECS_ID
|
||
|
local ansi = require("@tools/ansi")
|
||
|
|
||
|
local function pe(e: any)
|
||
|
local gen = ECS_GENERATION(e)
|
||
|
return ansi.green(`e{ECS_ID(e)}`)..ansi.yellow(`v{gen}`)
|
||
|
end
|
||
|
|
||
|
local function name(world: jecs.World, id: any)
|
||
|
return world:get(id, jecs.Name) or `${id}`
|
||
|
end
|
||
|
|
||
|
local function components(world: jecs.World, entity: any)
|
||
|
local r = jecs.entity_index_try_get(world.entity_index, entity)
|
||
|
if not r then
|
||
|
return false
|
||
|
end
|
||
|
|
||
|
local archetype = r.archetype
|
||
|
local row = r.row
|
||
|
print(`Entity {pe(entity)}`)
|
||
|
print("-----------------------------------------------------")
|
||
|
for i, column in archetype.columns do
|
||
|
local component = archetype.types[i]
|
||
|
local n
|
||
|
if jecs.IS_PAIR(component) then
|
||
|
n = `({name(world, jecs.pair_first(world, component))}, {name(world, jecs.pair_second(world, component))})`
|
||
|
else
|
||
|
n = name(world, component)
|
||
|
end
|
||
|
local data = column[row] or "TAG"
|
||
|
print(`| {n} | {data} |`)
|
||
|
end
|
||
|
print("-----------------------------------------------------")
|
||
|
return true
|
||
|
end
|
||
|
|
||
|
local world = jecs.world()
|
||
|
local A = world:component()
|
||
|
world:set(A, jecs.Name, "A")
|
||
|
local e = world:entity()
|
||
|
world:set(e, A, true)
|
||
|
components(world, e)
|
||
|
|
||
|
return {
|
||
|
components = components,
|
||
|
prettify = pe
|
||
|
}
|