1 import { System
} from '@serpentity/serpentity';
3 import PhysicalWithAttributesNode
from '../nodes/physical_with_attributes';
4 import Config
from '../config';
7 * Distribuets physics data to the related components
9 * @extends {external:Serpentity.System}
10 * @class PhysicsToAttributesSystem
11 * @param {object} config a configuration object to extend.
13 export default class PhysicsToAttributesSystem
extends System
{
15 constructor(config
= {}) {
20 * The node collection of physics entities
22 * @property {external:Serpentity.NodeCollection} physicalEntities
24 * @memberof PhysicsToAttributesSystem
26 this.physicalEntities
= null;
30 * Initializes system when added. Requests physics nodes
33 * @memberof PhysicsToAttributesSystem
35 * @param {external:Serpentity.Engine} engine the serpentity engine to
36 * which we are getting added
40 this.physicalEntities
= engine
.getNodes(PhysicalWithAttributesNode
);
44 * Clears system resources when removed.
48 * @memberof PhysicsToAttributesSystem
52 this.physicalEntities
= null;
56 * Runs on every update of the loop. Updates the other components
61 * @param {Number} currentFrameDuration the duration of the current
63 * @memberof PhysicsToAttributesSystem
65 update(currentFrameDuration
) {
67 for (const physicalEntity
of this.physicalEntities
) {
68 physicalEntity
.position
.x
= physicalEntity
.body
.body
.position
.x
* Config
.meterSize
;
69 physicalEntity
.position
.y
= physicalEntity
.body
.body
.position
.y
* Config
.meterSize
;
70 physicalEntity
.angle
.angle
= physicalEntity
.body
.body
.angle
;