From 22fdf1e4ac29237751557387b12b8ab78e542223 Mon Sep 17 00:00:00 2001 From: William Muir Date: Fri, 22 Sep 2017 21:00:28 +1200 Subject: [PATCH] Changed the boatType attribute from all around the place from String lit to enum #story[1274] --- src/main/java/seng302/gameServer/GameState.java | 3 ++- .../seng302/gameServer/ServerToClientThread.java | 3 ++- src/main/java/seng302/model/ClientYacht.java | 7 ++++--- src/main/java/seng302/model/ServerYacht.java | 9 +++++---- src/main/java/seng302/utilities/XMLParser.java | 3 ++- src/main/java/seng302/visualiser/GameView3D.java | 2 +- .../visualiser/controllers/cells/PlayerCell.java | 2 +- .../dialogs/BoatCustomizeController.java | 4 ++-- .../fxObjects/assets_3D/BoatMeshType.java | 13 ------------- src/test/java/seng302/model/UpdateYachtTest.java | 7 +++++-- src/test/java/seng302/models/YachtTest.java | 3 ++- .../java/seng302/utilities/BoatMeshTypeTest.java | 7 ------- .../visualiser/map/BoatSailAnimationToggleTest.java | 3 ++- 13 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/main/java/seng302/gameServer/GameState.java b/src/main/java/seng302/gameServer/GameState.java index 41c619b7..8ff2556c 100644 --- a/src/main/java/seng302/gameServer/GameState.java +++ b/src/main/java/seng302/gameServer/GameState.java @@ -18,6 +18,7 @@ import seng302.utilities.XMLParser; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.util.*; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; /** * A Static class to hold information about the current state of the game (model) @@ -704,7 +705,7 @@ public class GameState implements Runnable { playerYacht.setBoatColor(yachtColor); } else if (requestType.equals(CustomizeRequestType.SHAPE)) { String type = new String(customizeData); - playerYacht.setBoatType(type); + playerYacht.setBoatType(BoatMeshType.valueOf(type)); } } diff --git a/src/main/java/seng302/gameServer/ServerToClientThread.java b/src/main/java/seng302/gameServer/ServerToClientThread.java index 728e6adb..eb5a9ad0 100644 --- a/src/main/java/seng302/gameServer/ServerToClientThread.java +++ b/src/main/java/seng302/gameServer/ServerToClientThread.java @@ -33,6 +33,7 @@ import seng302.model.stream.packets.PacketType; import seng302.model.stream.packets.StreamPacket; import seng302.model.stream.xml.generator.RaceXMLTemplate; import seng302.utilities.XMLGenerator; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; /** * A class describing a single connection to a Client for the purposes of sending and receiving on @@ -125,7 +126,7 @@ public class ServerToClientThread implements Runnable { lName = all.get(ThreadLocalRandom.current().nextInt(0, all.size())); ServerYacht yacht = new ServerYacht( - "DINGHY", sourceId, sourceId.toString(), fName, fName + " " + lName, "NZ" + BoatMeshType.DINGHY, sourceId, sourceId.toString(), fName, fName + " " + lName, "NZ" ); player = new Player(socket, yacht); diff --git a/src/main/java/seng302/model/ClientYacht.java b/src/main/java/seng302/model/ClientYacht.java index 1ebaa3fc..2bc1ed91 100644 --- a/src/main/java/seng302/model/ClientYacht.java +++ b/src/main/java/seng302/model/ClientYacht.java @@ -15,6 +15,7 @@ import javafx.beans.property.ReadOnlyLongWrapper; import javafx.scene.paint.Color; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; /** * Yacht class for the racing boat.

