mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge remote-tracking branch 'origin/story1118_map_arrows' into 1124_Fixing_Order_And_Finish_Screen
# Conflicts: # src/main/java/seng302/gameServer/MainServerThread.java # src/main/java/seng302/visualiser/GameClient.java # src/main/java/seng302/visualiser/controllers/RaceViewController.java # src/main/resources/server_config/xml_templates/race.ftlh
This commit is contained in:
@@ -444,6 +444,7 @@ public class GameState implements Runnable {
|
||||
yacht.setHasPassedThroughGate(false);
|
||||
if (!markOrder.isLastMark(currentMarkSeqID)) {
|
||||
yacht.incrementMarkSeqID();
|
||||
yacht.incrementLegNumber();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +227,8 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
|
||||
|
||||
for (Player player : GameState.getPlayers()) {
|
||||
ServerYacht y = player.getYacht();
|
||||
BoatSubMessage m = new BoatSubMessage(y.getSourceId(), y.getBoatStatus(), 0,
|
||||
BoatSubMessage m = new BoatSubMessage(y.getSourceId(), y.getBoatStatus(),
|
||||
y.getLegNumber(),
|
||||
0, 0, 1234L,
|
||||
1234L);
|
||||
boatSubMessages.add(m);
|
||||
|
||||
@@ -2,7 +2,13 @@ package seng302.model;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.TimeZone;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import seng302.model.stream.parser.RaceStartData;
|
||||
import seng302.model.stream.parser.RaceStatusData;
|
||||
|
||||
@@ -21,8 +27,10 @@ public class RaceState {
|
||||
private long expectedStartTime;
|
||||
private boolean isRaceStarted = false;
|
||||
long timeTillStart;
|
||||
private ObservableList<ClientYacht> playerPositions;
|
||||
|
||||
public RaceState() {
|
||||
playerPositions = FXCollections.observableArrayList();
|
||||
}
|
||||
|
||||
public void updateState (RaceStatusData data) {
|
||||
@@ -69,4 +77,16 @@ public class RaceState {
|
||||
public boolean isRaceStarted () {
|
||||
return isRaceStarted;
|
||||
}
|
||||
|
||||
public void setBoats(Collection<ClientYacht> clientYachts) {
|
||||
playerPositions.setAll(clientYachts);
|
||||
}
|
||||
|
||||
public void sortPlayers() {
|
||||
playerPositions.sort(Comparator.comparingInt(ClientYacht::getLegNumber));
|
||||
}
|
||||
|
||||
public ObservableList<ClientYacht> getPlayerPositions() {
|
||||
return FXCollections.unmodifiableObservableList(playerPositions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public class ServerYacht extends Observable {
|
||||
private Double currentVelocity;
|
||||
private Boolean isAuto;
|
||||
private Double autoHeading;
|
||||
private Integer legNumber;
|
||||
|
||||
//Mark Rounding
|
||||
private Integer currentMarkSeqID;
|
||||
@@ -65,6 +66,7 @@ public class ServerYacht extends Observable {
|
||||
this.heading = 120.0; //In degrees
|
||||
this.currentVelocity = 0d; //in mms-1
|
||||
this.currentMarkSeqID = 0;
|
||||
this.legNumber = 0;
|
||||
|
||||
this.hasEnteredRoundingZone = false;
|
||||
this.hasPassedLine = false;
|
||||
@@ -381,5 +383,12 @@ public class ServerYacht extends Observable {
|
||||
return hasPassedLine;
|
||||
}
|
||||
|
||||
public void incrementLegNumber() {
|
||||
legNumber++;
|
||||
}
|
||||
|
||||
public Integer getLegNumber() {
|
||||
return legNumber;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,13 +95,8 @@ public class StreamParser {
|
||||
boatID = bytesToLong(
|
||||
Arrays.copyOfRange(payload, 24 + (i * 20), 28 + (i * 20)));
|
||||
boatStatus = (int) payload[28 + (i * 20)];
|
||||
|
||||
// setBoatLegPosition(boat, (int) payload[29 + (i * 20)]);
|
||||
// boat.setPenaltiesAwarded((int) payload[30 + (i * 20)]);
|
||||
// boat.setPenaltiesServed((int) payload[31 + (i * 20)]);
|
||||
estTimeAtNextMark = bytesToLong(
|
||||
Arrays.copyOfRange(payload, 32 + (i * 20), 38 + (i * 20)));
|
||||
// boat.setEstimateTimeTillNextMark(estTimeAtNextMark);
|
||||
estTimeAtFinish = bytesToLong(
|
||||
Arrays.copyOfRange(payload, 38 + (i * 20), 44 + (i * 20)));
|
||||
leg = (int) payload[29 + (i * 20)];
|
||||
|
||||
@@ -243,6 +243,7 @@ public class GameClient {
|
||||
allBoatsMap.forEach((id, boat) ->
|
||||
clientLobbyList.add(id + " " + boat.getBoatName())
|
||||
);
|
||||
raceState.setBoats(allBoatsMap.values());
|
||||
break;
|
||||
|
||||
case RACE_START_STATUS:
|
||||
@@ -323,7 +324,7 @@ public class GameClient {
|
||||
raceFinished = false;
|
||||
}
|
||||
}
|
||||
if (raceFinished == true) {
|
||||
if (raceFinished) {
|
||||
close();
|
||||
loadFinishScreenView();
|
||||
}
|
||||
@@ -333,16 +334,10 @@ public class GameClient {
|
||||
clientYacht.setEstimateTimeTillNextMark(raceState.getRaceTime() - boatData[1]);
|
||||
clientYacht.setEstimateTimeAtFinish(boatData[2]);
|
||||
int legNumber = (int) boatData[3];
|
||||
clientYacht.setLegNumber(legNumber);
|
||||
clientYacht.setBoatStatus((int) boatData[4]);
|
||||
if (legNumber != clientYacht.getLegNumber()) {
|
||||
int placing = 1;
|
||||
for (ClientYacht otherClientYacht : allBoatsMap.values()) {
|
||||
if (otherClientYacht.getSourceId() != boatData[0] &&
|
||||
clientYacht.getLegNumber() <= otherClientYacht.getLegNumber())
|
||||
placing++;
|
||||
}
|
||||
clientYacht.setPositionInteger(placing);
|
||||
clientYacht.setLegNumber(legNumber);
|
||||
raceState.sortPlayers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -117,6 +119,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));
|
||||
@@ -318,7 +329,6 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
public void run() {
|
||||
updateRaceTime();
|
||||
updateWind();
|
||||
updateOrder();
|
||||
// updateSparkLine();
|
||||
}
|
||||
}, 0, 1000);
|
||||
@@ -381,16 +391,10 @@ 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() {
|
||||
// positionVbox.getChildren().removeAll();
|
||||
// positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString());
|
||||
|
||||
// list of racing yacht id
|
||||
List<ClientYacht> sorted = new ArrayList<>(participants.values());
|
||||
sorted.sort(Comparator.comparingInt(ClientYacht::getPositionInteger));
|
||||
private void updateOrder(ObservableList<ClientYacht> yachts) {
|
||||
List<Text> vboxEntries = new ArrayList<>();
|
||||
|
||||
for (ClientYacht clientYacht : sorted) {
|
||||
for (ClientYacht clientYacht : yachts) {
|
||||
// System.out.println("yacht == null " + String.valueOf(yacht == null));
|
||||
if (clientYacht.getBoatStatus() == 3) { // 3 is finish status
|
||||
Text textToAdd = new Text(clientYacht.getPositionInteger() + ". " +
|
||||
|
||||
Reference in New Issue
Block a user