]> git.r.bdr.sh - rbdr/sumo/blob - lib/systems/reduce_velocity.js
652101424fc574a6c485e7b016c13abddbf2d1ea
[rbdr/sumo] / lib / systems / reduce_velocity.js
1 import { System } from '@serpentity/serpentity';
2
3 import LimitedVelocityNode from '../nodes/limited_velocity';
4
5 /**
6 * Reduces velocity if it exceeds threshold
7 *
8 * @extends {external:Serpentity.System}
9 * @class ReduceVelocitySystem
10 * @param {object} config a configuration object to extend.
11 */
12 export default class ReduceVelocitySystem extends System {
13
14 constructor(config = {}) {
15
16 super();
17
18 /**
19 * The node collection of entities that have external force
20 *
21 * @property {external:Serpentity.NodeCollection} limitedVelocityEntities
22 * @instance
23 * @memberof ReduceVelocitySystem
24 */
25 this.limitedVelocityEntities = null;
26 }
27
28 /**
29 * Initializes system when added. Requests limited velocity nodes
30 *
31 * @function added
32 * @memberof ReduceVelocitySystem
33 * @instance
34 * @param {external:Serpentity.Engine} engine the serpentity engine to
35 * which we are getting added
36 */
37 added(engine) {
38
39 this.limitedVelocityEntities = engine.getNodes(LimitedVelocityNode);
40 }
41
42 /**
43 * Clears system resources when removed.
44 *
45 * @function removed
46 * @instance
47 * @memberof ReduceVelocitySystem
48 */
49 removed() {
50
51 this.limitedVelocityEntities = null;
52 }
53
54 /**
55 * Runs on every update of the loop. Checks current velocity and adjusts if necessary
56 *
57 * @function update
58 * @instance
59 * @param {Number} currentFrameDuration the duration of the current
60 * frame
61 * @memberof ReduceVelocitySystem
62 */
63 update(currentFrameDuration) {
64
65 for (const limitedVelocityEntity of this.limitedVelocityEntities) {
66 console.log(limitedVelocityEntity.body.body.velocity, limitedVelocityEntity.maxVelocity.maxVelocity);
67 }
68 }
69 };
70