-'use strict';
+// Export submodules
+export { Component } from './serpentity/component.js';
+export { Entity } from './serpentity/entity.js';
+export { Node } from './serpentity/node.js';
+export { System } from './serpentity/system.js';
+
+import { NodeCollection } from './serpentity/node_collection.js';
/*
Serpentity is a simple entity framework inspired by Ash.
Usage:
- const Serpentity = require('serpentity');
+ import Serpentity from '@serpentity/serpentity';
## Instantiating an engine
Entities are the basic object of Serpentity, and they do nothing.
- const entity = new Serpentity.Entity();
+ import { Entity } from '@serpentity/serpentity';
+ const entity = new Entity();
All the behavior is added through components
Components define data that we can add to an entity. This data will
eventually be consumed by "Systems"
- const PositionComponent = class PositionComponent extends Serpentity.Component {
+ import { Component } from '@serpentity/serpentity';
+ const PositionComponent = class PositionComponent extends Component {
constructor(config) {
this.x = 0;
Nodes are sets of components that you define, so your system can require
entities that always follow the API defined in the node.
- const MovementNode = class MovementNode extends Serpentity.Node;
+ import { Node } from '@serpentity/serpentity';
+ const MovementNode = class MovementNode extends Node;
MovementNode.position = PositionComponent;
MovementNode.motion = MotionComponent;
Systems are called on every update, and they use components through nodes.
- const TestSystem = class TestSystem extends Serpentity.System {
+ import { System } from '@serpentity/serpentity';
+ const TestSystem = class TestSystem extends System {
added(engine){
this.nodeList = engine.getNodes(MovementNode);
Just run `engine.update(dt)` in your game loop :D
*/
-const Serpentity = class Serpentity {
+export default class Serpentity {
constructor(config) {
if (this.entities.indexOf(entity) >= 0) {
return false;
}
+
this.entities.push(entity);
for (const collection of this._nodeCollections) {
return this._nodeCollections[position].nodes;
}
- const nodeCollection = new Serpentity.NodeCollection({
- type : nodeType
+ const nodeCollection = new NodeCollection({
+ type: nodeType
});
this._nodeCollectionKeys.push(nodeType);
nodeCollection.add(entity);
}
- return nodeCollection.nodes;
+ return nodeCollection;
}
/*
system.update(dt);
}
}
-};
-
-// Add namespaced objects.
-Serpentity.Component = require('./serpentity/component.js');
-Serpentity.Entity = require('./serpentity/entity.js');
-Serpentity.Node = require('./serpentity/node.js');
-Serpentity.NodeCollection = require('./serpentity/node_collection.js');
-Serpentity.System = require('./serpentity/system.js');
-
-module.exports = Serpentity;
+}