]>
git.r.bdr.sh - rbdr/sumo/blob - lib/factories/sumo.js
b0e5416bf545f652fb82dcc9c95d4e05ce7f6fdf
1 import { Entity
} from '@serpentity/serpentity';
3 import PositionComponent
from '@serpentity/components.position';
4 import PixiContainerComponent
from '../components/pixi_container';
5 import PixiFactory
from '../factories/pixi';
8 * Factory object that contains many methods to create prefab entities.
16 * Creates a sumo entity and adds it to the engine. Can override
17 * position in the config object
19 * @function createSumo
20 * @memberof SumoFactory
21 * @param {external:Serpentity} [engine] the serpentity engine to attach
22 * to. If not sent, it will not be attached.
23 * @param {object} [config] the config to override the entity, accepts
24 * the key `position` as an object with an x and y property.
25 * @return {external:Serpentity.Entity} the created entity
27 createSumo(engine
, config
= {}) {
29 const entity
= new Entity();
31 entity
.addComponent(new PositionComponent(config
.position
));
33 const container
= config
.container
|| {
34 container: PixiFactory
.createSumo()
37 // Match the symbol position with the entity position on init
38 // Otherwise it's up to systems
39 const position
= entity
.getComponent(PositionComponent
);
40 container
.container
.position
.x
= position
.x
;
41 container
.container
.position
.y
= position
.y
;
43 entity
.addComponent(new PixiContainerComponent(container
));
46 engine
.addEntity(entity
);