Skip to content

Commit

Permalink
Adicionado atributos nos componentes
Browse files Browse the repository at this point in the history
  • Loading branch information
nidorx committed Dec 16, 2019
1 parent 16821f5 commit 944caff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ npm install --save ecs-lib
* [World](#world)
* [Component](#component)
* [Raw data access](#raw-data-access)
* [Secondary attributes](#secondary-attributes)
* [Entity](#entity)
* [Adding and removing from the world](#adding-and-removing-from-the-world)
* [Adding and removing components](#adding-and-removing-components)
Expand Down Expand Up @@ -117,6 +118,13 @@ boxCmp.data.width = 33;
console.log(boxCmp.data.width);
```

#### Secondary attributes
A component can have attributes. Attributes are secondary values used to save miscellaneous data required by some specialized systems.

```typescript
boxCmp.attr.specializedSystemMetadata = 33;
console.log(boxCmp.attr.specializedSystemMetadata);
```

### Entity

Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ export abstract class Component<T> {

public data: T;

/**
* A component can have attributes. Attributes are secondary values used to save miscellaneous data required by some
* specialized systems.
*/
public attr: {
[key: string]: any
} = {};

constructor(type: number, data: T) {
this.type = type;
this.data = data;
Expand Down

0 comments on commit 944caff

Please sign in to comment.