import { IWorld } from "./world.spec" ; import { IWorldBuilder , WorldBuilder } from "./world-builder/world-builder" ; import { IEntity } from "./entity.spec" ; const entities = new Map < string , IEntity > ( ) ; const worlds = new Set < IWorld > ( ) ; param world export function addWorld ( world ) { worlds . add ( world ) ; } /**
 * Build a new world and automatically add it to the list of worlds inside the ECS
 */ export function buildWorld ( ) { return new WorldBuilder ( ) . addCallback ( world => worlds . add ( world ) ) ; } param name export function findWorld ( name ) { let world ; for ( world of worlds ) { if ( world . name == name ) { return world ; } } } param id export function getEntity ( id ) { return entities . get ( id ) ; } param entity export function registerEntity ( entity ) { const id = entity . id ; if ( ! id ) { throw new Error ( 'Could not get ID from entity, did you forget to register a generator or pass an ID?' ) ; } entities . set ( id , entity ) ; } /**
 * Iterate over all registered worlds
 */ export function getWorlds ( ) { return worlds . values ( ) ; } param world export function removeWorld ( world ) { worlds . delete ( world ) ; }