mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
GameClient now extracts Tokens client side
#story[1250]
This commit is contained in:
@@ -29,9 +29,11 @@ import seng302.model.ServerYacht;
|
|||||||
import seng302.model.mark.CompoundMark;
|
import seng302.model.mark.CompoundMark;
|
||||||
import seng302.model.mark.Mark;
|
import seng302.model.mark.Mark;
|
||||||
import seng302.model.mark.MarkOrder;
|
import seng302.model.mark.MarkOrder;
|
||||||
|
import seng302.model.stream.xml.generator.RaceXMLTemplate;
|
||||||
import seng302.model.token.Token;
|
import seng302.model.token.Token;
|
||||||
import seng302.model.token.TokenType;
|
import seng302.model.token.TokenType;
|
||||||
import seng302.utilities.GeoUtility;
|
import seng302.utilities.GeoUtility;
|
||||||
|
import seng302.utilities.XMLGenerator;
|
||||||
import seng302.utilities.XMLParser;
|
import seng302.utilities.XMLParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.util.Map;
|
|||||||
import seng302.model.Limit;
|
import seng302.model.Limit;
|
||||||
import seng302.model.mark.CompoundMark;
|
import seng302.model.mark.CompoundMark;
|
||||||
import seng302.model.mark.Corner;
|
import seng302.model.mark.Corner;
|
||||||
|
import seng302.model.token.Token;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process a Document object containing race data in XML format and stores the data.
|
* Process a Document object containing race data in XML format and stores the data.
|
||||||
@@ -13,13 +14,16 @@ import seng302.model.mark.Corner;
|
|||||||
public class RaceXMLData {
|
public class RaceXMLData {
|
||||||
|
|
||||||
private List<Integer> participants;
|
private List<Integer> participants;
|
||||||
|
private List<Token> tokens;
|
||||||
private Map<Integer, CompoundMark> compoundMarks;
|
private Map<Integer, CompoundMark> compoundMarks;
|
||||||
private List<Corner> markSequence;
|
private List<Corner> markSequence;
|
||||||
private List<Limit> courseLimit;
|
private List<Limit> courseLimit;
|
||||||
|
|
||||||
public RaceXMLData(List<Integer> participants, List<CompoundMark> compoundMarks,
|
public RaceXMLData(List<Integer> participants, List<Token> tokens,
|
||||||
|
List<CompoundMark> compoundMarks,
|
||||||
List<Corner> markSequence, List<Limit> courseLimit) {
|
List<Corner> markSequence, List<Limit> courseLimit) {
|
||||||
this.participants = participants;
|
this.participants = participants;
|
||||||
|
this.tokens = tokens;
|
||||||
this.markSequence = markSequence;
|
this.markSequence = markSequence;
|
||||||
this.courseLimit = courseLimit;
|
this.courseLimit = courseLimit;
|
||||||
this.compoundMarks = new HashMap<>();
|
this.compoundMarks = new HashMap<>();
|
||||||
@@ -32,6 +36,10 @@ public class RaceXMLData {
|
|||||||
return participants;
|
return participants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Token> getTokens() {
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<Integer, CompoundMark> getCompoundMarks() {
|
public Map<Integer, CompoundMark> getCompoundMarks() {
|
||||||
return compoundMarks;
|
return compoundMarks;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import seng302.model.mark.Corner;
|
|||||||
import seng302.model.mark.Mark;
|
import seng302.model.mark.Mark;
|
||||||
import seng302.model.stream.xml.parser.RaceXMLData;
|
import seng302.model.stream.xml.parser.RaceXMLData;
|
||||||
import seng302.model.stream.xml.parser.RegattaXMLData;
|
import seng302.model.stream.xml.parser.RegattaXMLData;
|
||||||
|
import seng302.model.token.Token;
|
||||||
|
import seng302.model.token.TokenType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for parsing XML documents
|
* Utilities for parsing XML documents
|
||||||
@@ -182,12 +184,32 @@ public class XMLParser {
|
|||||||
Element docEle = doc.getDocumentElement();
|
Element docEle = doc.getDocumentElement();
|
||||||
return new RaceXMLData(
|
return new RaceXMLData(
|
||||||
extractParticpantIDs(docEle),
|
extractParticpantIDs(docEle),
|
||||||
|
extractTokens(docEle),
|
||||||
extractCompoundMarks(docEle),
|
extractCompoundMarks(docEle),
|
||||||
extractMarkOrder(docEle),
|
extractMarkOrder(docEle),
|
||||||
extractCourseLimit(docEle)
|
extractCourseLimit(docEle)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts token data
|
||||||
|
*/
|
||||||
|
private static List<Token> extractTokens(Element docEle) {
|
||||||
|
List<Token> tokens = new ArrayList<>();
|
||||||
|
NodeList tokenList = docEle.getElementsByTagName("Tokens").item(0).getChildNodes();
|
||||||
|
for (int i = 0; i < tokenList.getLength(); i++) {
|
||||||
|
Node tokenNode = tokenList.item(i);
|
||||||
|
if (tokenNode.getNodeName().equals("Token")) {
|
||||||
|
String tokenType = getNodeAttributeString(tokenNode, "TokenType");
|
||||||
|
Double lat = getNodeAttributeDouble(tokenNode, "TargetLat");
|
||||||
|
Double lng = getNodeAttributeDouble(tokenNode, "TargetLng");
|
||||||
|
tokens.add(new Token(TokenType.valueOf(tokenType), lat, lng));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts course limit data
|
* Extracts course limit data
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import seng302.model.stream.parser.RaceStatusData;
|
|||||||
import seng302.model.stream.parser.YachtEventData;
|
import seng302.model.stream.parser.YachtEventData;
|
||||||
import seng302.model.stream.xml.parser.RaceXMLData;
|
import seng302.model.stream.xml.parser.RaceXMLData;
|
||||||
import seng302.model.stream.xml.parser.RegattaXMLData;
|
import seng302.model.stream.xml.parser.RegattaXMLData;
|
||||||
|
import seng302.model.token.Token;
|
||||||
import seng302.utilities.StreamParser;
|
import seng302.utilities.StreamParser;
|
||||||
import seng302.utilities.XMLParser;
|
import seng302.utilities.XMLParser;
|
||||||
import seng302.visualiser.controllers.FinishScreenViewController;
|
import seng302.visualiser.controllers.FinishScreenViewController;
|
||||||
@@ -260,6 +261,7 @@ public class GameClient {
|
|||||||
courseData = XMLParser.parseRace(
|
courseData = XMLParser.parseRace(
|
||||||
StreamParser.extractXmlMessage(packet)
|
StreamParser.extractXmlMessage(packet)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (raceView != null) {
|
if (raceView != null) {
|
||||||
raceView.updateRaceData(courseData);
|
raceView.updateRaceData(courseData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
<Yacht SourceID="105" />
|
<Yacht SourceID="105" />
|
||||||
<Yacht SourceID="106" />
|
<Yacht SourceID="106" />
|
||||||
</Participants>
|
</Participants>
|
||||||
|
<Tokens>
|
||||||
|
</Tokens>
|
||||||
<Course>
|
<Course>
|
||||||
<CompoundMark CompoundMarkID="1" Name="Mark0">
|
<CompoundMark CompoundMarkID="1" Name="Mark0">
|
||||||
<Mark SeqID="1" Name="Start Line 1" TargetLat="57.6703330" TargetLng="11.8278330" SourceID="122" />
|
<Mark SeqID="1" Name="Start Line 1" TargetLat="57.6703330" TargetLng="11.8278330" SourceID="122" />
|
||||||
|
|||||||
Reference in New Issue
Block a user