diff --git a/dedicatedServer/src/main/java/app/App.java b/dedicatedServer/src/main/java/app/App.java index 3b36c43e..b2228131 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, 0); + Event raceEvent = new Event(false, 0, 5); } catch (Exception e) { diff --git a/racevisionGame/src/main/java/mock/app/Event.java b/racevisionGame/src/main/java/mock/app/Event.java index 602aed43..1a70b65c 100644 --- a/racevisionGame/src/main/java/mock/app/Event.java +++ b/racevisionGame/src/main/java/mock/app/Event.java @@ -40,24 +40,17 @@ public class Event { private String raceXML; private String regattaXML; private String boatXML; - private XMLFileType xmlFileType; - private Polars boatPolars; - /** * Data sources containing data from the xml files. */ - RaceDataSource raceDataSource; - BoatDataSource boatDataSource; - RegattaDataSource regattaDataSource; - - + private RaceDataSource raceDataSource; + private BoatDataSource boatDataSource; + private RegattaDataSource regattaDataSource; private ConnectionAcceptor connectionAcceptor; private LatestMessages latestMessages; - private CompositeCommand compositeCommand; - /** * This is used to allocate source IDs. */ @@ -66,22 +59,17 @@ public class Event { private RaceLogic raceLogic; private Thread raceThread; - private Thread connectionThread; - private int mapIndex; - - - - /** * Constructs an event, using various XML files. * @param singlePlayer Whether or not to create a single player event. * @param mapIndex Specifies which map to use. * @throws EventConstructionException Thrown if we cannot create an Event for any reason. */ - public Event(boolean singlePlayer, int mapIndex) throws EventConstructionException { + public Event(boolean singlePlayer, int mapIndex, int raceLength) throws + EventConstructionException { PolarParser.parseNewPolars("mock/polars/acc_polars.csv"); this.mapIndex = mapIndex; String raceXMLFile; @@ -125,8 +113,8 @@ public class Event { } else { this.raceXML = Event.setRaceXMLAtCurrentTimeToNow(XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8)); this.raceXML = RaceXMLCreator.alterRaceToWind(this.raceXML, XMLFileType.Contents, windAngle); - this.raceXML = RaceXMLCreator.scaleRaceSize(raceXML, windSpeed, 15 * 60 * 1000); - + this.raceXML = RaceXMLCreator.scaleRaceSize(raceXML, + windSpeed, raceLength); } this.boatXML = XMLReader.readXMLFileToString(boatsXMLFile, StandardCharsets.UTF_8); diff --git a/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java b/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java index af520a83..502e6ab6 100644 --- a/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java +++ b/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java @@ -21,6 +21,8 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; /** * Helper Class for creating a Race XML @@ -212,12 +214,16 @@ public class RaceXMLCreator { double averageSpeed = (bestDownWindSpeed + bestUpWindSpeed) / 2; double raceApproximateTime = getRaceLength(race, averageSpeed); double scale = milliseconds / raceApproximateTime; + Map hasBeenScaled = new HashMap<>(); for (XMLCorner cm: race.getCompoundMarkSequence().getCorner()){ int index = cm.getCompoundMarkID() - 1; XMLCompoundMark mark = race.getCourse().getCompoundMark().get(index); - for (XMLMark m: mark.getMark()){ - scalePoint(m, center, scale); + if (!hasBeenScaled.containsKey(mark)) { + for (XMLMark m : mark.getMark()) { + scalePoint(m, center, scale); + } } + hasBeenScaled.put(mark, true); } for (XMLLimit limit: race.getCourseLimit().getLimit()){ scalePoint(limit, center, scale); @@ -319,8 +325,13 @@ public class RaceXMLCreator { } - - + /** + * sets the current race time of the xml + * @param raceXML race xml to alter + * @param racePrestartTime prestart time + * @param racePreparatoryTime preparatory time + * @deprecated this should be used from the RaceXMLCreator not from this function + */ 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 = racePrestartTime + racePreparatoryTime; diff --git a/racevisionGame/src/main/java/visualiser/Controllers/HostGameController.java b/racevisionGame/src/main/java/visualiser/Controllers/HostGameController.java index 33583a38..dac62be0 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/HostGameController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/HostGameController.java @@ -4,6 +4,8 @@ import javafx.application.Platform; import javafx.fxml.FXML; import javafx.scene.control.Alert; import javafx.scene.control.ButtonType; +import javafx.scene.control.Label; +import javafx.scene.control.Slider; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import mock.app.Event; @@ -28,8 +30,12 @@ import java.util.logging.Logger; */ public class HostGameController extends Controller { private @FXML ImageView mapImage; + private @FXML Slider sliderLength; + private @FXML Label lblLength; private ArrayList listOfMaps; private int currentMapIndex = 0; + private int selectedRaceLength; // in minutes + private final int MAX_RACE_LENGTH = 30; // in minutes private DatagramSocket udpSocket; private MatchBrowserInterface matchBrowserInterface; @@ -37,8 +43,33 @@ public class HostGameController extends Controller { loadMaps(); this.udpSocket = MatchBrowserSingleton.getInstance().getUdpSocket(); this.matchBrowserInterface = MatchBrowserSingleton.getInstance().getMatchBrowserInterface(); + setRaceLengthSlider(); } + /** + * Sets up the values and display for a slider object which allows a user + * to select how many minutes long they would like their race to be. + */ + private void setRaceLengthSlider(){ + // set the listener to update the label + sliderLength.valueProperty().addListener((ov, old_val, new_val) -> { + selectedRaceLength = new_val.intValue(); + if (selectedRaceLength == 1){ + lblLength.setText(selectedRaceLength + " minute."); + } else { + lblLength.setText(selectedRaceLength + " minutes."); + } + }); + + // set values and marks to be displayed + sliderLength.setMin(2); + sliderLength.setMax(MAX_RACE_LENGTH); + sliderLength.setShowTickLabels(true); + sliderLength.setMajorTickUnit(MAX_RACE_LENGTH-1); + sliderLength.setBlockIncrement(1); + + sliderLength.getStylesheets().add("/css/slider.css"); + } /** @@ -64,7 +95,8 @@ public class HostGameController extends Controller { */ public void hostGamePressed() { try { - App.game = new Event(false, currentMapIndex); + App.game = new Event(false, currentMapIndex, + selectedRaceLength*60*1000); App.gameType = currentMapIndex; HttpMatchBrowserHost matchBrowserHost = new HttpMatchBrowserHost(); diff --git a/racevisionGame/src/main/resources/css/slider.css b/racevisionGame/src/main/resources/css/slider.css new file mode 100644 index 00000000..2cb9832d --- /dev/null +++ b/racevisionGame/src/main/resources/css/slider.css @@ -0,0 +1,16 @@ +.slider .thumb { + -fx-background-image: url("/visualiser/images/sun.png"); + -fx-background-size: 25px; + -fx-pref-height: 25px; + -fx-pref-width: 25px; + -fx-background-position: top; + -fx-background-repeat: no-repeat; + -fx-focus-color: transparent; + -fx-background-color: transparent; +} + +.slider .track { + -fx-control-inner-background: dodgerblue; + -fx-border-color: rgba(30, 144, 255, 0.44); + -fx-border-radius: 0.25em, 0.25em, 0.166667em; +} \ 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 cf82c285..3218c802 100644 --- a/racevisionGame/src/main/resources/visualiser/scenes/hostGame.fxml +++ b/racevisionGame/src/main/resources/visualiser/scenes/hostGame.fxml @@ -3,6 +3,7 @@ + @@ -12,19 +13,20 @@ - + - - - + + + - - - + + + + -