Skip to content

Commit

Permalink
Feat/string data type (#29)
Browse files Browse the repository at this point in the history
* docs: update README

* feat: add string data type
  • Loading branch information
3mcd authored May 17, 2020
1 parent 4374b65 commit a59f58f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ const entity = world.create([
])
```

Components are unremarkable objects other than a few reserved properties:
Components are just plain objects; unremarkable, other than a few reserved properties:

- `_t` is a unique integer identifying the component's type
- `_e` references the entity the component is actively associated with
- `_v` maintains the current version of the component, which is useful for change detection
- `_t` is a unique integer identifying the component's **type**
- `_e` references the **entity** the component is actively associated with
- `_v` maintains the current **version** of the component, which is useful for change detection

A position component assigned to entity `5` that has been modified three times might look like:

```ts
{ _t: 1, _e: 5, _v: 3, x: 123.4, y: 567.8 }
```

Entities are removed via the `world.destroy` method:
Entities can be removed (and all components subsequently de-referenced) via the `world.destroy` method:

```ts
world.destroy(entity)
Expand Down Expand Up @@ -110,7 +110,7 @@ for (const [position, player] of world.query(players)) {

### Filtering and change detection

Queried components are readonly by default. A mutable copy of the component can be obtained via the `world.mut(entity)` method.
Queried components are readonly by default. A mutable copy of a component can be obtained via `world.mut(entity)`.

```ts
const burning = query(Health, Burn)
Expand All @@ -120,7 +120,7 @@ for (const [health, burn] of world.query(burning)) {
}
```

As alluded to earlier, components are versioned. `world.mut` simply increments the component's `_v` property. `createChangedFilter` produces a filter that excludes entities whose components haven't changed since the entity was last iterated with the filter instance. This filter uses the component's version (`_v`) to this end.
Components are versioned as alluded to earlier. `world.mut` simply increments the component's `_v` property. `createChangedFilter` produces a filter that excludes entities whose components haven't changed since the entity was last iterated with the filter instance. This filter uses the component's version (`_v`) to this end.

```ts
import { createChangedFilter, query } from "@javelin/ecs"
Expand Down
9 changes: 9 additions & 0 deletions packages/ecs/src/schema/standard_data_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ export const boolean = createDataType<boolean>({
c[key] = value
},
})

export const string = createDataType<string>({
create(value = "") {
return value
},
reset(c, key, value = "") {
c[key] = value
},
})

0 comments on commit a59f58f

Please sign in to comment.