mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge branch 'develop' into story1118_map_arrows
# Conflicts: # src/main/java/seng302/gameServer/MainServerThread.java # src/main/java/seng302/model/RaceState.java # src/main/java/seng302/visualiser/GameClient.java # src/main/java/seng302/visualiser/controllers/RaceViewController.java
This commit is contained in:
@@ -14,7 +14,8 @@ import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.Pane;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.gameServer.MainServerThread;
|
||||
import seng302.gameServer.messages.BoatAction;
|
||||
import seng302.gameServer.server.messages.BoatAction;
|
||||
import seng302.gameServer.server.messages.BoatStatus;
|
||||
import seng302.model.ClientYacht;
|
||||
import seng302.model.RaceState;
|
||||
import seng302.model.stream.packets.StreamPacket;
|
||||
@@ -27,6 +28,7 @@ import seng302.model.stream.xml.parser.RaceXMLData;
|
||||
import seng302.model.stream.xml.parser.RegattaXMLData;
|
||||
import seng302.utilities.StreamParser;
|
||||
import seng302.utilities.XMLParser;
|
||||
import seng302.visualiser.controllers.FinishScreenViewController;
|
||||
import seng302.visualiser.controllers.LobbyController;
|
||||
import seng302.visualiser.controllers.LobbyController.CloseStatus;
|
||||
import seng302.visualiser.controllers.RaceViewController;
|
||||
@@ -190,6 +192,8 @@ public class GameClient {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
FinishScreenViewController controller = fxmlLoader.getController();
|
||||
controller.setFinishers(raceState.getPlayerPositions());
|
||||
return fxmlLoader;
|
||||
}
|
||||
|
||||
@@ -235,6 +239,7 @@ public class GameClient {
|
||||
allBoatsMap.forEach((id, boat) ->
|
||||
clientLobbyList.add(id + " " + boat.getBoatName())
|
||||
);
|
||||
raceState.setBoats(allBoatsMap.values());
|
||||
break;
|
||||
|
||||
case RACE_START_STATUS:
|
||||
@@ -291,26 +296,14 @@ public class GameClient {
|
||||
*/
|
||||
private void updateMarkRounding(MarkRoundingData roundingData) {
|
||||
if (allXMLReceived()) {
|
||||
ClientYacht yacht = allBoatsMap.get(roundingData.getBoatId());
|
||||
int placing = 1;
|
||||
// int originalPlacing = yacht.getPlacing();
|
||||
for (ClientYacht otherYacht : allBoatsMap.values()) {
|
||||
if (otherYacht != yacht && yacht.getLegNumber() + 1 <= otherYacht.getLegNumber()) {
|
||||
placing++;
|
||||
}
|
||||
}
|
||||
// if (placing != originalPlacing) {
|
||||
yacht.setPlacing(placing);
|
||||
for (ClientYacht otherYacht : allBoatsMap.values()) {
|
||||
if (otherYacht.getPlacing() < placing) {
|
||||
otherYacht.setPlacing(otherYacht.getPlacing() + 1);
|
||||
}
|
||||
}
|
||||
// }
|
||||
yacht.roundMark(
|
||||
courseData.getCompoundMarks().get(roundingData.getMarkId()),
|
||||
roundingData.getTimeStamp(),
|
||||
raceState.getRaceTime() - roundingData.getTimeStamp()
|
||||
ClientYacht clientYacht = allBoatsMap.get(roundingData.getBoatId());
|
||||
clientYacht.setMarkRoundingTime(roundingData.getTimeStamp());
|
||||
clientYacht.updateTimeSinceLastMarkProperty(
|
||||
raceState.getRaceTime() - roundingData.getTimeStamp());
|
||||
clientYacht.setLastMarkRounded(
|
||||
courseData.getCompoundMarks().get(
|
||||
roundingData.getMarkId()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -320,33 +313,34 @@ public class GameClient {
|
||||
raceState.updateState(data);
|
||||
boolean raceFinished = true;
|
||||
for (ClientYacht yacht : allBoatsMap.values()) {
|
||||
if (yacht.getBoatStatus() != 3) {
|
||||
if (yacht.getBoatStatus() != BoatStatus.FINISHED.getCode()) {
|
||||
raceFinished = false;
|
||||
}
|
||||
}
|
||||
if (raceFinished == true) {
|
||||
|
||||
for (long[] boatData : data.getBoatData()) {
|
||||
ClientYacht clientYacht = allBoatsMap.get((int) boatData[0]);
|
||||
clientYacht.setEstimateTimeTillNextMark(raceState.getRaceTime() - boatData[1]);
|
||||
clientYacht.setEstimateTimeAtFinish(boatData[2]);
|
||||
int legNumber = (int) boatData[3];
|
||||
clientYacht.setBoatStatus((int) boatData[4]);
|
||||
if (legNumber != clientYacht.getLegNumber()) {
|
||||
clientYacht.setLegNumber(legNumber);
|
||||
updatePlayerPositions();
|
||||
}
|
||||
}
|
||||
|
||||
if (raceFinished) {
|
||||
close();
|
||||
loadFinishScreenView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (long[] boatData : data.getBoatData()) {
|
||||
ClientYacht yacht = allBoatsMap.get((int) boatData[0]);
|
||||
yacht.setEstimateTimeTillNextMark(raceState.getRaceTime() - boatData[1]);
|
||||
yacht.setEstimateTimeAtFinish(boatData[2]);
|
||||
int legNumber = (int) boatData[3];
|
||||
// yacht.setLegNumber(legNumber);
|
||||
yacht.setBoatStatus((int) boatData[4]);
|
||||
// if (legNumber != yacht.getLegNumber()) {
|
||||
// System.out.println("WHAT THE FUCK IT WORKS????");
|
||||
// int placing = 1;
|
||||
// for (ClientYacht otherClientYacht : allBoatsMap.values()) {
|
||||
// if (otherClientYacht.getSourceId() != boatData[0] &&
|
||||
// yacht.getLegNumber() <= otherClientYacht.getLegNumber())
|
||||
// placing++;
|
||||
// }
|
||||
// yacht.setPlacing(placing);
|
||||
// }
|
||||
}
|
||||
private void updatePlayerPositions() {
|
||||
raceState.sortPlayers();
|
||||
for (ClientYacht yacht : raceState.getPlayerPositions()) {
|
||||
yacht.setPosition(raceState.getPlayerPositions().indexOf(yacht) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package seng302.visualiser.controllers;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
@@ -61,7 +62,7 @@ public class FinishScreenViewController implements Initializable {
|
||||
finishOrderTable.refresh();
|
||||
}
|
||||
|
||||
public void setFinishers(List<ClientYacht> participants) {
|
||||
public void setFinishers(Collection<ClientYacht> participants) {
|
||||
List<ClientYacht> sorted = new ArrayList<>(participants);
|
||||
sorted.sort(Comparator.comparingInt(ClientYacht::getPlacing));
|
||||
finishOrderTable.getItems().setAll(sorted);
|
||||
|
||||
@@ -11,6 +11,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.geometry.Point2D;
|
||||
@@ -73,6 +75,9 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
private ComboBox<ClientYacht> yachtSelectionComboBox;
|
||||
@FXML
|
||||
private Text fpsDisplay;
|
||||
@FXML
|
||||
private Text windSpeedText;
|
||||
|
||||
//Race Data
|
||||
private Map<Integer, ClientYacht> participants;
|
||||
private Map<Integer, CompoundMark> markers;
|
||||
@@ -102,8 +107,9 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
}
|
||||
|
||||
public void loadRace (
|
||||
Map<Integer, ClientYacht> participants, RaceXMLData raceData, RaceState raceState, ClientYacht player
|
||||
) {
|
||||
Map<Integer, ClientYacht> participants, RaceXMLData raceData, RaceState raceState,
|
||||
ClientYacht player) {
|
||||
|
||||
this.participants = participants;
|
||||
this.courseData = raceData;
|
||||
this.markers = raceData.getCompoundMarks();
|
||||
@@ -115,6 +121,15 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
initialiseBoatSelectionComboBox();
|
||||
initialiseSparkLine();
|
||||
|
||||
raceState.getPlayerPositions().addListener((ListChangeListener<ClientYacht>) c -> {
|
||||
while (c.next()) {
|
||||
if (c.wasPermutated()) {
|
||||
updateOrder(raceState.getPlayerPositions());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
updateOrder(raceState.getPlayerPositions());
|
||||
gameView = new GameView();
|
||||
gameView.setFrameRateFXText(fpsDisplay);
|
||||
Platform.runLater(() -> contentAnchorPane.getChildren().add(0, gameView));
|
||||
@@ -126,6 +141,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
gameView.enableZoom();
|
||||
gameView.setBoatAsPlayer(player);
|
||||
gameView.startRace();
|
||||
|
||||
raceState.addCollisionListener(gameView::drawCollision);
|
||||
raceState.windDirectionProperty().addListener((obs, oldDirection, newDirection) -> {
|
||||
gameView.setWindDir(newDirection.doubleValue());
|
||||
@@ -279,7 +295,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
* @param yacht The yacht to be updated on the sparkline
|
||||
* @param legNumber the leg number that the position will be assigned to
|
||||
*/
|
||||
void updateClientYachtPositionSparkline(ClientYacht yacht, Integer legNumber){
|
||||
void updateYachtPositionSparkline(ClientYacht yacht, Integer legNumber){
|
||||
for (XYChart.Series<String, Double> positionData : sparkLineData) {
|
||||
positionData.getData().add(
|
||||
new Data<>(
|
||||
@@ -363,9 +379,10 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
* Updates the wind direction arrow and text as from info from the StreamParser
|
||||
* @param direction the from north angle of the wind.
|
||||
*/
|
||||
private void updateWindDirection(double direction) {
|
||||
windDirectionText.setText(String.format("%.1f°", direction));
|
||||
windArrowText.setRotate(direction);
|
||||
private void updateWind() {
|
||||
windDirectionText.setText(String.format("%.1f°", raceState.getWindDirection()));
|
||||
windArrowText.setRotate(raceState.getWindDirection());
|
||||
windSpeedText.setText("Speed: " + String.format("%.1f", raceState.getWindSpeed()) + " Knots");
|
||||
}
|
||||
|
||||
|
||||
@@ -385,21 +402,20 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
* Updates the order of the yachts as from the StreamParser and sets them in the yacht order
|
||||
* section
|
||||
*/
|
||||
private void updateOrder() {
|
||||
List<ClientYacht> sorted = new ArrayList<>(participants.values());
|
||||
sorted.sort(Comparator.comparingInt(ClientYacht::getPlacing));
|
||||
private void updateOrder(ObservableList<ClientYacht> yachts) {
|
||||
List<Text> vboxEntries = new ArrayList<>();
|
||||
|
||||
for (ClientYacht yacht : sorted) {
|
||||
if (yacht.getBoatStatus() == 3) { // 3 is finish status
|
||||
Text textToAdd = new Text(yacht.getPlacing() + ". " +
|
||||
yacht.getShortName() + " (Finished)");
|
||||
for (int i = 0; i < yachts.size(); i++) {
|
||||
// System.out.println("yacht == null " + String.valueOf(yacht == null));
|
||||
if (yachts.get(i).getBoatStatus() == 3) { // 3 is finish status
|
||||
Text textToAdd = new Text(i + 1 + ". " +
|
||||
yachts.get(i).getShortName() + " (Finished)");
|
||||
textToAdd.setFill(Paint.valueOf("#d3d3d3"));
|
||||
vboxEntries.add(textToAdd);
|
||||
|
||||
} else {
|
||||
Text textToAdd = new Text(yacht.getPlacing() + ". " +
|
||||
yacht.getShortName() + " ");
|
||||
Text textToAdd = new Text(i + 1 + ". " +
|
||||
yachts.get(i).getShortName() + " ");
|
||||
textToAdd.setFill(Paint.valueOf("#d3d3d3"));
|
||||
textToAdd.setStyle("");
|
||||
vboxEntries.add(textToAdd);
|
||||
@@ -476,16 +492,17 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
}
|
||||
|
||||
|
||||
private Point2D getPointRotation(Point2D ref, Double distance, Double angle){
|
||||
Double newX = ref.getX() + (ref.getX() + distance -ref.getX())*Math.cos(angle) - (ref.getY() + distance -ref.getY())*Math.sin(angle);
|
||||
Double newY = ref.getY() + (ref.getX() + distance -ref.getX())*Math.sin(angle) + (ref.getY() + distance -ref.getY())*Math.cos(angle);
|
||||
private Point2D getPointRotation(Point2D ref, Double distance, Double angle) {
|
||||
Double newX = ref.getX() + (ref.getX() + distance - ref.getX()) * Math.cos(angle)
|
||||
- (ref.getY() + distance - ref.getY()) * Math.sin(angle);
|
||||
Double newY = ref.getY() + (ref.getX() + distance - ref.getX()) * Math.sin(angle)
|
||||
+ (ref.getY() + distance - ref.getY()) * Math.cos(angle);
|
||||
|
||||
return new Point2D(newX, newY);
|
||||
}
|
||||
|
||||
|
||||
public Line makeLeftLayline(Point2D startPoint, Double layLineAngle, Double baseAngle) {
|
||||
|
||||
Point2D ep = getPointRotation(startPoint, 50.0, baseAngle + layLineAngle);
|
||||
Line line = new Line(startPoint.getX(), startPoint.getY(), ep.getX(), ep.getY());
|
||||
return line;
|
||||
@@ -541,7 +558,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
TimeUnit.MILLISECONDS.toHours(milliseconds),
|
||||
TimeUnit.MILLISECONDS.toMinutes(milliseconds) % 60, //Modulus 60 minutes per hour
|
||||
TimeUnit.MILLISECONDS.toSeconds(milliseconds) % 60 //Modulus 60 seconds per minute
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
private void setAnnotations(Integer annotationLevel) {
|
||||
|
||||
Reference in New Issue
Block a user