npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

perform-ecs

v0.7.8

Published

Efficient Entity Component System framework

Downloads

43

Readme

perform-ecs MIT Licence TypeScript

Perform-ecs is a tiny and efficient TypeScript based Component-Entity-System framework. It was originally written for Open Stronghold - open source clone of Stronghold/Stronghold Crusader engine.

Why Entity Component System?

ECS is an architectural pattern used mostly in game development. An ECS follows the Composition over Inheritance principle to allow for greater flexibility when defining entities by building out of individual parts that can be mixed-and-matched. This eliminates the ambiguity problems of long inheritance chains and promotes clean design.

You can read more here Evolve your hierarchy or here Entity Systems Wiki

Features

  • Swift and efficient. The main principle is 'pay for what you use', so iterating over entities is really fast and you pay only when remove/add entities/components.
  • Easy to use API
  • Full TypeScript support when composing entities from components

Install

npm install perform-ecs --save

TS types inside.

Example

// create component
@makeComponent
export class TestPositionComponent extends Component {

    public x: number;
    public y: number;

    // this method will be called on every entity
    // parameters after the first one can be used for passing some data when creating entity
    public reset(obj: this, multipler: number = 1): void {
        obj.x = 10 * multipler;
        obj.y = 5 * multipler;
    }
}

// create system
export class TestPositionSystem extends System {

    // create view which will contain all entities that have 'TestPositionComponent'
    // types are fully supported here!
    public view = EntityViewFactory.createView({
        components: [TestPositionComponent],
        onEntityAdded: this.onEntityAdded.bind(this),
        onEntityRemoved: this.onEntityRemoved.bind(this),
    });

    public onEntityAdded(entity: SystemEntityType<this, "view">): void {
    }

    public onEntityRemoved(entity: SystemEntityType<this, "view">): void {
    }
    
    public update(delta: number): void {
      for(const entity of this.view.entities) {
          // do something
       }
    }
}

// prepare
const ecs = new ECS();
const positionSystem = new TestPositionSystem();
ecs.registerSystem(positionSystem);

// create entity
const entity = ecs.createEntity([
          {component: TestPositionComponent}]);
   
// create entity with arguments    
const entity2 = ecs.createEntity([
          {component: TestPositionComponent, args: [2]}]);   
          
assert(entity.x === 10);
assert(entity.y === 5);
assert(entity2.x === 20);
assert(entity2.y === 10);

// system 'update' methods will be called
ecs.update();

Docs

Coming soon

ToDo

  • [ ] Documentation
  • [ ] Benchmarks
  • [ ] More valuable tests
  • [ ] Check support for vanilla JS
  • [ ] Clean codebase
  • [ ] Multiple system views types, suitable for different cases, eg. when entities are removed/added very often.

License

This project is licensed under the MIT License - see the LICENSE.md file for details