mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Implemented observer and strategy pattern in BoatAnnotations, now renamed AnnotationsBox.
Also implemented various other small fixes and further refactored code. #refactor
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package seng302.model;
|
||||
|
||||
import javafx.beans.property.ReadOnlyDoubleProperty;
|
||||
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||
import javafx.beans.property.ReadOnlyLongProperty;
|
||||
import javafx.beans.property.ReadOnlyLongWrapper;
|
||||
import javafx.scene.paint.Color;
|
||||
import seng302.model.mark.Mark;
|
||||
import seng302.model.stream.packets.StreamPacket;
|
||||
import seng302.visualiser.controllers.RaceViewController;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -30,15 +32,14 @@ public class Boat {
|
||||
private Integer boatStatus;
|
||||
private Integer legNumber = 0;
|
||||
private Integer position = 0;
|
||||
private Integer penaltiesAwarded;
|
||||
private Integer penaltiesServed;
|
||||
private Long estimateTimeAtFinish;
|
||||
private Long markRoundTime;
|
||||
private Double lat;
|
||||
private Double lon;
|
||||
private Double heading;
|
||||
private double velocity;
|
||||
private Long timeTillNext;
|
||||
private Long markRoundTime;
|
||||
private ReadOnlyDoubleWrapper velocity = new ReadOnlyDoubleWrapper();
|
||||
private ReadOnlyLongWrapper timeTillNext = new ReadOnlyLongWrapper();
|
||||
private ReadOnlyLongWrapper timeSinceLastMark = new ReadOnlyLongWrapper();
|
||||
|
||||
// Mark rounding
|
||||
private Mark lastMarkRounded;
|
||||
@@ -94,8 +95,8 @@ public class Boat {
|
||||
this.legNumber = legNumber;
|
||||
}
|
||||
|
||||
public void setEstimateTimeAtNextMark(Long estimateTimeAtNextMark) {
|
||||
timeTillNext = estimateTimeAtNextMark;
|
||||
public void setEstimateTimeTillNextMark(Long estimateTimeAtNextMark) {
|
||||
timeTillNext.set(estimateTimeAtNextMark);
|
||||
}
|
||||
|
||||
public String getEstimateTimeAtFinish() {
|
||||
@@ -124,7 +125,7 @@ public class Boat {
|
||||
}
|
||||
|
||||
public void setVelocity(double velocity) {
|
||||
this.velocity = velocity;
|
||||
this.velocity.set(velocity);
|
||||
}
|
||||
|
||||
|
||||
@@ -132,12 +133,12 @@ public class Boat {
|
||||
this.markRoundTime = markRoundingTime;
|
||||
}
|
||||
|
||||
public double getVelocity() {
|
||||
return velocity;
|
||||
public ReadOnlyDoubleProperty getVelocityProperty() {
|
||||
return velocity.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
public Long getTimeTillNext() {
|
||||
return timeTillNext;
|
||||
public ReadOnlyLongProperty timeTillNextProperty() {
|
||||
return timeTillNext.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
public Long getMarkRoundTime() {
|
||||
@@ -189,4 +190,12 @@ public class Boat {
|
||||
return boatName;
|
||||
}
|
||||
|
||||
public void setTimeSinceLastMark (long timeSinceLastMark) {
|
||||
this.timeSinceLastMark.set(timeSinceLastMark);
|
||||
}
|
||||
|
||||
public ReadOnlyLongProperty timeSinceLastMarkProperty () {
|
||||
return timeSinceLastMark.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package seng302.model;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.TimeZone;
|
||||
import seng302.model.stream.parsers.RaceStartData;
|
||||
import seng302.model.stream.parsers.RaceStatusData;
|
||||
|
||||
/**
|
||||
* Class for storing race data that does not relate to specific vessels or marks such as time or wind.
|
||||
* Calculates the state of critical race attributes when relevant data is added.
|
||||
*/
|
||||
public class RaceState {
|
||||
|
||||
// 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 long raceTime;
|
||||
private long expectedStartTime;
|
||||
private boolean isRaceStarted;
|
||||
// long timeTillStart;
|
||||
|
||||
public RaceState() {
|
||||
}
|
||||
|
||||
public void updateState (RaceStatusData data) {
|
||||
this.windSpeed = data.getWindSpeed();
|
||||
this.windDirection = data.getWindDirection();
|
||||
this.raceTime = data.getCurrentTime();
|
||||
this.expectedStartTime = data.getExpectedStartTime();
|
||||
this.isRaceStarted = data.isRaceStarted();
|
||||
}
|
||||
|
||||
public void setTimeZone (TimeZone timeZone) {
|
||||
DATE_TIME_FORMAT.setTimeZone(timeZone);
|
||||
}
|
||||
|
||||
public void updateState (RaceStartData data) {
|
||||
// this.timeTillStart = data.getRaceStartTime();
|
||||
System.out.println(data.getRaceStartTime());
|
||||
}
|
||||
|
||||
public String getRaceTimeStr () {
|
||||
return DATE_TIME_FORMAT.format(raceTime);
|
||||
}
|
||||
|
||||
public long getTimeTillStart () {
|
||||
return (expectedStartTime - raceTime) / 1000;
|
||||
}
|
||||
|
||||
public double getWindSpeed() {
|
||||
return windSpeed;
|
||||
}
|
||||
|
||||
public double getWindDirection() {
|
||||
return windDirection;
|
||||
}
|
||||
|
||||
public long getRaceTime() {
|
||||
return raceTime;
|
||||
}
|
||||
|
||||
public long getExpectedStartTime() {
|
||||
return expectedStartTime;
|
||||
}
|
||||
|
||||
public boolean isRaceStarted () {
|
||||
return isRaceStarted;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package seng302.model;
|
||||
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.beans.property.LongProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.beans.property.SimpleLongProperty;
|
||||
|
||||
/**
|
||||
* Class for storing race data that does not relate to specific vessels or marks such as time or wind
|
||||
*/
|
||||
public class RaceStatus {
|
||||
double windSpeed;
|
||||
double windDirection;
|
||||
long raceTime;
|
||||
|
||||
}
|
||||
@@ -38,20 +38,6 @@ public class StreamParser {
|
||||
return heartbeat;
|
||||
}
|
||||
|
||||
private static String getTimeZoneString(RegattaXMLData regattaXML) {
|
||||
Integer offset = regattaXML.getUtcOffset();
|
||||
StringBuilder utcOffset = new StringBuilder();
|
||||
utcOffset.append("GMT");
|
||||
if (offset > 0) {
|
||||
utcOffset.append("+");
|
||||
utcOffset.append(offset);
|
||||
} else if (offset < 0) {
|
||||
utcOffset.append("-");
|
||||
utcOffset.append(offset);
|
||||
}
|
||||
return utcOffset.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the useful race status data from race status type packets. This method will also
|
||||
* print to the console the current state of the race (if it has started/finished or is about to
|
||||
@@ -112,7 +98,7 @@ public class StreamParser {
|
||||
// boat.setPenaltiesServed((int) payload[31 + (i * 20)]);
|
||||
Long estTimeAtNextMark = bytesToLong(
|
||||
Arrays.copyOfRange(payload, 32 + (i * 20), 38 + (i * 20)));
|
||||
// boat.setEstimateTimeAtNextMark(estTimeAtNextMark);
|
||||
// boat.setEstimateTimeTillNextMark(estTimeAtNextMark);
|
||||
Long estTimeAtFinish = bytesToLong(
|
||||
Arrays.copyOfRange(payload, 38 + (i * 20), 44 + (i * 20)));
|
||||
int leg = (int) payload[29 + (i * 20)];
|
||||
|
||||
Reference in New Issue
Block a user