Components, Resources & Queries
Working with Components
Section titled “Working with Components”- List built-ins:
const all = ecs.components();// map of aliases →ComponentType - Resolve one:
const Transform = ecs.component("Transform");// aliases are case-insensitive, with/withoutComponent - Create an instance:
const t = ecs.createComponent(Transform);
Custom Components
Section titled “Custom Components”// ID must match /[a-z0-9_-]/const Poison = ecs.registerComponent("poison");// Optional supplier lets you return a custom Java objectconst Custom = ecs.registerComponent("custom", () => new MyComponent());- Without a supplier, SimpleScripting uses a dynamic map-backed component (
JsDynamicComponent) withget/setmethods. - Custom components are fully serializable; pair them with codecs on the Java side if you need schema control.
Archetypes & Spawning
Section titled “Archetypes & Spawning”- Build a queryable archetype:
const movers = ecs.archetype([Transform, Velocity]); - Spawn entities with any component list:
const ref = ecs.spawn(worldRef, [t, v], "SPAWN");Resources
Section titled “Resources”Register global data that hangs off the registry, not specific entities:
const Cache = ecs.registerResource("my_cache", () => new MyCache());Resources persist through IResourceStorage when configured on the Java side.
Building Queries
Section titled “Building Queries”You can pass either arrays of component types or prebuilt Query objects into system options:
ecs.queryAll([Transform, Velocity])ecs.queryNot([Sleeping])ecs.queryOr([TeamA], [TeamB])ecs.queryAny()// wildcardecs.archetype([Transform, Velocity])// acts as aQuery
Data Conversions
Section titled “Data Conversions”Vector-like inputs accept {x,y,z}, arrays [x,y,z], or a single number (applied to all axes). This applies to helpers like setPosition, addForce, and component setters.
Next: wire those components into systems and listen to ECS events.