Merge remote-tracking branch 'origin/master' into story1299_next_mark_direction
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<XMLCompoundMark, Boolean> 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;
|
||||
|
||||
@@ -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<Image> 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();
|
||||
|
||||
Reference in New Issue
Block a user