Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ship-related event names #625

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/launch_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: '17'

- name: Run Launch Test
id: tests # Unique ID to reference later to color our message
run: |
Expand All @@ -24,10 +23,12 @@ jobs:
GRADLE_DIR: 'source' # Modify this to wherever './gradlew' is
- name: Archive game screenshot
uses: actions/upload-artifact@v3
if: always()
with:
name: game-screenshot
path: source/game_launched.xwd
- name: Archive logs
if: always()
uses: actions/upload-artifact@v3
with:
name: logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.function.Supplier;

import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.entities.factories.ShipFactory;
import com.csse3200.game.services.sound.EffectSoundFile;
import com.csse3200.game.areas.terrain.CropTileComponent;
import com.csse3200.game.areas.terrain.TerrainTile;
Expand Down Expand Up @@ -572,7 +573,7 @@ private boolean repair(Entity player, Vector2 mouseWorldPos) {
return false;
}
if (ship.getType() == EntityType.SHIP) {
ship.getEvents().trigger("addPart", 1);
ship.getEvents().trigger(ShipFactory.events.ADD_PART.name(), 1);
player.getComponent(InventoryComponent.class).removeItem(entity);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.badlogic.gdx.utils.JsonValue;
import com.csse3200.game.components.Component;
import com.csse3200.game.components.ship.ShipProgressComponent.Feature;
import com.csse3200.game.entities.factories.ShipFactory;
import com.csse3200.game.rendering.AnimationRenderComponent;

/**
Expand All @@ -24,7 +25,7 @@ public class ShipAnimationController extends Component {
public void create() {
super.create();
animator = this.entity.getComponent(AnimationRenderComponent.class);
entity.getEvents().addListener("progressUpdated", this::animateShipStage);
entity.getEvents().addListener(ShipFactory.events.PROGRESS_UPDATED.name(), this::animateShipStage);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonValue;
import com.csse3200.game.components.AuraLightComponent;
import com.csse3200.game.entities.factories.ShipFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -24,7 +25,7 @@ public ShipLightComponent() {
public void create() {
unlocked = false;

entity.getEvents().addListener("progressUpdated", this::progressUpdated);
entity.getEvents().addListener(ShipFactory.events.PROGRESS_UPDATED.name(), this::progressUpdated);
entity.getEvents().addListener("interact", this::toggleLight);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonValue;
import com.csse3200.game.components.Component;
import com.csse3200.game.entities.factories.ShipFactory;
import com.csse3200.game.missions.MissionManager;
import com.csse3200.game.services.ServiceLocator;

Expand Down Expand Up @@ -42,8 +43,8 @@ public void create() {
this.progress = 0;
unlockedFeatures = new HashSet<>();
// listen to add part call
entity.getEvents().addListener("addPart", this::incrementProgress);
entity.getEvents().addListener("removePart", this::decrementProgress);
entity.getEvents().addListener(ShipFactory.events.ADD_PART.name(), this::incrementProgress);
entity.getEvents().addListener(ShipFactory.events.REMOVE_PART.name(), this::decrementProgress);
}

/**
Expand All @@ -63,7 +64,7 @@ private void incrementProgress(int amount) {
}

// Only send progress update if repair actually happened
entity.getEvents().trigger("progressUpdated", this.progress, this.unlockedFeatures);
entity.getEvents().trigger(ShipFactory.events.PROGRESS_UPDATED.name(), this.progress, this.unlockedFeatures);
ServiceLocator.getMissionManager().getEvents().trigger(MissionManager.MissionEvent.SHIP_PART_ADDED.name());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.badlogic.gdx.utils.JsonValue;
import com.csse3200.game.components.Component;
import com.csse3200.game.components.ship.ShipProgressComponent.Feature;
import com.csse3200.game.entities.factories.ShipFactory;
import com.csse3200.game.services.ServiceLocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -25,7 +26,7 @@ public void create() {
unlocked = false;
timeSkipInProgress = false;

entity.getEvents().addListener("progressUpdated", this::progressUpdated);
entity.getEvents().addListener(ShipFactory.events.PROGRESS_UPDATED.name(), this::progressUpdated);
entity.getEvents().addListener("interact", this::triggerTimeSkip);

ServiceLocator.getTimeService().getEvents().addListener("morningTime", this::stopTimeSkip);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

public class ShipFactory {

public enum events {
ADD_PART,
REMOVE_PART,
PROGRESS_UPDATED
}

/**
* Creates a ship entity
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ void shouldUpdateAnimationOnProgressUpdate(String animationEvent, int progress,
private static Stream<Arguments> shouldUpdateAnimationOnProgressUpdate() {
return Stream.of(
// (animationEvent, progress, expectedAnimationName)
arguments("progressUpdated", -10, "default"),
arguments("progressUpdated", 0, "ship_0"),
arguments("progressUpdated", 4, "ship_1"),
arguments("progressUpdated", 6, "ship_2"),
arguments("progressUpdated", 10, "ship_3"),
arguments("progressUpdated", 12, "ship_3"),
arguments("progressUpdated", 16, "ship_4"),
arguments("progressUpdated", 20, "ship_5"),
arguments("progressUpdated", 30, "ship_5"));
arguments(ShipFactory.events.PROGRESS_UPDATED.name(), -10, "default"),
arguments(ShipFactory.events.PROGRESS_UPDATED.name(), 0, "ship_0"),
arguments(ShipFactory.events.PROGRESS_UPDATED.name(), 4, "ship_1"),
arguments(ShipFactory.events.PROGRESS_UPDATED.name(), 6, "ship_2"),
arguments(ShipFactory.events.PROGRESS_UPDATED.name(), 10, "ship_3"),
arguments(ShipFactory.events.PROGRESS_UPDATED.name(), 12, "ship_3"),
arguments(ShipFactory.events.PROGRESS_UPDATED.name(), 16, "ship_4"),
arguments(ShipFactory.events.PROGRESS_UPDATED.name(), 20, "ship_5"),
arguments(ShipFactory.events.PROGRESS_UPDATED.name(), 30, "ship_5"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.spy;

import com.csse3200.game.entities.factories.ShipFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -26,20 +27,20 @@ void initialiseTest() {

@Test()
void testIncrement() {
ship.getEvents().trigger("addPart", 1);
ship.getEvents().trigger(ShipFactory.events.ADD_PART.name(), 1);
assertEquals(shipProgressComponent.getProgress(), 1);
assertEquals(shipProgressComponent.getUnlockedFeatures().size(), 0);

ship.getEvents().trigger("addPart", 2);
ship.getEvents().trigger(ShipFactory.events.ADD_PART.name(), 2);
assertEquals(shipProgressComponent.getProgress(), 3);
assertTrue(shipProgressComponent.getUnlockedFeatures().contains(ShipProgressComponent.Feature.BED));

ship.getEvents().trigger("addPart", 5);
ship.getEvents().trigger(ShipFactory.events.ADD_PART.name(), 5);
assertEquals(shipProgressComponent.getProgress(), 8);
assertTrue(shipProgressComponent.getUnlockedFeatures().contains(ShipProgressComponent.Feature.BED));
assertTrue(shipProgressComponent.getUnlockedFeatures().contains(ShipProgressComponent.Feature.LIGHT));

ship.getEvents().trigger("addPart", 7);
ship.getEvents().trigger(ShipFactory.events.ADD_PART.name(), 7);
assertEquals(shipProgressComponent.getProgress(), 15);
assertTrue(shipProgressComponent.getUnlockedFeatures().contains(ShipProgressComponent.Feature.BED));
assertTrue(shipProgressComponent.getUnlockedFeatures().contains(ShipProgressComponent.Feature.LIGHT));
Expand All @@ -49,11 +50,11 @@ void testIncrement() {
@Test()
void testDecrement() {
// Start by unlocking all features
ship.getEvents().trigger("addPart", 15);
ship.getEvents().trigger("removePart", 5);
ship.getEvents().trigger(ShipFactory.events.ADD_PART.name(), 15);
ship.getEvents().trigger(ShipFactory.events.REMOVE_PART.name(), 5);
// Ensure the feature remains unlocked
assertTrue(shipProgressComponent.getUnlockedFeatures().contains(ShipProgressComponent.Feature.STORAGE));
ship.getEvents().trigger("removePart", 10);
ship.getEvents().trigger(ShipFactory.events.REMOVE_PART.name(), 10);
assertTrue(shipProgressComponent.getUnlockedFeatures().contains(ShipProgressComponent.Feature.BED));
assertTrue(shipProgressComponent.getUnlockedFeatures().contains(ShipProgressComponent.Feature.LIGHT));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.csse3200.game.components.ship;

import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.ShipFactory;
import com.csse3200.game.extensions.GameExtension;
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ServiceLocator;
Expand Down Expand Up @@ -56,7 +57,7 @@ void updatesTimeWhenUnlocked(int initialDay, int initialHour, int initialMinute,
verify(mockTimeSource, times(0)).setTimeScale(200f);

// unlock the feature
testEntity.getEvents().trigger("progressUpdated", 4, new HashSet<>(List.of(ShipProgressComponent.Feature.BED)));
testEntity.getEvents().trigger(ShipFactory.events.PROGRESS_UPDATED.name(), 4, new HashSet<>(List.of(ShipProgressComponent.Feature.BED)));

// should trigger a time change now
testEntity.getEvents().trigger("interact");
Expand Down