Copied remaining files into appropriate package. These need to be refactored and put into the shared package.
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import seng302.RaceConnection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Controls the connection that the VIsualiser can connect to.
|
||||
*/
|
||||
public class ConnectionController extends Controller {
|
||||
@FXML
|
||||
private AnchorPane connectionWrapper;
|
||||
@FXML
|
||||
private TableView connectionTable;
|
||||
@FXML
|
||||
private TableColumn<RaceConnection, String> hostnameColumn;
|
||||
@FXML
|
||||
private TableColumn<RaceConnection, String> statusColumn;
|
||||
@FXML
|
||||
private Button connectButton;
|
||||
|
||||
@FXML
|
||||
private TextField urlField;
|
||||
@FXML
|
||||
private TextField portField;
|
||||
|
||||
private ObservableList<RaceConnection> connections;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
// TODO - replace with config file
|
||||
connections = FXCollections.observableArrayList();
|
||||
connections.add(new RaceConnection("livedata.americascup.com", 4941));
|
||||
connections.add(new RaceConnection("localhost", 4942));
|
||||
|
||||
connectionTable.setItems(connections);
|
||||
hostnameColumn.setCellValueFactory(cellData -> cellData.getValue().hostnameProperty());
|
||||
statusColumn.setCellValueFactory(cellData -> cellData.getValue().statusProperty());
|
||||
|
||||
connectionTable.getSelectionModel().selectedItemProperty().addListener((obs, prev, curr) -> {
|
||||
if (curr != null && ((RaceConnection)curr).check()) connectButton.setDisable(false);
|
||||
else connectButton.setDisable(true);
|
||||
});
|
||||
connectButton.setDisable(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current status of all connections.
|
||||
*/
|
||||
public void checkConnections() {
|
||||
for(RaceConnection connection: connections) {
|
||||
connection.check();
|
||||
}
|
||||
}
|
||||
|
||||
public AnchorPane startWrapper(){
|
||||
return connectionWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to host currently selected in table. Button enabled only if host is ready.
|
||||
*/
|
||||
public void connectSocket() {
|
||||
try{
|
||||
RaceConnection connection = (RaceConnection)connectionTable.getSelectionModel().getSelectedItem();
|
||||
Socket socket = new Socket(connection.getHostname(), connection.getPort());
|
||||
connectionWrapper.setVisible(false);
|
||||
parent.enterLobby(socket);
|
||||
} catch (IOException e) { /* Never reached */ }
|
||||
}
|
||||
|
||||
/**
|
||||
* adds a new connection
|
||||
*/
|
||||
public void addConnection(){
|
||||
String hostName = urlField.getText();
|
||||
String portString = portField.getText();
|
||||
try{
|
||||
int port = Integer.parseInt(portString);
|
||||
connections.add(new RaceConnection(hostName, port));
|
||||
}catch(NumberFormatException e){
|
||||
System.err.println("Port number entered is not a number");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
import javafx.fxml.Initializable;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Controller parent for app controllers.
|
||||
* Created by fwy13 on 15/03/2017.
|
||||
*/
|
||||
public abstract class Controller implements Initializable {
|
||||
protected MainController parent;
|
||||
|
||||
/**
|
||||
* Sets the parent of the application
|
||||
*
|
||||
* @param parent controller
|
||||
*/
|
||||
public void setParent(MainController parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisation class that is run on start up.
|
||||
*
|
||||
* @param location resources location
|
||||
* @param resources resources bundle
|
||||
*/
|
||||
@Override
|
||||
public abstract void initialize(URL location, ResourceBundle resources);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import seng302.Model.Boat;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
|
||||
/**
|
||||
* Finish Screen for when the race finishs.
|
||||
*/
|
||||
public class FinishController extends Controller {
|
||||
|
||||
@FXML
|
||||
AnchorPane finishWrapper;
|
||||
|
||||
@FXML
|
||||
TableView<Boat> boatInfoTable;
|
||||
|
||||
@FXML
|
||||
TableColumn<Boat, String> boatRankColumn;
|
||||
|
||||
@FXML
|
||||
TableColumn<Boat, String> boatNameColumn;
|
||||
|
||||
@FXML
|
||||
Label raceWinnerLabel;
|
||||
|
||||
/**
|
||||
* Sets up the finish table
|
||||
* @param boats Boats to display
|
||||
*/
|
||||
private void setFinishTable(ObservableList<Boat> boats){
|
||||
boatInfoTable.setItems(boats);
|
||||
boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
||||
boatRankColumn.setCellValueFactory(cellData -> cellData.getValue().positionProperty());
|
||||
|
||||
raceWinnerLabel.setText("Winner: "+ boatNameColumn.getCellObservableValue(0).getValue());
|
||||
raceWinnerLabel.setWrapText(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources){
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the table
|
||||
* @param boats boats to display on the table.
|
||||
*/
|
||||
public void enterFinish(ObservableList<Boat> boats){
|
||||
finishWrapper.setVisible(true);
|
||||
setFinishTable(boats);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.RaceClock;
|
||||
import seng302.VisualiserInput;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Controller that everything is overlayed onto. This makes it so that changing scenes does not resize your stage.
|
||||
*/
|
||||
public class MainController extends Controller {
|
||||
@FXML private StartController startController;
|
||||
@FXML private RaceController raceController;
|
||||
@FXML private ConnectionController connectionController;
|
||||
@FXML private FinishController finishController;
|
||||
|
||||
public void beginRace(VisualiserInput visualiserInput, RaceClock raceClock) {
|
||||
raceController.startRace(visualiserInput, raceClock);
|
||||
}
|
||||
|
||||
public void enterLobby(Socket socket) {
|
||||
startController.enterLobby(socket);
|
||||
}
|
||||
|
||||
public void enterFinish(ObservableList<Boat> boats) { finishController.enterFinish(boats); }
|
||||
|
||||
/**
|
||||
* Main Controller for the applications will house the menu and the displayed pane.
|
||||
*
|
||||
* @param location of resources
|
||||
* @param resources bundle
|
||||
*/
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
startController.setParent(this);
|
||||
raceController.setParent(this);
|
||||
connectionController.setParent(this);
|
||||
finishController.setParent(this);
|
||||
AnchorPane.setTopAnchor(startController.startWrapper(), 0.0);
|
||||
AnchorPane.setBottomAnchor(startController.startWrapper(), 0.0);
|
||||
AnchorPane.setLeftAnchor(startController.startWrapper(), 0.0);
|
||||
AnchorPane.setRightAnchor(startController.startWrapper(), 0.0);
|
||||
|
||||
AnchorPane.setTopAnchor(connectionController.startWrapper(), 0.0);
|
||||
AnchorPane.setBottomAnchor(connectionController.startWrapper(), 0.0);
|
||||
AnchorPane.setLeftAnchor(connectionController.startWrapper(), 0.0);
|
||||
AnchorPane.setRightAnchor(connectionController.startWrapper(), 0.0);
|
||||
|
||||
AnchorPane.setTopAnchor(finishController.finishWrapper, 0.0);
|
||||
AnchorPane.setBottomAnchor(finishController.finishWrapper, 0.0);
|
||||
AnchorPane.setLeftAnchor(finishController.finishWrapper, 0.0);
|
||||
AnchorPane.setRightAnchor(finishController.finishWrapper, 0.0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.chart.LineChart;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import seng302.Mock.StreamedRace;
|
||||
import seng302.VisualiserInput;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 15/03/2017.
|
||||
*/
|
||||
public class RaceController extends Controller {
|
||||
private ResizableRaceCanvas raceMap;
|
||||
private ResizableRaceMap raceBoundaries;
|
||||
|
||||
private RaceClock raceClock;
|
||||
private Sparkline sparkline;
|
||||
|
||||
private int legNum;
|
||||
|
||||
@FXML GridPane canvasBase;
|
||||
@FXML Pane arrow;
|
||||
@FXML SplitPane race;
|
||||
@FXML StackPane arrowPane;
|
||||
@FXML Label timer;
|
||||
@FXML Label FPS;
|
||||
@FXML Label timeZone;
|
||||
@FXML CheckBox showFPS;
|
||||
@FXML TableView<Boat> boatInfoTable;
|
||||
@FXML TableColumn<Boat, String> boatPlacingColumn;
|
||||
@FXML TableColumn<Boat, String> boatTeamColumn;
|
||||
@FXML TableColumn<Boat, String> boatMarkColumn;
|
||||
@FXML TableColumn<Boat, String> boatSpeedColumn;
|
||||
@FXML LineChart<Number, Number> sparklineChart;
|
||||
@FXML AnchorPane annotationPane;
|
||||
|
||||
/**
|
||||
* Updates the ResizableRaceCanvas (raceMap) with most recent data
|
||||
*
|
||||
* @param boats boats that are to be displayed in the race
|
||||
* @param boatMarkers Markers for boats
|
||||
* @see ResizableRaceCanvas
|
||||
*/
|
||||
public void updateMap(ObservableList<Boat> boats, ObservableList<Marker> boatMarkers) {
|
||||
raceMap.setBoats(boats);
|
||||
raceMap.setBoatMarkers(boatMarkers);
|
||||
raceMap.update();
|
||||
raceBoundaries.draw();
|
||||
//stop if the visualiser is no longer running
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the array listened by the TableView (boatInfoTable) that displays the boat information.
|
||||
*
|
||||
* @param race Race to listen to.
|
||||
*/
|
||||
public void setInfoTable(StreamedRace race) {
|
||||
boatInfoTable.setItems(race.getStartingBoats());
|
||||
boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
||||
boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp());
|
||||
boatMarkColumn.setCellValueFactory(cellData -> cellData.getValue().getCurrentLegName());
|
||||
boatPlacingColumn.setCellValueFactory(cellData -> cellData.getValue().positionProperty());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
//listener for fps
|
||||
showFPS.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
if (showFPS.isSelected()) {
|
||||
FPS.setVisible(true);
|
||||
} else {
|
||||
FPS.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and sets initial display for Sparkline for race positions.
|
||||
* @param boats boats to display on the sparkline
|
||||
*/
|
||||
public void createSparkLine(ObservableList<Boat> boats){
|
||||
sparkline = new Sparkline(boats, legNum, sparklineChart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the sparkline to display current boat positions.
|
||||
* @param boatsInRace used for current boat positions.
|
||||
*/
|
||||
public void updateSparkline(ObservableList<Boat> boatsInRace){
|
||||
sparkline.updateSparkline(boatsInRace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes and runs the race, based on the user's chosen scale factor
|
||||
* Currently uses an example racecourse
|
||||
*
|
||||
* @param visualiserInput input from network
|
||||
* @param raceClock The RaceClock to use for the race's countdown/elapsed duration + timezone.
|
||||
*/
|
||||
public void startRace(VisualiserInput visualiserInput, RaceClock raceClock) {
|
||||
|
||||
legNum = visualiserInput.getCourse().getLegs().size()-1;
|
||||
|
||||
makeArrow();
|
||||
|
||||
raceMap = new ResizableRaceCanvas(visualiserInput.getCourse());
|
||||
raceMap.setMouseTransparent(true);
|
||||
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
||||
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
||||
raceMap.draw();
|
||||
raceMap.setVisible(true);
|
||||
raceMap.setArrow(arrow.getChildren().get(0));
|
||||
|
||||
canvasBase.getChildren().add(0, raceMap);
|
||||
|
||||
raceBoundaries = new ResizableRaceMap(visualiserInput.getCourse());
|
||||
raceBoundaries.setMouseTransparent(true);
|
||||
raceBoundaries.widthProperty().bind(canvasBase.widthProperty());
|
||||
raceBoundaries.heightProperty().bind(canvasBase.heightProperty());
|
||||
raceBoundaries.draw();
|
||||
raceBoundaries.setVisible(true);
|
||||
|
||||
canvasBase.getChildren().add(0, raceBoundaries);
|
||||
|
||||
race.setVisible(true);
|
||||
|
||||
timeZone.setText(raceClock.getTimeZone());
|
||||
|
||||
//RaceClock.duration isn't necessarily being changed in the javaFX thread, so we need to runlater the update.
|
||||
raceClock.durationProperty().addListener((observable, oldValue, newValue) -> {
|
||||
Platform.runLater(() -> {
|
||||
timer.setText(newValue);
|
||||
});
|
||||
});
|
||||
|
||||
this.raceClock = raceClock;
|
||||
raceMap.setRaceClock(raceClock);
|
||||
|
||||
StreamedRace newRace = new StreamedRace(visualiserInput, this);
|
||||
|
||||
initializeFPS();
|
||||
|
||||
// set up annotation displays
|
||||
new Annotations(annotationPane, raceMap);
|
||||
|
||||
new Thread((newRace)).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish Race View
|
||||
* @param boats boats there are in the race.
|
||||
*/
|
||||
public void finishRace(ObservableList<Boat> boats){
|
||||
race.setVisible(false);
|
||||
parent.enterFinish(boats);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value for the fps label
|
||||
*
|
||||
* @param fps fps that the label will be updated to
|
||||
*/
|
||||
public void setFrames(String fps) {
|
||||
FPS.setText((fps));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up FPS display at bottom of screen
|
||||
*/
|
||||
private void initializeFPS() {
|
||||
showFPS.setVisible(true);
|
||||
showFPS.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
if (showFPS.isSelected()) {
|
||||
FPS.setVisible(true);
|
||||
} else {
|
||||
FPS.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void makeArrow() {
|
||||
arrowPane.getChildren().add(arrow);
|
||||
}
|
||||
|
||||
public RaceClock getRaceClock() {
|
||||
return raceClock;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import seng302.Mock.StreamedCourse;
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.RaceClock;
|
||||
import seng302.VisualiserInput;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Controller to for waiting for the race to start
|
||||
*/
|
||||
public class StartController extends Controller implements Observer {
|
||||
|
||||
@FXML private GridPane start;
|
||||
@FXML private AnchorPane startWrapper;
|
||||
@FXML private Label raceTitleLabel;
|
||||
@FXML private Label raceStartLabel;
|
||||
|
||||
@FXML private TableView<Boat> boatNameTable;
|
||||
@FXML private TableColumn<Boat, String> boatNameColumn;
|
||||
@FXML private TableColumn<Boat, String> boatCodeColumn;
|
||||
@FXML private Label timeZoneTime;
|
||||
@FXML private Label timer;
|
||||
@FXML private Label raceStatusLabel;
|
||||
|
||||
//@FXML Button fifteenMinButton;
|
||||
|
||||
private RaceClock raceClock;
|
||||
|
||||
private StreamedCourse raceData;
|
||||
private int raceStat;
|
||||
|
||||
private VisualiserInput visualiserInput;
|
||||
|
||||
///Tracks whether the race has been started (that is, has startRaceNoScaling() be called).
|
||||
private boolean hasRaceStarted = false;
|
||||
|
||||
//Tracks whether or not a clock has been created and setup, which occurs after receiving enough information.
|
||||
private boolean hasCreatedClock = false;
|
||||
|
||||
/**
|
||||
* Begins the race with a scale factor of 1
|
||||
*/
|
||||
private void startRaceNoScaling() {
|
||||
//while(visualiserInput.getRaceStatus() == null);//TODO probably remove this.
|
||||
|
||||
countdownTimer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources){
|
||||
raceData = new StreamedCourse();
|
||||
raceData.addObserver(this);
|
||||
}
|
||||
|
||||
public AnchorPane startWrapper(){
|
||||
return startWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiliases the tables that are to be shown on the pane
|
||||
*/
|
||||
private void initialiseTables() {
|
||||
List<Boat> boats = raceData.getBoats();
|
||||
ObservableList<Boat> observableBoats = FXCollections.observableArrayList(boats);
|
||||
|
||||
boatNameTable.setItems(observableBoats);
|
||||
boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
||||
boatCodeColumn.setCellValueFactory(new PropertyValueFactory<>("abbrev"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Countdown timer until race starts.
|
||||
*/
|
||||
private void countdownTimer() {
|
||||
new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
raceStat = visualiserInput.getRaceStatus().getRaceStatus();
|
||||
raceStatusLabel.setText("Race Status: " + visualiserInput.getRaceStatus().getRaceStatus());
|
||||
if (raceStat==2 || raceStat == 3) {
|
||||
stop();
|
||||
|
||||
startWrapper.setVisible(false);
|
||||
start.setVisible(false);
|
||||
|
||||
parent.beginRace(visualiserInput, raceClock);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the clock that displays the time of at the current race venue.
|
||||
*/
|
||||
private void setRaceClock() {
|
||||
raceClock = new RaceClock(raceData.getZonedDateTime());
|
||||
|
||||
raceClock.timeStringProperty().addListener((observable, oldValue, newValue) -> {
|
||||
Platform.runLater(() -> {
|
||||
timeZoneTime.setText(newValue);
|
||||
});
|
||||
});
|
||||
//TEMP REMOVE
|
||||
//timeZoneTime.textProperty().bind(raceClock.timeStringProperty());
|
||||
raceClock.run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time that the race is going to start.
|
||||
*/
|
||||
private void setStartingTime() {
|
||||
String dateFormat = "'Starting time:' HH:mm dd/MM/YYYY";
|
||||
Platform.runLater(()-> {
|
||||
long utcTime = visualiserInput.getRaceStatus().getExpectedStartTime();
|
||||
raceClock.setStartingTime(raceClock.getLocalTime(utcTime));
|
||||
raceStartLabel.setText(DateTimeFormatter.ofPattern(dateFormat).format(raceClock.getStartingTime()));
|
||||
|
||||
raceClock.durationProperty().addListener((observable, oldValue, newValue) -> {
|
||||
Platform.runLater(() -> {
|
||||
timer.setText(newValue);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* set the current time, may be used to update the time on the clock.
|
||||
*/
|
||||
private void setCurrentTime() {
|
||||
Platform.runLater(()->
|
||||
raceClock.setUTCTime(visualiserInput.getRaceStatus().getCurrentTime())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
if(o instanceof StreamedCourse) {
|
||||
StreamedCourse streamedCourse = (StreamedCourse) o;
|
||||
if(streamedCourse.hasReadBoats()) {
|
||||
initialiseTables();
|
||||
}
|
||||
if(streamedCourse.hasReadRegatta()) {
|
||||
Platform.runLater(() -> raceTitleLabel.setText(streamedCourse.getRegattaName()));
|
||||
}
|
||||
if (streamedCourse.hasReadCourse()) {
|
||||
Platform.runLater(() -> {
|
||||
if (!this.hasCreatedClock) {
|
||||
this.hasCreatedClock = true;
|
||||
setRaceClock();
|
||||
if (visualiserInput.getRaceStatus() == null) {
|
||||
return;//TEMP BUG FIX if the race isn't sending race status messages (our mock currently doesn't), then it would block the javafx thread with the previous while loop.
|
||||
}// TODO - replace with observer on VisualiserInput
|
||||
setStartingTime();
|
||||
setCurrentTime();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//TODO this is a somewhat temporary fix for when not all of the race data (boats, course, regatta) is received in time.
|
||||
//Previously, startRaceNoScaling was called in the enterLobby function after the visualiserInput was started, but when connecting to the official data source it sometimes didn't send all of the race data, causing startRaceNoScaling to start, even though we didn't have enough information to start it.
|
||||
if (streamedCourse.hasReadBoats() && streamedCourse.hasReadCourse() && streamedCourse.hasReadRegatta()) {
|
||||
Platform.runLater(() -> {
|
||||
if (!this.hasRaceStarted) {
|
||||
if(visualiserInput.getRaceStatus() == null) {
|
||||
}
|
||||
else {
|
||||
this.hasRaceStarted = true;
|
||||
startRaceNoScaling();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show starting information for a race given a socket.
|
||||
* @param socket network source of information
|
||||
*/
|
||||
public void enterLobby(Socket socket) {
|
||||
startWrapper.setVisible(true);
|
||||
try {
|
||||
visualiserInput = new VisualiserInput(socket, raceData);
|
||||
new Thread(visualiserInput).start();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user