Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] update readme #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ class Health extends Component {

Component properties and methods:

- **static properties = {}** object that defines the properties of the component. These can also reference an entity or
an array of entites by setting the default value to `<Entity>` and `<EntityArray>` respectively!
- **static properties = {}** object that defines the properties of the component. These can also reference an entity.
- **static allowMultiple = false** are multiple of this component type allowed? If true, components will either be stored as an object or array on the entity, depending on `keyProperty`.
- **static keyProperty = null** what property should be used as the key for accessing this component. if `allowMultiple` is false, this has no effect. If this property is omitted, it will be stored as an array on the component.
- **entity** returns the Entity this component is attached to
Expand Down Expand Up @@ -354,6 +353,52 @@ player.equipmentSlot.rightHand.destroy();

```

This can also be done with an array as the following example shows.

```js
export class Inventory extends Component {
static properties = {
list: [],
};

onPickUp(event) {
this.list.push(event.data);

if (event.data.position) {
event.data.remove(event.data.position);
}
}

onDrop(event) {
remove(this.list, (item) => item.id === event.data.id);
event.data.add(Position, this.entity.position);
}
}
```

Here it shows how consumption of an item would remove it from the inventory
```js
const entity = player.inventory.list[selectedInventoryIndex];

if (entity) {
if (entity.has(Effects)) {
entity.effects.forEach((x) =>
player.add(ActiveEffects, { ...x.serialize() })
);
}

// it's best to filter the array down and overwrite the old one
// if you use the destroy() method, the item would still linger in the inventory, marked as destroyed.
player.inventory.list = player.inventory.list.filter(
(item) => item.id !== entity.id
);

if (selectedInventoryIndex > player.inventory.list.length - 1)
selectedInventoryIndex = player.inventory.list.length - 1;
}

```

### Query

Queries keep track of sets of entities defined by component types. They are limited to the world they're created in.
Expand Down