Fixed course xml reader. #story[782]
This commit is contained in:
@@ -164,8 +164,7 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|||||||
* @return value of "compoundMarkID" attribute
|
* @return value of "compoundMarkID" attribute
|
||||||
*/
|
*/
|
||||||
private int getCompoundMarkID(Element element) {
|
private int getCompoundMarkID(Element element) {
|
||||||
//return Integer.parseInt(element.getAttribute("CompoundMarkID"));
|
return Integer.parseInt(element.getAttribute("CompoundMarkID"));
|
||||||
return 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,10 +183,11 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|||||||
private void readCompoundMarkSequence() throws StreamedCourseXMLException {
|
private void readCompoundMarkSequence() throws StreamedCourseXMLException {
|
||||||
Element nCompoundMarkSequence = (Element) doc.getElementsByTagName("CompoundMarkSequence").item(0);
|
Element nCompoundMarkSequence = (Element) doc.getElementsByTagName("CompoundMarkSequence").item(0);
|
||||||
NodeList nCorners = nCompoundMarkSequence.getElementsByTagName("Corner");
|
NodeList nCorners = nCompoundMarkSequence.getElementsByTagName("Corner");
|
||||||
Marker lastMarker = getMarker(getCompoundMarkID((Element)nCorners.item(0)));
|
Element markXML = (Element)nCorners.item(0);
|
||||||
String legName = getCompoundMarkName(getCompoundMarkID((Element)nCorners.item(0)));
|
Marker lastMarker = getMarker(getCompoundMarkID(markXML));
|
||||||
|
String legName = getCompoundMarkName(getCompoundMarkID(markXML));
|
||||||
for(int i = 1; i < nCorners.getLength(); i++) {
|
for(int i = 1; i < nCorners.getLength(); i++) {
|
||||||
Element markXML = (Element)nCorners.item(i);
|
markXML = (Element)nCorners.item(i);
|
||||||
Marker currentMarker = getMarker(getCompoundMarkID(markXML));
|
Marker currentMarker = getMarker(getCompoundMarkID(markXML));
|
||||||
legs.add(new Leg(legName, lastMarker, currentMarker, i-1));
|
legs.add(new Leg(legName, lastMarker, currentMarker, i-1));
|
||||||
lastMarker = currentMarker;
|
lastMarker = currentMarker;
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import seng302.Controllers.RaceController;
|
|||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
import seng302.Model.*;
|
import seng302.Model.*;
|
||||||
import seng302.Networking.MessageDecoders.BoatLocationDecoder;
|
import seng302.Networking.MessageDecoders.BoatLocationDecoder;
|
||||||
|
import seng302.Networking.Utils.BoatStatusMessage;
|
||||||
|
import seng302.Networking.Utils.ByteConverter;
|
||||||
|
import seng302.Networking.Utils.Enums.BoatStatus;
|
||||||
import seng302.Networking.Utils.BoatLocationMessage;
|
import seng302.Networking.Utils.BoatLocationMessage;
|
||||||
import seng302.RaceDataSource;
|
import seng302.RaceDataSource;
|
||||||
import seng302.VisualiserInput;
|
import seng302.VisualiserInput;
|
||||||
@@ -51,18 +54,26 @@ public class StreamedRace extends Race {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the position of the boat, this updates the boats current position.
|
* Checks the position of the boat.
|
||||||
*
|
*
|
||||||
* @param boat Boat that the position is to be updated for.
|
* @param boat Boat that the position is to be updated for.
|
||||||
* @param timeElapsed Time that has elapse since the start of the the race.
|
* @param timeElapsed Time that has elapse since the start of the the race.
|
||||||
* @see BoatInRace
|
* @see BoatInRace
|
||||||
*/
|
*/
|
||||||
protected void checkPosition(Boat boat, long timeElapsed) {
|
protected void checkPosition(Boat boat, long timeElapsed) {
|
||||||
if (boat.getCurrentLeg().getName().toLowerCase().contains("finish")) {
|
StreamedCourse raceData = visualiserInput.getCourse();
|
||||||
//boat has finished
|
BoatStatusMessage boatStatusMessage = visualiserInput.getBoatStatus().get(boat.getSourceID());
|
||||||
|
BoatStatus boatStatus = BoatStatus.valueOf(boatStatusMessage.getBoatStatus());
|
||||||
|
int legNumber = boatStatusMessage.getLegNumber();
|
||||||
|
|
||||||
|
if (boatStatus == BoatStatus.DNF) {
|
||||||
|
boat.setDnf(true);
|
||||||
|
} else if (boatStatus == BoatStatus.FINISHED || legNumber > raceData.getLegs().size()) {
|
||||||
boatsFinished++;
|
boatsFinished++;
|
||||||
boat.setFinished(true);
|
|
||||||
boat.setTimeFinished(timeElapsed);
|
boat.setTimeFinished(timeElapsed);
|
||||||
|
boat.setFinished(true);
|
||||||
|
} else {
|
||||||
|
boat.setCurrentLeg(raceData.getLegs().get(legNumber));
|
||||||
}
|
}
|
||||||
//Update the boat display table in the GUI to reflect the leg change
|
//Update the boat display table in the GUI to reflect the leg change
|
||||||
updatePositions();
|
updatePositions();
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ public class VisualiserInput implements Runnable
|
|||||||
|
|
||||||
private Map<Integer, BoatStatusMessage> boatStatus;
|
private Map<Integer, BoatStatusMessage> boatStatus;
|
||||||
|
|
||||||
public VisualiserInput(StreamedCourse course) throws IOException{
|
|
||||||
public VisualiserInput(Socket socket, StreamedCourse course) throws IOException{
|
public VisualiserInput(Socket socket, StreamedCourse course) throws IOException{
|
||||||
|
|
||||||
this.connectionSocket = socket;
|
this.connectionSocket = socket;
|
||||||
|
|||||||
@@ -76,7 +76,9 @@ public class StreamedRaceTest {
|
|||||||
"M2",
|
"M2",
|
||||||
"Gate"
|
"Gate"
|
||||||
};
|
};
|
||||||
for(int i = 0; i < legs.size(); i++) assertEquals(expectedNames[i], legs.get(i).getName());
|
for(int i = 0; i < legs.size(); i++) {
|
||||||
|
assertEquals(expectedNames[i], legs.get(i).getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user