]>
git.r.bdr.sh - rbdr/sumo/blob - lib/systems/create_coupling_line.js
1 import { System
} from '@serpentity/serpentity';
2 import { Graphics
} from 'pixi.js';
4 import PositionComponent
from '@serpentity/components.position';
6 import RenderableCoupleNode
from '../nodes/renderable_couple';
9 * Renders renderable objects using pixi
11 * @extends {external:Serpentity.System}
12 * @class CreateCouplingLineSystem
13 * @param {object} config a configuration object to extend.
15 export default class CreateCouplingLineSystem
extends System
{
17 constructor(config
= {}) {
22 * The node collection of coupled entities entities
24 * @property {external:Serpentity.NodeCollection} coupledEntities
26 * @memberof CreateCouplingLineSystem
28 this.coupledEntities
= null;
32 * Initializes system when added. Requests renderable nodes and
35 * @memberof CreateCouplingLineSystem
37 * @param {external:Serpentity.Engine} engine the serpentity engine to
38 * which we are getting added
42 this.coupledEntities
= engine
.getNodes(RenderableCoupleNode
);
46 * Clears system resources when removed.
50 * @memberof CreateCouplingLineSystem
54 this.coupledEntities
= null;
58 * Runs on every update of the loop. Does nothing.
62 * @param {Number} currentFrameDuration the duration of the current
64 * @memberof CreateCouplingLineSystem
66 update(currentFrameDuration
) {
68 for (const rootEntity
of this.coupledEntities
) {
70 const rootGraphic
= rootEntity
.container
.container
;
71 rootGraphic
.removeChildren();
73 let lineGraphic
= new Graphics();
74 lineGraphic
= lineGraphic
.lineStyle(5, 0xffffff, 0.9);
76 let initialPosition
= false;
78 for (const coupledEntity
of rootEntity
.coupledEntities
.coupledEntities
) {
79 if (coupledEntity
.hasComponent(PositionComponent
)) {
81 const position
= coupledEntity
.getComponent(PositionComponent
);
83 if (!initialPosition
) {
84 lineGraphic
= lineGraphic
.moveTo(position
.x
, position
.y
);
85 initialPosition
= true;
89 lineGraphic
= lineGraphic
.lineTo(position
.x
, position
.y
);
93 rootGraphic
.addChild(lineGraphic
);