diff --git a/src/main/java/seng302/gameServer/GameState.java b/src/main/java/seng302/gameServer/GameState.java index 0b495a8e..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) @@ -702,6 +703,9 @@ public class GameState implements Runnable { int blue = customizeData[2] & 0xFF; Color yachtColor = Color.rgb(red, green, blue); playerYacht.setBoatColor(yachtColor); + } else if (requestType.equals(CustomizeRequestType.SHAPE)) { + String type = new String(customizeData); + playerYacht.setBoatType(BoatMeshType.valueOf(type)); } } diff --git a/src/main/java/seng302/gameServer/ServerToClientThread.java b/src/main/java/seng302/gameServer/ServerToClientThread.java index 1138f53d..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( - "Yacht", 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 89715852..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; @@ -46,7 +47,7 @@ public class ClientYacht extends Observable { private Integer position; private Long estimateTimeAtFinish; - private Boolean sailIn = false; + private Boolean sailIn = true; private Integer currentMarkSeqID = 0; private Long markRoundTime; private Long timeTillNext; @@ -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 f2d54538..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) @@ -20,12 +21,12 @@ import java.util.Observer; */ public class ServerYacht { - private Logger logger = LoggerFactory.getLogger(ClientYacht.class); + private Logger logger = LoggerFactory.getLogger(ServerYacht.class); 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,4 +422,11 @@ public class ServerYacht { return boatColor; } + public void setBoatType(BoatMeshType boatType) { + this.boatType = boatType; + } + + public BoatMeshType getBoatType() { + return boatType; + } } diff --git a/src/main/java/seng302/utilities/XMLParser.java b/src/main/java/seng302/utilities/XMLParser.java index a903daaf..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,16 +140,14 @@ 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"), XMLParser.getNodeAttributeString(currentBoat, "BoatName"), XMLParser.getNodeAttributeString(currentBoat, "Country")); yacht.setColour(Color.web(getNodeAttributeString(currentBoat, "Color"))); - if (yacht.getBoatType().equals("Yacht")) { - competingBoats.put(yacht.getSourceId(), yacht); - } + competingBoats.put(yacht.getSourceId(), yacht); } } return competingBoats; diff --git a/src/main/java/seng302/visualiser/GameView3D.java b/src/main/java/seng302/visualiser/GameView3D.java index c5b52286..63d0203d 100644 --- a/src/main/java/seng302/visualiser/GameView3D.java +++ b/src/main/java/seng302/visualiser/GameView3D.java @@ -30,6 +30,7 @@ import seng302.model.token.Token; import seng302.utilities.GeoUtility; import seng302.utilities.Sounds; import seng302.visualiser.fxObjects.MarkArrowFactory; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; import seng302.visualiser.fxObjects.assets_3D.BoatObject; import seng302.visualiser.fxObjects.assets_3D.Marker3D; import seng302.visualiser.fxObjects.assets_3D.ModelFactory; @@ -459,7 +460,7 @@ public class GameView3D { final List wakes = new ArrayList<>(); for (ClientYacht clientYacht : yachts) { Color colour = clientYacht.getColour(); - newBoat = new BoatObject(); + newBoat = new BoatObject(clientYacht.getBoatType()); newBoat.setFill(colour); boatObjects.put(clientYacht, newBoat); wakesGroup.getChildren().add(newBoat.getWake()); @@ -568,6 +569,7 @@ public class GameView3D { } public void setBoatAsPlayer (ClientYacht playerYacht) { + playerYacht.toggleSail(); playerBoatAnimationTimer = new AnimationTimer() { double count = 60; diff --git a/src/main/java/seng302/visualiser/controllers/LobbyController.java b/src/main/java/seng302/visualiser/controllers/LobbyController.java index bbb39f75..67b1dfbd 100644 --- a/src/main/java/seng302/visualiser/controllers/LobbyController.java +++ b/src/main/java/seng302/visualiser/controllers/LobbyController.java @@ -33,6 +33,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.ResourceBundle; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; public class LobbyController implements Initializable { @@ -129,6 +130,8 @@ public class LobbyController implements Initializable { controller.setPlayerName(this.playerBoats .get(ViewManager.getInstance().getGameClient().getServerThread().getClientId()) .getBoatName()); + controller.setCurrentBoat(this.playerBoats.get(ViewManager.getInstance().getGameClient().getServerThread().getClientId()) + .getBoatType()); return customizationDialog; } @@ -202,7 +205,7 @@ public class LobbyController implements Initializable { FXMLLoader loader = new FXMLLoader( getClass().getResource("/views/cells/PlayerCell.fxml")); - loader.setController(new PlayerCell(playerId, yacht.getBoatName(), yacht.getColour())); + loader.setController(new PlayerCell(playerId, yacht)); try { pane = loader.load(); diff --git a/src/main/java/seng302/visualiser/controllers/ViewManager.java b/src/main/java/seng302/visualiser/controllers/ViewManager.java index 165d0c39..8e966813 100644 --- a/src/main/java/seng302/visualiser/controllers/ViewManager.java +++ b/src/main/java/seng302/visualiser/controllers/ViewManager.java @@ -278,6 +278,8 @@ public class ViewManager { stage.setMinHeight(500); stage.setMinWidth(800); + stage.setTitle("Party Parrots At Sea"); + stage.getIcons().add(new Image(getClass().getResourceAsStream("/PP.png"))); stage.setOnCloseRequest(e -> closeAll()); stage.setScene(scene); stage.show(); diff --git a/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java b/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java index 6fb35708..21bd6644 100644 --- a/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java +++ b/src/main/java/seng302/visualiser/controllers/cells/PlayerCell.java @@ -6,6 +6,7 @@ import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; +import seng302.model.ClientYacht; import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; import seng302.visualiser.fxObjects.assets_3D.BoatModel; import seng302.visualiser.fxObjects.assets_3D.ModelFactory; @@ -24,11 +25,13 @@ public class PlayerCell { private String name; private Color boatColor; private Integer playerId; + private BoatMeshType boatType; - public PlayerCell(Integer playerId, String playerName, Color color) { + public PlayerCell(Integer playerId, ClientYacht yacht) { this.playerId = playerId; - this.name = playerName; - this.boatColor = color; + this.name = yacht.getBoatName(); + this.boatColor = yacht.getColour(); + this.boatType = yacht.getBoatType(); } public void initialize() { @@ -37,7 +40,7 @@ public class PlayerCell { // Add Rotating Boat to Player Cell with players color on it. Group group = new Group(); boatPane.getChildren().add(group); - BoatModel bo = ModelFactory.boatIconView(BoatMeshType.DINGHY, this.boatColor); + BoatModel bo = ModelFactory.boatIconView(boatType, boatColor); group.getChildren().add(bo.getAssets()); } diff --git a/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java b/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java index 339f08b8..4b02ac9a 100644 --- a/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java +++ b/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java @@ -6,15 +6,24 @@ import com.jfoenix.controls.JFXTextField; import com.jfoenix.validation.RequiredFieldValidator; import java.net.URL; import java.util.ResourceBundle; -import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; +import javafx.geometry.Insets; +import javafx.scene.Group; +import javafx.scene.PointLight; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.CornerRadii; +import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import seng302.gameServer.messages.CustomizeRequestType; import seng302.utilities.Sounds; import seng302.visualiser.ClientToServerThread; import seng302.visualiser.controllers.LobbyController; import seng302.visualiser.controllers.ViewManager; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; +import seng302.visualiser.fxObjects.assets_3D.BoatModel; +import seng302.visualiser.fxObjects.assets_3D.ModelFactory; import seng302.visualiser.validators.FieldLengthValidator; import seng302.visualiser.validators.ValidationTools; @@ -28,13 +37,16 @@ public class BoatCustomizeController implements Initializable{ @FXML private JFXTextField boatName; @FXML - void colorChanged(ActionEvent event) { - Color color = colorPicker.getValue(); + private Pane boatPane; + @FXML + void colorChanged() { + refreshBoat(); } //---------FXML END---------// private ClientToServerThread socketThread; private LobbyController lobbyController; + private BoatMeshType currentBoat; @Override public void initialize(URL location, ResourceBundle resources) { @@ -48,6 +60,8 @@ public class BoatCustomizeController implements Initializable{ playerNameLengthValidator.setMessage("Player name too long."); boatName.setValidators(playerNameLengthValidator, playerNameReqValidator); + boatPane.setBackground( + new Background(new BackgroundFill(Color.SKYBLUE, CornerRadii.EMPTY, Insets.EMPTY))); submitBtn.setOnMouseReleased(event -> { Sounds.playButtonClick(); @@ -78,7 +92,10 @@ public class BoatCustomizeController implements Initializable{ colorArray[2] = (byte) blue; socketThread.sendCustomizationRequest(CustomizeRequestType.COLOR, colorArray); + socketThread.sendCustomizationRequest(CustomizeRequestType.SHAPE, currentBoat.toString().getBytes()); lobbyController.closeCustomizationDialog(); + + } } @@ -93,4 +110,36 @@ public class BoatCustomizeController implements Initializable{ public void setParentController(LobbyController lobbyController){ this.lobbyController = lobbyController; } + + public void setCurrentBoat(BoatMeshType boatType) { + currentBoat = boatType; + displayCurrentBoat(); + } + + public void nextBoat() { + currentBoat = BoatMeshType.getNextBoatType(currentBoat); + displayCurrentBoat(); + } + + public void prevBoat() { + currentBoat = BoatMeshType.getPrevBoatType(currentBoat); + displayCurrentBoat(); + } + + private void displayCurrentBoat() { + boatPane.getChildren().clear(); + Group group = new Group(); + boatPane.getChildren().add(group); + BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); + group.getChildren().add(bo.getAssets()); + group.getChildren().add(new PointLight()); + } + + private void refreshBoat() { + boatPane.getChildren().clear(); + Group group = new Group(); + boatPane.getChildren().add(group); + BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); + group.getChildren().add(bo.getAssets()); + } } 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 9b74aa69..65c9714c 100644 --- a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java +++ b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java @@ -2,21 +2,54 @@ package seng302.visualiser.fxObjects.assets_3D; /** * Enum for boat meshes. Enum values should be of the form : - * ENUM_VALUE (hull file, mast file, Y offset of mast CoR from origin, sail file, Y offset of sail CoR from origin) + * ENUM_VALUE (hull file, mast file, Y offset of mast CoR from origin, sail file, Y offset of sail CoR from origin, jib file, fixed sail) * Files must be valid .stl files. */ public enum BoatMeshType { - DINGHY ("dinghy_hull.stl", "dinghy_mast.stl", -1.36653, "dinghy_sail.stl", -1.36653); + DINGHY("dinghy_hull.stl", "dinghy_mast.stl", 1.36653, "dinghy_sail.stl", 1.36653, null, false), + CAT_ATE_A_MERINGUE("catamaran_hull.stl", "catamaran_mast.stl", 0.997, "catamaran_sail.stl", + 0.997, null, false), + PIRATE_SHIP("pirateship_hull.stl", "pirateship_mast.stl", -0.5415, "pirateship_mainsail.stl", + -0.5415, "pirateship_frontsail.stl", true); - final String hullFile, mastFile, sailFile; + final String hullFile, mastFile, sailFile, jibFile; final double mastOffset, sailOffset; + final boolean fixedSail; + final static BoatMeshType[] boatTypes = new BoatMeshType[]{DINGHY, CAT_ATE_A_MERINGUE, PIRATE_SHIP}; - BoatMeshType(String hullFile, String mastFile, double mastOffset, String sailFile, double sailOffset) { + BoatMeshType(String hullFile, String mastFile, double mastOffset, String sailFile, + double sailOffset, String jibFile, boolean fixedSail) { this.hullFile = hullFile; this.mastFile = mastFile; this.mastOffset = mastOffset; this.sailFile = sailFile; this.sailOffset = sailOffset; + this.jibFile = jibFile; + this.fixedSail = fixedSail; + } + + + //TODO kre39 make something not terrible to cycle through boat types + public static BoatMeshType getNextBoatType(BoatMeshType boatType) { + for (int i = 0; i < boatTypes.length; i++) { + if (i == boatTypes.length -1) { + return boatTypes[0]; + } else if (boatType == boatTypes[i]) { + return boatTypes[i+1]; + } + } + return boatType; + } + + public static BoatMeshType getPrevBoatType(BoatMeshType boatType) { + for (int i = 0; i < boatTypes.length; i++) { + if (i == 0 && boatType == boatTypes[i]) { + return boatTypes[boatTypes.length -1]; + } else if (boatType == boatTypes[i]) { + return boatTypes[i-1]; + } + } + return boatType; } } diff --git a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatModel.java b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatModel.java index b1373c67..0562d4f7 100644 --- a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatModel.java +++ b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatModel.java @@ -34,14 +34,16 @@ public class BoatModel extends Model { * @param degrees The rotation of the sail in degrees */ public void rotateSail(double degrees) { - MeshView mast = getMeshViewChild(MAST_INDEX); - MeshView sail = getMeshViewChild(SAIL_INDEX); - mast.getTransforms().setAll( - new Rotate(degrees, -meshType.mastOffset, 0,0, new Point3D(0, 0, 1)) - ); - sail.getTransforms().setAll( - new Rotate(degrees, -meshType.sailOffset, 0,0, new Point3D(0, 0, 1)) - ); + if (!meshType.fixedSail) { + MeshView mast = getMeshViewChild(MAST_INDEX); + MeshView sail = getMeshViewChild(SAIL_INDEX); + mast.getTransforms().setAll( + new Rotate(degrees, 0, -meshType.mastOffset, 0, new Point3D(0, 0, 1)) + ); + sail.getTransforms().setAll( + new Rotate(degrees, 0, -meshType.sailOffset,0, new Point3D(0, 0, 1)) + ); + } } public void hideSail() { diff --git a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatObject.java b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatObject.java index 57975935..abf969a8 100644 --- a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatObject.java +++ b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatObject.java @@ -11,7 +11,7 @@ import javafx.scene.transform.Rotate; /** * BoatGroup is a javafx group that by default contains a graphical objects for representing a 2 * dimensional boat. It contains a single polygon for the boat, a group of lines to show it's path, - * a wake object and two text labels to annotate the boat teams name and the boats velocity. The + * a wake object and two text labels to annotate the boat teams name and the boatTypes velocity. The * boat will update it's position onscreen everytime UpdatePosition is called unless the window is * minimized in which case it attempts to store animations and apply them when the window is * maximised. @@ -28,15 +28,15 @@ public class BoatObject extends Group { private Group wake; private Color colour = Color.BLACK; private Boolean isSelected = false; - private Rotate rotation = new Rotate(0,0,1); + private Rotate rotation = new Rotate(0, new Point3D(0,0,1)); private List selectedBoatListenerListeners = new ArrayList<>(); /** * Creates a BoatGroup with the default triangular boat polygon. */ - public BoatObject() { - boatAssets = ModelFactory.boatGameView(BoatMeshType.DINGHY, colour); + public BoatObject(BoatMeshType boatMeshType) { + boatAssets = ModelFactory.boatGameView(boatMeshType, colour); boatAssets.hideSail(); boatAssets.getAssets().getTransforms().addAll( rotation @@ -66,8 +66,6 @@ public class BoatObject extends Group { * @param windDir . */ public void moveTo(double x, double y, double rotation, double velocity, Boolean sailIn, double windDir) { - Double dx = Math.abs(boatAssets.getAssets().getLayoutX() - x); - Double dy = Math.abs(boatAssets.getAssets().getLayoutY() - y); Platform.runLater(() -> { rotateTo(rotation, sailIn, windDir); this.layoutXProperty().setValue(x); diff --git a/src/main/java/seng302/visualiser/fxObjects/assets_3D/ModelFactory.java b/src/main/java/seng302/visualiser/fxObjects/assets_3D/ModelFactory.java index b49c36c1..91f832ad 100644 --- a/src/main/java/seng302/visualiser/fxObjects/assets_3D/ModelFactory.java +++ b/src/main/java/seng302/visualiser/fxObjects/assets_3D/ModelFactory.java @@ -7,6 +7,7 @@ import javafx.geometry.Point3D; import javafx.scene.AmbientLight; import javafx.scene.CacheHint; import javafx.scene.Group; +import javafx.scene.PointLight; import javafx.scene.paint.Color; import javafx.scene.paint.PhongMaterial; import javafx.scene.shape.Circle; @@ -18,7 +19,7 @@ import javafx.scene.transform.Translate; /** - * Factory class for creating 3D models of boats. + * Factory class for creating 3D models of boatTypes. */ public class ModelFactory { @@ -51,6 +52,35 @@ public class ModelFactory { return bo; } + public static BoatModel boatCustomiseView(BoatMeshType boatType, Color primaryColour) { + Group boatAssets = getUnmodifiedBoatModel(boatType, primaryColour); + final Rotate animationRotate = new Rotate(0, new Point3D(0,0,1)); + boatAssets.getTransforms().addAll( + new Scale(8.0, 8.0, 8.0), + new Rotate(-70, new Point3D(1,0,0)), + new Translate(16,50, 1), + animationRotate + ); + + boatAssets.getTransforms().add(animationRotate); + BoatModel bo = new BoatModel(boatAssets, null, boatType); + bo.rotateSail(45); + + bo.setAnimation(new AnimationTimer() { + double boatAngle = 0; + Rotate rotate = animationRotate; + @Override + public void handle(long now) { + boatAngle += 0.5; + rotate.setAngle(boatAngle); + } + }); + boatAssets.getChildren().addAll( + new AmbientLight() + ); + return bo; + } + public static BoatModel boatRotatingView(BoatMeshType boatType, Color primaryColour) { Group boatAssets = getUnmodifiedBoatModel(boatType, primaryColour); boatAssets.getTransforms().addAll( @@ -84,20 +114,29 @@ public class ModelFactory { } private static Group getUnmodifiedBoatModel(BoatMeshType boatType, Color primaryColour) { + Group boatAssets = new Group(); - MeshView hull = importFile(boatType.hullFile); + MeshView hull = importSTL(boatType.hullFile); hull.setMaterial(new PhongMaterial(primaryColour)); - MeshView mast = importFile(boatType.mastFile); + MeshView mast = importSTL(boatType.mastFile); mast.setMaterial(new PhongMaterial(primaryColour)); - MeshView sail = importFile(boatType.sailFile); + MeshView sail = importSTL(boatType.sailFile); sail.setMaterial(new PhongMaterial(Color.WHITE)); - boatAssets.getChildren().addAll(hull, mast, sail); + + if (boatType.jibFile != null) { + MeshView jib = importSTL(boatType.jibFile); + sail.setMaterial(new PhongMaterial(Color.WHITE)); + boatAssets.getChildren().addAll(hull, mast, sail, jib); + } else { + boatAssets.getChildren().addAll(hull, mast, sail); + } + return boatAssets; } - private static MeshView importFile(String fileName) { + private static MeshView importSTL(String fileName) { StlMeshImporter importer = new StlMeshImporter(); - importer.read(ModelFactory.class.getResource("/meshes/" + fileName)); + importer.read(ModelFactory.class.getResource("/meshes/boatSTLs/" + fileName)); MeshView importedFile = new MeshView(importer.getImport()); importedFile.setCache(true); importedFile.setCacheHint(CacheHint.SCALE_AND_ROTATE); diff --git a/src/main/java/seng302/visualiser/test3d.java b/src/main/java/seng302/visualiser/test3d.java deleted file mode 100644 index 6440e563..00000000 --- a/src/main/java/seng302/visualiser/test3d.java +++ /dev/null @@ -1,108 +0,0 @@ -package seng302.visualiser; - -import com.interactivemesh.jfx.importer.stl.StlMeshImporter; -import javafx.animation.AnimationTimer; -import javafx.application.Application; -import javafx.geometry.Point3D; -import javafx.scene.Camera; -import javafx.scene.Group; -import javafx.scene.PerspectiveCamera; -import javafx.scene.Scene; -import javafx.scene.SceneAntialiasing; -import javafx.scene.paint.Color; -import javafx.scene.paint.PhongMaterial; -import javafx.scene.shape.MeshView; -import javafx.scene.transform.Rotate; -import javafx.scene.transform.Scale; -import javafx.scene.transform.Translate; -import javafx.stage.Stage; - -/** - * Created by cir27 on 7/09/17. - */ -public class test3d extends Application { - - Group root = new Group(); - Scene scene; - - @Override - public void start(Stage primaryStage) throws Exception { -// camera = new PerspectiveCamera(); -// gameObjects = new Group(); -// root3D = new Group(camera, gameObjects); - scene = new Scene( - root, 1000, 1000, true, SceneAntialiasing.BALANCED - ); - gameView3DTest(); - primaryStage.setScene(scene); - primaryStage.show(); -// scene.setCamera(camera); -// primaryStage.setScene(scene); -// primaryStage.show(); -// -// StlMeshImporter importer = new StlMeshImporter(); -// importer.read(test3d.class.getResource("/meshes/dinghy_hull.stl").toString()); -// MeshView boat = new MeshView(importer.getImport()); -// boat.setMaterial(new PhongMaterial(Color.GREENYELLOW)); -// -// importer = new StlMeshImporter(); -// importer.read(getClass().getResource("/meshes/dinghy_mast.stl").toString()); -// MeshView mast = new MeshView(importer.getImport()); -// mast.setMaterial(new PhongMaterial(Color.GREENYELLOW)); -// -// importer = new StlMeshImporter(); -// importer.read(getClass().getResource("/meshes/dinghy_sail.stl").toString()); -// MeshView sail = new MeshView(importer.getImport()); -// sail.setMaterial(new PhongMaterial(Color.LIGHTGREY)); -// -// gameObjects.getChildren().addAll(boat, mast, sail); -// -// gameObjects.getTransforms().add(new Scale(25, 25,25)); -// gameObjects.getTransforms().add(new Translate(15, 20,0)); -// gameObjects.getTransforms().addAll( -// new Rotate(90, new Point3D(0,0,1)), -// new Rotate(90, new Point3D(0, 1, 0)) -// ); -// -//// PointLight light = new PointLight(); -//// light.setLightOn(true); -//// light.getTransforms().add(new Translate(15, 20, 0)); -//// -//// PointLight light2 = new PointLight(); -//// light2.setLightOn(true); -//// light2.getTransforms().add(new Translate(30, 40, 0)); -// -//// root3D.getChildren().addAll(light); -// -// scene.setOnKeyPressed(event -> { -// switch (event.getCode()) { -// case UP: -// gameObjects.getTransforms().add(new Rotate(5, new Point3D(0,0,1))); -// break; -// case DOWN: -// gameObjects.getTransforms().add(new Rotate(-5, new Point3D(0,0,1))); -// break; -// case LEFT: -// gameObjects.getTransforms().add(new Rotate(-5, new Point3D(0,1,0))); -// break; -// case RIGHT: -// gameObjects.getTransforms().add(new Rotate(5, new Point3D(0,1,0))); -// break; -// } -// }); -// -// AnimationTimer animationTimer = new AnimationTimer() { -// @Override -// public void handle(long now) { -// sail.getTransforms().add(new Rotate(0.5, 0, -1.36653, 0, new Point3D(0, 0, 1))); -// } -// }; -// -//// animationTimer.start(); - } - - private void gameView3DTest() { - GameView3D gameView3D = new GameView3D(); - root.getChildren().add(gameView3D.getAssets()); - } -} diff --git a/src/main/resources/meshes/boatSTLs/catamaran_hull.stl b/src/main/resources/meshes/boatSTLs/catamaran_hull.stl new file mode 100644 index 00000000..a7f70e54 Binary files /dev/null and b/src/main/resources/meshes/boatSTLs/catamaran_hull.stl differ diff --git a/src/main/resources/meshes/boatSTLs/catamaran_mast.stl b/src/main/resources/meshes/boatSTLs/catamaran_mast.stl new file mode 100644 index 00000000..536184da Binary files /dev/null and b/src/main/resources/meshes/boatSTLs/catamaran_mast.stl differ diff --git a/src/main/resources/meshes/boatSTLs/catamaran_sail.stl b/src/main/resources/meshes/boatSTLs/catamaran_sail.stl new file mode 100644 index 00000000..273b1d5b Binary files /dev/null and b/src/main/resources/meshes/boatSTLs/catamaran_sail.stl differ diff --git a/src/main/resources/meshes/boatSTLs/dinghy_hull.stl b/src/main/resources/meshes/boatSTLs/dinghy_hull.stl new file mode 100644 index 00000000..9450b75f Binary files /dev/null and b/src/main/resources/meshes/boatSTLs/dinghy_hull.stl differ diff --git a/src/main/resources/meshes/boatSTLs/dinghy_mast.stl b/src/main/resources/meshes/boatSTLs/dinghy_mast.stl new file mode 100644 index 00000000..2ab71fcf Binary files /dev/null and b/src/main/resources/meshes/boatSTLs/dinghy_mast.stl differ diff --git a/src/main/resources/meshes/boatSTLs/dinghy_sail.stl b/src/main/resources/meshes/boatSTLs/dinghy_sail.stl new file mode 100644 index 00000000..f10f0c78 Binary files /dev/null and b/src/main/resources/meshes/boatSTLs/dinghy_sail.stl differ diff --git a/src/main/resources/meshes/boatSTLs/pirateship_frontsail.stl b/src/main/resources/meshes/boatSTLs/pirateship_frontsail.stl new file mode 100644 index 00000000..b344e825 Binary files /dev/null and b/src/main/resources/meshes/boatSTLs/pirateship_frontsail.stl differ diff --git a/src/main/resources/meshes/boatSTLs/pirateship_hull.stl b/src/main/resources/meshes/boatSTLs/pirateship_hull.stl new file mode 100644 index 00000000..b15804b8 Binary files /dev/null and b/src/main/resources/meshes/boatSTLs/pirateship_hull.stl differ diff --git a/src/main/resources/meshes/boatSTLs/pirateship_mainsail.stl b/src/main/resources/meshes/boatSTLs/pirateship_mainsail.stl new file mode 100644 index 00000000..c421901a Binary files /dev/null and b/src/main/resources/meshes/boatSTLs/pirateship_mainsail.stl differ diff --git a/src/main/resources/meshes/boatSTLs/pirateship_mast.stl b/src/main/resources/meshes/boatSTLs/pirateship_mast.stl new file mode 100644 index 00000000..d15ab860 Binary files /dev/null and b/src/main/resources/meshes/boatSTLs/pirateship_mast.stl differ diff --git a/src/main/resources/meshes/dinghy_hull.stl b/src/main/resources/meshes/dinghy_hull.stl deleted file mode 100644 index 56a443a7..00000000 Binary files a/src/main/resources/meshes/dinghy_hull.stl and /dev/null differ diff --git a/src/main/resources/meshes/dinghy_mast.stl b/src/main/resources/meshes/dinghy_mast.stl deleted file mode 100644 index d4040f90..00000000 Binary files a/src/main/resources/meshes/dinghy_mast.stl and /dev/null differ diff --git a/src/main/resources/meshes/dinghy_sail.stl b/src/main/resources/meshes/dinghy_sail.stl deleted file mode 100644 index 12f4b334..00000000 Binary files a/src/main/resources/meshes/dinghy_sail.stl and /dev/null differ diff --git a/src/main/resources/server_config/xml_templates/boats.ftlh b/src/main/resources/server_config/xml_templates/boats.ftlh index 8186e000..26fae383 100644 --- a/src/main/resources/server_config/xml_templates/boats.ftlh +++ b/src/main/resources/server_config/xml_templates/boats.ftlh @@ -12,7 +12,7 @@ <#list boats as boat> - diff --git a/src/main/resources/views/dialogs/BoatCustomizeDialog.fxml b/src/main/resources/views/dialogs/BoatCustomizeDialog.fxml index 8e8653cf..1d355a33 100644 --- a/src/main/resources/views/dialogs/BoatCustomizeDialog.fxml +++ b/src/main/resources/views/dialogs/BoatCustomizeDialog.fxml @@ -1,5 +1,10 @@ + + + + + @@ -10,54 +15,44 @@ - + + - - - - + + + + + - - - + + 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 new file mode 100644 index 00000000..743c7f1e --- /dev/null +++ b/src/test/java/seng302/utilities/BoatMeshTypeTest.java @@ -0,0 +1,28 @@ +package seng302.utilities; + +import org.junit.Assert; +import org.junit.Test; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; + +/** + * Basic tests for the next and previous methods + * Created by kre39 on 20/09/17. + */ +public class BoatMeshTypeTest { + + + @Test + public void testNextBoatMeshType() { + BoatMeshType currentBoat = BoatMeshType.DINGHY; + BoatMeshType nextBoat = BoatMeshType.getNextBoatType(currentBoat); + Assert.assertEquals(BoatMeshType.CAT_ATE_A_MERINGUE, nextBoat); + } + + @Test + public void testPreviousBoatMeshType() { + BoatMeshType currentBoat = BoatMeshType.CAT_ATE_A_MERINGUE; + BoatMeshType prevBoat = BoatMeshType.getPrevBoatType(currentBoat); + Assert.assertEquals(BoatMeshType.DINGHY, prevBoat); + } + +} 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