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/develop' into Story80_BoatCustomization
# Conflicts: # src/main/java/seng302/gameServer/GameState.java # src/main/java/seng302/gameServer/ServerPacketParser.java # src/main/java/seng302/gameServer/ServerToClientThread.java # src/main/java/seng302/gameServer/messages/ChatterMessage.java # src/main/java/seng302/gameServer/messages/MarkRoundingMessage.java # src/main/java/seng302/model/ServerYacht.java # src/main/java/seng302/visualiser/ClientToServerThread.java # src/main/java/seng302/visualiser/GameClient.java # src/main/java/seng302/visualiser/GameView.java
This commit is contained in:
@@ -8,6 +8,8 @@ import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import javafx.beans.property.ReadOnlyDoubleProperty;
|
||||
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||
import javafx.beans.property.ReadOnlyIntegerProperty;
|
||||
import javafx.beans.property.ReadOnlyIntegerWrapper;
|
||||
import javafx.beans.property.ReadOnlyLongProperty;
|
||||
import javafx.beans.property.ReadOnlyLongWrapper;
|
||||
import javafx.scene.paint.Color;
|
||||
@@ -28,19 +30,24 @@ public class ClientYacht extends Observable {
|
||||
Boolean sailsIn, double velocity);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface MarkRoundingListener {
|
||||
void notifyRounding(ClientYacht yacht, CompoundMark markPassed, int legNumber);
|
||||
}
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(ClientYacht.class);
|
||||
|
||||
|
||||
//BOTH AFAIK
|
||||
private String boatType;
|
||||
private Integer sourceId;
|
||||
private String hullID; //matches HullNum in the XML spec.
|
||||
private String shortName;
|
||||
private String boatName;
|
||||
private String country;
|
||||
private Integer position;
|
||||
|
||||
private Long estimateTimeAtFinish;
|
||||
private Boolean sailIn = false;
|
||||
private Boolean sailIn = true;
|
||||
private Integer currentMarkSeqID = 0;
|
||||
private Long markRoundTime;
|
||||
private Long timeTillNext;
|
||||
@@ -50,13 +57,13 @@ public class ClientYacht extends Observable {
|
||||
private Integer boatStatus;
|
||||
private Double currentVelocity;
|
||||
|
||||
//CLIENT SIDE
|
||||
private List<YachtLocationListener> locationListeners = new ArrayList<>();
|
||||
private List<MarkRoundingListener> markRoundingListeners = new ArrayList<>();
|
||||
private ReadOnlyDoubleWrapper velocityProperty = new ReadOnlyDoubleWrapper();
|
||||
private ReadOnlyLongWrapper timeTillNextProperty = new ReadOnlyLongWrapper();
|
||||
private ReadOnlyLongWrapper timeSinceLastMarkProperty = new ReadOnlyLongWrapper();
|
||||
private ReadOnlyIntegerWrapper placingProperty = new ReadOnlyIntegerWrapper();
|
||||
private CompoundMark lastMarkRounded;
|
||||
private Integer positionInt = 0;
|
||||
private Color colour;
|
||||
|
||||
public ClientYacht(String boatType, Integer sourceId, String hullID, String shortName,
|
||||
@@ -146,12 +153,16 @@ public class ClientYacht extends Observable {
|
||||
this.estimateTimeAtFinish = estimateTimeAtFinish;
|
||||
}
|
||||
|
||||
public Integer getPositionInteger() {
|
||||
return positionInt;
|
||||
public Integer getPlacing() {
|
||||
return placingProperty.get();
|
||||
}
|
||||
|
||||
public void setPositionInteger(Integer position) {
|
||||
this.positionInt = position;
|
||||
public void setPlacing(Integer position) {
|
||||
placingProperty.set(position);
|
||||
}
|
||||
|
||||
public ReadOnlyIntegerProperty placingProperty() {
|
||||
return placingProperty.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
public void updateVelocityProperty(double velocity) {
|
||||
@@ -190,6 +201,14 @@ public class ClientYacht extends Observable {
|
||||
return location;
|
||||
}
|
||||
|
||||
public Integer getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Integer position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void toggleSail() {
|
||||
sailIn = !sailIn;
|
||||
}
|
||||
@@ -240,14 +259,6 @@ public class ClientYacht extends Observable {
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
// public Double getCurrentVelocity() {
|
||||
// return currentVelocity;
|
||||
// }
|
||||
//
|
||||
// public void setCurrentVelocity(Double currentVelocity) {
|
||||
// this.currentVelocity = currentVelocity;
|
||||
// }
|
||||
|
||||
|
||||
public void updateLocation(double lat, double lng, double heading, double velocity) {
|
||||
setLocation(lat, lng);
|
||||
@@ -263,7 +274,25 @@ public class ClientYacht extends Observable {
|
||||
locationListeners.add(listener);
|
||||
}
|
||||
|
||||
public void addMarkRoundingListener(MarkRoundingListener listener) {
|
||||
markRoundingListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeMarkRoundingListener(MarkRoundingListener listener) {
|
||||
markRoundingListeners.remove(listener);
|
||||
}
|
||||
|
||||
public boolean getSailIn () {
|
||||
return sailIn;
|
||||
}
|
||||
|
||||
public void roundMark(CompoundMark mark, long markRoundTime, long timeSinceLastMark) {
|
||||
this.markRoundTime = markRoundTime;
|
||||
timeSinceLastMarkProperty.set(timeSinceLastMark);
|
||||
lastMarkRounded = mark;
|
||||
legNumber += 1;
|
||||
for (MarkRoundingListener listener : markRoundingListeners) {
|
||||
listener.notifyRounding(this, lastMarkRounded, legNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,17 @@ package seng302.model;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.TimeZone;
|
||||
import javafx.beans.property.ReadOnlyDoubleProperty;
|
||||
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import seng302.model.stream.parser.RaceStartData;
|
||||
import seng302.model.stream.parser.RaceStatusData;
|
||||
|
||||
@@ -12,22 +22,30 @@ import seng302.model.stream.parser.RaceStatusData;
|
||||
*/
|
||||
public class RaceState {
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CollisionListener {
|
||||
void notifyCollision(GeoPoint location);
|
||||
}
|
||||
|
||||
// private final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
private final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
private double windSpeed;
|
||||
private double windDirection;
|
||||
private ReadOnlyDoubleWrapper windSpeed = new ReadOnlyDoubleWrapper();
|
||||
private ReadOnlyDoubleWrapper windDirection = new ReadOnlyDoubleWrapper();
|
||||
private long serverSystemTime;
|
||||
private long expectedStartTime;
|
||||
private boolean isRaceStarted = false;
|
||||
long timeTillStart;
|
||||
private ObservableList<ClientYacht> playerPositions;
|
||||
private List<ClientYacht> collisions = new ArrayList<>();
|
||||
private List<CollisionListener> collisionListeners = new ArrayList<>();
|
||||
|
||||
public RaceState() {
|
||||
playerPositions = FXCollections.observableArrayList();
|
||||
}
|
||||
|
||||
public void updateState (RaceStatusData data) {
|
||||
this.windSpeed = data.getWindSpeed();
|
||||
this.windDirection = data.getWindDirection();
|
||||
this.windSpeed.set(data.getWindSpeed());
|
||||
this.windDirection.set(data.getWindDirection());
|
||||
this.serverSystemTime = data.getCurrentTime();
|
||||
this.expectedStartTime = data.getExpectedStartTime();
|
||||
this.isRaceStarted = data.isRaceStarted();
|
||||
@@ -55,11 +73,15 @@ public class RaceState {
|
||||
}
|
||||
|
||||
public double getWindSpeed() {
|
||||
return windSpeed;
|
||||
return windSpeed.doubleValue();
|
||||
}
|
||||
|
||||
public double getWindDirection() {
|
||||
return windDirection;
|
||||
public ReadOnlyDoubleProperty windSpeedProperty() {
|
||||
return windSpeed.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
public ReadOnlyDoubleProperty windDirectionProperty() {
|
||||
return windDirection.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
public long getRaceTime() {
|
||||
@@ -69,4 +91,32 @@ public class RaceState {
|
||||
public boolean isRaceStarted () {
|
||||
return isRaceStarted;
|
||||
}
|
||||
|
||||
public void setBoats(Collection<ClientYacht> clientYachts) {
|
||||
playerPositions.setAll(clientYachts);
|
||||
}
|
||||
|
||||
public void sortPlayers() {
|
||||
playerPositions.sort((yacht1, yacht2) -> Integer.compare(yacht2.getLegNumber(),
|
||||
yacht1.getLegNumber()));
|
||||
}
|
||||
|
||||
public ObservableList<ClientYacht> getPlayerPositions() {
|
||||
return playerPositions;
|
||||
}
|
||||
|
||||
public void storeCollision(ClientYacht yacht) {
|
||||
collisions.add(yacht);
|
||||
for (CollisionListener collisionListener : collisionListeners) {
|
||||
collisionListener.notifyCollision(yacht.getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
public void addCollisionListener(CollisionListener collisionListener) {
|
||||
collisionListeners.add(collisionListener);
|
||||
}
|
||||
|
||||
public void removeCollisionListener(CollisionListener collisionListener) {
|
||||
collisionListeners.remove(collisionListener);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ public class ServerYacht extends Observable {
|
||||
private Double currentVelocity;
|
||||
private Boolean isAuto;
|
||||
private Double autoHeading;
|
||||
private Integer legNumber;
|
||||
|
||||
//Mark Rounding
|
||||
private Integer currentMarkSeqID;
|
||||
@@ -68,6 +69,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.boatColor = Colors.getColor(sourceId - 1);
|
||||
|
||||
this.hasEnteredRoundingZone = false;
|
||||
@@ -389,6 +391,14 @@ public class ServerYacht extends Observable {
|
||||
return hasPassedLine;
|
||||
}
|
||||
|
||||
public void incrementLegNumber() {
|
||||
legNumber++;
|
||||
}
|
||||
|
||||
public Integer getLegNumber() {
|
||||
return legNumber;
|
||||
}
|
||||
|
||||
public void setBoatColor(Color color) {
|
||||
this.boatColor = color;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class CompoundMark {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setRoundingSide(RoundingSide roundingSide) {
|
||||
public void setRoundingSide(RoundingSide roundingSide) {;
|
||||
switch (roundingSide) {
|
||||
case SP:
|
||||
getSubMark(1).setRoundingSide(RoundingSide.STARBOARD);
|
||||
|
||||
@@ -104,10 +104,11 @@ public class MarkOrder {
|
||||
List<Corner> corners = data.getMarkSequence();
|
||||
Map<Integer, CompoundMark> marks = data.getCompoundMarks();
|
||||
List<CompoundMark> course = new ArrayList<>();
|
||||
|
||||
for (Corner corner : corners){
|
||||
CompoundMark compoundMark = marks.get(corner.getCompoundMarkID());
|
||||
compoundMark.setRoundingSide(RoundingSide.getRoundingSide(corner.getRounding()));
|
||||
compoundMark.setRoundingSide(
|
||||
RoundingSide.getRoundingSide(corner.getRounding())
|
||||
);
|
||||
course.add(compoundMark);
|
||||
allMarks.addAll(compoundMark.getMarks());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user