From 619ca1e8c8333671472996ccc768d4112c5e660b Mon Sep 17 00:00:00 2001 From: Praccen Date: Sat, 30 Sep 2023 19:48:03 +0200 Subject: [PATCH] Formatting --- .../ECS/Systems/ParticleSpawnerSystem.ts | 4 +- code/src/Engine/Utils/ESCUtils.ts | 48 ++++++++++--------- code/src/Game/PlayerCharacter.ts | 30 ++++++++---- code/src/Game/States/Game.ts | 18 +++++-- code/src/Game/States/Menu.ts | 1 - 5 files changed, 61 insertions(+), 40 deletions(-) diff --git a/code/src/Engine/ECS/Systems/ParticleSpawnerSystem.ts b/code/src/Engine/ECS/Systems/ParticleSpawnerSystem.ts index 6c1cfa7..445ca45 100644 --- a/code/src/Engine/ECS/Systems/ParticleSpawnerSystem.ts +++ b/code/src/Engine/ECS/Systems/ParticleSpawnerSystem.ts @@ -19,9 +19,7 @@ export default class ParticleSpawnerSystem extends System { e.getComponent(ComponentTypeEnum.POSITIONPARENT) ); if (posComp == undefined) { - posComp = ( - e.getComponent(ComponentTypeEnum.POSITION) - ); + posComp = e.getComponent(ComponentTypeEnum.POSITION); } if (particleComp) { diff --git a/code/src/Engine/Utils/ESCUtils.ts b/code/src/Engine/Utils/ESCUtils.ts index 22db8fb..4dfaf29 100644 --- a/code/src/Engine/Utils/ESCUtils.ts +++ b/code/src/Engine/Utils/ESCUtils.ts @@ -6,31 +6,33 @@ import Vec3 from "../Maths/Vec3"; export module ECSUtils { export function CalculatePosition(entity: Entity): Vec3 { - let posComp = entity.getComponent(ComponentTypeEnum.POSITION); - let posParentComp = entity.getComponent(ComponentTypeEnum.POSITIONPARENT); + let posComp = ( + entity.getComponent(ComponentTypeEnum.POSITION) + ); + let posParentComp = ( + entity.getComponent(ComponentTypeEnum.POSITIONPARENT) + ); - let tempMatrix = new Matrix4(null); - if (posComp == undefined) { - if (posParentComp == undefined) { - return null; - } + let tempMatrix = new Matrix4(null); + if (posComp == undefined) { + if (posParentComp == undefined) { + return null; + } - posParentComp.calculateMatrix(tempMatrix); - } - else { - if (posParentComp != undefined) { - posParentComp.calculateMatrix(tempMatrix); - } - posComp.calculateMatrix(tempMatrix); - } + posParentComp.calculateMatrix(tempMatrix); + } else { + if (posParentComp != undefined) { + posParentComp.calculateMatrix(tempMatrix); + } + posComp.calculateMatrix(tempMatrix); + } - let posVector = tempMatrix.multiplyVector4(new Vector4([0, 0, 0, 1])); - let pos = new Vec3() - .setValues( - posVector.elements[0], - posVector.elements[1], - posVector.elements[2] - ); - return pos; + let posVector = tempMatrix.multiplyVector4(new Vector4([0, 0, 0, 1])); + let pos = new Vec3().setValues( + posVector.elements[0], + posVector.elements[1], + posVector.elements[2] + ); + return pos; } } diff --git a/code/src/Game/PlayerCharacter.ts b/code/src/Game/PlayerCharacter.ts index 7e827e4..71a6cab 100644 --- a/code/src/Game/PlayerCharacter.ts +++ b/code/src/Game/PlayerCharacter.ts @@ -56,7 +56,10 @@ export default class PlayerCharacter { this.groupPositionComp.scale.setValues(0.25, 0.25, 0.25); this.bodyEntity = this.ecsManager.createEntity(); - this.ecsManager.addComponent(this.bodyEntity, new GraphicsComponent(bodyMesh)); + this.ecsManager.addComponent( + this.bodyEntity, + new GraphicsComponent(bodyMesh) + ); let posComp = new PositionComponent(); posComp.rotation.y = 90.0; this.ecsManager.addComponent(this.bodyEntity, posComp); @@ -84,13 +87,21 @@ export default class PlayerCharacter { nrOfFireParticles ); for (let i = 0; i < nrOfFireParticles; i++) { - let dir = new Vec3([Math.random() * 8.0 - 4.0, 7.0, Math.random() * 8.0 - 4.0]); + let dir = new Vec3([ + Math.random() * 8.0 - 4.0, + 7.0, + Math.random() * 8.0 - 4.0, + ]); fireParticles.setParticleData( i, new Vec3(), 0.1, dir, - new Vec3(dir).flip().multiply(10.0).setValues(null, 0.0, null).add(new Vec3([0.0, -8.0, 0.0])) + new Vec3(dir) + .flip() + .multiply(10.0) + .setValues(null, 0.0, null) + .add(new Vec3([0.0, -8.0, 0.0])) ); } fireParticles.sizeChangePerSecond = -0.2; @@ -170,7 +181,7 @@ export default class PlayerCharacter { // Handle rotation let targetRotation = 90 - Math.atan2(accVec.z, accVec.x) * (180 / Math.PI); - let diff = targetRotation - (this.groupPositionComp.rotation.y); + let diff = targetRotation - this.groupPositionComp.rotation.y; if (diff > 180) { diff -= 360; } else if (diff < -180) { @@ -230,10 +241,11 @@ export default class PlayerCharacter { ); } else if (input.joystickRightDirection.length2() > 0.0) { this.cameraFocusComp.offset.add( - new Vec3(this.rendering.camera.getRight()).multiply(dt * 8.0 * input.joystickRightDirection.x) + new Vec3(this.rendering.camera.getRight()).multiply( + dt * 8.0 * input.joystickRightDirection.x + ) ); - } - else if (this.movComp) { + } else if (this.movComp) { this.cameraFocusComp.offset.subtract( new Vec3(this.movComp.velocity).multiply(dt * 3.0) ); @@ -290,9 +302,7 @@ export default class PlayerCharacter { // } } - private resetAnimation() { - - } + private resetAnimation() {} private walkAnimation(animationSpeed: number = 7.5) { this.resetAnimation(); diff --git a/code/src/Game/States/Game.ts b/code/src/Game/States/Game.ts index 4b10b7c..7c12822 100644 --- a/code/src/Game/States/Game.ts +++ b/code/src/Game/States/Game.ts @@ -77,7 +77,11 @@ export default class Game extends State { dirLight.direction.setValues(0.2, -0.4, -0.7); dirLight.colour.setValues(0.1, 0.1, 0.4); - this.playerCharacter = new PlayerCharacter(this.scene, this.rendering, this.ecsManager); + this.playerCharacter = new PlayerCharacter( + this.scene, + this.rendering, + this.ecsManager + ); this.menuButton = this.overlayRendering.getNewButton(); this.menuButton.position.x = 0.9; @@ -144,13 +148,21 @@ export default class Game extends State { nrOfFireParticles ); for (let i = 0; i < nrOfFireParticles; i++) { - let dir = new Vec3([Math.random() * 8.0 - 4.0, 2.5, Math.random() * 8.0 - 4.0]); + let dir = new Vec3([ + Math.random() * 8.0 - 4.0, + 2.5, + Math.random() * 8.0 - 4.0, + ]); fireParticles.setParticleData( i, new Vec3(), 0.1, dir, - new Vec3(dir).flip().multiply(2.3).setValues(null, 0.0, null).add(new Vec3([0.0, 1.5, 0.0])) + new Vec3(dir) + .flip() + .multiply(2.3) + .setValues(null, 0.0, null) + .add(new Vec3([0.0, 1.5, 0.0])) ); } fireParticles.sizeChangePerSecond = -0.05; diff --git a/code/src/Game/States/Menu.ts b/code/src/Game/States/Menu.ts index 50027cc..a9901e7 100644 --- a/code/src/Game/States/Menu.ts +++ b/code/src/Game/States/Menu.ts @@ -58,7 +58,6 @@ export default class Menu extends State { async init() { super.init(); this.overlayRendering.show(); - } reset() {