Skip to content

Commit 42891f5

Browse files
authored
Update README for 1.0 (#164)
1 parent 4fd799a commit 42891f5

File tree

3 files changed

+87
-23
lines changed

3 files changed

+87
-23
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ end_of_line = lf
99
charset = utf-8
1010
trim_trailing_whitespace = true
1111
insert_final_newline = true
12+
13+
[*.md]
14+
trim_trailing_whitespace = false

packages/miniplex-react/README.md

+33-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
[![Version](https://img.shields.io/npm/v/miniplex-react)](https://www.npmjs.com/package/miniplex-react)
2-
[![Downloads](https://img.shields.io/npm/dt/miniplex-react.svg)](https://www.npmjs.com/package/miniplex-react)
3-
[![Bundle Size](https://img.shields.io/bundlephobia/min/miniplex-react?label=bundle%20size)](https://bundlephobia.com/result?p=miniplex-react)
1+
[![Tests](https://img.shields.io/github/workflow/status/hmans/miniplex/Tests?label=CI&style=for-the-badge)](https://github.com/hmans/miniplex/actions/workflows/tests.yml)
2+
[![Downloads](https://img.shields.io/npm/dt/miniplex-react.svg?style=for-the-badge)](https://www.npmjs.com/package/miniplex-react)
3+
[![Bundle Size](https://img.shields.io/bundlephobia/min/miniplex-react?style=for-the-badge&label=bundle%20size)](https://bundlephobia.com/result?p=miniplex-react)
44

55
# miniplex-react
66

77
### React glue for [miniplex], the gentle game entity manager.
88

9+
> **Note** This package contains the React glue for Miniplex. This documentation assumes that you are familiar with how Miniplex works. If you haven't done so already, please read the [Miniplex documentation](https://github.com/hmans/miniplex/tree/main/packages/miniplex#readme) first.
10+
911
## Installation
1012

1113
Add `miniplex-react` and its peer dependency `miniplex` to your application using your favorite package manager, eg.
@@ -85,7 +87,7 @@ const Player = () => (
8587

8688
This will, once mounted, create a single entity in your ECS world, and add the `position` and `health` components to it. Once unmounted, it will also automatically destroy the entity.
8789

88-
### Storing objects in components
90+
### Capturing object refs into components
8991

9092
If your components are designed to store rich objects, and these can be expressed as React components providing Refs, you can pass a single React child to `<Component>`, and its Ref value will automatically be picked up. For example, let's imagine a react-three-fiber based game that allows entities to have a scene object:
9193

@@ -253,6 +255,8 @@ const Health = () => {
253255
254256
### Managed Entity Collections
255257
258+
> **Note** This feature is still experimental and may change (or even be removed) in the future.
259+
256260
In games and other ECS-oriented applications, you will often have several distinct _entity types_ -- like spaceships, asteroids, bullets, explosions, etc. -- even if these entities are composed of several shared ECS components. All entities within a specific entity type are typically composed from the same set of components (eg. spaceships always have a position and a velocity), and rendered in a similar manner (eg. bullets will always be rendered using a small box mesh, but with varying materials.)
257261
258262
The `<ManagedEntities>` React component is an abstraction over this. It will take over management and rendering of such an entity type, assuming that this type can be identified by the presence of a specific tag (a tag being a miniplex component that is always just `true` and doesn't hold any additional data; miniplex provides a `Tag` type and constant for this.)
@@ -300,3 +304,28 @@ A couple of important notes:
300304
Find me on [Twitter](https://twitter.com/hmans) or the [Poimandres Discord](https://discord.gg/aAYjm2p7c7).
301305
302306
[miniplex]: https://github.com/hmans/miniplex
307+
308+
## License
309+
310+
```
311+
Copyright (c) 2022 Hendrik Mans
312+
313+
Permission is hereby granted, free of charge, to any person obtaining
314+
a copy of this software and associated documentation files (the
315+
"Software"), to deal in the Software without restriction, including
316+
without limitation the rights to use, copy, modify, merge, publish,
317+
distribute, sublicense, and/or sell copies of the Software, and to
318+
permit persons to whom the Software is furnished to do so, subject to
319+
the following conditions:
320+
321+
The above copyright notice and this permission notice shall be
322+
included in all copies or substantial portions of the Software.
323+
324+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
325+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
326+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
327+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
328+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
329+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
330+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
331+
```

packages/miniplex/README.md

+51-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
[![Tests](https://github.com/hmans/miniplex/actions/workflows/tests.yml/badge.svg)](https://github.com/hmans/miniplex/actions/workflows/tests.yml)
2-
[![Downloads](https://img.shields.io/npm/dt/miniplex.svg)](https://www.npmjs.com/package/miniplex)
3-
[![Bundle Size](https://img.shields.io/bundlephobia/min/miniplex?label=bundle%20size)](https://bundlephobia.com/result?p=miniplex)
1+
![Miniplex](https://user-images.githubusercontent.com/1061/193760498-fb6b4d42-f48b-48b4-b7c1-b5b5674df55c.jpg)
2+
[![Tests](https://img.shields.io/github/workflow/status/hmans/miniplex/Tests?label=CI&style=for-the-badge)](https://github.com/hmans/miniplex/actions/workflows/tests.yml)
3+
[![Downloads](https://img.shields.io/npm/dt/miniplex.svg?style=for-the-badge)](https://www.npmjs.com/package/miniplex)
4+
[![Bundle Size](https://img.shields.io/bundlephobia/min/miniplex?style=for-the-badge&label=bundle%20size)](https://bundlephobia.com/result?p=miniplex)
45

5-
# Miniplex
6+
## Testimonials
7+
8+
> Tested @hmans' Miniplex library over the weekend and after having previously implemented an ECS for my wip browser game, I have to say **Miniplex feels like the "right" way to do ECS in #r3f**. - [Brian Breiholz](https://twitter.com/BrianBreiholz/status/1577182839509962752)
69
710
## Ecosystem
811

9-
- [![Version](https://img.shields.io/npm/v/miniplex)](https://www.npmjs.com/package/miniplex) [miniplex](https://github.com/hmans/miniplex/tree/main/packages/miniplex)
10-
- [![Version](https://img.shields.io/npm/v/miniplex-react)](https://www.npmjs.com/package/miniplex-react) [miniplex-react](https://github.com/hmans/miniplex/tree/main/packages/miniplex-react)
12+
- **[miniplex](https://github.com/hmans/miniplex/tree/main/packages/miniplex)**
13+
The core package. Use it in any JavaScript or TypeScript project.
14+
- **[miniplex-react](https://github.com/hmans/miniplex/tree/main/packages/miniplex-react)**
15+
React bindings. Create, extend and render entities declaratively.
1116

1217
## Introduction
1318

1419
**Miniplex is an entity management system for games and similarly demanding applications.** Instead of creating separate buckets for different types of entities (eg. asteroids, enemies, pickups, the player, etc.), you throw all of them into a single store, describe their properties through components, and then write code that performs updates on entities of specific types.
1520

16-
If you're familiar with Entity Component System architecture, this will sound familiar to you -- and rightfully so, for Miniplex is, first and foremost, a very straight-forward ECS implementation.
21+
If you're familiar with **Entity Component System** architecture, this will sound familiar to you -- and rightfully so, for Miniplex is, first and foremost, a very straight-forward ECS implementation!
1722

1823
If you're hearing about this approach for the first time, maybe it will sound a little counter-intuitive -- but once you dive into it, you will understand how it can help you decouple concerns and keep your codebase well-structured and maintainable. [This post](https://community.amethyst.rs/t/archetypal-vs-grouped-ecs-architectures-my-take/1344) has a nice summary:
1924

@@ -35,7 +40,7 @@ If you've used other Entity Component System libraries before, here's how Minipl
3540

3641
### Entities are just normal JavaScript objects
3742

38-
Entities are just **plain JavaScript objects**, and components are just **properties on those objects**. Component data can be **anything** you need, from primitive values to entire class instances, or even [reactive stores](https://github.com/hmans/statery). Miniplex aims to put developer experience first, and the most important way it does this is by making its usage feel as natural as possible in a JavaScript setting.
43+
Entities are just **plain JavaScript objects**, and components are just **properties on those objects**. Component data can be **anything** you need, from primitive values to entire class instances, or even [entire reactive stores](https://github.com/hmans/statery). Miniplex puts developer experience first, and the most important way it does this is by making its usage feel as natural as possible in a JavaScript setting.
3944

4045
Miniplex does not expect you to programmatically declare component types before using them, but if you're using TypeScript, you can provide a type describing your entities and Miniplex will provide full edit- and compile-time type hints and safety.
4146

@@ -47,7 +52,7 @@ Systems are extremely straight-forward: just write simple functions that operate
4752

4853
### Archetypal Queries
4954

50-
Entity queries are performed through **archetypes**, with archetypes representing a subset of your world's entities that have a specific set of components. More complex querying capabilities may be added at a later date.
55+
Entity queries are performed through **archetypes**, with individual archetypes representing a subset of your world's entities that have a specific set of components. More complex querying capabilities may be added at a later date.
5156

5257
### Focus on Object Identities over numerical IDs
5358

@@ -57,17 +62,19 @@ Most interactions with Miniplex are using **object identity** to identify entiti
5762

5863
Miniplex can be used in any JavaScript or TypeScript project, regardless of which extra frameworks you might be using. Integrations with frameworks like React are provided as separate packages, so here we will only talk about framework-less usage.
5964

65+
Specifically, if you intend to use Miniplex in a React project, please don't miss the [miniplex-react](https://github.com/hmans/miniplex/tree/main/packages/miniplex-react) documentation!
66+
6067
### Creating a World
6168

62-
Miniplex manages entities in worlds, which act as a containers for entities as well as an API for interacting with them. You can have one big world in your project, or several smaller worlds handling separate concerns.
69+
Miniplex manages entities in worlds, which act as containers for entities as well as an API for interacting with them. You can have one big world in your project, or several smaller worlds handling separate concerns.
6370

6471
```ts
6572
import { World } from "miniplex"
6673

6774
const world = new World()
6875
```
6976

70-
### Typing your Entities (optional, but recommended)
77+
### Typing your Entities (optional, but recommended!)
7178

7279
If you're using TypeScript, you can define a type that describes your entities and provide it to the `World` constructor to get full type support in all interactions with it:
7380

@@ -122,8 +129,8 @@ const movingEntities = world.archetype("position", "velocity")
122129
Now we can implement our system, which is really just a function -- or any other piece of code -- that uses the archetype to fetch the associated entities and then iterates over them:
123130

124131
```ts
125-
function movementSystem(world) {
126-
for (const { position, velocity } of movingEntities.entities) {
132+
function movementSystem() {
133+
for (const { position, velocity } of movingEntities) {
127134
position.x += velocity.x
128135
position.y += velocity.y
129136
position.z += velocity.z
@@ -271,19 +278,19 @@ function movementSystem(world) {
271278
}
272279
```
273280

274-
This will incur a modest, but noticeable performance penalty, since you would be calling and returning from a function for every entity in the archetype. It is typically recommended to use either a `for/of` loop:
281+
This will incur a modest, but noticeable performance penalty, since you would be calling and returning from a function for every entity in the archetype. If performance is a concern, it is recommended to use either a `for/of` loop:
275282

276283
```ts
277284
function movementSystem(world) {
278-
for (const { position, velocity } of movingEntities.entities) {
285+
for (const { position, velocity } of movingEntities) {
279286
position.x += velocity.x
280287
position.y += velocity.y
281288
position.z += velocity.z
282289
}
283290
}
284291
```
285292

286-
Or a classic `for` loop:
293+
Or a classic `for` loop with numerical index access:
287294

288295
```ts
289296
function movementSystem(world) {
@@ -308,7 +315,7 @@ For example, creating your archetypes within a system function like this will wo
308315
function movementSystem(world) {
309316
const movingEntities = world.archetype("position", "velocity")
310317

311-
for (const { position, velocity } of movingEntities.entities) {
318+
for (const { position, velocity } of movingEntities) {
312319
position.x += velocity.x
313320
position.y += velocity.y
314321
position.z += velocity.z
@@ -321,8 +328,8 @@ Instead, create the archetype outside of your system:
321328
```ts
322329
const movingEntities = world.archetype("position", "velocity")
323330

324-
function movementSystem(world) {
325-
for (const { position, velocity } of movingEntities.entities) {
331+
function movementSystem() {
332+
for (const { position, velocity } of movingEntities) {
326333
position.x += velocity.x
327334
position.y += velocity.y
328335
position.z += velocity.z
@@ -333,3 +340,28 @@ function movementSystem(world) {
333340
## Questions?
334341

335342
Find me on [Twitter](https://twitter.com/hmans) or the [Poimandres Discord](https://discord.gg/aAYjm2p7c7).
343+
344+
## License
345+
346+
```
347+
Copyright (c) 2022 Hendrik Mans
348+
349+
Permission is hereby granted, free of charge, to any person obtaining
350+
a copy of this software and associated documentation files (the
351+
"Software"), to deal in the Software without restriction, including
352+
without limitation the rights to use, copy, modify, merge, publish,
353+
distribute, sublicense, and/or sell copies of the Software, and to
354+
permit persons to whom the Software is furnished to do so, subject to
355+
the following conditions:
356+
357+
The above copyright notice and this permission notice shall be
358+
included in all copies or substantial portions of the Software.
359+
360+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
361+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
362+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
363+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
364+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
365+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
366+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
367+
```

0 commit comments

Comments
 (0)