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

simpleecs-lib

v1.0.1

Published

A JavaScript ECS that prioritizes simplicity and ease of use.

Downloads

149

Readme

SimpleECS

A JavaScript ECS library that prioritizes ease of use, written because I found the ECS library I was using to be complex.

Instead of having classes and components, almost the entire program is a single JS object. This object uses maps to store data, and has getter and setter functions to keep the experience as simple as can be.

You aren't meant to interact with any of the world's instance variables directly: instead, use the getter and setter methods to interact with your entities and components. I'll tell you the instance variables, anyway.

Documentation for the library

  • World
    • The supreme data structure that represents the entire ECS. Its constructor is the World() function.
    • Instance variables
      • archetypes: A map data structure, for storing entities of similar kinds. For example, you might have a "circle" archetype for tables, or soccer balls or basketballs and a "square" archetype for houses or counters or boxes. This is for efficiency, so that as you amass data, searches don't take as long. The user isn't meant to modify this variable outside of a method that uses it.
      • systems: Another map, that instead keys strings to functions. This map represents every system in the ECS. . The user isn't meant to modify this variable outside of a method that uses it.
      • nextEntityId: A number that is incremented each time a new entity is added. The user isn't meant to interact with this variable.
      • entitiesById: A map that maps entities to integers, like so: Map(id: entity). The user isn't meant to modify this variable outside of a method that uses it.
      • entitiesByName: A map that maps strings that represent meaningful names to entities, like so: Map(string: entity). The user isn't meant to modify this variable outside of a method that uses it.
      • running: A boolean that represents whether or not the game(or scene, or whatever the ECS is being used for) should end or not.
      • frameId: A variable that stores the result of the requestAnimationFrame() being called by the world's methods, so that the game loop can start and end as needed. The user isn't meant to interact with this variable.
      • fps: A variable that represents the FPS of the program. The user isn't meant to modify this variable.
    • Methods
      • AddSystem: Adds a system to the world.
      • AddArchetype: Adds an archetype to the world.
      • AddEntity: Adds an entity to the specified archetype, as well as entitiesById and entitiesByName, with the specified component data.
      • AddComponent: Adds the specified component data to the specified entity to the specified archetype, with the specified name.
      • GetArchetypes: Gets all archetypes in the ECS.
      • GetArchetype: Gets a singular, specified archetype.
      • GetFPS: Gets the FPS of the program.
      • GetEntities: Gets all entities in the specified archetype.
      • GetEntity: Gets the single entity that was specified by name.
      • GetComponents: Gets all components associated with a single entity.
      • GetComponent: Gets a single component associated with a single entity.
      • GetSystems: Gets every system associated with the world.
      • GetSystem: Gets a single system, specified by name.
      • GetRunning: Returns true or false, depending on if the ECS is running or not.
      • GetNextEntityById: Returns nextEntityById.
      • GetEntitiesById: Returns entitiesById.
      • GetEntitiesByName: Returns entitiesByName.
      • RemoveArchetype: Removes an archetype from the world.
      • RemoveComponent: Removes a single component from the specified entity.
      • RemoveEntity: Removes an entity by name.
      • RemoveSystem: Removes a system by name.
      • SetRunning: Changes the running variable to be either true or false.
  • Functions
  • Start: Starts the game/scene, calls all systems in a for loop, and records the FPS. The "FPS" argument of this function takes a boolean. It's a toggle that prints out the FPS if true, for the purpose of debugging.
  • Cleanup: Acts as a destructor for the world object. Clears all of the data associated with the world.