mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Reimplemented race position in the race view. Removed Boat class and Yacht class is replaced completely. Race position "-" shows properly on start screen. Removed BoatTest and TeamsParserTest. Fixed estimated time till finish on server.
#story[818]
This commit is contained in:
@@ -14,10 +14,7 @@ import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.stage.Stage;
|
||||
import seng302.models.Boat;
|
||||
import seng302.models.BoatGroup;
|
||||
import seng302.models.Colors;
|
||||
import seng302.models.RaceObject;
|
||||
import seng302.models.*;
|
||||
import seng302.models.mark.*;
|
||||
import seng302.models.parsers.StreamParser;
|
||||
import seng302.models.parsers.packets.BoatPositionPacket;
|
||||
@@ -326,13 +323,16 @@ public class CanvasController {
|
||||
*/
|
||||
private void drawBoats() {
|
||||
// Map<Boat, TimelineInfo> timelineInfos = raceViewController.getTimelineInfos();
|
||||
List<Boat> boats = raceViewController.getStartingBoats();
|
||||
// List<Boat> boats = raceViewController.getStartingBoats();
|
||||
Map<Integer, Yacht> boats = StreamParser.getBoats();
|
||||
Double startingX = raceObjects.get(0).getLayoutX();
|
||||
Double startingY = raceObjects.get(0).getLayoutY();
|
||||
Group boatAnnotations = new Group();
|
||||
|
||||
for (Boat boat : boats) {
|
||||
BoatGroup boatGroup = new BoatGroup(boat, Colors.getColor());
|
||||
for (Yacht boat : boats.values()) {
|
||||
// for (Boat boat : boats) {
|
||||
boat.setColour(Colors.getColor());
|
||||
BoatGroup boatGroup = new BoatGroup(boat, boat.getColour());
|
||||
boatGroup.moveTo(startingX, startingY, 0d);
|
||||
//boatGroup.setStage(raceViewController.getStage());
|
||||
raceObjects.add(boatGroup);
|
||||
|
||||
@@ -65,9 +65,7 @@ public class Controller implements Initializable {
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
realTime.setText(format.format(System.currentTimeMillis()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,14 +142,14 @@ public class Controller implements Initializable {
|
||||
posCol.setCellValueFactory(
|
||||
new PropertyValueFactory<>("position")
|
||||
);
|
||||
if (StreamParser.isRaceStarted()) {
|
||||
data.addAll(StreamParser.getBoatsPos().values());
|
||||
} else {
|
||||
for (Yacht boat : StreamParser.getBoats().values()) {
|
||||
boat.setPosition("-");
|
||||
data.add(boat);
|
||||
}
|
||||
}
|
||||
// if (StreamParser.isRaceStarted()) {
|
||||
data.addAll(StreamParser.getBoatsPos().values());
|
||||
// } else {
|
||||
// for (Yacht boat : StreamParser.getBoats().values()) {
|
||||
// boat.setPosition("-");
|
||||
// data.add(boat);
|
||||
// }
|
||||
// }
|
||||
teamList.refresh();
|
||||
|
||||
// posCol.setSortType(TableColumn.SortType.ASCENDING);
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package seng302.controllers;
|
||||
|
||||
import seng302.models.Boat;
|
||||
import seng302.models.Race;
|
||||
import seng302.models.Yacht;
|
||||
import seng302.models.parsers.ConfigParser;
|
||||
import seng302.models.parsers.CourseParser;
|
||||
import seng302.models.parsers.StreamParser;
|
||||
import seng302.models.parsers.TeamsParser;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
@@ -41,23 +41,24 @@ public class RaceController {
|
||||
Race race = new Race();
|
||||
// StreamParser.xmlObject
|
||||
// Read team names from file
|
||||
TeamsParser tp = new TeamsParser(teamsConfigFile);
|
||||
// TeamsParser tp = new TeamsParser(teamsConfigFile);
|
||||
|
||||
// Read course from file
|
||||
ConfigParser config = new ConfigParser(configFile);
|
||||
// ConfigParser config = new ConfigParser(configFile);
|
||||
|
||||
ArrayList<String> boatNames = new ArrayList<>();
|
||||
ArrayList<Boat> teams = tp.getBoats();
|
||||
// ArrayList<Boat> teams = tp.getBoats();
|
||||
Map<Long, Yacht> teams = StreamParser.getBoatsPos();
|
||||
|
||||
//get race size
|
||||
int numberOfBoats = teams.size();
|
||||
|
||||
//get time scale
|
||||
double timeScale = config.getTimeScale();
|
||||
race.setTimeScale(timeScale);
|
||||
// double timeScale = config.getTimeScale();
|
||||
// race.setTimeScale(timeScale);
|
||||
|
||||
for (Boat boat : teams) {
|
||||
boatNames.add(boat.getTeamName());
|
||||
for (Yacht boat : teams.values()) {
|
||||
boatNames.add(boat.getBoatName());
|
||||
race.addBoat(boat);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class RaceResultController implements Initializable{
|
||||
int boatPosition = this.race.getFinishedBoats().length;
|
||||
|
||||
for (int i = this.race.getFinishedBoats().length - 1; i >= 0; i--){
|
||||
resultsVBox.getChildren().add(0, new Text(boatPosition + ": " + this.race.getFinishedBoats()[i].getTeamName()));
|
||||
resultsVBox.getChildren().add(0, new Text(boatPosition + ": " + this.race.getFinishedBoats()[i].getBoatName()));
|
||||
boatPosition--;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package seng302.controllers;
|
||||
|
||||
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
|
||||
import javafx.animation.Animation;
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.Timeline;
|
||||
@@ -44,11 +45,11 @@ public class RaceViewController extends Thread{
|
||||
@FXML
|
||||
private CanvasController includedCanvasController;
|
||||
|
||||
private ArrayList<Boat> startingBoats = new ArrayList<>();
|
||||
private ArrayList<Yacht> startingBoats = new ArrayList<>();
|
||||
private boolean displayFps;
|
||||
private Timeline timerTimeline;
|
||||
private Map<Boat, TimelineInfo> timelineInfos = new HashMap<>();
|
||||
private ArrayList<Boat> boatOrder = new ArrayList<>();
|
||||
private Map<Yacht, TimelineInfo> timelineInfos = new HashMap<>();
|
||||
private ArrayList<Yacht> boatOrder = new ArrayList<>();
|
||||
private Race race;
|
||||
private Stage stage;
|
||||
|
||||
@@ -57,7 +58,7 @@ public class RaceViewController extends Thread{
|
||||
RaceController raceController = new RaceController();
|
||||
raceController.initializeRace();
|
||||
race = raceController.getRace();
|
||||
for (Boat boat : race.getBoats()) {
|
||||
for (Yacht boat : race.getBoats()) {
|
||||
startingBoats.add(boat);
|
||||
}
|
||||
// try{
|
||||
@@ -72,6 +73,7 @@ public class RaceViewController extends Thread{
|
||||
initializeTimer();
|
||||
initializeSettings();
|
||||
initialiseWindDirection();
|
||||
initialisePositionVBox();
|
||||
//set wind direction!!!!!!! can't find another place to put my code --haoming
|
||||
// double windDirection = new ConfigParser("/config/config.xml").getWindDirection();
|
||||
// windDirectionText.setText(String.format("%.1f°", windDirection));
|
||||
@@ -160,12 +162,26 @@ public class RaceViewController extends Thread{
|
||||
windDirTimeline.playFromStart();
|
||||
}
|
||||
|
||||
private void initialisePositionVBox() {
|
||||
|
||||
Timeline posVBoxTimeline = new Timeline();
|
||||
posVBoxTimeline.setCycleCount(Timeline.INDEFINITE);
|
||||
posVBoxTimeline.getKeyFrames().add(
|
||||
new KeyFrame(Duration.seconds(1),
|
||||
event -> {
|
||||
showOrder();
|
||||
})
|
||||
);
|
||||
posVBoxTimeline.playFromStart();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates time line for each boat, and stores time time into timelineInfos hash map
|
||||
*/
|
||||
private void initializeTimelines() {
|
||||
HashMap<Boat, List> boat_events = race.getEvents();
|
||||
for (Boat boat : boat_events.keySet()) {
|
||||
HashMap<Yacht, List> boat_events = race.getEvents();
|
||||
for (Yacht boat : boat_events.keySet()) {
|
||||
startingBoats.add(boat);
|
||||
// // x, y are the real time coordinates
|
||||
// DoubleProperty x = new SimpleDoubleProperty();
|
||||
@@ -271,13 +287,13 @@ public class RaceViewController extends Thread{
|
||||
}
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
Boat boat = event.getBoat();
|
||||
Yacht boat = event.getBoat();
|
||||
boatOrder.remove(boat);
|
||||
boat.setMarkLastPast(event.getMarkPosInRace());
|
||||
boatOrder.add(boat);
|
||||
boatOrder.sort(new Comparator<Boat>() {
|
||||
boatOrder.sort(new Comparator<Yacht>() {
|
||||
@Override
|
||||
public int compare(Boat b1, Boat b2) {
|
||||
public int compare(Yacht b1, Yacht b2) {
|
||||
return b2.getMarkLastPast() - b1.getMarkLastPast();
|
||||
}
|
||||
});
|
||||
@@ -288,8 +304,20 @@ public class RaceViewController extends Thread{
|
||||
positionVbox.getChildren().clear();
|
||||
positionVbox.getChildren().removeAll();
|
||||
|
||||
for (Boat boat : boatOrder) {
|
||||
positionVbox.getChildren().add(new Text(boat.getShortName() + " " + boat.getSpeedInKnots() + " Knots"));
|
||||
// for (Boat boat : boatOrder) {
|
||||
// positionVbox.getChildren().add(new Text(boat.getShortName() + " " + boat.getSpeedInKnots() + " Knots"));
|
||||
// }
|
||||
|
||||
for (Yacht boat : StreamParser.getBoatsPos().values()) {
|
||||
System.out.println(boat.getBoatStatus());
|
||||
if (boat.getBoatStatus() == 3) { // 3 is finish status
|
||||
positionVbox.getChildren().add(new Text(boat.getPosition() + ". " +
|
||||
boat.getShortName() + " (Finished)"));
|
||||
} else {
|
||||
positionVbox.getChildren().add(new Text(boat.getPosition() + ". " +
|
||||
boat.getShortName() + " "));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,11 +369,11 @@ public class RaceViewController extends Thread{
|
||||
return race;
|
||||
}
|
||||
|
||||
public Map<Boat, TimelineInfo> getTimelineInfos() {
|
||||
public Map<Yacht, TimelineInfo> getTimelineInfos() {
|
||||
return timelineInfos;
|
||||
}
|
||||
|
||||
public ArrayList<Boat> getStartingBoats(){
|
||||
public ArrayList<Yacht> getStartingBoats(){
|
||||
return startingBoats;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user