diff --git a/dedicatedServer/src/main/java/app/App.java b/dedicatedServer/src/main/java/app/App.java index 34ee2c5b..3b36c43e 100644 --- a/dedicatedServer/src/main/java/app/App.java +++ b/dedicatedServer/src/main/java/app/App.java @@ -21,7 +21,7 @@ public class App extends Application { public void start(Stage primaryStage) { try { //TODO should read a configuration file to configure server? - Event raceEvent = new Event(false); + Event raceEvent = new Event(false, 0); } catch (Exception e) { diff --git a/racevisionGame/src/main/java/mock/app/Event.java b/racevisionGame/src/main/java/mock/app/Event.java index 6f778852..93f33ab5 100644 --- a/racevisionGame/src/main/java/mock/app/Event.java +++ b/racevisionGame/src/main/java/mock/app/Event.java @@ -18,6 +18,7 @@ import shared.exceptions.InvalidRegattaDataException; import shared.exceptions.XMLReaderException; import shared.model.Bearing; import shared.model.Constants; +import shared.xml.XMLUtilities; import javax.xml.bind.JAXBException; import javax.xml.parsers.ParserConfigurationException; @@ -70,6 +71,8 @@ public class Event { private Thread connectionThread; + private int mapIndex; + @@ -79,11 +82,32 @@ public class Event { * @param singlePlayer Whether or not to create a single player event. * @throws EventConstructionException Thrown if we cannot create an Event for any reason. */ - public Event(boolean singlePlayer) throws EventConstructionException { + public Event(boolean singlePlayer, int mapIndex) throws EventConstructionException { - String raceXMLFile = "mock/mockXML/raceTest.xml"; +// System.out.println(XMLUtilities.validateXML(this.getClass().getClassLoader().getResource("mock/mockXML/iMapLayout.xml").toString() +// , this.getClass().getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd"))); + this.mapIndex = mapIndex; + String raceXMLFile; String boatsXMLFile = "mock/mockXML/boatTest.xml"; String regattaXMLFile = "mock/mockXML/regattaTest.xml"; + switch (mapIndex){ + case 0:raceXMLFile = "mock/mockXML/raceSixPlayers.xml"; + break; + case 1:raceXMLFile = "mock/mockXML/oMapLayout.xml"; + break; + case 2: raceXMLFile = "mock/mockXML/iMapLayout.xml"; + break; + case 3: raceXMLFile = "mock/mockXML/mMapLayout.xml"; + break; + case 4: + raceXMLFile = "mock/mockXML/raceTutorial.xml"; + boatsXMLFile = "mock/mockXML/boatTutorial.xml"; + regattaXMLFile = "mock/mockXML/regattaTutorial.xml"; + break; + default: raceXMLFile = "mock/mockXML/raceSixPlayers.xml"; + + } + if (singlePlayer) { raceXMLFile = "mock/mockXML/raceSinglePlayer.xml"; @@ -95,7 +119,9 @@ public class Event { //this.raceXML = RaceXMLCreator.alterRaceToWind(raceXMLFile, 90); this.raceXML = XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8); this.raceXML = Event.setRaceXMLAtCurrentTimeToNow(XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8)); - + if(mapIndex==4){ + this.raceXML = Event.setRaceXMLAtCurrentTimeToNow(XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8), 1000, 5000); + } this.boatXML = XMLReader.readXMLFileToString(boatsXMLFile, StandardCharsets.UTF_8); this.regattaXML = XMLReader.readXMLFileToString(regattaXMLFile, StandardCharsets.UTF_8); @@ -178,9 +204,15 @@ public class Event { * @return String containing edited xml */ public static String setRaceXMLAtCurrentTimeToNow(String raceXML) { + return setRaceXMLAtCurrentTimeToNow(raceXML, Constants.RacePreStartTime, Constants.RacePreparatoryTime); + } + public static String setRaceXMLAtCurrentTimeToNow(String raceXML, long racePreStartTime, long racePreparatoryTime){ //The start time is current time + 4 minutes. prestart is 3 minutes, and we add another minute. - long millisecondsToAdd = Constants.RacePreStartTime + (1 * 60 * 1000); + + long millisecondsToAdd = racePreStartTime + racePreparatoryTime; + + long secondsToAdd = millisecondsToAdd / 1000; //Scale the time using our time scalar. secondsToAdd = secondsToAdd / Constants.RaceTimeScale; @@ -190,7 +222,6 @@ public class Event { raceXML = raceXML.replace("RACE_CREATION_TIME", dateFormat.format(creationTime)); raceXML = raceXML.replace("RACE_START_TIME", dateFormat.format(creationTime.plusSeconds(secondsToAdd))); - return raceXML; } diff --git a/racevisionGame/src/main/java/mock/model/SourceIdAllocator.java b/racevisionGame/src/main/java/mock/model/SourceIdAllocator.java index 17a7e85f..f590d9b7 100644 --- a/racevisionGame/src/main/java/mock/model/SourceIdAllocator.java +++ b/racevisionGame/src/main/java/mock/model/SourceIdAllocator.java @@ -42,6 +42,7 @@ public class SourceIdAllocator { } List allocatedIDs = mockRace.getRaceDataSource().getParticipants(); + List allIDs = new ArrayList<>(mockRace.getBoatDataSource().getBoats().keySet()); //Get list of unallocated ids. diff --git a/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java b/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java index 5cb74625..0e538925 100644 --- a/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java +++ b/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java @@ -74,7 +74,7 @@ public class RaceXMLCreator { * @throws SAXException error in schema file * @throws ParserConfigurationException error in parsing the schema file */ - public static String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException, IOException, SAXException, ParserConfigurationException { + public static String alterRaceToWind(String s, double degrees, boolean tutorial) throws XMLReaderException, InvalidRaceDataException, JAXBException, IOException, SAXException, ParserConfigurationException { RaceXMLReader reader = new RaceXMLReader(s, XMLFileType.ResourcePath); XMLRace race = XMLUtilities.xmlToClass( @@ -82,7 +82,11 @@ public class RaceXMLCreator { RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd"), XMLRace.class); - setRaceXMLAtCurrentTimeToNow(race); + if(tutorial){ + setRaceXMLAtCurrentTimeToNow(race, 1000l, 5000l); + } else { + setRaceXMLAtCurrentTimeToNow(race); + } double raceOriginalBearing = getLineAngle(getLeewardGate(reader).getMark1Position(), getWindwardGate(reader).getMark1Position()); @@ -93,6 +97,7 @@ public class RaceXMLCreator { return XMLUtilities.classToXML(race); } + /** * Rotate the features in a race such as the boundary, and the marks. * @param race the race to alter @@ -180,14 +185,11 @@ public class RaceXMLCreator { } - /** - * Sets the xml description of the race to show the race was created now, and starts in 4 minutes - * @param raceXML The race.xml contents. - */ - public static void setRaceXMLAtCurrentTimeToNow(XMLRace raceXML) { + + public static void setRaceXMLAtCurrentTimeToNow(XMLRace raceXML, long racePrestartTime, long racePreparatoryTime){ //The start time is current time + 4 minutes. prestart is 3 minutes, and we add another minute. - long millisecondsToAdd = Constants.RacePreStartTime + (1 * 60 * 1000); + long millisecondsToAdd = racePrestartTime + racePreparatoryTime; long secondsToAdd = millisecondsToAdd / 1000; //Scale the time using our time scalar. secondsToAdd = secondsToAdd / Constants.RaceTimeScale; @@ -198,4 +200,13 @@ public class RaceXMLCreator { raceXML.getRaceStartTime().setTime(dateFormat.format(creationTime.plusSeconds(secondsToAdd))); } + /** + * Sets the xml description of the race to show the race was created now, and starts in 4 minutes + * @param raceXML The race.xml contents. + */ + public static void setRaceXMLAtCurrentTimeToNow(XMLRace raceXML) { + setRaceXMLAtCurrentTimeToNow(raceXML, Constants.RacePreStartTime, Constants.RacePreparatoryTime); + + } + } diff --git a/racevisionGame/src/main/java/shared/model/Constants.java b/racevisionGame/src/main/java/shared/model/Constants.java index a415ece2..81e0d81b 100644 --- a/racevisionGame/src/main/java/shared/model/Constants.java +++ b/racevisionGame/src/main/java/shared/model/Constants.java @@ -5,7 +5,6 @@ package shared.model; * Created by Erika on 19-Mar-17. */ public class Constants { - /** * Multiply by this factor to convert nautical miles to meters. *
@@ -15,8 +14,6 @@ public class Constants { */ public static final int NMToMetersConversion = 1852; - - /** * Multiply by this factor to convert Knots to millimeters per second. *
@@ -26,8 +23,6 @@ public class Constants { */ public static final double KnotsToMMPerSecond = 514.444; - - /** * The scale factor of the race. * Frame periods are multiplied by this to get the amount of time a single frame represents. @@ -38,20 +33,13 @@ public class Constants { /** * The race pre-start time, in milliseconds. 3 minutes. */ - // - // TODO: CHANGE BACK TO 3 MINUTES BEFORE MERGING TO MASTER - public static final long RacePreStartTime = 30000; //3 * 60 * 1000; - + public static final long RacePreStartTime = 3 * 60 * 1000; /** * The race preparatory time, in milliseconds. 1 minute. */ public static final long RacePreparatoryTime = 1 * 60 * 1000; - - - - /** * The number of milliseconds in one hour. *
@@ -69,7 +57,4 @@ public class Constants { * Divide by this factor to convert hours to seconds. */ public static long OneHourSeconds = 1 * 60 * 60; - - - } diff --git a/racevisionGame/src/main/java/visualiser/Controllers/HostController.java b/racevisionGame/src/main/java/visualiser/Controllers/HostController.java index 008276ef..cc850fad 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/HostController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/HostController.java @@ -1,29 +1,28 @@ package visualiser.Controllers; -import com.interactivemesh.jfx.importer.stl.StlMeshImporter; -import javafx.animation.AnimationTimer; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; import javafx.fxml.FXML; -import javafx.scene.control.Alert; -import javafx.scene.control.ButtonType; -import javafx.scene.control.SplitPane; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.GridPane; -import javafx.scene.shape.Box; -import javafx.scene.shape.Mesh; -import javafx.scene.shape.MeshView; -import javafx.scene.shape.Shape3D; -import javafx.scene.transform.Rotate; +import javafx.stage.Stage; import mock.app.Event; +import org.xml.sax.SAXException; import mock.exceptions.EventConstructionException; -import visualiser.model.View3D; +import shared.exceptions.InvalidBoatDataException; +import shared.exceptions.InvalidRaceDataException; +import shared.exceptions.InvalidRegattaDataException; +import shared.exceptions.XMLReaderException; +import javax.xml.bind.JAXBException; +import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.net.Socket; import java.net.URL; -import java.util.Optional; +import java.util.ArrayList; +import java.util.Arrays; import java.util.ResourceBundle; import java.util.logging.Level; import java.util.logging.Logger; @@ -34,72 +33,48 @@ import java.util.logging.Logger; public class HostController extends Controller { -// @FXML -// TextField gameNameField; -// -// @FXML -// TextField hostNameField; - @FXML - private ImageView imageView; + TextField gameNameField; @FXML - AnchorPane hostWrapper; + TextField hostNameField; @FXML - AnchorPane imagePane; + AnchorPane hostWrapper; @FXML - SplitPane splitPane; + Button previousButton; @FXML - AnchorPane specPane; + Button nextButton; @FXML - GridPane playerContainer; + ImageView mapImage; private Event game; - private View3D view3D; + private ArrayList listOfMaps; + private int currentMapIndex = 0; + @Override - public void initialize(URL location, ResourceBundle resources) { - ObservableList shapes = FXCollections.observableArrayList(); - - view3D = new View3D(); - view3D.setItems(shapes); - playerContainer.add(view3D, 0,0); - - URL asset = HostController.class.getClassLoader().getResource("assets/V1.2 Complete Boat.stl"); - - StlMeshImporter importer = new StlMeshImporter(); - importer.read(asset); - MeshView mesh = new MeshView(importer.getImport()); - shapes.add(mesh); - - view3D.setPivot(mesh); - view3D.setDistance(50); - view3D.setYaw(45); - view3D.setPitch(20); - - Rotate rotation = new Rotate(0, Rotate.Y_AXIS); - mesh.getTransforms().addAll(rotation, new Rotate(-90, Rotate.X_AXIS)); - - AnimationTimer rotate = new AnimationTimer() { - @Override - public void handle(long now) { - rotation.setAngle(rotation.getAngle() + 0.1); - } - }; - rotate.start(); + public void initialize(URL location, ResourceBundle resources){ + Image ac35Map = new Image(getClass().getClassLoader().getResourceAsStream("images/AC35_Racecourse_MAP.png")); + Image oMap = new Image(getClass().getClassLoader().getResourceAsStream("images/oMapLayout.png")); + Image iMap = new Image(getClass().getClassLoader().getResourceAsStream("images/iMapLayout.png")); + Image mMap = new Image(getClass().getClassLoader().getResourceAsStream("images/mMapLayout.png")); + + listOfMaps = new ArrayList(Arrays.asList(ac35Map, oMap, iMap, mMap)); + mapImage.setImage(listOfMaps.get(currentMapIndex)); } /** * Hosts a game + * @throws IOException if socket cannot be connected to */ - public void hostGamePressed() { + public void hostGamePressed() throws IOException{ try { - this.game = new Event(false); + this.game = new Event(false, currentMapIndex); connectSocket("localhost", 4942); } catch (EventConstructionException e) { Logger.getGlobal().log(Level.SEVERE, "Could not create Event.", e); @@ -132,10 +107,7 @@ public class HostController extends Controller { * Hosts a game. */ public void hostGame(){ - splitPane.setResizableWithParent(specPane, false); - splitPane.lookupAll(".split-pane-divider").stream().forEach(div -> div.setMouseTransparent(true)); - imageView.fitWidthProperty().bind(imagePane.widthProperty()); - imageView.fitHeightProperty().bind(imagePane.heightProperty()); + mapImage.fitWidthProperty().bind(((Stage) mapImage.getScene().getWindow()).widthProperty().multiply(0.6)); hostWrapper.setVisible(true); } @@ -143,23 +115,31 @@ public class HostController extends Controller { * Menu button pressed. Prompt alert then return to menu */ public void menuBtnPressed(){ - Alert alert = new Alert(Alert.AlertType.CONFIRMATION); - alert.setTitle("Quitting race"); - alert.setContentText("Do you wish to quit the race?"); - alert.setHeaderText("You are about to quit the race"); - Optional result = alert.showAndWait(); - if(result.get() == ButtonType.OK){ - hostWrapper.setVisible(false); - parent.enterTitle(); - } + hostWrapper.setVisible(false); + parent.enterTitle(); } - /** - * Start button pressed. Currently only prints out start - */ - public void startBtnPressed(){ - //System.out.println("Should start the race. This button is only visible for the host"); - hostGamePressed(); + public void nextImage(){ + increaseIndex(); + mapImage.setImage(listOfMaps.get(currentMapIndex)); } + public void previousImage(){ + decreaseIndex(); + mapImage.setImage(listOfMaps.get(currentMapIndex)); + } + private void increaseIndex(){ + currentMapIndex = (currentMapIndex + 1)%listOfMaps.size(); + } + + private void decreaseIndex(){ + currentMapIndex = ((((currentMapIndex - 1)%listOfMaps.size())+listOfMaps.size())%listOfMaps.size()); + } + + public void setGameType(int gameType){ + this.currentMapIndex = gameType; + } + + public int getGameType(){ return this.currentMapIndex; } + } diff --git a/racevisionGame/src/main/java/visualiser/Controllers/MainController.java b/racevisionGame/src/main/java/visualiser/Controllers/MainController.java index e1aa1ede..b81bf918 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/MainController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/MainController.java @@ -86,6 +86,20 @@ public class MainController extends Controller { */ public void startCss(){titleController.setDayMode();} + /** + * host controller host a game + * @throws IOException throws exception + */ + public void beginGame() throws IOException { + hostController.hostGamePressed(); + } + + public void setGameType(int gameType){ + hostController.setGameType(gameType); + } + + public int getGameType(){ return hostController.getGameType(); } + /** * Main Controller for the applications will house the menu and the displayed pane. * diff --git a/racevisionGame/src/main/java/visualiser/Controllers/RaceController.java b/racevisionGame/src/main/java/visualiser/Controllers/RaceController.java index 043726f7..f4eacb5e 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/RaceController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/RaceController.java @@ -1,6 +1,6 @@ package visualiser.Controllers; - +import com.interactivemesh.jfx.importer.stl.StlMeshImporter; import javafx.animation.AnimationTimer; import javafx.application.Platform; import javafx.collections.FXCollections; @@ -14,20 +14,27 @@ import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.GridPane; -import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; +import javafx.scene.shape.MeshView; +import javafx.scene.shape.Sphere; +import javafx.scene.transform.Translate; import javafx.util.Callback; import network.Messages.Enums.RaceStatusEnum; +import shared.dataInput.RaceDataSource; import shared.model.Leg; +import shared.model.Mark; import visualiser.app.App; +import visualiser.enums.TutorialState; import visualiser.gameController.ControllerClient; import visualiser.gameController.Keys.ControlKey; +import visualiser.layout.Subject3D; +import visualiser.layout.View3D; import visualiser.model.*; +import visualiser.utils.GPSConverter; import java.io.IOException; import java.net.URL; -import java.util.Optional; -import java.util.ResourceBundle; +import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -38,53 +45,46 @@ import static visualiser.app.App.keyFactory; * Controller used to display a running race. */ public class RaceController extends Controller { - - /** * The race object which describes the currently occurring race. */ private VisualiserRaceEvent visualiserRace; - /** * Service for sending keystrokes to server */ private ControllerClient controllerClient; - private boolean isHost; - /** - * The canvas that draws the race. - */ - private ResizableRaceCanvas raceCanvas; + private TutorialState currentState; + + private ArrayList tutorialStates; + + private boolean isTutorial = false; + + private String keyToPress; - /** - * The sparkline graph. - */ - private Sparkline sparkline; /** * state of the info table */ private boolean infoTableShow; + private View3D view3D; + private ObservableList viewSubjects; + /** * The arrow controller. */ @FXML private ArrowController arrowController; - - @FXML private GridPane canvasBase; + @FXML private SplitPane racePane; - @FXML private SplitPane race; + @FXML private Label tutorialText; - /** - * This is the root node of the arrow control. - */ - @FXML private Pane arrow; /** * This is the pane we place the actual arrow control inside of. @@ -100,9 +100,6 @@ public class RaceController extends Controller { @FXML private TableColumn boatMarkColumn; @FXML private TableColumn boatSpeedColumn; @FXML private LineChart sparklineChart; - @FXML private AnchorPane annotationPane; - - /** * Ctor. @@ -112,11 +109,10 @@ public class RaceController extends Controller { @Override public void initialize(URL location, ResourceBundle resources) { -// KeyFactory keyFactory = KeyFactory.getFactory(); infoTableShow = true; // Initialise keyboard handler - race.addEventFilter(KeyEvent.KEY_PRESSED, event -> { + racePane.addEventFilter(KeyEvent.KEY_PRESSED, event -> { String codeString = event.getCode().toString(); if (codeString.equals("TAB")){toggleTable();} @@ -125,13 +121,27 @@ public class RaceController extends Controller { if(controlKey != null) { try { controlKey.onAction(); // Change key state if applicable + + //Check if current race is a tutorial + if (isTutorial){ + //Check if current tutorial state has the same boat protocol code as key press + if (controlKey.getProtocolCode().equals(currentState.getAction())){ + //Update tutorial + checkTutorialState(); + } + } + controllerClient.sendKey(controlKey); event.consume(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); Logger.getGlobal().log(Level.WARNING, "RaceController was interrupted on thread: " + Thread.currentThread() + "while sending: " + controlKey, e); + } catch (Exception e) { + e.printStackTrace(); } } + + if(event.getCode() == KeyCode.ESCAPE) { try { @@ -142,7 +152,7 @@ public class RaceController extends Controller { Optional result = alert.showAndWait(); if (result.get() == ButtonType.OK) { parent.endEvent(); - race.setVisible(false); + racePane.setVisible(false); App.app.showMainStage(App.getStage()); } } else { @@ -151,7 +161,7 @@ public class RaceController extends Controller { alert.setContentText("Do you wish to quit the race?"); Optional result = alert.showAndWait(); if (result.get() == ButtonType.OK) { - race.setVisible(false); + racePane.setVisible(false); App.app.showMainStage(App.getStage()); } } @@ -175,14 +185,10 @@ public class RaceController extends Controller { //Information table. initialiseInfoTable(this.visualiserRace); - //Sparkline. - initialiseSparkline(this.visualiserRace); - //Arrow. initialiseArrow(this.visualiserRace); - //Race canvas. - initialiseRaceCanvas(this.visualiserRace); + initialiseView3D(this.visualiserRace); //Race timezone label. initialiseRaceTimezoneLabel(this.visualiserRace); @@ -190,11 +196,106 @@ public class RaceController extends Controller { //Race clock. initialiseRaceClock(this.visualiserRace); - //Start the race animation timer. raceTimer(); } + private void initialiseView3D(VisualiserRaceEvent race) { + viewSubjects = FXCollections.observableArrayList(); + + // Import boat mesh + URL asset = HostController.class.getClassLoader().getResource("assets/V1.2 Complete Boat.stl"); + StlMeshImporter importer = new StlMeshImporter(); + importer.read(asset); + + // Configure camera angles and control + view3D = new View3D(); + view3D.setDistance(1050); + view3D.setYaw(0); + view3D.setPitch(60); + view3D.enableTracking(); + //newPane.getChildren().add(view3D); + canvasBase.add(view3D, 0, 0); + + // Set up projection from GPS to view + RaceDataSource raceData = visualiserRace.getVisualiserRaceState().getRaceDataSource(); + final GPSConverter gpsConverter = new GPSConverter(raceData, 450, 450); + + view3D.setItems(viewSubjects); + // Position and add each mark to view + for(Mark mark: race.getVisualiserRaceState().getMarks()) { + Subject3D subject = new Subject3D(new Sphere(2)); + subject.setX(gpsConverter.convertGPS(mark.getPosition()).getX()); + subject.setZ(gpsConverter.convertGPS(mark.getPosition()).getY()); + + viewSubjects.add(subject); + } + // Position and add each boat to view + for(VisualiserBoat boat: race.getVisualiserRaceState().getBoats()) { + MeshView mesh = new MeshView(importer.getImport()); + Subject3D subject = new Subject3D(mesh); + viewSubjects.add(subject); + + // Track this boat's movement with the new subject + AnimationTimer trackBoat = new AnimationTimer() { + @Override + public void handle(long now) { + subject.setHeading(boat.getBearing().degrees()); + subject.setX(gpsConverter.convertGPS(boat.getPosition()).getX()); + subject.setZ(gpsConverter.convertGPS(boat.getPosition()).getY()); + } + }; + trackBoat.start(); + } + // Fix initial bird's-eye position + view3D.updatePivot(new Translate(250, 0, 210)); + + // Bind zooming to scrolling + view3D.setOnScroll(e -> { + view3D.updateDistance(e.getDeltaY()); + }); + + // Bind zooming to keypress (Z/X default) + racePane.addEventFilter(KeyEvent.KEY_PRESSED, e -> { + ControlKey key = keyFactory.getKey(e.getCode().toString()); + if(key != null) { + switch (key.toString()) { + case "Zoom In": + //Check if race is a tutorial + if (isTutorial) { + //Check if the current tutorial state is zoom-in + if (currentState.equals(TutorialState.ZOOMIN)) { + try { + //Update tutorial + checkTutorialState(); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + } + view3D.updateDistance(-10); + break; + case "Zoom Out": + //Check if race is a tutorial + if(isTutorial) { + //Check if current tutorial state is zoom-out + if (currentState.equals(TutorialState.ZOOMOUT)) { + try { + //Update tutorial + checkTutorialState(); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + } + view3D.updateDistance(10); + break; + } + } + }); + } + + /** @@ -337,42 +438,8 @@ public class RaceController extends Controller { } - - /** - * Initialises the {@link Sparkline}, and listens to a specified {@link VisualiserRaceEvent}. - * @param race The race to listen to. - */ - private void initialiseSparkline(VisualiserRaceEvent race) { - //The race.getBoats() we are passing in is sorted by position in race inside the race class. - this.sparkline = new Sparkline(this.visualiserRace.getVisualiserRaceState(), this.sparklineChart); - } - - /** - * Initialises the {@link ResizableRaceCanvas}, provides the race to read data from. - * @param race Race to read data from. - */ - private void initialiseRaceCanvas(VisualiserRaceEvent race) { - - //Create canvas. - raceCanvas = new ResizableRaceCanvas(race.getVisualiserRaceState()); - - //Set properties. - raceCanvas.setMouseTransparent(true); - raceCanvas.widthProperty().bind(canvasBase.widthProperty()); - raceCanvas.heightProperty().bind(canvasBase.heightProperty()); - - //Draw it and show it. - raceCanvas.draw(); - raceCanvas.setVisible(true); - - //Add to scene. - canvasBase.getChildren().add(0, raceCanvas); - } - - - /** - * Intialises the race time zone label with the race's time zone. + * Initialises the race time zone label with the race's time zone. * @param race The race to get time zone from. */ private void initialiseRaceTimezoneLabel(VisualiserRaceEvent race) { @@ -407,14 +474,29 @@ public class RaceController extends Controller { this.controllerClient = controllerClient; this.isHost = isHost; - initialiseRace(); - //Display this controller. - race.setVisible(true); + //Check if the game is a tutorial + if (parent.getGameType()==4){ + isTutorial = true; + tutorialText.setVisible(true); + tutorialStates = new ArrayList<>(Arrays.asList(TutorialState.values())); + + currentState = tutorialStates.get(0); + tutorialStates.remove(0); + + searchMapForKey("Upwind"); + + tutorialText.setText("Welcome to the tutorial! Exit at anytime with ESC. \nWe will first learn how to turn upwind. Press " + keyToPress + " to turn upwind."); + + } else { + isTutorial = false; + tutorialText.setVisible(false); + } + initialiseRace(); - // set up annotation displays - new Annotations(annotationPane, raceCanvas); + //Display this controller. + racePane.setVisible(true); } /** @@ -422,7 +504,7 @@ public class RaceController extends Controller { * @param boats boats there are in the race. */ public void finishRace(ObservableList boats) { - race.setVisible(false); + racePane.setVisible(false); parent.enterFinish(boats); } @@ -457,18 +539,13 @@ public class RaceController extends Controller { finishRace(visualiserRace.getVisualiserRaceState().getBoats()); } else { - //Otherwise, render the canvas. - raceCanvas.drawRace(); - - //Sort the tableview. Doesn't automatically work for all columns. boatInfoTable.sort(); - } //Return to main screen if we lose connection. if (!visualiserRace.getServerConnection().isAlive()) { - race.setVisible(false); + racePane.setVisible(false); //parent.enterTitle(); try { App.app.showMainStage(App.getStage()); @@ -490,10 +567,10 @@ public class RaceController extends Controller { * toggles if the info table is shown */ private void toggleTable() { - double tablePercent = 1 - (boatPlacingColumn.getPrefWidth() + boatTeamColumn.getPrefWidth() + boatMarkColumn.getPrefWidth() + boatSpeedColumn.getPrefWidth())/race.getWidth(); + double tablePercent = 1 - (boatPlacingColumn.getPrefWidth() + boatTeamColumn.getPrefWidth() + boatMarkColumn.getPrefWidth() + boatSpeedColumn.getPrefWidth())/racePane.getWidth(); if (infoTableShow){ - race.setDividerPositions(tablePercent); + racePane.setDividerPositions(tablePercent); arrowPane.setScaleX(0.5); arrowPane.setScaleY(0.5); @@ -501,7 +578,7 @@ public class RaceController extends Controller { arrowPane.setTranslateY(0 - arrowPane.getScene().getHeight()/4); }else{ - race.setDividerPositions(1); + racePane.setDividerPositions(1); arrowPane.setScaleX(1); arrowPane.setScaleY(1); @@ -513,4 +590,108 @@ public class RaceController extends Controller { infoTableShow = !infoTableShow; } + /** + * Get the next tutorial state + */ + private void updateTutorialState(){ + //Next tutorial state is popped from list + currentState = tutorialStates.get(0); + tutorialStates.remove(0); + } + + /** + * Search key map for key given string of command + * @param command the command of the key + */ + private void searchMapForKey(String command){ + //For loop through keyFactory + for (Map.Entry entry: keyFactory.getKeyState().entrySet()){ + if(entry.getValue().toString().equals(command)){ + + //Found next key required to press + keyToPress = entry.getKey(); + } + } + } + + /** + * Updates tutorial state and gui display for tutorial text + * @throws Exception Exception thrown + */ + private void checkTutorialState() throws Exception { + //Switch statement to check what the current tutorial state is + switch (currentState){ + case UPWIND: + //Set next key to press as the downwind key + searchMapForKey("Downwind"); + //Update tutorial text + tutorialText.setText("Nice! To turn downwind press " + keyToPress + "."); + updateTutorialState(); + break; + case DOWNWIND: + //Set next key to press as the tack/gybe key + searchMapForKey("Tack/Gybe"); + //Update tutorial text + tutorialText.setText("Nice! To tack or gybe press " + keyToPress + "."); + updateTutorialState(); + break; + case TACKGYBE: + //Set next key to press as the VMG key + searchMapForKey("VMG"); + //Update tutorial text + tutorialText.setText("Nice! To use VMG press " + keyToPress + ". This will turn the boat."); + updateTutorialState(); + break; + case VMG: + //Set next key to press as the sails-in key + searchMapForKey("Toggle Sails"); + //Update tutorial text + tutorialText.setText("Nice! To sails in press " + keyToPress + ". This will stop the boat."); + updateTutorialState(); + break; + case SAILSIN: + //Set next key to press as the sails-out key + searchMapForKey("Toggle Sails"); + //Update tutorial text + tutorialText.setText("Nice! To sails out press " + keyToPress + " again. The will start moving again."); + updateTutorialState(); + break; + case SAILSOUT: + //Set next key to press as the zoom-in key + searchMapForKey("Zoom In"); + //Update tutorial text + tutorialText.setText("Nice! To zoom in press " + keyToPress + "."); + updateTutorialState(); + break; + case ZOOMIN: + //Set next key to press as the zoom-out key + searchMapForKey("Zoom Out"); + //Update tutorial text + tutorialText.setText("Nice! You will also be able to zoom into boats and marks by clicking them. To zoom out press " + keyToPress + "."); + updateTutorialState(); + break; + case ZOOMOUT: + //Finished tutorial. Display pop-up for exiting the tutorial + tutorialText.setText("Congratulations! You're done!"); + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Finished Tutorial"); + alert.setHeaderText("You have finished the tutorial."); + alert.setContentText("Now you know the controls you are ready to race!"); + Optional result = alert.showAndWait(); + if (result.get() == ButtonType.OK) { + parent.endEvent(); + racePane.setVisible(false); + App.app.showMainStage(App.getStage()); + } + break; + default: + //State not found. Exit tutorial to title menu + parent.endEvent(); + racePane.setVisible(false); + App.app.showMainStage(App.getStage()); + break; + } + + } + } diff --git a/racevisionGame/src/main/java/visualiser/Controllers/StartController.java b/racevisionGame/src/main/java/visualiser/Controllers/StartController.java index 890eb816..290837ae 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/StartController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/StartController.java @@ -86,9 +86,6 @@ public class StartController extends Controller { - - - /** * Ctor. */ @@ -218,31 +215,30 @@ public class StartController extends Controller { * Countdown timer until race starts. */ private void countdownTimer() { - new AnimationTimer() { - @Override - public void handle(long arg0) { + new AnimationTimer() { + @Override + public void handle(long arg0) { - //Get the current race status. - RaceStatusEnum raceStatus = visualiserRaceEvent.getVisualiserRaceState().getRaceStatusEnum(); + //Get the current race status. + RaceStatusEnum raceStatus = visualiserRaceEvent.getVisualiserRaceState().getRaceStatusEnum(); - //Display it. - raceStatusLabel.setText("Race Status: " + raceStatus.name()); + //If the race has reached the preparatory phase, or has started... + if (raceStatus == RaceStatusEnum.WARNING + || raceStatus == RaceStatusEnum.PREPARATORY + || raceStatus == RaceStatusEnum.STARTED) { + //Stop this timer. + stop(); + //Hide this, and display the race controller. + startWrapper.setVisible(false); + //start.setVisible(false);//TODO is this needed? - //If the race has reached the preparatory phase, or has started... - if (raceStatus == RaceStatusEnum.PREPARATORY || raceStatus == RaceStatusEnum.STARTED) { - //Stop this timer. - stop(); - - //Hide this, and display the race controller. - startWrapper.setVisible(false); - //start.setVisible(false);//TODO is this needed? - - parent.beginRace(visualiserRaceEvent, controllerClient, isHost); + parent.beginRace(visualiserRaceEvent, controllerClient, isHost); + } } - } - }.start(); + }.start(); + } diff --git a/racevisionGame/src/main/java/visualiser/Controllers/TitleController.java b/racevisionGame/src/main/java/visualiser/Controllers/TitleController.java index aa2edf13..1d38ead6 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/TitleController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/TitleController.java @@ -6,16 +6,24 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.control.RadioButton; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Pane; import javafx.stage.Modality; import javafx.stage.Stage; +import mock.app.Event; +import mock.exceptions.EventConstructionException; import javafx.stage.WindowEvent; import visualiser.app.App; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Controller for the opening title window. @@ -33,6 +41,12 @@ public class TitleController extends Controller { RadioButton dayModeRD; @FXML RadioButton nightModeRD; + @FXML + Label tutorialLabel; + @FXML + Pane menuPane; + @FXML + ImageView imgSun; /** * Method called when the 'host a game' button is pressed. @@ -42,6 +56,7 @@ public class TitleController extends Controller { */ public void hostAGame() throws IOException { titleWrapper.setVisible(false); + parent.setGameType(0); parent.hostGame(); App.getStage().setResizable(true); } @@ -68,7 +83,10 @@ public class TitleController extends Controller { */ public void setDayMode(){ dayModeRD.getScene().getStylesheets().clear(); + menuPane.getStylesheets().clear(); + imgSun.setImage(new Image(getClass().getResource("/visualiser/images/sun.png").toExternalForm())); dayModeRD.getScene().getStylesheets().add("/css/dayMode.css"); + menuPane.setStyle("-fx-background-color: #6be6ff;"); nightModeRD.setSelected(false); } @@ -77,12 +95,17 @@ public class TitleController extends Controller { */ public void setNightMode(){ nightModeRD.getScene().getStylesheets().clear(); + menuPane.getStylesheets().clear(); + imgSun.setImage(new Image(getClass().getResource("/visualiser/images/sunsleep.png").toExternalForm())); nightModeRD.getScene().getStylesheets().add("/css/nightMode.css"); + menuPane.setStyle("-fx-background-color: #1f2c60;"); dayModeRD.setSelected(false); } @Override public void initialize(URL location, ResourceBundle resources) { + tutorialLabel.setWrapText(true); + } /** @@ -114,4 +137,12 @@ public class TitleController extends Controller { } } + + public void tutorialStartPressed() throws IOException { + titleWrapper.setVisible(false); + parent.setGameType(4); + parent.beginGame(); + + } + } diff --git a/racevisionGame/src/main/java/visualiser/app/App.java b/racevisionGame/src/main/java/visualiser/app/App.java index e095e04e..d33fd2b4 100644 --- a/racevisionGame/src/main/java/visualiser/app/App.java +++ b/racevisionGame/src/main/java/visualiser/app/App.java @@ -3,6 +3,7 @@ package visualiser.app; import javafx.animation.FadeTransition; import javafx.application.Application; import javafx.application.Platform; +import javafx.beans.property.ReadOnlyObjectProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.concurrent.Task; @@ -14,6 +15,7 @@ import javafx.geometry.Rectangle2D; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Label; +import javafx.scene.control.ListView; import javafx.scene.control.ProgressBar; import javafx.scene.effect.DropShadow; import javafx.scene.image.Image; @@ -95,7 +97,7 @@ public class App extends Application { ); updateMessage("Preparing ingredients . . ."); - Thread.sleep(200); + Thread.sleep(100); for (int i = 0; i < burgerFilling.size(); i++) { Thread.sleep(100); updateProgress(i + 1, burgerFilling.size()); diff --git a/racevisionGame/src/main/java/visualiser/enums/TutorialState.java b/racevisionGame/src/main/java/visualiser/enums/TutorialState.java new file mode 100644 index 00000000..ab811a43 --- /dev/null +++ b/racevisionGame/src/main/java/visualiser/enums/TutorialState.java @@ -0,0 +1,66 @@ +package visualiser.enums; + +import javafx.scene.input.KeyCode; +import network.Messages.BoatAction; +import network.Messages.Enums.BoatActionEnum; +import visualiser.gameController.Keys.ControlKey; +import static visualiser.app.App.keyFactory; + +import java.util.ArrayList; + +/** + * State of which stage the tutorial is currently in + */ +public enum TutorialState { + + /** + * State for upwind in tutorial + */ + UPWIND(BoatActionEnum.UPWIND), + + /** + * State for downwind in tutorial + */ + DOWNWIND(BoatActionEnum.DOWNWIND), + + /** + * State for tacking/gybing in tutorial + */ + TACKGYBE(BoatActionEnum.TACK_GYBE), + + /** + * State for vmg in tutorial + */ + VMG(BoatActionEnum.AUTO_PILOT), + + /** + * State for sails-in in tutorial + */ + SAILSIN(BoatActionEnum.SAILS_IN), + + /** + * State for sails-out in tutorial + */ + SAILSOUT(BoatActionEnum.SAILS_OUT), + + /** + * State for zoom-in in tutorial + */ + ZOOMIN(null), + + /** + * State for zoom-out in tutorial + */ + ZOOMOUT(null); + + private BoatActionEnum action; + + TutorialState(BoatActionEnum action){ + this.action = action; + } + + public BoatActionEnum getAction(){ + return action; + } + +} diff --git a/racevisionGame/src/main/java/visualiser/gameController/Keys/ControlKey.java b/racevisionGame/src/main/java/visualiser/gameController/Keys/ControlKey.java index dd489f73..ce4b341e 100644 --- a/racevisionGame/src/main/java/visualiser/gameController/Keys/ControlKey.java +++ b/racevisionGame/src/main/java/visualiser/gameController/Keys/ControlKey.java @@ -1,6 +1,5 @@ package visualiser.gameController.Keys; -import javafx.scene.input.KeyCode; import network.Messages.Enums.BoatActionEnum; /** @@ -45,7 +44,7 @@ public abstract class ControlKey { /** * What this key should do when the command is issued for it to do its job. */ - public abstract void onAction();//may want to make it take in a visualiser and stuff in the future. + public abstract void onAction(); /** * What to do when the key is held diff --git a/racevisionGame/src/main/java/visualiser/layout/Subject3D.java b/racevisionGame/src/main/java/visualiser/layout/Subject3D.java new file mode 100644 index 00000000..af76f4f4 --- /dev/null +++ b/racevisionGame/src/main/java/visualiser/layout/Subject3D.java @@ -0,0 +1,65 @@ +package visualiser.layout; + +import javafx.scene.shape.Shape3D; +import javafx.scene.transform.Rotate; +import javafx.scene.transform.Translate; + +/** + * Wrapper for controlling the position and heading of rendered 3D models. + */ +public class Subject3D { + /** + * Rendered mesh + */ + private Shape3D mesh; + + /** + * Position translation updated by state listeners + */ + private Translate position; + + /** + * Heading rotation updated by state listeners + */ + private Rotate heading; + + /** + * Constructor for view subject wrapper + * @param mesh to be rendered + */ + public Subject3D(Shape3D mesh) { + this.mesh = mesh; + this.position = new Translate(); + this.heading = new Rotate(0, Rotate.Y_AXIS); + + this.mesh.getTransforms().addAll(position, heading, new Rotate(90, Rotate.X_AXIS), new Rotate(180, Rotate.Y_AXIS)); + } + + public Shape3D getMesh() { + return mesh; + } + + public Translate getPosition() { + return this.position; + } + + public Rotate getHeading() { + return heading; + } + + public void setX(double x) { + position.setX(x); + } + + public void setY(double y) { + position.setY(y); + } + + public void setZ(double z) { + position.setZ(z); + } + + public void setHeading(double angle) { + heading.setAngle(angle); + } +} diff --git a/racevisionGame/src/main/java/visualiser/layout/View3D.java b/racevisionGame/src/main/java/visualiser/layout/View3D.java new file mode 100644 index 00000000..27fe6086 --- /dev/null +++ b/racevisionGame/src/main/java/visualiser/layout/View3D.java @@ -0,0 +1,260 @@ +package visualiser.layout; + +import javafx.beans.value.ChangeListener; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; +import javafx.scene.Group; +import javafx.scene.PerspectiveCamera; +import javafx.scene.SubScene; +import javafx.scene.input.PickResult; +import javafx.scene.layout.Pane; +import javafx.scene.paint.Color; +import javafx.scene.shape.Shape3D; +import javafx.scene.transform.Rotate; +import javafx.scene.transform.Translate; + +import java.util.HashMap; +import java.util.Map; + +/** + * Control for rendering 3D objects visible through a PerspectiveCamera. Implements Adapter Pattern to + * interface with camera, and allows clients to add shapes to the scene. All scenes contain sea plane and + * sky box, whose textures are set with special methods. + */ +public class View3D extends Pane { + /** + * Container for group and camera + */ + private SubScene scene; + /** + * Observable list of renderable items + */ + private ObservableList items; + /** + * Map for selecting Subject3D from Shape3D + */ + private Map selectionMap; + /** + * Subject tracked by camera + */ + private Subject3D target; + /** + * Rendering container for shapes + */ + private Group world; + /** + * Near limit of view frustum + */ + private double nearClip; + /** + * Far limit of view frustum + */ + private double farClip; + /** + * Camera origin + */ + private Translate pivot; + /** + * Distance of camera from pivot point + */ + private Translate distance; + /** + * Angle along ground between z-axis and camera + */ + private Rotate yaw; + /** + * Angle between ground plane and camera direction + */ + private Rotate pitch; + /** + * Single listener for subject heading changes + */ + private ChangeListener pivotHeading = (o, prev, curr) -> yaw.setAngle((double)curr); + /** + * Single listener for subject position (x) changes + */ + private ChangeListener pivotX = (o, prev, curr) -> pivot.setX((double)curr); + /** + * Single listener for subject position (y) changes + */ + private ChangeListener pivotY = (o, prev, curr) -> pivot.setY((double)curr); + /** + * Single listener for subject position (z) changes + */ + private ChangeListener pivotZ = (o, prev, curr) -> pivot.setZ((double)curr); + /** + * Distance to switch from third person to bird's eye + */ + private double THIRD_PERSON_LIMIT = 100; + + /** + * Default constructor for View3D. Sets up Scene and PerspectiveCamera. + */ + public View3D() { + this.world = new Group(); + this.selectionMap = new HashMap<>(); + this.target = null; + this.scene = new SubScene(world, 300, 300); + + scene.widthProperty().bind(this.widthProperty()); + scene.heightProperty().bind(this.heightProperty()); + scene.setFill(new Color(0.2, 0.6, 1, 1)); + + scene.setCamera(buildCamera()); + + this.getChildren().add(scene); + } + + /** + * Sets up camera view frustum and binds transformations + * @return perspective camera + */ + private PerspectiveCamera buildCamera() { + PerspectiveCamera camera = new PerspectiveCamera(true); + + // Set up view frustum + nearClip = 0.1; + farClip = 3000.0; + camera.setNearClip(nearClip); + camera.setFarClip(farClip); + + // Set up transformations + pivot = new Translate(); + distance = new Translate(); + yaw = new Rotate(0, Rotate.Y_AXIS); + pitch = new Rotate(0, Rotate.X_AXIS); + camera.getTransforms().addAll(pivot, yaw, pitch, distance); + + return camera; + } + + /** + * Provide the list of subjects to be automatically added or removed from the view as the list + * changes. + * @param items list managed by client + */ + public void setItems(ObservableList items) { + this.items = items; + this.items.addListener((ListChangeListener) c -> { + while(c.next()) { + if (c.wasRemoved() || c.wasAdded()) { + for (Subject3D shape : c.getRemoved()) { + world.getChildren().remove(shape.getMesh()); + selectionMap.remove(shape.getMesh()); + } + for (Subject3D shape : c.getAddedSubList()) { + world.getChildren().add(shape.getMesh()); + selectionMap.put(shape.getMesh(), shape); + } + } + } + }); + } + + /** + * Intercept mouse clicks on subjects in view. The applied listener cannot be removed. + */ + public void enableTracking() { + scene.setOnMousePressed(e -> { + PickResult result = e.getPickResult(); + if(result != null && result.getIntersectedNode() != null && result.getIntersectedNode() instanceof Shape3D) { + trackSubject(selectionMap.get(result.getIntersectedNode())); + } + }); + } + + /** + * Stop camera from following the last selected subject + */ + private void untrackSubject() { + if(target != null) { + target.getPosition().xProperty().removeListener(pivotX); + target.getPosition().yProperty().removeListener(pivotY); + target.getPosition().zProperty().removeListener(pivotZ); + target.getHeading().angleProperty().removeListener(pivotHeading); + } + } + + /** + * Set camera to follow the selected subject + * @param subject to track + */ + private void trackSubject(Subject3D subject) { + untrackSubject(); + target = subject; + + updatePivot(target.getPosition()); + setYaw(target.getHeading().getAngle()); + + target.getPosition().xProperty().addListener(pivotX); + target.getPosition().yProperty().addListener(pivotY); + target.getPosition().zProperty().addListener(pivotZ); + target.getHeading().angleProperty().addListener(pivotHeading); + + this.setDistance(THIRD_PERSON_LIMIT); + this.setPitch(20); + } + + public void setNearClip(double nearClip) { + this.nearClip = nearClip; + } + + public void setFarClip(double farClip) { + this.farClip = farClip; + } + + /** + * Sets the coordinates of the camera pivot once. + * @param pivot source of coordinates + */ + public void updatePivot(Translate pivot) { + this.pivot.setX(pivot.getX()); + this.pivot.setY(pivot.getY()); + this.pivot.setZ(pivot.getZ()); + } + + /** + * Set distance of camera from pivot + * @param distance in units + */ + public void setDistance(double distance) { + this.distance.setZ(-distance); + } + + /** + * Adds delta to current distance and changes camera mode if applicable. + * Third person limit specifies the distance at which a third person camera + * switches to bird's-eye, remaining focused on the same position. + * @param delta amount to change distance by + */ + public void updateDistance(double delta) { + double distance = -this.distance.getZ() + delta; + + if(distance <= 0) { + this.setDistance(0); + } else if(distance > THIRD_PERSON_LIMIT) { + untrackSubject(); + this.setYaw(0); + this.setPitch(60); + this.setDistance(distance); + } else { + this.setDistance(distance); + } + } + + /** + * Set angle of camera from z-axis along ground + * @param yaw in degrees + */ + public void setYaw(double yaw) { + this.yaw.setAngle(yaw); + } + + /** + * Set elevation of camera + * @param pitch in degrees + */ + public void setPitch(double pitch) { + this.pitch.setAngle(-pitch); + } +} diff --git a/racevisionGame/src/main/java/visualiser/model/BoatDisplay3D.java b/racevisionGame/src/main/java/visualiser/model/BoatDisplay3D.java deleted file mode 100644 index 9314f5cd..00000000 --- a/racevisionGame/src/main/java/visualiser/model/BoatDisplay3D.java +++ /dev/null @@ -1,18 +0,0 @@ -package visualiser.model; - -import com.interactivemesh.jfx.importer.Importer; -import javafx.scene.layout.Pane; - -/** - * Created by fwy13 on 29/08/17. - */ -public class BoatDisplay3D extends Pane { - - - public BoatDisplay3D(String filePath){ - super(); -// Shape3D -// this.getChildren().add(); - } - -} diff --git a/racevisionGame/src/main/java/visualiser/model/View3D.java b/racevisionGame/src/main/java/visualiser/model/View3D.java deleted file mode 100644 index 6affb906..00000000 --- a/racevisionGame/src/main/java/visualiser/model/View3D.java +++ /dev/null @@ -1,145 +0,0 @@ -package visualiser.model; - -import javafx.collections.ListChangeListener; -import javafx.collections.ObservableList; -import javafx.scene.Group; -import javafx.scene.PerspectiveCamera; -import javafx.scene.SubScene; -import javafx.scene.layout.Pane; -import javafx.scene.paint.Color; -import javafx.scene.shape.Shape3D; -import javafx.scene.transform.Rotate; -import javafx.scene.transform.Translate; - -/** - * Control for rendering 3D objects visible through a PerspectiveCamera. Implements Adapter Pattern to - * interface with camera, and allows clients to add shapes to the scene. All scenes contain sea plane and - * sky box, whose textures are set with special methods. - */ -public class View3D extends Pane { - /** - * Observable list of renderable items - */ - private ObservableList items; - /** - * Rendering container for shapes - */ - private Group world; - /** - * Near limit of view frustum - */ - private double nearClip; - /** - * Far limit of view frustum - */ - private double farClip; - /** - * Position camera pivots around - */ - private Translate pivot; - /** - * Distance of camera from pivot point - */ - private Translate distance; - /** - * Angle along ground between z-axis and camera - */ - private Rotate yaw; - /** - * Angle between ground plane and camera direction - */ - private Rotate pitch; - - /** - * Default constructor for View3D. Sets up Scene and PerspectiveCamera. - */ - public View3D() { - world = new Group(); - - SubScene scene = new SubScene(world, 300, 300); - scene.widthProperty().bind(this.widthProperty()); - scene.heightProperty().bind(this.heightProperty()); - scene.setFill(Color.BLACK); - - scene.setCamera(buildCamera()); - - this.getChildren().add(scene); - } - - /** - * Sets up camera view frustum and binds transformations - * @return perspective camera - */ - private PerspectiveCamera buildCamera() { - PerspectiveCamera camera = new PerspectiveCamera(true); - - // Set up view frustum - nearClip = 0.1; - farClip = 1000.0; - camera.setNearClip(nearClip); - camera.setFarClip(farClip); - - // Set up transformations - pivot = new Translate(); - distance = new Translate(); - yaw = new Rotate(0, Rotate.Y_AXIS); - pitch = new Rotate(0, Rotate.X_AXIS); - camera.getTransforms().addAll(pivot, yaw, pitch, distance); - - return camera; - } - - public void setItems(ObservableList items) { - this.items = items; - this.items.addListener((ListChangeListener) c -> { - while(c.next()) { - if (c.wasRemoved() || c.wasAdded()) { - for (Shape3D shape : c.getRemoved()) world.getChildren().remove(shape); - for (Shape3D shape : c.getAddedSubList()) world.getChildren().add(shape); - } - } - }); - } - - public void setNearClip(double nearClip) { - this.nearClip = nearClip; - } - - public void setFarClip(double farClip) { - this.farClip = farClip; - } - - /** - * Set object to centre on camera - * @param pivot centred object - */ - public void setPivot(Shape3D pivot) { - this.pivot.setX(pivot.getTranslateX()); - this.pivot.setY(pivot.getTranslateY()); - this.pivot.setZ(pivot.getTranslateZ()); - } - - /** - * Set distance of camera from pivot - * @param distance in units - */ - public void setDistance(double distance) { - this.distance.setZ(-distance); - } - - /** - * Set angle of camera from z-axis along ground - * @param yaw in degrees - */ - public void setYaw(double yaw) { - this.yaw.setAngle(yaw); - } - - /** - * Set elevation of camera - * @param pitch in degrees - */ - public void setPitch(double pitch) { - this.pitch.setAngle(-pitch); - } -} diff --git a/racevisionGame/src/main/java/visualiser/model/VisualiserBoat.java b/racevisionGame/src/main/java/visualiser/model/VisualiserBoat.java index 6cbfdaa3..555def15 100644 --- a/racevisionGame/src/main/java/visualiser/model/VisualiserBoat.java +++ b/racevisionGame/src/main/java/visualiser/model/VisualiserBoat.java @@ -1,11 +1,10 @@ package visualiser.model; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; import javafx.scene.paint.Color; import network.Messages.Enums.BoatStatusEnum; -import shared.model.Azimuth; -import shared.model.Boat; -import shared.model.Constants; -import shared.model.GPSCoordinate; +import shared.model.*; import java.time.Duration; import java.time.ZonedDateTime; @@ -61,7 +60,8 @@ public class VisualiserBoat extends Boat { private boolean isClientBoat = false; - + private ObjectProperty positionProperty; + private ObjectProperty bearingProperty; /** @@ -239,4 +239,38 @@ public class VisualiserBoat extends Boat { public void setClientBoat(boolean clientBoat) { isClientBoat = clientBoat; } + + @Override + public GPSCoordinate getPosition() { + return positionProperty.get(); + } + + @Override + public void setPosition(GPSCoordinate position) { + if(this.positionProperty == null) { + this.positionProperty = new SimpleObjectProperty<>(); + } + this.positionProperty.set(position); + } + + public ObjectProperty positionProperty() { + return positionProperty; + } + + @Override + public Bearing getBearing() { + return bearingProperty.get(); + } + + @Override + public void setBearing(Bearing bearing) { + if(this.bearingProperty == null) { + this.bearingProperty = new SimpleObjectProperty<>(); + } + this.bearingProperty.set(bearing); + } + + public ObjectProperty bearingProperty() { + return bearingProperty; + } } diff --git a/racevisionGame/src/main/java/visualiser/utils/GPSConverter.java b/racevisionGame/src/main/java/visualiser/utils/GPSConverter.java new file mode 100644 index 00000000..22dd937f --- /dev/null +++ b/racevisionGame/src/main/java/visualiser/utils/GPSConverter.java @@ -0,0 +1,104 @@ +package visualiser.utils; + +import shared.dataInput.RaceDataSource; +import shared.model.GPSCoordinate; +import visualiser.model.GraphCoordinate; + +/** + * Converts GPS coordinates to view volume coordinates. Longitudes are equally spaced at all latitudes, + * which leads to inaccurate distance measurements close to the poles. This is acceptable as races are + * not likely to be set there. + */ +public class GPSConverter { + private double longRight; + private double longLeft; + private double latBottom; + private double latTop; + /** + * Conversion factor from longitude to view units + */ + private double longitudeFactor; + /** + * Conversion factor from latitude to view units + */ + private double latitudeFactor; + + /** + * Set up projection with default view boundaries from RaceDataSource + * @param source for view boundaries + * @param longitudeFactor separation of a degree of longitude in view units + * @param latitudeFactor separation of a degree of latitude in view units + */ + public GPSConverter(RaceDataSource source, double longitudeFactor, double latitudeFactor) { + this.latTop = source.getMapTopLeft().getLatitude(); + this.longLeft = source.getMapTopLeft().getLongitude(); + this.latBottom = source.getMapBottomRight().getLatitude(); + this.longRight = source.getMapBottomRight().getLongitude(); + this.longitudeFactor = longitudeFactor; + this.latitudeFactor = latitudeFactor; + } + + /** + * Converts GPS coordinates to coordinates for container. + * It is assumed that the provided GPSCoordinate will always be within the GPSCoordinate boundaries of the RaceMap. + * + * @param lat GPS latitude + * @param lon GPS longitude + * @return GraphCoordinate (pair of doubles) + * @see GraphCoordinate + */ + private GraphCoordinate convertGPS(double lat, double lon) { + + //Calculate the width/height, in gps coordinates, of the map. + double longWidth = longRight - longLeft; + double latHeight = latBottom - latTop; + + //Calculate the distance between the specified coordinate and the edge of the map. + double longDelta = lon - longLeft; + double latDelta = lat - latTop; + + //Calculate the proportion along horizontally, from the left, the coordinate should be. + double longProportion = longDelta / longWidth; + //Calculate the proportion along vertically, from the top, the coordinate should be. + double latProportion = latDelta / latHeight; + + //Check which metric dimension of our map is smaller. We use this to ensure that any rendered stuff retains its correct aspect ratio, and that everything is visible on screen. + double smallerDimension = Math.min(longitudeFactor, latitudeFactor); + + //Calculate the x and y pixel coordinates. + //We take the complement of latProportion to flip it. + int x = (int) (longProportion * smallerDimension); + int y = (int) (latProportion * smallerDimension); + + //Because we try to maintain the correct aspect ratio, we will end up with "spare" pixels along the larger dimension (e.g., width 800, height 600, 200 extra pixels along width). + double extraDistance = Math.abs(longitudeFactor - latitudeFactor); + //We therefore "center" the coordinates along this larger dimension, by adding half of the extra pixels. + if (longitudeFactor > latitudeFactor) { + x += extraDistance / 2; + } else { + y += extraDistance / 2; + } + + + //Finally, create the GraphCoordinate. + GraphCoordinate graphCoordinate = new GraphCoordinate(x, y); + + + return graphCoordinate; + + } + + /** + * Converts the GPS Coordinate to GraphCoordinate. + * It is assumed that the provided GPSCoordinate will always be within the GPSCoordinate boundaries of the RaceMap. + * + * @param coordinate GPSCoordinate representation of Latitude and Longitude. + * @return GraphCoordinate that the GPS is coordinates are to be displayed on the map. + * @see GraphCoordinate + * @see GPSCoordinate + */ + public GraphCoordinate convertGPS(GPSCoordinate coordinate) { + return convertGPS(coordinate.getLatitude(), coordinate.getLongitude()); + } + +} diff --git a/racevisionGame/src/main/resources/css/dayMode.css b/racevisionGame/src/main/resources/css/dayMode.css index aa14c68b..b62f8391 100644 --- a/racevisionGame/src/main/resources/css/dayMode.css +++ b/racevisionGame/src/main/resources/css/dayMode.css @@ -53,5 +53,39 @@ } #arrowImage { - -fx-image: url("/visualiser/images/arrow.png"); + -fx-graphic: url("/visualiser/images/arrow.png"); +} + +#nextButton { + -fx-background-image: url("/visualiser/images/ArrowRoundRight.png"); + -fx-background-size: 60px; + -fx-background-repeat: no-repeat; + -fx-background-position: center center; + -fx-focus-color: transparent; + -fx-background-color: transparent; +} +#nextButton:pressed { + -fx-background-image: url("/visualiser/images/ArrowRoundRightClicked.png"); + -fx-background-size: 60px; + -fx-background-repeat: no-repeat; + -fx-background-position: center center; + -fx-focus-color: transparent; + -fx-background-color: transparent; +} + +#previousButton { + -fx-background-image: url("/visualiser/images/ArrowRoundLeft.png"); + -fx-background-size: 60px; + -fx-background-repeat: no-repeat; + -fx-background-position: center center; + -fx-focus-color: transparent; + -fx-background-color: transparent; +} +#previousButton:pressed { + -fx-background-image: url("/visualiser/images/ArrowRoundLeftClicked.png"); + -fx-background-size: 60px; + -fx-background-repeat: no-repeat; + -fx-background-position: center center; + -fx-focus-color: transparent; + -fx-background-color: transparent; } diff --git a/racevisionGame/src/main/resources/css/nightMode.css b/racevisionGame/src/main/resources/css/nightMode.css index 7fe6a67b..deefa51a 100644 --- a/racevisionGame/src/main/resources/css/nightMode.css +++ b/racevisionGame/src/main/resources/css/nightMode.css @@ -57,3 +57,37 @@ #arrowImage { -fx-image: url("/visualiser/images/arrowLight.png"); } + +#nextButton { + -fx-background-image: url("/visualiser/images/ArrowRoundRight.png"); + -fx-background-size: 60px; + -fx-background-repeat: no-repeat; + -fx-background-position: center center; + -fx-focus-color: transparent; + -fx-background-color: transparent; +} +#nextButton:pressed { + -fx-background-image: url("/visualiser/images/ArrowRoundRightClicked.png"); + -fx-background-size: 60px; + -fx-background-repeat: no-repeat; + -fx-background-position: center center; + -fx-focus-color: transparent; + -fx-background-color: transparent; +} + +#previousButton { + -fx-background-image: url("/visualiser/images/ArrowRoundLeft.png"); + -fx-background-size: 60px; + -fx-background-repeat: no-repeat; + -fx-background-position: center center; + -fx-focus-color: transparent; + -fx-background-color: transparent; +} +#previousButton:pressed { + -fx-background-image: url("/visualiser/images/ArrowRoundLeftClicked.png"); + -fx-background-size: 60px; + -fx-background-repeat: no-repeat; + -fx-background-position: center center; + -fx-focus-color: transparent; + -fx-background-color: transparent; +} diff --git a/racevisionGame/src/main/resources/images/AC35_Racecourse_MAP.png b/racevisionGame/src/main/resources/images/AC35_Racecourse_MAP.png new file mode 100644 index 00000000..1b5e39ca Binary files /dev/null and b/racevisionGame/src/main/resources/images/AC35_Racecourse_MAP.png differ diff --git a/racevisionGame/src/main/resources/images/iMapLayout.png b/racevisionGame/src/main/resources/images/iMapLayout.png new file mode 100644 index 00000000..5932a60d Binary files /dev/null and b/racevisionGame/src/main/resources/images/iMapLayout.png differ diff --git a/racevisionGame/src/main/resources/images/mMapLayout.png b/racevisionGame/src/main/resources/images/mMapLayout.png new file mode 100644 index 00000000..fa0af51f Binary files /dev/null and b/racevisionGame/src/main/resources/images/mMapLayout.png differ diff --git a/racevisionGame/src/main/resources/images/oMapLayout.png b/racevisionGame/src/main/resources/images/oMapLayout.png new file mode 100644 index 00000000..ca520959 Binary files /dev/null and b/racevisionGame/src/main/resources/images/oMapLayout.png differ diff --git a/racevisionGame/src/main/resources/mock/mockXML/boatTutorial.xml b/racevisionGame/src/main/resources/mock/mockXML/boatTutorial.xml new file mode 100644 index 00000000..023c5090 --- /dev/null +++ b/racevisionGame/src/main/resources/mock/mockXML/boatTutorial.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/racevisionGame/src/main/resources/mock/mockXML/iMapLayout.xml b/racevisionGame/src/main/resources/mock/mockXML/iMapLayout.xml new file mode 100644 index 00000000..ca914b12 --- /dev/null +++ b/racevisionGame/src/main/resources/mock/mockXML/iMapLayout.xml @@ -0,0 +1,53 @@ + + + 5326 + FLEET + RACE_CREATION_TIME + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/racevisionGame/src/main/resources/mock/mockXML/mMapLayout.xml b/racevisionGame/src/main/resources/mock/mockXML/mMapLayout.xml new file mode 100644 index 00000000..ce715ba6 --- /dev/null +++ b/racevisionGame/src/main/resources/mock/mockXML/mMapLayout.xml @@ -0,0 +1,43 @@ + + + 5326 + FLEET + RACE_CREATION_TIME + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/racevisionGame/src/main/resources/mock/mockXML/oMapLayout.xml b/racevisionGame/src/main/resources/mock/mockXML/oMapLayout.xml new file mode 100644 index 00000000..5021bbba --- /dev/null +++ b/racevisionGame/src/main/resources/mock/mockXML/oMapLayout.xml @@ -0,0 +1,49 @@ + + + 5326 + FLEET + RACE_CREATION_TIME + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/racevisionGame/src/main/resources/mock/mockXML/raceSinglePlayer.xml b/racevisionGame/src/main/resources/mock/mockXML/raceSinglePlayer.xml index e9e9378a..c4efcd17 100644 --- a/racevisionGame/src/main/resources/mock/mockXML/raceSinglePlayer.xml +++ b/racevisionGame/src/main/resources/mock/mockXML/raceSinglePlayer.xml @@ -5,7 +5,6 @@ RACE_CREATION_TIME - diff --git a/racevisionGame/src/main/resources/mock/mockXML/raceTest.xml b/racevisionGame/src/main/resources/mock/mockXML/raceSixPlayers.xml similarity index 100% rename from racevisionGame/src/main/resources/mock/mockXML/raceTest.xml rename to racevisionGame/src/main/resources/mock/mockXML/raceSixPlayers.xml diff --git a/racevisionGame/src/main/resources/mock/mockXML/raceThreePlayers.xml b/racevisionGame/src/main/resources/mock/mockXML/raceThreePlayers.xml deleted file mode 100644 index e0b81837..00000000 --- a/racevisionGame/src/main/resources/mock/mockXML/raceThreePlayers.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - 5326 - FLEET - RACE_CREATION_TIME - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/racevisionGame/src/main/resources/mock/mockXML/raceTutorial.xml b/racevisionGame/src/main/resources/mock/mockXML/raceTutorial.xml new file mode 100644 index 00000000..47519d00 --- /dev/null +++ b/racevisionGame/src/main/resources/mock/mockXML/raceTutorial.xml @@ -0,0 +1,43 @@ + + + 9999 + FLEET + RACE_CREATION_TIME + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/racevisionGame/src/main/resources/mock/mockXML/regattaTutorial.xml b/racevisionGame/src/main/resources/mock/mockXML/regattaTutorial.xml new file mode 100644 index 00000000..d7f6b9e7 --- /dev/null +++ b/racevisionGame/src/main/resources/mock/mockXML/regattaTutorial.xml @@ -0,0 +1,10 @@ + + 0 + Race Tutorial + Tutorial + -36.82791529 + 174.81218919 + 0.00 + 12 + 14.1 + \ No newline at end of file diff --git a/racevisionGame/src/main/resources/visualiser/images/ArrowRoundLeft.png b/racevisionGame/src/main/resources/visualiser/images/ArrowRoundLeft.png new file mode 100644 index 00000000..ea4f4d64 Binary files /dev/null and b/racevisionGame/src/main/resources/visualiser/images/ArrowRoundLeft.png differ diff --git a/racevisionGame/src/main/resources/visualiser/images/ArrowRoundLeftClicked.png b/racevisionGame/src/main/resources/visualiser/images/ArrowRoundLeftClicked.png new file mode 100644 index 00000000..794ba57c Binary files /dev/null and b/racevisionGame/src/main/resources/visualiser/images/ArrowRoundLeftClicked.png differ diff --git a/racevisionGame/src/main/resources/visualiser/images/ArrowRoundRight.png b/racevisionGame/src/main/resources/visualiser/images/ArrowRoundRight.png new file mode 100644 index 00000000..751698cb Binary files /dev/null and b/racevisionGame/src/main/resources/visualiser/images/ArrowRoundRight.png differ diff --git a/racevisionGame/src/main/resources/visualiser/images/ArrowRoundRightClicked.png b/racevisionGame/src/main/resources/visualiser/images/ArrowRoundRightClicked.png new file mode 100644 index 00000000..10c1b53b Binary files /dev/null and b/racevisionGame/src/main/resources/visualiser/images/ArrowRoundRightClicked.png differ diff --git a/racevisionGame/src/main/resources/visualiser/images/sunsleep.png b/racevisionGame/src/main/resources/visualiser/images/sunsleep.png new file mode 100644 index 00000000..e52b2674 Binary files /dev/null and b/racevisionGame/src/main/resources/visualiser/images/sunsleep.png differ diff --git a/racevisionGame/src/main/resources/visualiser/mock/mockXML/raceXML/raceTutorial.xml b/racevisionGame/src/main/resources/visualiser/mock/mockXML/raceXML/raceTutorial.xml new file mode 100644 index 00000000..db7a6978 --- /dev/null +++ b/racevisionGame/src/main/resources/visualiser/mock/mockXML/raceXML/raceTutorial.xml @@ -0,0 +1,91 @@ + + + + + 99999999 + + Match + + 2011-08-06T13:25:00-0000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/racevisionGame/src/main/resources/visualiser/scenes/hostgame.fxml b/racevisionGame/src/main/resources/visualiser/scenes/hostgame.fxml index ab14abaf..0767dd44 100644 --- a/racevisionGame/src/main/resources/visualiser/scenes/hostgame.fxml +++ b/racevisionGame/src/main/resources/visualiser/scenes/hostgame.fxml @@ -1,44 +1,61 @@ - + - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/racevisionGame/src/main/resources/visualiser/scenes/main.fxml b/racevisionGame/src/main/resources/visualiser/scenes/main.fxml index 7aff44c0..074a9b31 100644 --- a/racevisionGame/src/main/resources/visualiser/scenes/main.fxml +++ b/racevisionGame/src/main/resources/visualiser/scenes/main.fxml @@ -7,7 +7,7 @@ - + diff --git a/racevisionGame/src/main/resources/visualiser/scenes/race.fxml b/racevisionGame/src/main/resources/visualiser/scenes/race.fxml index bbc1c077..af2bf8a3 100644 --- a/racevisionGame/src/main/resources/visualiser/scenes/race.fxml +++ b/racevisionGame/src/main/resources/visualiser/scenes/race.fxml @@ -1,5 +1,11 @@ + + + + + + @@ -22,83 +28,91 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/racevisionGame/src/test/java/shared/dataInput/BoatsXMLTest.java b/racevisionGame/src/test/java/shared/dataInput/BoatsXMLTest.java deleted file mode 100644 index 35e21a0e..00000000 --- a/racevisionGame/src/test/java/shared/dataInput/BoatsXMLTest.java +++ /dev/null @@ -1,47 +0,0 @@ -//package seng302.Mock; -// -//import org.junit.Before; -//import org.junit.Test; -// -//import java.util.HashMap; -//import java.util.Map; -// -//import static org.junit.Assert.assertEquals; -// -///** -// * Created by jjg64 on 21/04/17. -// */ -//public class BoatsXMLTest { -// private BoatXMLReader boatXMLReader; -// -// @Before -// public void setup() { -// try { -// boatXMLReader = new BoatXMLReader("mockXML/boatXML/boatTest.xml", false); -// } catch (Exception e) { -// e.printStackTrace(); -// //fail("Cannot find mockXML/raceXML/raceTest.xml in the resources folder"); -// } -// } -// -// @Test -// public void testInvalidParticipant() { -// Map inputParticipants = new HashMap<>(); -// inputParticipants.put(420, new StreamedBoat(420)); -// boatXMLReader.setParticipants(inputParticipants); -// boatXMLReader.read(); -// assertEquals(boatXMLReader.getBoats().size(), 0); -// } -// -// @Test -// public void testValidParticipant() { -// Map inputParticipants = new HashMap<>(); -// inputParticipants.put(101, new StreamedBoat(101)); -// boatXMLReader.setParticipants(inputParticipants); -// boatXMLReader.read(); -// assertEquals(boatXMLReader.getBoats().size(), 1); -// StreamedBoat boat = (StreamedBoat) boatXMLReader.getBoats().get(0); -// assertEquals(boat.getSourceID(), 101); -// } -// -//} diff --git a/racevisionGame/src/test/java/shared/dataInput/FailBoatXMLTest.java b/racevisionGame/src/test/java/shared/dataInput/FailBoatXMLTest.java deleted file mode 100644 index a299c2bf..00000000 --- a/racevisionGame/src/test/java/shared/dataInput/FailBoatXMLTest.java +++ /dev/null @@ -1,26 +0,0 @@ -//package seng302.Mock; -// -//import org.junit.Test; -//import org.xml.sax.SAXException; -// -//import javax.xml.parsers.ParserConfigurationException; -//import java.io.IOException; -//import java.text.ParseException; -// -///** -// * Created by jjg64 on 1/05/17. -// */ -//public class FailBoatXMLTest { -// private final String path = "mockXML/boatXML/"; -// -// @Test(expected = NumberFormatException.class) -// public void invalidSourceID() throws SAXException, ParserConfigurationException, ParseException, IOException { -// new BoatXMLReader(path + "invalidSourceID.xml"); -// } -// -// @Test(expected = NullPointerException.class) -// public void insufficientInformation() throws SAXException, ParserConfigurationException, ParseException, IOException { -// new BoatXMLReader(path + "insufficientInformation.xml"); -// } -// -//} diff --git a/racevisionGame/src/test/java/shared/model/RaceTest.java b/racevisionGame/src/test/java/shared/model/RaceTest.java deleted file mode 100644 index 3334aefd..00000000 --- a/racevisionGame/src/test/java/shared/model/RaceTest.java +++ /dev/null @@ -1,345 +0,0 @@ -//package shared.model; -// -// -//import mock.model.Polars; -//import org.junit.Before; -//import org.junit.Ignore; -//import org.junit.Test; -//import org.mockito.Mockito; -//import org.xml.sax.SAXException; -// -//import javax.xml.parsers.ParserConfigurationException; -//import java.io.IOException; -//import java.text.ParseException; -//import java.util.ArrayList; -// -//import static org.junit.Assert.*; -//import static org.mockito.Mockito.*; -// -///** -// * Created by esa46 on 15/03/17. -// */ -//public class RaceTest{ -// -// -// private CompoundMark ORIGIN; -// -// private CompoundMark THREE_NM_FROM_ORIGIN; -// -// private CompoundMark FIFTEEN_NM_FROM_ORIGIN; -// -// private ArrayList TEST_LEGS = new ArrayList<>(); -// -// private int START_LEG_DISTANCE = 3; -// private int MIDDLE_LEG_DISTANCE = 12; -// -// private Leg START_LEG; -// -// private Leg MIDDLE_LEG; -// -// private Leg FINISH_LEG; -// -// -// @Before -// public void setUp() { -// -// ORIGIN = new CompoundMark( -// 1, -// "origin compound", -// new Mark(1, "test origin 1", new GPSCoordinate(0, 0)) ); -// -// -// THREE_NM_FROM_ORIGIN = new CompoundMark( -// 2, -// "3 NM from origin compound", -// new Mark(2, "test mark 2", new GPSCoordinate(0.050246769, 0)) ); -// -// -// FIFTEEN_NM_FROM_ORIGIN = new CompoundMark( -// 3, -// "15 NM from origin compound", -// new Mark(3, "test mark 3", new GPSCoordinate(0.251233845, 0)) ); -// -// -// START_LEG = new Leg("Start", ORIGIN, THREE_NM_FROM_ORIGIN, 0); -// -// -// MIDDLE_LEG = new Leg("Middle", THREE_NM_FROM_ORIGIN, FIFTEEN_NM_FROM_ORIGIN, 1); -// -// -// FINISH_LEG = new Leg("Finish", FIFTEEN_NM_FROM_ORIGIN, FIFTEEN_NM_FROM_ORIGIN, 2); -// -// -// TEST_LEGS.add(START_LEG); -// TEST_LEGS.add(MIDDLE_LEG); -// TEST_LEGS.add(FINISH_LEG); -// } -// -// @Ignore -// @Test -// public void countdownTimerSendsBoatLocations() { -// -// try { -// MockOutput mockOutput = Mockito.mock(MockOutput.class); -// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars()); -// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource); -// Race testRace = new Race(raceDataSource, mockOutput); -// testRace.initialiseBoats(); -// testRace.countdownTimer.handle(1); -// verify(mockOutput, atLeast(boatDataSource.getBoats().size())).parseBoatLocation(anyInt(), anyDouble(), anyDouble(), anyDouble(), anyDouble(), anyLong()); -// -// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { -// e.printStackTrace(); -// fail(); -// } -// } -// -// @Ignore -// @Test -// public void countdownTimerSendsRaceStatusMessages() { -// -// try { -// MockOutput mockOutput = Mockito.mock(MockOutput.class); -// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars())); -// Race testRace = new Race(dataSource, mockOutput); -// testRace.initialiseBoats(); -// testRace.countdownTimer.handle(1); -// verify(mockOutput, atLeast(1)).parseRaceStatus(any()); -// -// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { -// e.printStackTrace(); -// fail(); -// } -// } -// -// @Ignore -// @Test -// public void checkPositionFinishedUpdatesNumberFinishedBoats() { -// -// try { -// MockOutput mockOutput = Mockito.mock(MockOutput.class); -// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars())); -// Race testRace = new Race(dataSource, mockOutput); -// testRace.initialiseBoats(); -// Boat testBoat = testRace.getBoats().get(0); -// testBoat.setCurrentLeg(FINISH_LEG); -// testBoat.setDistanceTravelledInLeg(1); -// testRace.checkPosition(testBoat, 1); -// -// assertEquals(testRace.getNumberOfActiveBoats(), 0); -// -// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { -// e.printStackTrace(); -// fail(); -// } -// } -// -// @Ignore -// @Test -// public void checkPositionSetFinishedBoatVelocityTo0() { -// -// try { -// MockOutput mockOutput = Mockito.mock(MockOutput.class); -// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars())); -// Race testRace = new Race(dataSource, mockOutput); -// testRace.initialiseBoats(); -// Boat testBoat = testRace.getBoats().get(0); -// testBoat.setCurrentLeg(FINISH_LEG); -// testBoat.setDistanceTravelledInLeg(1); -// testRace.checkPosition(testBoat, 1); -// -// assertEquals(testBoat.getCurrentSpeed(), 0, 1e-8); -// -// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { -// e.printStackTrace(); -// fail(); -// } -// } -// -// @Ignore -// @Test -// public void checkPositionSetsFinishTime() { -// -// try { -// MockOutput mockOutput = Mockito.mock(MockOutput.class); -// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars())); -// Race testRace = new Race(dataSource, mockOutput); -// testRace.initialiseBoats(); -// Boat testBoat = testRace.getBoats().get(0); -// testBoat.setCurrentLeg(FINISH_LEG); -// testBoat.setDistanceTravelledInLeg(1); -// testRace.checkPosition(testBoat, 1); -// -// assertEquals(testBoat.getTimeFinished(), 1, 1e-8); -// -// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { -// e.printStackTrace(); -// fail(); -// } -// } -// -// @Ignore -// @Test -// public void checkPositionUnfinishedDoesntUpdateNumberFinishedBoats() { -// -// try { -// MockOutput mockOutput = Mockito.mock(MockOutput.class); -// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars())); -// Race testRace = new Race(dataSource, mockOutput); -// testRace.initialiseBoats(); -// Boat testBoat = testRace.getBoats().get(0); -// testBoat.setCurrentLeg(START_LEG); -// testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE); -// testRace.checkPosition(testBoat, 1); -// -// assertEquals(testRace.getNumberOfActiveBoats(), 1); -// -// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { -// e.printStackTrace(); -// fail(); -// } -// } -// -// -// @Ignore -// @Test -// public void distanceTravelledBeforeUpdatingLegIsRetained() { -// -// try { -// MockOutput mockOutput = Mockito.mock(MockOutput.class); -// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars())); -// Race testRace = new Race(dataSource, mockOutput); -// testRace.initialiseBoats(); -// Boat testBoat = testRace.getBoats().get(0); -// testBoat.setCurrentLeg(START_LEG); -// testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE + 1); -// testRace.checkPosition(testBoat, 0); -// -// assertEquals(testBoat.getDistanceTravelledInLeg(), 1, 1e-7); -// -// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { -// e.printStackTrace(); -// fail(); -// } -// } -// -// @Ignore -// @Test -// public void doNotFinishAnswersYesIf100PercentChance() { -// -// try { -// MockOutput mockOutput = Mockito.mock(MockOutput.class); -// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars()); -// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource); -// Race testRace = new Race(raceDataSource, mockOutput); -// -// testRace.setDnfChance(100); -// assertTrue(testRace.doNotFinish()); -// -// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { -// e.printStackTrace(); -// fail(); -// } -// } -// -// @Ignore -// @Test -// public void doNotFinishAnswersNoIf0PercentChance() { -// -// try { -// MockOutput mockOutput = Mockito.mock(MockOutput.class); -// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars()); -// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource); -// Race testRace = new Race(raceDataSource, mockOutput); -// testRace.setDnfChance(0); -// assertFalse(testRace.doNotFinish()); -// -// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { -// e.printStackTrace(); -// fail(); -// } -// } -// -// @Ignore -// @Test -// public void boatsAreSetToDNF() { -// try { -// MockOutput mockOutput = Mockito.mock(MockOutput.class); -// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars()); -// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource); -// Race testRace = new Race(raceDataSource, mockOutput); -// testRace.setDnfChance(100); -// Boat testBoat = testRace.getBoats().get(0); -// testBoat.setCurrentLeg(START_LEG); -// testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE + 1); -// testRace.checkPosition(testBoat, 1); -// assertEquals(testBoat.getCurrentLeg().getName(), "DNF"); -// -// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { -// e.printStackTrace(); -// fail(); -// } -// -// } -// -// @Ignore -// @Test -// public void updatePositionIgnoresFinishedBoats() { -// try { -// MockOutput mockOutput = Mockito.mock(MockOutput.class); -// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars()); -// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource); -// Race testRace = new Race(raceDataSource, mockOutput); -// Boat testBoat = testRace.getBoats().get(0); -// testBoat.setCurrentLeg(FINISH_LEG); -// testBoat.setCurrentPosition(ORIGIN.getAverageGPSCoordinate()); -// testRace.updatePosition(testBoat, 1, 1); -// assertEquals(testBoat.getCurrentPosition(), ORIGIN.getAverageGPSCoordinate()); -// -// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { -// e.printStackTrace(); -// fail(); -// } -// } -// -// @Ignore -// @Test -// public void updatePositionChangesBoatPosition() { -// try { -// MockOutput mockOutput = Mockito.mock(MockOutput.class); -// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars()); -// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource); -// Race testRace = new Race(raceDataSource, mockOutput); -// testRace.initialiseBoats(); -// Boat testBoat = testRace.getBoats().get(0); -// testBoat.setCurrentLeg(START_LEG); -// testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE - 1); -// testBoat.setCurrentPosition(ORIGIN.getAverageGPSCoordinate()); -// testRace.updatePosition(testBoat, 100, 100); -// assertFalse(testBoat.getCurrentPosition() == ORIGIN.getAverageGPSCoordinate()); -// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { -// e.printStackTrace(); -// fail(); -// } -// } -// -// @Ignore -// @Test -// public void windDirectionCorrectValues(){ -//// try { -//// MockOutput mockOutput = Mockito.mock(MockOutput.class); -//// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml"); -//// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource); -//// Race testRace = new Race(raceDataSource, mockOutput); -//// testRace.setChangeWind(1); -//// testRace.setWindDir(65535); -//// testRace.changeWindDir(); -//// assertEquals(100, testRace.getWind()); -//// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { -//// e.printStackTrace(); -//// fail(); -//// } -// } -// -// -//} diff --git a/racevisionGame/src/test/java/visualiser/model/VisualiserRaceTest.java b/racevisionGame/src/test/java/visualiser/model/VisualiserRaceTest.java deleted file mode 100644 index ef5e691a..00000000 --- a/racevisionGame/src/test/java/visualiser/model/VisualiserRaceTest.java +++ /dev/null @@ -1,100 +0,0 @@ -//package visualiser.model; -// -// -//import org.junit.Before; -//import org.junit.Test; -//import shared.dataInput.RaceXMLReader; -//import shared.dataInput.XMLReader; -//import shared.exceptions.InvalidRaceDataException; -//import shared.model.GPSCoordinate; -// -//import java.nio.charset.StandardCharsets; -//import java.util.List; -// -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.fail; -// -///** -// * Tests only work on the current version of mockXML/raceXML/raceTest.xml -// */ -//public class VisualiserRaceTest { -// private RaceXMLReader streamedCourseXMLReader; -// private List boundary; -// -// @Before -// public void setup() { -// try { -// streamedCourseXMLReader = new RaceXMLReader(XMLReader.readXMLFileToString("mockXML/raceXML/raceTest.xml", StandardCharsets.UTF_8)); -// boundary = streamedCourseXMLReader.getBoundary(); -// } catch (InvalidRaceDataException e) { -// e.printStackTrace(); -// fail("Cannot find mockXML/raceXML/raceTest.xml in the resources folder"); -// } -// } -// -// @Test -// public void testAllBoundaryPointsRead() { -// assertEquals(boundary.size(), 10); -// } -// -// @Test -// public void testBoundaryPointData() { -// // First point -// assertEquals(boundary.get(0).getLatitude(), -36.8325, 1e-6); -// assertEquals(boundary.get(0).getLongitude(), 174.8325, 1e-6); -// -// // Last point -// assertEquals(boundary.get(boundary.size() - 1).getLatitude(), -36.83417, 1e-6); -// assertEquals(boundary.get(boundary.size() - 1).getLongitude(), 174.84767, 1e-6); -// } -// -// @Test -// public void testMapEdges() { -// double maxLatitude = streamedCourseXMLReader.getMapBottomRight().getLatitude() - streamedCourseXMLReader.getPadding(); -// double maxLongitude = streamedCourseXMLReader.getMapBottomRight().getLongitude() - streamedCourseXMLReader.getPadding(); -// double minLatitude = streamedCourseXMLReader.getMapTopLeft().getLatitude() - streamedCourseXMLReader.getPadding(); -// double minLongitude = streamedCourseXMLReader.getMapTopLeft().getLongitude() - streamedCourseXMLReader.getPadding(); -// -// assertEquals(maxLatitude, -36.81033, 1e-6); -// assertEquals(maxLongitude, 174.88217, 1e-6); -// assertEquals(minLatitude, -36.83417, 1e-6); -// assertEquals(minLongitude, 174.81983, 1e-6); -// } -// -// @Test -// public void testRaceSettings() { -// -// } -// -// @Test -// public void correctLegSequence() { -// List legs = streamedCourseXMLReader.getLegs(); -// String[] expectedNames = { -// "StartLine", -// "M1", -// "M2", -// "Gate" -// }; -// for(int i = 0; i < legs.size(); i++) { -// assertEquals(expectedNames[i], legs.get(i).getName()); -// } -// } -// -// /** -// * raceTest.xml is not compliant with this test. Markers are positioned far out of bounds. -// */ -// @Test -// @Ignore -// public void markersWithinRaceBoundaries() { -// GPSCoordinate topLeft = streamedCourseXMLReader.getMapTopLeft(); -// GPSCoordinate bottomRight = streamedCourseXMLReader.getMapBottomRight(); -// -// for(Marker compoundMark : streamedCourseXMLReader.getMarkers()) { -// GPSCoordinate centre = compoundMark.getAverageGPSCoordinate(); -// assertTrue(centre.getLatitude() < bottomRight.getLatitude()); -// assertTrue(centre.getLatitude() > topLeft.getLatitude()); -// assertTrue(centre.getLongitude() > bottomRight.getLongitude()); -// assertTrue(centre.getLongitude() < topLeft.getLongitude()); -// } -// } -//} diff --git a/settings/keyBindings.xml b/settings/keyBindings.xml index 2b807e17..8aa46d6c 100644 --- a/settings/keyBindings.xml +++ b/settings/keyBindings.xml @@ -1,5 +1,5 @@ - + SPACE @@ -10,8 +10,8 @@ - DOWN - + LEFT + X @@ -22,12 +22,12 @@ - Z - + RIGHT + - UP - + Z +