Set it so the lobby view switches to race view depending on the race status passed in by the mock.
-Removed start button in lobby as it should be automatic. -TODO: Synchronize the times across the whole race as they do not matching. #Story[782]
This commit is contained in:
@@ -10,6 +10,7 @@ import seng302.Model.Boat;
|
|||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.transform.OutputKeys;
|
||||||
import javax.xml.transform.Transformer;
|
import javax.xml.transform.Transformer;
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
import javax.xml.transform.TransformerFactory;
|
import javax.xml.transform.TransformerFactory;
|
||||||
@@ -56,6 +57,8 @@ public class BoatData {
|
|||||||
// write the content into xml file
|
// write the content into xml file
|
||||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
Transformer transformer = transformerFactory.newTransformer();
|
Transformer transformer = transformerFactory.newTransformer();
|
||||||
|
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||||
|
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
|
||||||
DOMSource source = new DOMSource(doc);
|
DOMSource source = new DOMSource(doc);
|
||||||
|
|
||||||
//Serialize document.
|
//Serialize document.
|
||||||
@@ -63,6 +66,8 @@ public class BoatData {
|
|||||||
StreamResult result = new StreamResult(stringWriter);
|
StreamResult result = new StreamResult(stringWriter);
|
||||||
transformer.transform(source, result);
|
transformer.transform(source, result);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(stringWriter.toString());
|
||||||
return stringWriter.toString();
|
return stringWriter.toString();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ public class BoatLocationDecoder {
|
|||||||
currentSet = Arrays.copyOfRange(encodedBoatLocation,52, 54);
|
currentSet = Arrays.copyOfRange(encodedBoatLocation,52, 54);
|
||||||
rudderAngle = Arrays.copyOfRange(encodedBoatLocation,54, 56);
|
rudderAngle = Arrays.copyOfRange(encodedBoatLocation,54, 56);
|
||||||
|
|
||||||
|
// System.out.println(bytesToInt(sourceID));
|
||||||
|
// System.out.println(bytesToInt(boatSpeed));
|
||||||
|
|
||||||
message = new BoatLocationMessage(messageVersionNumber, bytesToLong(time),
|
message = new BoatLocationMessage(messageVersionNumber, bytesToLong(time),
|
||||||
bytesToInt(sourceID), bytesToInt(seqNum),
|
bytesToInt(sourceID), bytesToInt(seqNum),
|
||||||
deviceType, bytesToInt(latitude),
|
deviceType, bytesToInt(latitude),
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ public class BoatLocationMessage extends AC35Data
|
|||||||
this.roll = 0;
|
this.roll = 0;
|
||||||
this.boatSpeed = convertBoatSpeedDoubleToInt(boatSpeed);
|
this.boatSpeed = convertBoatSpeedDoubleToInt(boatSpeed);
|
||||||
this.boatCOG = 0;
|
this.boatCOG = 0;
|
||||||
this.boatSOG = 0;
|
this.boatSOG = convertBoatSpeedDoubleToInt(boatSpeed);
|
||||||
this.apparentWindSpeed = 0;
|
this.apparentWindSpeed = 0;
|
||||||
this.apparentWindAngle = 0;
|
this.apparentWindAngle = 0;
|
||||||
this.trueWindSpeed = 0;
|
this.trueWindSpeed = 0;
|
||||||
@@ -190,8 +190,6 @@ public class BoatLocationMessage extends AC35Data
|
|||||||
int coordinateInt = (int) ((coordinate / 180.0) * 2147483648.0);
|
int coordinateInt = (int) ((coordinate / 180.0) * 2147483648.0);
|
||||||
|
|
||||||
return coordinateInt;
|
return coordinateInt;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ import javafx.beans.value.ChangeListener;
|
|||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import seng302.Mock.StreamedRace;
|
import seng302.Mock.StreamedRace;
|
||||||
import seng302.Model.*;
|
import seng302.Model.*;
|
||||||
@@ -129,7 +131,7 @@ public class RaceController extends Controller {
|
|||||||
raceMap.drawRaceMap();
|
raceMap.drawRaceMap();
|
||||||
raceMap.setVisible(true);
|
raceMap.setVisible(true);
|
||||||
|
|
||||||
canvasBase.getChildren().add(raceMap);
|
canvasBase.getChildren().add(0, raceMap);
|
||||||
race.setVisible(true);
|
race.setVisible(true);
|
||||||
|
|
||||||
//Initialize save annotation array, fps listener, and annotation listeners
|
//Initialize save annotation array, fps listener, and annotation listeners
|
||||||
|
|||||||
@@ -22,10 +22,8 @@ import java.net.Socket;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.List;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Observable;
|
import java.util.*;
|
||||||
import java.util.Observer;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by esa46 on 6/04/17.
|
* Created by esa46 on 6/04/17.
|
||||||
@@ -35,6 +33,7 @@ public class StartController extends Controller implements Observer {
|
|||||||
@FXML private GridPane start;
|
@FXML private GridPane start;
|
||||||
@FXML private AnchorPane startWrapper;
|
@FXML private AnchorPane startWrapper;
|
||||||
@FXML private Label raceTitleLabel;
|
@FXML private Label raceTitleLabel;
|
||||||
|
@FXML private Label raceStartLabel;
|
||||||
|
|
||||||
@FXML private TableView<Boat> boatNameTable;
|
@FXML private TableView<Boat> boatNameTable;
|
||||||
@FXML private TableColumn<Boat, String> boatNameColumn;
|
@FXML private TableColumn<Boat, String> boatNameColumn;
|
||||||
@@ -104,7 +103,6 @@ public class StartController extends Controller implements Observer {
|
|||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
long startTime = currentTime + (PRERACE_TIME/scaleFactor);
|
long startTime = currentTime + (PRERACE_TIME/scaleFactor);
|
||||||
DateFormat timerFormat = new SimpleDateFormat("'Race Clock:' -HH:mm:ss");
|
DateFormat timerFormat = new SimpleDateFormat("'Race Clock:' -HH:mm:ss");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(long arg0) {
|
public void handle(long arg0) {
|
||||||
timeLeft = startTime - currentTime;
|
timeLeft = startTime - currentTime;
|
||||||
@@ -124,7 +122,7 @@ public class StartController extends Controller implements Observer {
|
|||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setRaceClock() {
|
private void setRaceClock() {
|
||||||
raceClock = new RaceClock(raceData.getZonedDateTime());
|
raceClock = new RaceClock(raceData.getZonedDateTime());
|
||||||
timeZoneTime.textProperty().bind(raceClock.timeStringProperty());
|
timeZoneTime.textProperty().bind(raceClock.timeStringProperty());
|
||||||
|
|
||||||
@@ -140,6 +138,20 @@ public class StartController extends Controller implements Observer {
|
|||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setStartingTime() {
|
||||||
|
String dateFormat = "'Starting time:' HH:mm dd/MM/YYYY";
|
||||||
|
Platform.runLater(()-> {
|
||||||
|
long utcTime = visualiserInput.getRaceStatus().getExpectedStartTime();
|
||||||
|
raceStartLabel.setText(DateTimeFormatter.ofPattern(dateFormat).format(raceClock.getLocalTime(utcTime)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCurrentTime() {
|
||||||
|
Platform.runLater(()->
|
||||||
|
raceClock.setTime(raceClock.getLocalTime(visualiserInput.getRaceStatus().getCurrentTime()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable o, Object arg) {
|
public void update(Observable o, Object arg) {
|
||||||
if(o instanceof StreamedCourse) {
|
if(o instanceof StreamedCourse) {
|
||||||
@@ -150,7 +162,12 @@ public class StartController extends Controller implements Observer {
|
|||||||
Platform.runLater(() -> raceTitleLabel.setText(((StreamedCourse)o).getRegattaName()));
|
Platform.runLater(() -> raceTitleLabel.setText(((StreamedCourse)o).getRegattaName()));
|
||||||
}
|
}
|
||||||
if (((StreamedCourse) o).hasReadCourse()) {
|
if (((StreamedCourse) o).hasReadCourse()) {
|
||||||
Platform.runLater(() -> setRaceClock());
|
Platform.runLater(() -> {
|
||||||
|
setRaceClock();
|
||||||
|
while(visualiserInput.getRaceStatus() == null);
|
||||||
|
setStartingTime();
|
||||||
|
setCurrentTime();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,10 @@ public class StreamedRace extends Race {
|
|||||||
|
|
||||||
int legNumber = boatStatusMessage.getLegNumber();
|
int legNumber = boatStatusMessage.getLegNumber();
|
||||||
|
|
||||||
|
if (legNumber >= 1 && legNumber < legs.size()) {
|
||||||
|
boat.setCurrentLeg(legs.get(legNumber));
|
||||||
|
}
|
||||||
|
|
||||||
if (boatStatus == BoatStatus.DNF) {
|
if (boatStatus == BoatStatus.DNF) {
|
||||||
boat.setDnf(true);
|
boat.setDnf(true);
|
||||||
} else if (boatStatus == BoatStatus.FINISHED || legNumber > raceData.getLegs().size()) {
|
} else if (boatStatus == BoatStatus.FINISHED || legNumber > raceData.getLegs().size()) {
|
||||||
@@ -84,7 +88,7 @@ public class StreamedRace extends Race {
|
|||||||
double lon = boatLocationMessage.getLongitudeDouble();
|
double lon = boatLocationMessage.getLongitudeDouble();
|
||||||
boat.setCurrentPosition(new GPSCoordinate(lat, lon));
|
boat.setCurrentPosition(new GPSCoordinate(lat, lon));
|
||||||
boat.setHeading(boatLocationMessage.getHeadingDegrees());
|
boat.setHeading(boatLocationMessage.getHeadingDegrees());
|
||||||
boat.setVelocity(boatLocationMessage.getBoatSpeed() * MMPS_TO_KN);
|
boat.setVelocity(boatLocationMessage.getBoatSOG() * MMPS_TO_KN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ public abstract class Race implements Runnable {
|
|||||||
for(Boat boat: startingBoats) {
|
for(Boat boat: startingBoats) {
|
||||||
if(boat != null) {
|
if(boat != null) {
|
||||||
boat.setPosition(Integer.toString(startingBoats.indexOf(boat) + 1));
|
boat.setPosition(Integer.toString(startingBoats.indexOf(boat) + 1));
|
||||||
if (boat.getCurrentLeg().getName().equals("DNF") || boat.getCurrentLeg().getLegNumber() == 0)
|
if (boat.isDnf() || !boat.isStarted() || boat.getCurrentLeg().getLegNumber() < 0)
|
||||||
boat.setPosition("-");
|
boat.setPosition("-");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user