import { System } from '@serpentity/serpentity'; import LimitedVelocityNode from '../nodes/limited_velocity'; /** * Reduces velocity if it exceeds threshold * * @extends {external:Serpentity.System} * @class ReduceVelocitySystem * @param {object} config a configuration object to extend. */ export default class ReduceVelocitySystem extends System { constructor(config = {}) { super(); /** * The node collection of entities that have external force * * @property {external:Serpentity.NodeCollection} limitedVelocityEntities * @instance * @memberof ReduceVelocitySystem */ this.limitedVelocityEntities = null; } /** * Initializes system when added. Requests limited velocity nodes * * @function added * @memberof ReduceVelocitySystem * @instance * @param {external:Serpentity.Engine} engine the serpentity engine to * which we are getting added */ added(engine) { this.limitedVelocityEntities = engine.getNodes(LimitedVelocityNode); } /** * Clears system resources when removed. * * @function removed * @instance * @memberof ReduceVelocitySystem */ removed() { this.limitedVelocityEntities = null; } /** * Runs on every update of the loop. Checks current velocity and adjusts if necessary * * @function update * @instance * @param {Number} currentFrameDuration the duration of the current * frame * @memberof ReduceVelocitySystem */ update(currentFrameDuration) { for (const limitedVelocityEntity of this.limitedVelocityEntities) { console.log(limitedVelocityEntity.body.body.velocity, limitedVelocityEntity.maxVelocity.maxVelocity); } } }