| 1 | 1 | local jecs = require("@jecs") |
| 2 | 1 | local ECS_GENERATION = jecs.ECS_GENERATION |
| 3 | 1 | local ECS_ID = jecs.ECS_ID |
| 4 | 1 | local ansi = require("@tools/ansi") |
| 5 | N/A | | >
| 6 | 1 | local function pe(e: any) |
| 7 | 0 | local gen = ECS_GENERATION(e) |
| 8 | 0 | return ansi.green(`e{ECS_ID(e)}`) .. ansi.yellow(`v{gen}`) |
| 9 | N/A | end | >
| 10 | N/A | | >
| 11 | 1 | local function name(world: jecs.World, id: any) |
| 12 | 0 | return world:get(id, jecs.Name) or `${id}` |
| 13 | N/A | end | >
| 14 | N/A | | >
| 15 | 1 | local function components(world: jecs.World, entity: any) |
| 16 | 0 | local r = jecs.entity_index_try_get(world.entity_index, entity) |
| 17 | 0 | if not r then |
| 18 | 0 | return false |
| 19 | N/A | end | >
| 20 | N/A | | >
| 21 | 0 | local archetype = r.archetype |
| 22 | 0 | local row = r.row |
| 23 | 0 | print(`Entity {pe(entity)}`) |
| 24 | 0 | print("-----------------------------------------------------") |
| 25 | 0 | for i, column in archetype.columns do |
| 26 | 0 | local component = archetype.types[i] |
| 27 | 0 | local n |
| 28 | 0 | if jecs.IS_PAIR(component) then |
| 29 | 0 | n = `({name(world, jecs.pair_first(world, component))}, {name(world, jecs.pair_second(world, component))})` |
| 30 | 0 | else |
| 31 | 0 | n = name(world, component) |
| 32 | N/A | end | >
| 33 | 0 | local data = column[row] or "TAG" |
| 34 | 0 | print(`| {n} | {data} |`) |
| 35 | N/A | end | >
| 36 | 0 | print("-----------------------------------------------------") |
| 37 | 0 | return true |
| 38 | N/A | end | >
| 39 | N/A | | >
| 40 | 1 | return { |
| 41 | 1 | components = components, |
| 42 | 1 | prettify = pe, |
| 43 | 0 | } |