Merge branch 'develop' into Story1274_custom_boat_stats

# Conflicts:
#	src/main/java/seng302/model/ServerYacht.java
#	src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java
This commit is contained in:
Kusal Ekanayake
2017-09-23 14:48:50 +12:00
14 changed files with 55 additions and 79 deletions
@@ -18,6 +18,7 @@ import seng302.utilities.XMLParser;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import java.util.*; import java.util.*;
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
/** /**
* A Static class to hold information about the current state of the game (model) * 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); playerYacht.setBoatColor(yachtColor);
} else if (requestType.equals(CustomizeRequestType.SHAPE)) { } else if (requestType.equals(CustomizeRequestType.SHAPE)) {
String type = new String(customizeData); String type = new String(customizeData);
playerYacht.setBoatType(type); playerYacht.setBoatType(BoatMeshType.valueOf(type));
} }
} }
@@ -33,6 +33,7 @@ import seng302.model.stream.packets.PacketType;
import seng302.model.stream.packets.StreamPacket; import seng302.model.stream.packets.StreamPacket;
import seng302.model.stream.xml.generator.RaceXMLTemplate; import seng302.model.stream.xml.generator.RaceXMLTemplate;
import seng302.utilities.XMLGenerator; 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 * 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())); lName = all.get(ThreadLocalRandom.current().nextInt(0, all.size()));
ServerYacht yacht = new ServerYacht( 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); player = new Player(socket, yacht);
+4 -3
View File
@@ -15,6 +15,7 @@ import javafx.beans.property.ReadOnlyLongWrapper;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
/** /**
* Yacht class for the racing boat. <p> Class created to store more variables (eg. boat statuses) * Yacht class for the racing boat. <p> 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 Logger logger = LoggerFactory.getLogger(ClientYacht.class);
private String boatType; private BoatMeshType boatType;
private Integer sourceId; private Integer sourceId;
private String hullID; //matches HullNum in the XML spec. private String hullID; //matches HullNum in the XML spec.
private String shortName; private String shortName;
@@ -64,7 +65,7 @@ public class ClientYacht extends Observable {
private ReadOnlyIntegerWrapper placingProperty = new ReadOnlyIntegerWrapper(); private ReadOnlyIntegerWrapper placingProperty = new ReadOnlyIntegerWrapper();
private Color colour; 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) { String boatName, String country) {
this.boatType = boatType; this.boatType = boatType;
this.sourceId = sourceId; this.sourceId = sourceId;
@@ -88,7 +89,7 @@ public class ClientYacht extends Observable {
super.addObserver(o); super.addObserver(o);
} }
public String getBoatType() { public BoatMeshType getBoatType() {
return boatType; return boatType;
} }
+9 -14
View File
@@ -12,6 +12,9 @@ import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
import java.util.Observable;
import java.util.Observer;
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
/** /**
* Yacht class for the racing boat. <p> Class created to store more variables (eg. boat statuses) * Yacht class for the racing boat. <p> Class created to store more variables (eg. boat statuses)
@@ -20,10 +23,10 @@ import java.util.Objects;
*/ */
public class ServerYacht { public class ServerYacht {
private Logger logger = LoggerFactory.getLogger(ClientYacht.class); private Logger logger = LoggerFactory.getLogger(ServerYacht.class);
//Boat info //Boat info
private String boatType; private BoatMeshType boatType;
private Double turnStep = 5.0; private Double turnStep = 5.0;
private Double maxSpeedMultiplier = 1.0; private Double maxSpeedMultiplier = 1.0;
private Double acceleration = 1.0; private Double acceleration = 1.0;
@@ -58,7 +61,7 @@ public class ServerYacht {
private Long powerUpStartTime; 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) { String boatName, String country) {
setBoatType(boatType); setBoatType(boatType);
this.boatStatus = BoatStatus.PRESTART; this.boatStatus = BoatStatus.PRESTART;
@@ -422,16 +425,7 @@ public class ServerYacht {
return boatColor; return boatColor;
} }
public void setBoatType(String boatType) { public void setBoatType(BoatMeshType boatType) {
BoatMeshType boatMeshType;
for (BoatMeshType boatMesh: BoatMeshType.values()) {
if (Objects.equals(boatType, boatMesh.toString())) {
boatMeshType = boatMesh;
turnStep = turnStep * boatMeshType.turnStep;
maxSpeedMultiplier = boatMeshType.maxSpeedMultiplier;
acceleration = boatMeshType.accelerationMultiplier;
}
}
this.boatType = boatType; this.boatType = boatType;
} }
@@ -443,7 +437,8 @@ public class ServerYacht {
return acceleration; return acceleration;
} }
public String getBoatType() {
public BoatMeshType getBoatType() {
return boatType; return boatType;
} }
} }
@@ -18,6 +18,7 @@ import seng302.model.stream.xml.parser.RaceXMLData;
import seng302.model.stream.xml.parser.RegattaXMLData; import seng302.model.stream.xml.parser.RegattaXMLData;
import seng302.model.token.Token; import seng302.model.token.Token;
import seng302.model.token.TokenType; import seng302.model.token.TokenType;
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
/** /**
* Utilities for parsing XML documents * Utilities for parsing XML documents
@@ -139,7 +140,7 @@ public class XMLParser {
if (currentBoat.getNodeName().equals("Boat")) { if (currentBoat.getNodeName().equals("Boat")) {
// Boat boat = new Boat(currentBoat); // Boat boat = new Boat(currentBoat);
ClientYacht yacht = new ClientYacht( ClientYacht yacht = new ClientYacht(
XMLParser.getNodeAttributeString(currentBoat, "Type"), BoatMeshType.valueOf(XMLParser.getNodeAttributeString(currentBoat, "Type")),
XMLParser.getNodeAttributeInt(currentBoat, "SourceID"), XMLParser.getNodeAttributeInt(currentBoat, "SourceID"),
XMLParser.getNodeAttributeString(currentBoat, "HullNum"), XMLParser.getNodeAttributeString(currentBoat, "HullNum"),
XMLParser.getNodeAttributeString(currentBoat, "ShortName"), XMLParser.getNodeAttributeString(currentBoat, "ShortName"),
@@ -460,7 +460,7 @@ public class GameView3D {
final List<Group> wakes = new ArrayList<>(); final List<Group> wakes = new ArrayList<>();
for (ClientYacht clientYacht : yachts) { for (ClientYacht clientYacht : yachts) {
Color colour = clientYacht.getColour(); Color colour = clientYacht.getColour();
newBoat = new BoatObject(BoatMeshType.getBoatMeshType(clientYacht.getBoatType())); newBoat = new BoatObject(clientYacht.getBoatType());
newBoat.setFill(colour); newBoat.setFill(colour);
boatObjects.put(clientYacht, newBoat); boatObjects.put(clientYacht, newBoat);
wakesGroup.getChildren().add(newBoat.getWake()); wakesGroup.getChildren().add(newBoat.getWake());
@@ -205,7 +205,7 @@ public class LobbyController implements Initializable {
FXMLLoader loader = new FXMLLoader( FXMLLoader loader = new FXMLLoader(
getClass().getResource("/views/cells/PlayerCell.fxml")); getClass().getResource("/views/cells/PlayerCell.fxml"));
loader.setController(new PlayerCell(playerId, yacht.getBoatName(), yacht.getColour(), yacht.getBoatType())); loader.setController(new PlayerCell(playerId, yacht));
try { try {
pane = loader.load(); pane = loader.load();
@@ -6,6 +6,7 @@ import javafx.scene.control.Label;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import seng302.model.ClientYacht;
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
import seng302.visualiser.fxObjects.assets_3D.BoatModel; import seng302.visualiser.fxObjects.assets_3D.BoatModel;
import seng302.visualiser.fxObjects.assets_3D.ModelFactory; import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
@@ -24,13 +25,13 @@ public class PlayerCell {
private String name; private String name;
private Color boatColor; private Color boatColor;
private Integer playerId; private Integer playerId;
private BoatMeshType boatype; private BoatMeshType boatType;
public PlayerCell(Integer playerId, String playerName, Color color, String boatType) { public PlayerCell(Integer playerId, ClientYacht yacht) {
this.playerId = playerId; this.playerId = playerId;
this.name = playerName; this.name = yacht.getBoatName();
this.boatColor = color; this.boatColor = yacht.getColour();
this.boatype = BoatMeshType.getBoatMeshType(boatType); this.boatType = yacht.getBoatType();
} }
public void initialize() { public void initialize() {
@@ -39,7 +40,7 @@ public class PlayerCell {
// Add Rotating Boat to Player Cell with players color on it. // Add Rotating Boat to Player Cell with players color on it.
Group group = new Group(); Group group = new Group();
boatPane.getChildren().add(group); boatPane.getChildren().add(group);
BoatModel bo = ModelFactory.boatIconView(this.boatype, this.boatColor); BoatModel bo = ModelFactory.boatIconView(boatType, boatColor);
group.getChildren().add(bo.getAssets()); group.getChildren().add(bo.getAssets());
} }
@@ -6,7 +6,6 @@ import com.jfoenix.controls.JFXTextField;
import com.jfoenix.validation.RequiredFieldValidator; import com.jfoenix.validation.RequiredFieldValidator;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.geometry.Insets; import javafx.geometry.Insets;
@@ -47,9 +46,8 @@ public class BoatCustomizeController implements Initializable{
@FXML @FXML
private Pane boatPane; private Pane boatPane;
@FXML @FXML
void colorChanged(ActionEvent event) { void colorChanged() {
Color color = colorPicker.getValue(); refreshBoat();
RefreshBoat();
} }
//---------FXML END---------// //---------FXML END---------//
@@ -72,6 +70,8 @@ public class BoatCustomizeController implements Initializable{
playerNameLengthValidator.setMessage("Player name too long."); playerNameLengthValidator.setMessage("Player name too long.");
boatName.setValidators(playerNameLengthValidator, playerNameReqValidator); boatName.setValidators(playerNameLengthValidator, playerNameReqValidator);
boatPane.setBackground(
new Background(new BackgroundFill(Color.SKYBLUE, CornerRadii.EMPTY, Insets.EMPTY)));
submitBtn.setOnMouseReleased(event -> { submitBtn.setOnMouseReleased(event -> {
Sounds.playButtonClick(); Sounds.playButtonClick();
@@ -79,7 +79,6 @@ public class BoatCustomizeController implements Initializable{
}); });
submitBtn.setOnMouseEntered(e -> Sounds.playHoverSound()); submitBtn.setOnMouseEntered(e -> Sounds.playHoverSound());
} }
/** /**
@@ -123,42 +122,34 @@ public class BoatCustomizeController implements Initializable{
} }
public void setCurrentBoat(String boatType) { public void setCurrentBoat(String boatType) {
Group group = new Group(); currentBoat = boatType;
this.currentBoat = BoatMeshType.getBoatMeshType(boatType); displayCurrentBoat();
boatPane.setBackground(new Background(new BackgroundFill(Color.SKYBLUE, CornerRadii.EMPTY, Insets.EMPTY))); refreshStatBars(currentBoat);
boatPane.getChildren().add(group);
BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue());
group.getChildren().add(bo.getAssets());
group.getChildren().add(new PointLight());
refreshStatBars(bo);
} }
public void nextBoat(ActionEvent actionEvent) { public void nextBoat() {
boatPane.getChildren().clear();
Group group = new Group();
boatPane.getChildren().add(group);
currentBoat = BoatMeshType.getNextBoatType(currentBoat); currentBoat = BoatMeshType.getNextBoatType(currentBoat);
BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); displayCurrentBoat();
group.getChildren().add(bo.getAssets()); refreshStatBars(currentBoat);
group.getChildren().add(new PointLight()); }
refreshStatBars(bo);
public void prevBoat() {
currentBoat = BoatMeshType.getPrevBoatType(currentBoat);
displayCurrentBoat();
refreshStatBars(currentBoat);
} }
public void prevBoat(ActionEvent actionEvent) { private void displayCurrentBoat() {
boatPane.getChildren().clear(); boatPane.getChildren().clear();
Group group = new Group(); Group group = new Group();
boatPane.getChildren().add(group); boatPane.getChildren().add(group);
currentBoat = BoatMeshType.getPrevBoatType(currentBoat);
BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue());
group.getChildren().add(bo.getAssets()); group.getChildren().add(bo.getAssets());
group.getChildren().add(new PointLight()); group.getChildren().add(new PointLight());
refreshStatBars(bo);
} }
private void RefreshBoat() { private void refreshBoat() {
boatPane.getChildren().clear(); boatPane.getChildren().clear();
Group group = new Group(); Group group = new Group();
boatPane.getChildren().add(group); boatPane.getChildren().add(group);
@@ -35,19 +35,6 @@ public enum BoatMeshType {
this.turnStep = turnStep; this.turnStep = turnStep;
} }
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 //TODO kre39 make something not terrible to cycle through boat types
public static BoatMeshType getNextBoatType(BoatMeshType boatType) { public static BoatMeshType getNextBoatType(BoatMeshType boatType) {
@@ -5,6 +5,7 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import seng302.gameServer.GameState; import seng302.gameServer.GameState;
import seng302.utilities.GeoUtility; import seng302.utilities.GeoUtility;
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
import static seng302.gameServer.GameState.checkCollision; import static seng302.gameServer.GameState.checkCollision;
@@ -14,8 +15,10 @@ import static seng302.gameServer.GameState.checkCollision;
*/ */
public class UpdateYachtTest { public class UpdateYachtTest {
private ServerYacht yacht1 = new ServerYacht("Yacht", 1, "1", "Yacht" + 1, "Yacht" + 1, "Test1"); private ServerYacht yacht1 = new ServerYacht(BoatMeshType.DINGHY, 1, "1", "Yacht" + 1,
private ServerYacht yacht2 = new ServerYacht("Yacht", 2, "2", "Yacht" + 2, "Yacht" + 2, "Test2"); "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 geoPoint1 = new GeoPoint(50.0, 50.0);
private GeoPoint geoPoint2 = GeoUtility.getGeoCoordinate(geoPoint1, 90.0, 50.0); private GeoPoint geoPoint2 = GeoUtility.getGeoCoordinate(geoPoint1, 90.0, 50.0);
+2 -1
View File
@@ -4,6 +4,7 @@ import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import seng302.gameServer.GameState; import seng302.gameServer.GameState;
import seng302.model.ServerYacht; import seng302.model.ServerYacht;
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
public class YachtTest { public class YachtTest {
@@ -17,7 +18,7 @@ public class YachtTest {
@BeforeClass @BeforeClass
public static void setUp() { public static void setUp() {
new GameState("localhost"); 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"); gs = new GameState("localhost");
} }
@@ -25,11 +25,4 @@ public class BoatMeshTypeTest {
Assert.assertEquals(BoatMeshType.DINGHY, prevBoat); 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);
}
} }
@@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import seng302.model.ClientYacht; import seng302.model.ClientYacht;
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
/** /**
* Created by kre39 on 6/08/17. * Created by kre39 on 6/08/17.
@@ -16,7 +17,7 @@ public class BoatSailAnimationToggleTest {
@Before @Before
public void setup() throws Exception{ 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 @Test