-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ecs): add automatic key assign to component
- Loading branch information
1 parent
01f73dc
commit 9b6beda
Showing
12 changed files
with
42 additions
and
16 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 @@ | ||
export * from './typeDecorator'; |
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,9 @@ | ||
export function Type(value: string) { | ||
return function (constructor: Function) { | ||
constructor.prototype.__type = value; | ||
}; | ||
} | ||
|
||
export function typeOf(object: any): string { | ||
return object.__type; | ||
} |
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 +1,2 @@ | ||
export * from './color'; | ||
export * from './color'; | ||
export * from './decorators'; |
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
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,15 +1,21 @@ | ||
import { BaseComponent, IComponent } from "../components"; | ||
import { typeOf } from "../../core"; | ||
import { IComponent } from "../components"; | ||
import { IEntity } from "./IEntity"; | ||
|
||
export class BaseEntity implements IEntity { | ||
private components: Map<string, IComponent> = new Map(); | ||
|
||
public addComponent(key: string, component: IComponent): void { | ||
this.components.set(key, component); | ||
public addComponent(component: IComponent): void { | ||
this.components.set(typeOf(component), component); | ||
component.setContainer(this); | ||
} | ||
|
||
public getComponent<Component extends IComponent>(key: string): Component | undefined { | ||
return this.components.get(key) as Component; | ||
/** | ||
* Gets the first component matching a specific type | ||
* @param type | ||
* @returns the first component found with the type | ||
*/ | ||
public getComponent<Component extends IComponent>(type: string): Component | undefined { | ||
return this.components.get(type) as Component; | ||
} | ||
} |
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,6 +1,6 @@ | ||
import { IComponent } from "../components"; | ||
|
||
export interface IEntity { | ||
addComponent(key: string, component: IComponent): void; | ||
getComponent<T extends IComponent>(key: string): T | undefined; | ||
addComponent(component: IComponent): void; | ||
getComponent<T extends IComponent>(type: string): T | undefined; | ||
} |
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