diff --git a/.github/workflows/launch_tests.yaml b/.github/workflows/launch_tests.yaml index 5b910364c..efa6b383a 100644 --- a/.github/workflows/launch_tests.yaml +++ b/.github/workflows/launch_tests.yaml @@ -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: | @@ -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 diff --git a/source/core/src/main/com/csse3200/game/components/items/ItemActions.java b/source/core/src/main/com/csse3200/game/components/items/ItemActions.java index 95c7120fb..a09dfbf1d 100644 --- a/source/core/src/main/com/csse3200/game/components/items/ItemActions.java +++ b/source/core/src/main/com/csse3200/game/components/items/ItemActions.java @@ -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; @@ -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; } diff --git a/source/core/src/main/com/csse3200/game/components/ship/ShipAnimationController.java b/source/core/src/main/com/csse3200/game/components/ship/ShipAnimationController.java index db3657505..737936bdd 100644 --- a/source/core/src/main/com/csse3200/game/components/ship/ShipAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/ship/ShipAnimationController.java @@ -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; /** @@ -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); } /** diff --git a/source/core/src/main/com/csse3200/game/components/ship/ShipLightComponent.java b/source/core/src/main/com/csse3200/game/components/ship/ShipLightComponent.java index aeb663e40..5769099cb 100644 --- a/source/core/src/main/com/csse3200/game/components/ship/ShipLightComponent.java +++ b/source/core/src/main/com/csse3200/game/components/ship/ShipLightComponent.java @@ -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; @@ -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); } diff --git a/source/core/src/main/com/csse3200/game/components/ship/ShipProgressComponent.java b/source/core/src/main/com/csse3200/game/components/ship/ShipProgressComponent.java index 1024c54c5..f289436ea 100644 --- a/source/core/src/main/com/csse3200/game/components/ship/ShipProgressComponent.java +++ b/source/core/src/main/com/csse3200/game/components/ship/ShipProgressComponent.java @@ -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; @@ -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); } /** @@ -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()); } } diff --git a/source/core/src/main/com/csse3200/game/components/ship/ShipTimeSkipComponent.java b/source/core/src/main/com/csse3200/game/components/ship/ShipTimeSkipComponent.java index 209b3036c..02f3cf6eb 100644 --- a/source/core/src/main/com/csse3200/game/components/ship/ShipTimeSkipComponent.java +++ b/source/core/src/main/com/csse3200/game/components/ship/ShipTimeSkipComponent.java @@ -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; @@ -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); diff --git a/source/core/src/main/com/csse3200/game/entities/factories/ShipFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/ShipFactory.java index 0ecaeb63f..a998144cb 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/ShipFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/ShipFactory.java @@ -15,6 +15,12 @@ public class ShipFactory { + public enum events { + ADD_PART, + REMOVE_PART, + PROGRESS_UPDATED + } + /** * Creates a ship entity * diff --git a/source/core/src/test/com/csse3200/game/components/ship/ShipAnimationControllerTest.java b/source/core/src/test/com/csse3200/game/components/ship/ShipAnimationControllerTest.java index 3ccd46a1d..bfaffbbf8 100644 --- a/source/core/src/test/com/csse3200/game/components/ship/ShipAnimationControllerTest.java +++ b/source/core/src/test/com/csse3200/game/components/ship/ShipAnimationControllerTest.java @@ -55,14 +55,14 @@ void shouldUpdateAnimationOnProgressUpdate(String animationEvent, int progress, private static Stream 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")); } } diff --git a/source/core/src/test/com/csse3200/game/components/ship/ShipProgressComponentTest.java b/source/core/src/test/com/csse3200/game/components/ship/ShipProgressComponentTest.java index edb765b58..a1e1351d2 100644 --- a/source/core/src/test/com/csse3200/game/components/ship/ShipProgressComponentTest.java +++ b/source/core/src/test/com/csse3200/game/components/ship/ShipProgressComponentTest.java @@ -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; @@ -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)); @@ -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)); } diff --git a/source/core/src/test/com/csse3200/game/components/ship/ShipTimeSkipComponentTest.java b/source/core/src/test/com/csse3200/game/components/ship/ShipTimeSkipComponentTest.java index 6d450143c..b8b495b2f 100644 --- a/source/core/src/test/com/csse3200/game/components/ship/ShipTimeSkipComponentTest.java +++ b/source/core/src/test/com/csse3200/game/components/ship/ShipTimeSkipComponentTest.java @@ -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; @@ -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");