Class created to store more variables (eg. boat statuses) @@ -37,7 +38,7 @@ public class ClientYacht extends Observable { private Logger logger = LoggerFactory.getLogger(ClientYacht.class); - private String boatType; + private BoatMeshType boatType; private Integer sourceId; private String hullID; //matches HullNum in the XML spec. private String shortName; @@ -64,7 +65,7 @@ public class ClientYacht extends Observable { private ReadOnlyIntegerWrapper placingProperty = new ReadOnlyIntegerWrapper(); private Color colour; - public ClientYacht(String boatType, Integer sourceId, String hullID, String shortName, + public ClientYacht(BoatMeshType boatType, Integer sourceId, String hullID, String shortName, String boatName, String country) { this.boatType = boatType; this.sourceId = sourceId; @@ -88,7 +89,7 @@ public class ClientYacht extends Observable { super.addObserver(o); } - public String getBoatType() { + public BoatMeshType getBoatType() { return boatType; } diff --git a/src/main/java/seng302/model/ServerYacht.java b/src/main/java/seng302/model/ServerYacht.java index 99314776..e7d936ca 100644 --- a/src/main/java/seng302/model/ServerYacht.java +++ b/src/main/java/seng302/model/ServerYacht.java @@ -12,6 +12,7 @@ import seng302.utilities.GeoUtility; import java.util.HashMap; import java.util.Observable; import java.util.Observer; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; /** * Yacht class for the racing boat.

Class created to store more variables (eg. boat statuses) @@ -25,7 +26,7 @@ public class ServerYacht { public static final Double TURN_STEP = 5.0; //Boat info - private String boatType; + private BoatMeshType boatType; private Integer sourceId; private String hullID; //matches HullNum in the XML spec. private String shortName; @@ -57,7 +58,7 @@ public class ServerYacht { private Long powerUpStartTime; - public ServerYacht(String boatType, Integer sourceId, String hullID, String shortName, + public ServerYacht(BoatMeshType boatType, Integer sourceId, String hullID, String shortName, String boatName, String country) { this.boatType = boatType; this.boatStatus = BoatStatus.PRESTART; @@ -421,11 +422,11 @@ public class ServerYacht { return boatColor; } - public void setBoatType(String boatType) { + public void setBoatType(BoatMeshType boatType) { this.boatType = boatType; } - public String getBoatType() { + public BoatMeshType getBoatType() { return boatType; } } diff --git a/src/main/java/seng302/utilities/XMLParser.java b/src/main/java/seng302/utilities/XMLParser.java index 7a8bbac4..71da1248 100644 --- a/src/main/java/seng302/utilities/XMLParser.java +++ b/src/main/java/seng302/utilities/XMLParser.java @@ -18,6 +18,7 @@ import seng302.model.stream.xml.parser.RaceXMLData; import seng302.model.stream.xml.parser.RegattaXMLData; import seng302.model.token.Token; import seng302.model.token.TokenType; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; /** * Utilities for parsing XML documents @@ -139,7 +140,7 @@ public class XMLParser { if (currentBoat.getNodeName().equals("Boat")) { // Boat boat = new Boat(currentBoat); ClientYacht yacht = new ClientYacht( - XMLParser.getNodeAttributeString(currentBoat, "Type"), + BoatMeshType.valueOf(XMLParser.getNodeAttributeString(currentBoat, "Type")), XMLParser.getNodeAttributeInt(currentBoat, "SourceID"), XMLParser.getNodeAttributeString(currentBoat, "HullNum"), XMLParser.getNodeAttributeString(currentBoat, "ShortName"), diff --git a/src/main/java/seng302/visualiser/GameView3D.java b/src/main/java/seng302/visualiser/GameView3D.java index 73815023..63d0203d 100644 --- a/src/main/java/seng302/visualiser/GameView3D.java +++ b/src/main/java/seng302/visualiser/GameView3D.java @@ -460,7 +460,7 @@ public class GameView3D { final List wakes = new ArrayList<>(); for (ClientYacht clientYacht : yachts) { Color colour = clientYacht.getColour(); - newBoat = new BoatObject(BoatMeshType.getBoatMeshType(clientYacht.getBoatType())); + newBoat = new BoatObject(clientYacht.getBoatType()); newBoat.setFill(colour); boatObjects.put(clientYacht, newBoat); wakesGroup.getChildren().add(newBoat.getWake()); diff --git a/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java b/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java index adba9968..21bd6644 100644 --- a/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java +++ b/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java @@ -31,7 +31,7 @@ public class PlayerCell { this.playerId = playerId; this.name = yacht.getBoatName(); this.boatColor = yacht.getColour(); - this.boatType = BoatMeshType.getBoatMeshType(yacht.getBoatType()); + this.boatType = yacht.getBoatType(); } public void initialize() { diff --git a/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java b/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java index 9926cc27..4b02ac9a 100644 --- a/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java +++ b/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java @@ -111,8 +111,8 @@ public class BoatCustomizeController implements Initializable{ this.lobbyController = lobbyController; } - public void setCurrentBoat(String boatType) { - currentBoat = BoatMeshType.getBoatMeshType(boatType); + public void setCurrentBoat(BoatMeshType boatType) { + currentBoat = boatType; displayCurrentBoat(); } diff --git a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java index 947a63f5..65c9714c 100644 --- a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java +++ b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java @@ -29,19 +29,6 @@ public enum BoatMeshType { this.fixedSail = fixedSail; } - public static BoatMeshType getBoatMeshType(String boatType) { - switch (boatType){ - case "DINGHY": - return DINGHY; - case "CAT_ATE_A_MERINGUE": - return CAT_ATE_A_MERINGUE; - case "PIRATE_SHIP": - return PIRATE_SHIP; - default: - return DINGHY; - } - } - //TODO kre39 make something not terrible to cycle through boat types public static BoatMeshType getNextBoatType(BoatMeshType boatType) { diff --git a/src/test/java/seng302/model/UpdateYachtTest.java b/src/test/java/seng302/model/UpdateYachtTest.java index 7eaaf990..79c02cb2 100644 --- a/src/test/java/seng302/model/UpdateYachtTest.java +++ b/src/test/java/seng302/model/UpdateYachtTest.java @@ -5,6 +5,7 @@ import org.junit.Before; import org.junit.Test; import seng302.gameServer.GameState; import seng302.utilities.GeoUtility; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; import static seng302.gameServer.GameState.checkCollision; @@ -14,8 +15,10 @@ import static seng302.gameServer.GameState.checkCollision; */ public class UpdateYachtTest { - private ServerYacht yacht1 = new ServerYacht("Yacht", 1, "1", "Yacht" + 1, "Yacht" + 1, "Test1"); - private ServerYacht yacht2 = new ServerYacht("Yacht", 2, "2", "Yacht" + 2, "Yacht" + 2, "Test2"); + private ServerYacht yacht1 = new ServerYacht(BoatMeshType.DINGHY, 1, "1", "Yacht" + 1, + "Yacht" + 1, "Test1"); + private ServerYacht yacht2 = new ServerYacht(BoatMeshType.DINGHY, 2, "2", "Yacht" + 2, + "Yacht" + 2, "Test2"); private GeoPoint geoPoint1 = new GeoPoint(50.0, 50.0); private GeoPoint geoPoint2 = GeoUtility.getGeoCoordinate(geoPoint1, 90.0, 50.0); diff --git a/src/test/java/seng302/models/YachtTest.java b/src/test/java/seng302/models/YachtTest.java index 3f342ff5..b73dc61c 100644 --- a/src/test/java/seng302/models/YachtTest.java +++ b/src/test/java/seng302/models/YachtTest.java @@ -4,6 +4,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import seng302.gameServer.GameState; import seng302.model.ServerYacht; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; public class YachtTest { @@ -17,7 +18,7 @@ public class YachtTest { @BeforeClass public static void setUp() { new GameState("localhost"); - y1 = new ServerYacht("Yacht", 1, "Y1", "Y1", "Yacht 1", "C1"); + y1 = new ServerYacht(BoatMeshType.DINGHY, 1, "Y1", "Y1", "Yacht 1", "C1"); gs = new GameState("localhost"); } diff --git a/src/test/java/seng302/utilities/BoatMeshTypeTest.java b/src/test/java/seng302/utilities/BoatMeshTypeTest.java index baca1b14..743c7f1e 100644 --- a/src/test/java/seng302/utilities/BoatMeshTypeTest.java +++ b/src/test/java/seng302/utilities/BoatMeshTypeTest.java @@ -25,11 +25,4 @@ public class BoatMeshTypeTest { Assert.assertEquals(BoatMeshType.DINGHY, prevBoat); } - @Test - public void testGetBoatMeshType() { - BoatMeshType currentBoat = BoatMeshType.getBoatMeshType("DINGHY"); - Assert.assertEquals(BoatMeshType.DINGHY, currentBoat); - BoatMeshType wrongBoat = BoatMeshType.getBoatMeshType("NOT A REAL BOAT"); - Assert.assertEquals(BoatMeshType.DINGHY, wrongBoat); - } } diff --git a/src/test/java/seng302/visualiser/map/BoatSailAnimationToggleTest.java b/src/test/java/seng302/visualiser/map/BoatSailAnimationToggleTest.java index 70c5c80b..9e95f169 100644 --- a/src/test/java/seng302/visualiser/map/BoatSailAnimationToggleTest.java +++ b/src/test/java/seng302/visualiser/map/BoatSailAnimationToggleTest.java @@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; import seng302.model.ClientYacht; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; /** * Created by kre39 on 6/08/17. @@ -16,7 +17,7 @@ public class BoatSailAnimationToggleTest { @Before public void setup() throws Exception{ - yacht = new ClientYacht("Yacht", 1, "YACHT", "YAC", "Test Yacht", "NZ"); + yacht = new ClientYacht(BoatMeshType.DINGHY, 1, "YACHT", "YAC", "Test Yacht", "NZ"); } @Test