1.0.0-pre.81 • Published 4 months ago

mani-game-engine v1.0.0-pre.81

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

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.73

5 months ago

1.0.0-pre.72

5 months ago

1.0.0-pre.80

4 months ago

1.0.0-pre.81

4 months ago

1.0.0-pre.75

5 months ago

1.0.0-pre.74

5 months ago

1.0.0-pre.77

5 months ago

1.0.0-pre.76

5 months ago

1.0.0-pre.79

4 months ago

1.0.0-pre.78

5 months ago

1.0.0-pre.71

10 months ago

1.0.0-pre.70

10 months ago

1.0.0-pre.68

10 months ago

1.0.0-pre.69

10 months ago

1.0.0-pre.64

11 months ago

1.0.0-pre.63

11 months ago

1.0.0-pre.66

11 months ago

1.0.0-pre.65

11 months ago

1.0.0-pre.67

11 months ago

1.0.0-pre.62

11 months ago

1.0.0-pre.60

1 year ago

1.0.0-pre.61

1 year ago

1.0.0-pre.59

1 year ago

1.0.0-pre.58

1 year ago

1.0.0-pre.57

2 years ago

1.0.0-pre.55

2 years ago

1.0.0-pre.56

2 years ago

1.0.0-pre.53

2 years ago

1.0.0-pre.52

2 years ago

1.0.0-pre.54

2 years ago

1.0.0-pre.51

2 years ago

1.0.0-pre.50

2 years ago

1.0.0-pre.46

2 years ago

1.0.0-pre.45

2 years ago

1.0.0-pre.48

2 years ago

1.0.0-pre.47

2 years ago

1.0.0-pre.49

2 years ago

1.0.0-pre.42

3 years ago

1.0.0-pre.41

3 years ago

1.0.0-pre.44

3 years ago

1.0.0-pre.43

3 years ago

1.0.0-pre.40

3 years ago

1.0.0-pre.35

3 years ago

1.0.0-pre.37

3 years ago

1.0.0-pre.36

3 years ago

1.0.0-pre.39

3 years ago

1.0.0-pre.38

3 years ago

1.0.0-pre.33

3 years ago

1.0.0-pre.34

3 years ago

1.0.0-pre.20

3 years ago

1.0.0-pre.22

3 years ago

1.0.0-pre.21

3 years ago

1.0.0-pre.24

3 years ago

1.0.0-pre.23

3 years ago

1.0.0-pre.25

3 years ago

1.0.0-pre.28

3 years ago

1.0.0-pre.29

3 years ago

1.0.0-pre.31

3 years ago

1.0.0-pre.30

3 years ago

1.0.0-pre.32

3 years ago

1.0.0-pre.13

3 years ago

1.0.0-pre.15

3 years ago

1.0.0-pre.14

3 years ago

1.0.0-pre.17

3 years ago

1.0.0-pre.16

3 years ago

1.0.0-pre.19

3 years ago

1.0.0-pre.18

3 years ago

1.0.0-pre.12

4 years ago

1.0.0-pre.11

4 years ago

1.0.0-pre.10

4 years ago

1.0.0-pre.9

4 years ago

1.0.0-pre.8

4 years ago

1.0.0-pre.7

4 years ago

1.0.0-pre.5

4 years ago

1.0.0-pre.4

6 years ago

1.0.0-pre.3

6 years ago

1.0.0-pre.2

6 years ago

1.0.0-pre.1

6 years ago