]> git.r.bdr.sh - rbdr/sumo/blame - lib/systems/attributes_to_renderable.js
Merge branch 'feature/rbdr-gitlab-pipeline' into 'develop'
[rbdr/sumo] / lib / systems / attributes_to_renderable.js
CommitLineData
493ec31c
RBR
1import { System } from '@serpentity/serpentity';
2
3import RenderableWithAttributesNode from '../nodes/renderable_with_attributes';
4
5/**
6 * Updates the renderables based on their attribuets
7 *
8 * @extends {external:Serpentity.System}
9 * @class AttributesToRenderableSystem
10 * @param {object} config a configuration object to extend.
11 */
12export default class AttributesToRenderableSystem extends System {
13
14 constructor(config = {}) {
15
16 super();
17
18 /**
19 * The node collection of renderable entities
20 *
21 * @property {external:Serpentity.NodeCollection} renderables
22 * @instance
23 * @memberof AttributesToRenderableSystem
24 */
25 this.renderables = null;
26 }
27
28 /**
29 * Initializes system when added. Requests renderable nodes and
30 * attaches to event listeners to add / remove them to pixi stage
31 *
32 * @function added
33 * @memberof AttributesToRenderableSystem
34 * @instance
35 * @param {external:Serpentity.Engine} engine the serpentity engine to
36 * which we are getting added
37 */
38 added(engine) {
39
40 this.renderables = engine.getNodes(RenderableWithAttributesNode);
41 }
42
43 /**
44 * Clears system resources when removed.
45 *
46 * @function removed
47 * @instance
48 * @memberof AttributesToRenderableSystem
49 */
50 removed() {
51
52 this.renderables = null;
53 }
54
55 /**
56 * Runs on every update of the loop. Updates the graphics so they're
57 * rendered correctly
58 *
59 * @function update
60 * @instance
61 * @param {Number} currentFrameDuration the duration of the current
62 * frame
63 * @memberof AttributesToRenderableSystem
64 */
65 update(currentFrameDuration) {
66
67 for (const renderable of this.renderables) {
68 renderable.container.container.position.x = renderable.position.x;
69 renderable.container.container.position.y = renderable.position.y;
70 renderable.container.container.rotation = renderable.angle.angle;
71 }
72 }
73};