miniplex

A ๐Ÿ‘ฉโ€๐Ÿ’ป developer-friendly entity management system for ๐Ÿ•น games and similarly demanding applications, based on ๐Ÿ›  ECS architecture.

MIT License

Downloads
15.2K
Stars
764
Committers
10

Bot releases are visible (Hide)

miniplex - [email protected]

Published by github-actions[bot] over 2 years ago

Patch Changes

  • db987cd: Improve typings within useEntities.
miniplex - [email protected]

Published by github-actions[bot] over 2 years ago

Minor Changes

  • cc4032d: Breaking Change: createEntity will now, like in earlier versions of this library, mutate the first argument that is passed into it (and return it). This allows for patterns where you create the actual entity object before you actually convert it into an entity through createEntity.

Patch Changes

  • b93a831: The internal IDs that are being generated for entities have been changed slightly, as they now start at 0 (instead of 1) and are always equal to the position of the entity within the world's entities array. The behavior of destroyEntity has also been changed to null the destroyed entity's entry in that array, instead of cutting the entity from it.

    This change allows you to confidently and reliably use the entity ID (found in the internal miniplex component, entity.__miniplex.id) when integrating with non-miniplex systems, including storing data in TypedArrays (for which miniplex may gain built-in support at some point in the future; this change is also in preparation for that.)

miniplex - [email protected]

Published by github-actions[bot] over 2 years ago

Minor Changes

  • cc4032d: New: useEntities is a new hook that will create and return a specified number of entities, initialized through an optional entity factory. useEntity does the same, but just for a single entity.
miniplex - [email protected]

Published by github-actions[bot] over 2 years ago

Patch Changes

  • 68cff32: Fix React 18 Strict Mode compatibility in <Component>.
miniplex - [email protected]

Published by github-actions[bot] over 2 years ago

Patch Changes

  • 0c1ce64: Now uses useEffect instead of useLayoutEffect, which should make it easier to use the components in server-side React.
miniplex - [email protected]

Published by github-actions[bot] over 2 years ago

Minor Changes

  • b4cee80: Breaking Change: createEntity will now always return a new object, and not return the one passed to it.

  • 544f231: Typescript: You no longer need to mix in IEntity into your own entity types, as part of a wider refactoring of the library's typings. Also, createWorld will now return a RegisteredEntity<YourEntity> type that reflects the presence of the automatically added internal __miniplex component, and makes a lot of interactions with the world instance safer than it was previously.

  • 544f231: Breaking Change: Miniplex will no longer automatically add an id component to created entities. If your project has been making use of these automatically generated IDs, you will now need to add them yourself.

    Example:

    let nextId = 0
    
    /* Some component factories */
    const id = () => ({ id: nextId++ })
    const name = (name) => ({ name })
    
    const world = new World()
    const entity = world.createEntity(id(), name("Alice"))
    

    Note: Keep in mind that Miniplex doesn't care about entity IDs much, since all interactions with the world are done through object references. Your project may not need to add IDs to entities at all; if it does, this can now be done using any schema that your project requires (numerical IDs, UUIDs, ...).

Patch Changes

  • b4cee80: createEntity now allows you to pass multiple parameters, each representing a partial entity. This makes the use of component factory functions more convenient. Example:

    /* Provide a bunch of component factories */
    const position = (x = 0, y = 0) => ({ position: { x, y } })
    const velocity = (x = 0, y = 0) => ({ velocity: { x, y } })
    const health = (initial) => ({
      health: { max: initial, current: initial }
    })
    
    const world = new World()
    
    const entity = world.createEntity(
      position(0, 0),
      velocity(5, 7),
      health(1000)
    )
    

    Typescript Note: The first argument will always be typechecked against your entity type, so if your entity type has required components, you will need to pass a first argument that satisfies these. The remaining arguments are expected to be partials of your entity type.

  • b4cee80: Breaking Change: world.queue.createEntity no longer returns an entity (which didn't make a whole lot of semantic sense to begin with.)