Refactored mock.Event to work with MockRace.
Fixed the networking imports. Race now keeps a reference to its Race, Boat, and Regatta data sources. VisualiserRace can be provided with new Race/Boat/Regatta data sources during runtime. Currently it updates boundary and legs with a new RaceDataSource, and marker boats with a new BoatDataSource.
This commit is contained in:
@@ -77,25 +77,19 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
*/
|
||||
private RaceTypeEnum raceType;
|
||||
|
||||
//TODO maybe remove these?
|
||||
private Map<Integer, Boat> boats;
|
||||
private Map<Integer, Mark> marks;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for Streamed Race XML
|
||||
* @param filePath file path to read
|
||||
* @param boatData data of the boats in race
|
||||
* @throws XMLReaderException Thrown if an XML reader cannot be constructed for the given file.
|
||||
* @throws InvalidRaceDataException Thrown if the XML file is invalid in some way.
|
||||
*/
|
||||
public RaceXMLReader(String filePath, BoatDataSource boatData) throws XMLReaderException, InvalidRaceDataException {
|
||||
public RaceXMLReader(String filePath) throws XMLReaderException, InvalidRaceDataException {
|
||||
|
||||
super(filePath);
|
||||
|
||||
this.boats = boatData.getBoats();
|
||||
this.marks = boatData.getMarkerBoats();
|
||||
|
||||
//Attempt to read race xml file.
|
||||
try {
|
||||
|
||||
@@ -7,7 +7,7 @@ import network.Messages.Enums.BoatStatusEnum;
|
||||
/**
|
||||
* Boat Model that is used to store information on the boats that are running in the race.
|
||||
*/
|
||||
public abstract class Boat {
|
||||
public class Boat {
|
||||
/**
|
||||
* The name of the boat/team.
|
||||
*/
|
||||
|
||||
@@ -25,6 +25,21 @@ import static java.lang.Math.cos;
|
||||
public abstract class Race implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* The source of race related data.
|
||||
*/
|
||||
protected RaceDataSource raceDataSource;
|
||||
|
||||
/**
|
||||
* The source of boat related data.
|
||||
*/
|
||||
protected BoatDataSource boatDataSource;
|
||||
|
||||
/**
|
||||
* The source of regatta related data.
|
||||
*/
|
||||
protected RegattaDataSource regattaDataSource;
|
||||
|
||||
|
||||
/**
|
||||
* A list of compound marks in the race.
|
||||
@@ -90,15 +105,19 @@ public abstract class Race implements Runnable {
|
||||
*/
|
||||
public Race(BoatDataSource boatDataSource, RaceDataSource raceDataSource, RegattaDataSource regattaDataSource) {
|
||||
|
||||
//Keep a reference to data sources.
|
||||
this.raceDataSource = raceDataSource;
|
||||
this.boatDataSource = boatDataSource;
|
||||
this.regattaDataSource = regattaDataSource;
|
||||
|
||||
|
||||
this.compoundMarks = raceDataSource.getCompoundMarks();
|
||||
|
||||
this.boundary = raceDataSource.getBoundary();
|
||||
|
||||
|
||||
//We add a "dummy" leg at the end of the race.
|
||||
this.legs = raceDataSource.getLegs();
|
||||
this.legs.add(new Leg("Finish", this.legs.size()));
|
||||
this.useLegsList(raceDataSource.getLegs());
|
||||
|
||||
|
||||
this.raceId = raceDataSource.getRaceId();
|
||||
|
||||
@@ -126,8 +145,15 @@ public abstract class Race implements Runnable {
|
||||
protected abstract void initialiseBoats();
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Updates the race to use a new list of legs, and adds a dummy "Finish" leg at the end.
|
||||
* @param legs The new list of legs to use.
|
||||
*/
|
||||
protected void useLegsList(List<Leg> legs) {
|
||||
//We add a "dummy" leg at the end of the race.
|
||||
this.legs = legs;
|
||||
this.legs.add(new Leg("Finish", this.legs.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not a specific leg is the last leg in the race.
|
||||
|
||||
Reference in New Issue
Block a user