Giter Club home page Giter Club logo

js13k-ecs's Introduction

js13k-ecs

A 1kb entity component system, designed for js13k.

NPM versionBuild Status

  • Tiny: weighs about one kilobyte gzipped

Install

This project uses node and npm. Go check them out if you don't have them locally installed.

$ npm install js13k-ecs

Then with a module bundler like rollup or webpack, use as you would anything else:

// using ES6 modules
import ecs from 'js13k-ecs';

// using CommonJS modules
var ecs = require('js13k-ecs');

The UMD build is also available on unpkg:

<script src="https://unpkg.com/js13k-ecs/dist/ecs.umd.js"></script>

You can find the library on window.ecs.

Usage

See example folder. Live example

API

ecs

register(...Components)

Registers components for use by the library. Components must be classes or constructor functions. No other requirements are imposed on the components. Note that there is currently a limit of 32 registered components.

process(...systems)

Adds systems for use by the library. Systems must be instances of classes or objects. Systems must implement the update method.

create(id)

Creates the entity with the specified id. If id is not specified, serial numbers starting with 1 are generated and encoded in base36. Returns the created entity.

get(id)

Returns the entity with the specified id or undefined if it is not present.

select(...Components)

Returns a selection of entities that have the specified set of components. The sample is updated real-time and always relevant.

The selector has the length property, which stores the number of entities in the sample and the iterate(fn) method, with which you can loop through all entities.

update(delta)

Successively calls update methods on all systems, passing them the delta parameter. Returns the object that contains the duration of the execution of the systems.

Entity

add(...components)

Adds the components to the entity.

remove(...Components)

Removes components of the Components class from the entity. Calls the destructor method of each component if it is present.

has(Component)

Returns true if the entity has a component of the Component class and false otherwise.

get(Component)

Returns a component of the Component class or undefined if it is not present.

eject()

Removes the entity from all selectors and sets its id to zero. Calls the destructor method of each component if it is present.

js13k-ecs's People

Contributors

hectate avatar kutuluk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

js13k-ecs's Issues

option to extend Entity class?

I'm using js13k-ecs in a roguelike project for pretty much everything in the game. It's going along great but I ran into a little hurdle that I hadn't quite decided how to overcome. Basically, I created a set of Entity classes that collected all the necessary bits and threw them into the ECS for me during the constructor. Essentially freeing me up to simply put down let player = new Player(...); and end up with everything in place.
All fine and dandy until I realized that my player object was not a part of the Entity class itself and therefore would need constant workaround of stuff like player.entity to access the ECS belonging to the object, and by extension any related components.
To simplify, I thought I could extend the js13k-ecs Entity class so that the Player class would play well (hah) with the ECS directly. Sadly, the Entity class is not exported so that's not possible.

What I'm curious about is, am I breaking something or doing something wrong if I simply added the export keyword to the Entity class in my version (and, should we add it to the entire module this way)? I'm self-taught at JS and it's entirely possible that I've missed something obvious. I appreciate any feedback you have. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.