1.0.0-pre.61 • Published 2 months ago
mani-game-engine v1.0.0-pre.61
Use entity component system
import {EntityComponent, GetComponent, GetEntity, Inject, Injector} from 'mani-injector';
class Service {}
class FooComponent {}
class BarComponent {}
class FirstEntity {
@EntityComponent
foo: FooComponent = new FooComponent();
}
class SecondEntity {
@EntityComponent
foo: FooComponent = new FooComponent();
@EntityComponent
bar: BarComponent = new BarComponent();
}
// this system is created for every entity that has a FooComponent
class FooSystem {
constructor(
// get a reference to the component when the system is created for a specific entity
@GetComponent readonly foo: FooComponent,
// you can get the entity object
@GetEntity readonly entity:Object
) {}
}
// this system is created for every entity that has a BarComponent
class BarSystem {
constructor(
@GetComponent readonly bar: BarComponent,
) {}
}
// this system is created for every entity that has a FooComponent and a BarComponent
class FooBarSystem {
constructor(
@GetComponent readonly foo: FooComponent,
@GetComponent readonly bar: BarComponent,
// you can inject everything that is mapped in the injector
@Inject readonly service: Service
) {}
}
const injector = new Injector();
injector.registerSystem(FooSystem);
injector.registerSystem(BarSystem);
injector.registerSystem(FooBarSystem);
injector.map(Service).toSingleton();
const entity1 = new FirstEntity();
const entity2 = new SecondEntity();
// array with one instance of FooSystem with a reference to the component
console.log(injector.createSystems(entity1));
// array with 3 systems
// one instance of FooSystem
// one instance of BarSystem
// one instance of FooBarSystem
console.log(injector.createSystems(entity2));
1.0.0-pre.60
2 months ago
1.0.0-pre.61
2 months ago
1.0.0-pre.59
2 months ago
1.0.0-pre.58
2 months ago
1.0.0-pre.57
4 months ago
1.0.0-pre.55
11 months ago
1.0.0-pre.56
11 months ago
1.0.0-pre.53
1 year ago
1.0.0-pre.52
1 year ago
1.0.0-pre.54
1 year ago
1.0.0-pre.51
1 year ago
1.0.0-pre.50
1 year ago
1.0.0-pre.46
1 year ago
1.0.0-pre.45
1 year ago
1.0.0-pre.48
1 year ago
1.0.0-pre.47
1 year ago
1.0.0-pre.49
1 year ago
1.0.0-pre.42
1 year ago
1.0.0-pre.41
1 year ago
1.0.0-pre.44
1 year ago
1.0.0-pre.43
1 year ago
1.0.0-pre.40
1 year ago
1.0.0-pre.35
1 year ago
1.0.0-pre.37
1 year ago
1.0.0-pre.36
1 year ago
1.0.0-pre.39
1 year ago
1.0.0-pre.38
1 year ago
1.0.0-pre.33
2 years ago
1.0.0-pre.34
2 years ago
1.0.0-pre.20
2 years ago
1.0.0-pre.22
2 years ago
1.0.0-pre.21
2 years ago
1.0.0-pre.24
2 years ago
1.0.0-pre.23
2 years ago
1.0.0-pre.25
2 years ago
1.0.0-pre.28
2 years ago
1.0.0-pre.29
2 years ago
1.0.0-pre.31
2 years ago
1.0.0-pre.30
2 years ago
1.0.0-pre.32
2 years ago
1.0.0-pre.13
2 years ago
1.0.0-pre.15
2 years ago
1.0.0-pre.14
2 years ago
1.0.0-pre.17
2 years ago
1.0.0-pre.16
2 years ago
1.0.0-pre.19
2 years ago
1.0.0-pre.18
2 years ago
1.0.0-pre.12
3 years ago
1.0.0-pre.11
3 years ago
1.0.0-pre.10
3 years ago
1.0.0-pre.9
3 years ago
1.0.0-pre.8
3 years ago
1.0.0-pre.7
3 years ago
1.0.0-pre.5
3 years ago
1.0.0-pre.4
4 years ago
1.0.0-pre.3
5 years ago
1.0.0-pre.2
5 years ago
1.0.0-pre.1
5 years ago