Updated code to check if boat is in the race before displaying in the leaderboard

#story[923]
This commit is contained in:
Zhi You Tan
2017-05-23 20:00:23 +12:00
parent 2686dac62e
commit 6d7c36e31f
2 changed files with 56 additions and 24 deletions
@@ -2,6 +2,7 @@ package seng302.controllers;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
@@ -23,6 +24,7 @@ import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import seng302.models.Yacht;
import seng302.models.stream.StreamParser;
import seng302.models.stream.XMLParser.RaceXMLObject.Participant;
public class StartScreenController implements Initializable {
@@ -56,12 +58,11 @@ public class StartScreenController implements Initializable {
contentPane.getChildren().removeAll();
contentPane.getChildren().clear();
contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
contentPane.getChildren().addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
}
catch(javafx.fxml.LoadException e){
contentPane.getChildren()
.addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
} catch (javafx.fxml.LoadException e) {
e.printStackTrace();
}
catch(IOException e){
} catch (IOException e) {
e.printStackTrace();
}
}
@@ -161,10 +162,27 @@ public class StartScreenController implements Initializable {
new PropertyValueFactory<>("position")
);
if (StreamParser.isRaceStarted()) {
data.addAll(StreamParser.getBoatsPos().values());
} else {
data.addAll(StreamParser.getBoats().values());
// check if the boat is racing
ArrayList<Participant> participants = StreamParser.getXmlObject().getRaceXML()
.getParticipants();
ArrayList<Integer> participantIDs = new ArrayList<>();
for (Participant p : participants) {
participantIDs.add(p.getsourceID());
}
// add boats to the start screen list
if (StreamParser.isRaceStarted()) { // if race is started, use StreamParser.getBoatsPos()
for (Yacht boat : StreamParser.getBoatsPos().values()) {
if (participantIDs.contains(boat.getSourceID())) {
data.add(boat);
}
}
} else { // else use StreamParser.getBoats()
for (Yacht boat : StreamParser.getBoats().values()) {
if (participantIDs.contains(boat.getSourceID())) {
data.add(boat);
}
}
}
teamList.refresh();
}