Entity Component System library for javascript
adjective physically concerning land or its inhabitants.
Geotic is an ECS library focused on performance, features, and non-intrusive design. View benchmarks.
This library is heavily inspired by ECS in Caves of Qud. Watch these talks to get inspired!
Python user? Check out the Python port of this library, ecstremity!
npm install geoticBelow is a contrived example which shows the basics of geotic:
…The Engine class is used to register all components and prefabs, and create new Worlds.
import { Engine } from 'geotic';
const engine = new Engine();
engine.registerComponent(clazz);
engine.registerPrefab({ ... });
engine.destroyWorld(world);Engine properties and methods:
The World class is a container for entities. Usually only one instance is needed,
but it can be useful to spin up more for offscreen work.
…World properties and methods:
Entity. optionally provide an IDEntity by IDentity.destroy()A unique id and a collection of components.
…Component properties and methods:
keyProperty.allowMultiple is false, this has no effect. If this property is omitted, it will be stored as an array on the component.true if this component is destroyedThis example shows how allowMultiple and keyProperty work:
…Queries keep track of sets of entities defined by component types. They are limited to the world they're created in.
…true if the given entity is being tracked by the query. Mostly used internallySet the immutableResults option to false if you are not modifying the result set. This option defaults to true. WARNING: When this option is set to false, strange behaviour can occur if you modify the results. See issue #55.
const query = world.createQuery({
all: [A, B],
immutableResult: false, // defaults to TRUE
});
const results = query.get();
results.splice(0, 1); // DANGER! do not modify results if immutableResult is false!example Save game state by serializing all entities and components
const saveGame = () => {
const data = world.serialize();
localStorage.setItem('savegame', data);
};
...
const loadGame = () => {
const data = localStorage.getItem('savegame');
world.deserialize(data);
};Events are used to send a message to all components on an entity. Components can attach data to the event and prevent it from continuing to other entities.
The geotic event system is modelled aver this talk by Brian Bucklew - AI in Qud and Sproggiwood.
…Prefabs are a pre-defined template of components.
The prefab system is modelled after this talk by Thomas Biskup - There be dragons: Entity Component Systems for Roguelikes.
…No open issues yet, or sync has not completed.