-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
617 additions
and
772 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
"@miniplex/core": patch | ||
--- | ||
|
||
Aaaaah, another rewrite of the core library! `@miniplex/core` kept the same lightweight core, but the `World` is now much more aware of archetypes and what kind of entities they represent. This was done to allow for better introspection and to fix some remaining issues like [#204](https://github.com/hmans/miniplex/issues/204)]. | ||
|
||
The `WithRequiredKeys` type has been renamed to `WithComponents`. | ||
|
||
`world.archetype()` now allows two forms: | ||
|
||
```ts | ||
world.archetype("position", "velocity") | ||
world.archetype({ all: ["position", "velocity"] }) | ||
``` | ||
|
||
The second form involves a query object that can also have `any` and `none` keys: | ||
|
||
```ts | ||
world.archetype({ | ||
all: ["position", "velocity"], | ||
none: ["dead"] | ||
}) | ||
``` | ||
|
||
**Breaking Change:** `bucket.derive()` has been removed. It was cool and fun and cute, but also a little too generic to be useful. Similar to Miniplex 1.0, there is only the _world_ and a series of _archetypes_ now. (But both share the same lightweight `Bucket` base class that can also be used standalone.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
"@miniplex/react": patch | ||
--- | ||
|
||
`<Archetype>` has been changed to match the new query capabilities of the core library's `world.archetype` function. All of these are now valid: | ||
|
||
```tsx | ||
<Archetype query="position" /> | ||
<Archetype query={["position", "velocity"]} /> | ||
<Archetype query={{ all: ["position", "velocity"], none: ["dead"] }} /> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { WithRequiredKeys } from "miniplex" | ||
import { WithComponents } from "miniplex" | ||
import { Entity } from "../state" | ||
|
||
export const RenderableEntity = ({ | ||
entity | ||
}: { | ||
entity: WithRequiredKeys<Entity, "render"> | ||
entity: WithComponents<Entity, "render"> | ||
}) => <>{entity.render}</> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Bucket } from "./Bucket" | ||
import { IEntity, Query } from "./types" | ||
|
||
/** | ||
* A bucket type that stores entities belonging to a specific archetype. | ||
* This archetype is expressed as a `Query` object, stored in the archetype's | ||
* `query` property. | ||
*/ | ||
export class Archetype<E extends IEntity> extends Bucket<E> { | ||
constructor(public query: Query<E>) { | ||
super() | ||
} | ||
|
||
matchesEntity(entity: E): boolean { | ||
return this.matchesComponents(Object.keys(entity)) | ||
} | ||
|
||
matchesComponents(components: (keyof E)[]): boolean { | ||
const all = | ||
this.query.all === undefined || | ||
this.query.all.every((key) => components.includes(key)) | ||
|
||
const any = | ||
this.query.any === undefined || | ||
this.query.any.some((key) => components.includes(key)) | ||
|
||
const none = | ||
this.query.none === undefined || | ||
this.query.none.every((key) => !components.includes(key)) | ||
|
||
return all && any && none | ||
} | ||
} |
Oops, something went wrong.