Skip to content

Commit

Permalink
Removed EngineerMenuComponent. Modified forest game area for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandmcneilly committed Oct 15, 2023
1 parent 9d33fc9 commit ab7fc53
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ public void create() {

spawnScrap();
spawnGapScanners();
Entity engineer = EngineerFactory.createEngineer();
Entity engineer2= EngineerFactory.createEngineer();

spawnEntityAt(engineer, new GridPoint2(1, 4), true, true);
spawnEntityAt(engineer2, new GridPoint2(1, 5), true, true);


// spawnTNTTower();
// spawnWeaponTower();
Expand Down Expand Up @@ -971,9 +977,8 @@ private void spawnIncome() {
private void spawnGapScanners() {
GameTime gameTime = ServiceLocator.getTimeSource();
long currSpawnTime = gameTime.getTime();
long diff = currSpawnTime - this.lastSpawnTime;

// Don't spawn an engineer if not enough time has passed
long diff = currSpawnTime - this.lastSpawnTime;
if (diff < ENGINEER_MIN_SPAWN_INTERVAL) {
return;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.badlogic.gdx.audio.Sound;
import com.csse3200.game.components.Component;
import com.csse3200.game.components.npc.EngineerMenuComponent;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.ServiceLocator;

Expand Down Expand Up @@ -214,10 +213,7 @@ public void setClicked(boolean clicked) {
*/
public void deselectEngineer(String currentAnimation) {
AnimationRenderComponent animator = this.entity.getComponent(AnimationRenderComponent.class);
EngineerMenuComponent menu = this.entity.getComponent(EngineerMenuComponent.class);

animator.startAnimation(currentAnimation.substring(0, currentAnimation.lastIndexOf('_')));
menu.removeMenu();
setClicked(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.csse3200.game.ai.tasks.AITaskComponent;
import com.csse3200.game.components.CombatStatsComponent;
import com.csse3200.game.components.TouchAttackComponent;
import com.csse3200.game.components.npc.EngineerMenuComponent;
import com.csse3200.game.components.player.HumanAnimationController;
import com.csse3200.game.components.tasks.human.HumanWanderTask;
import com.csse3200.game.entities.Entity;
Expand Down Expand Up @@ -58,7 +57,6 @@ public static Entity createEngineer() {
.addComponent(new CombatStatsComponent(config.health, config.baseAttack))
.addComponent(animator)
.addComponent(new HumanAnimationController())
.addComponent(new EngineerMenuComponent())
.addComponent(aiComponent);

engineer.getComponent(AITaskComponent.class).addTask(new HumanWanderTask(COMBAT_TASK_PRIORITY, ENGINEER_RANGE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.csse3200.game.ai.tasks.AITaskComponent;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.ai.tasks.Task;
import com.csse3200.game.components.npc.EngineerMenuComponent;
import com.csse3200.game.components.player.HumanAnimationController;
import com.csse3200.game.components.tasks.human.HumanMovementTask;
import com.csse3200.game.components.tasks.human.HumanWanderTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.EntityService;
import com.csse3200.game.entities.factories.EngineerFactory;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.ServiceLocator;
Expand All @@ -28,7 +23,7 @@ public class EngineerInputComponent extends InputComponent {
private Camera camera;
private EntityService entityService;

private Entity selectedEngineer = null;
public Entity selectedEngineer = null;
private boolean moveClicked = false;

public EngineerInputComponent(Game game, Camera camera) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.csse3200.game.input;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.Camera;
import com.csse3200.game.components.player.HumanAnimationController;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.EntityService;
import com.csse3200.game.entities.factories.EngineerFactory;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.ServiceLocator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

public class EngineerInputComponentTest {
private EngineerInputComponent engineerInputComponent;


@BeforeEach
public void setup() {
EntityService mockEntityService = mock(EntityService.class);
ServiceLocator.registerEntityService(mockEntityService);

Camera mockCamera = mock(Camera.class);
Game game = mock(Game.class);
this.engineerInputComponent = new EngineerInputComponent(game, mockCamera);
}

@Test
public void testTouchDownWithNoSelectedEngineer() {
when(ServiceLocator.getEntityService().getEntityAtPositionLayer(anyFloat(), anyFloat(), anyShort())).thenReturn(null);
// nothing happened -> false
boolean result = engineerInputComponent.touchDown(0, 0, 0, 0);
assertFalse(result);
// no engineer should be selected
assertNull(engineerInputComponent.selectedEngineer);
}
}

0 comments on commit ab7fc53

Please sign in to comment.