-
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.
Merge pull request #10 from RuggeroVisintin/RuggeroVisintin/issue2
RuggeroVisintin/issue2
- Loading branch information
Showing
21 changed files
with
162 additions
and
1 deletion.
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 '../core'; |
Empty file.
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,8 @@ | ||
import { IEntity } from "../entities"; | ||
import { IComponent } from "./IComponent"; | ||
|
||
export class BaseComponent implements IComponent { | ||
public getContainer(): IEntity { | ||
throw new Error("Method not implemented."); | ||
} | ||
} |
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,5 @@ | ||
import { IEntity } from "../entities"; | ||
|
||
export interface IComponent { | ||
getContainer(): IEntity; | ||
} |
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,12 @@ | ||
import { BaseComponent } from "./BaseComponent"; | ||
|
||
export enum ShapeType { | ||
Rectangle = 0 | ||
} | ||
|
||
/** | ||
* Represents a primitive Shape like rectangle, circle, etc | ||
*/ | ||
export class ShapeComponent extends BaseComponent { | ||
public shapeType: ShapeType = ShapeType.Rectangle; | ||
} |
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,16 @@ | ||
import { BaseComponent } from "./BaseComponent"; | ||
|
||
interface Position2D { | ||
x: number; | ||
y: number; | ||
} | ||
|
||
interface Size2D { | ||
width: number; | ||
height: number; | ||
} | ||
|
||
export class TransformComponent extends BaseComponent { | ||
public position: Position2D = { x: 0, y: 0 }; | ||
public size: Size2D = { width: 0, height: 0 }; | ||
} |
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,4 @@ | ||
export * from './IComponent'; | ||
export * from './BaseComponent'; | ||
export * from './TransformComponent'; | ||
export * from './ShapeComponent'; |
Empty file.
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,14 @@ | ||
import { BaseComponent } from "../components"; | ||
import { IEntity } from "./IEntity"; | ||
|
||
export class BaseEntity implements IEntity { | ||
private components: Map<string, BaseComponent> = new Map(); | ||
|
||
public addComponent<Component extends BaseComponent>(key: string, component: Component): void { | ||
this.components.set(key, component); | ||
} | ||
|
||
public getComponent<Component extends BaseComponent>(key: string): Component | undefined { | ||
return this.components.get(key) 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { IComponent } from "../components"; | ||
|
||
export interface IEntity { | ||
addComponent(key: string, component: IComponent): void; | ||
getComponent(key: string): IComponent | 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './BaseEntity'; | ||
export * from './IEntity'; |
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,3 @@ | ||
export * from './entities'; | ||
export * from './components'; | ||
export * from './systems'; |
Empty file.
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,6 @@ | ||
import { BaseComponent } from "../components"; | ||
|
||
export interface ISystem { | ||
registerComponent(component: BaseComponent): void; | ||
update(): void; | ||
} |
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,14 @@ | ||
import { ShapeComponent } from "../components"; | ||
import { ISystem } from "./ISystem"; | ||
|
||
export class RenderSystem implements ISystem { | ||
public readonly components: ShapeComponent[] = [] | ||
|
||
public registerComponent(component: ShapeComponent): void { | ||
this.components.push(component); | ||
} | ||
|
||
public update(): void { | ||
throw new Error('NotImplemented'); | ||
} | ||
} |
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,2 @@ | ||
export * from './ISystem'; | ||
export * from './RenderSystem'; |
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 @@ | ||
console.log('RUN') | ||
export * from './core'; | ||
export * from './ecs'; |
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,7 @@ | ||
import { BaseComponent } from "../../../src"; | ||
|
||
describe('ecs/components/BaseComponent', () => { | ||
it('Should construct', () => { | ||
new BaseComponent(); | ||
}) | ||
}) |
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,23 @@ | ||
import { TransformComponent } from "../../../src" | ||
|
||
describe('ecs/components/TransformComponent', () => { | ||
describe('constructor', () => { | ||
it('Should default position to 0,0 if not defined', () => { | ||
const transformComponent = new TransformComponent(); | ||
|
||
expect(transformComponent.position).toEqual({ | ||
x: 0, | ||
y: 0 | ||
}) | ||
}) | ||
|
||
it('Should default size to 0,0 if not defiend', () => { | ||
const transformComponent = new TransformComponent(); | ||
|
||
expect(transformComponent.size).toEqual({ | ||
width: 0, | ||
height: 0 | ||
}) | ||
}) | ||
}) | ||
}) |
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,23 @@ | ||
import { BaseComponent, BaseEntity } from "../../../src"; | ||
|
||
describe('ecs/entities/BaseEntity', () => { | ||
const baseEntity = new BaseEntity(); | ||
|
||
describe('.addComponent()', () => { | ||
it('Should add component to entity', () => { | ||
const testComponent = new BaseComponent(); | ||
|
||
baseEntity.addComponent<BaseComponent>('testComponent', testComponent); | ||
expect(baseEntity.getComponent<BaseComponent>('testComponent')).toEqual(testComponent); | ||
}); | ||
}) | ||
|
||
describe('.getComponent()', () => { | ||
it('Should retrieve a specific component given a specific key', () => { | ||
const testComponent = new BaseComponent(); | ||
baseEntity.addComponent<BaseComponent>('testComponent', testComponent); | ||
|
||
expect(baseEntity.getComponent<BaseComponent>('testComponent')).toEqual(testComponent); | ||
}) | ||
}) | ||
}) |
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,14 @@ | ||
import { RenderSystem, ShapeComponent } from "../../../src" | ||
|
||
describe('systems/RenderSystem', () => { | ||
describe('.registerComponent()', () => { | ||
const renderSystem = new RenderSystem(); | ||
const myTestShape = new ShapeComponent(); | ||
|
||
it('Should register the component into the RenderSystem components list', () => { | ||
renderSystem.registerComponent(myTestShape); | ||
|
||
expect(renderSystem.components).toContain(myTestShape); | ||
}) | ||
}) | ||
}) |