Added race boats to XML Generator

Tags: #story[1047]
This commit is contained in:
Michael Rausch
2017-07-21 16:56:46 +12:00
parent 5df7efda03
commit 33fae9d69a
10 changed files with 40 additions and 15 deletions
@@ -321,7 +321,7 @@ public class CanvasController {
} }
for (Yacht boat : boats.values()) { for (Yacht boat : boats.values()) {
if (participantIDs.contains(boat.getSourceID())) { if (participantIDs.contains(boat.getSourceId())) {
boat.setColour(Colors.getColor()); boat.setColour(Colors.getColor());
BoatGroup boatGroup = new BoatGroup(boat, boat.getColour()); BoatGroup boatGroup = new BoatGroup(boat, boat.getColour());
boatGroups.add(boatGroup); boatGroups.add(boatGroup);
@@ -68,7 +68,7 @@ public class FinishScreenViewController implements Initializable {
// add data to table // add data to table
for (Yacht boat : ClientPacketParser.getBoatsPos().values()) { for (Yacht boat : ClientPacketParser.getBoatsPos().values()) {
if (participantIDs.contains(boat.getSourceID())) { if (participantIDs.contains(boat.getSourceId())) {
data.add(boat); data.add(boat);
} }
} }
@@ -199,7 +199,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
*/ */
void updateSparkLine(){ void updateSparkLine(){
// Collect the racing boats that aren't already in the chart // Collect the racing boats that aren't already in the chart
ArrayList<Yacht> sparkLineCandidates = startingBoats.stream().filter(yacht -> !sparkLineData.containsKey(yacht.getSourceID()) ArrayList<Yacht> sparkLineCandidates = startingBoats.stream().filter(yacht -> !sparkLineData.containsKey(yacht.getSourceId())
&& yacht.getPosition() != null & yacht.getPosition() != "-").collect(Collectors.toCollection(ArrayList::new)); && yacht.getPosition() != null & yacht.getPosition() != "-").collect(Collectors.toCollection(ArrayList::new));
// Obtain the qualifying boats to set the max on the Y axis // Obtain the qualifying boats to set the max on the Y axis
@@ -212,7 +212,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
Series<String, Double> yachtData = new Series<>(); Series<String, Double> yachtData = new Series<>();
yachtData.setName(yacht.getBoatName()); yachtData.setName(yacht.getBoatName());
yachtData.getData().add(new XYChart.Data<>(Integer.toString(yacht.getLegNumber()), 1 + racingBoats.size() - Double.parseDouble(yacht.getPosition()))); yachtData.getData().add(new XYChart.Data<>(Integer.toString(yacht.getLegNumber()), 1 + racingBoats.size() - Double.parseDouble(yacht.getPosition())));
sparkLineData.put(yacht.getSourceID(), yachtData); sparkLineData.put(yacht.getSourceId(), yachtData);
}); });
// Lambda function to sort the series in order of leg (later legs shown more to the right) // Lambda function to sort the series in order of leg (later legs shown more to the right)
@@ -242,7 +242,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
* @param legNumber the leg number that the position will be assigned to * @param legNumber the leg number that the position will be assigned to
*/ */
public static void updateYachtPositionSparkline(Yacht yacht, Integer legNumber){ public static void updateYachtPositionSparkline(Yacht yacht, Integer legNumber){
XYChart.Series<String, Double> positionData = sparkLineData.get(yacht.getSourceID()); XYChart.Series<String, Double> positionData = sparkLineData.get(yacht.getSourceId());
positionData.getData().add(new XYChart.Data<>(Integer.toString(legNumber), 1 + racingBoats.size() - Double.parseDouble(yacht.getPosition()))); positionData.getData().add(new XYChart.Data<>(Integer.toString(legNumber), 1 + racingBoats.size() - Double.parseDouble(yacht.getPosition())));
} }
@@ -381,7 +381,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
if (ClientPacketParser.isRaceStarted()) { if (ClientPacketParser.isRaceStarted()) {
for (Yacht boat : ClientPacketParser.getBoatsPos().values()) { for (Yacht boat : ClientPacketParser.getBoatsPos().values()) {
if (participantIDs.contains(boat.getSourceID())) { // check if the boat is racing if (participantIDs.contains(boat.getSourceId())) { // check if the boat is racing
if (boat.getBoatStatus() == 3) { // 3 is finish status if (boat.getBoatStatus() == 3) { // 3 is finish status
Text textToAdd = new Text(boat.getPosition() + ". " + Text textToAdd = new Text(boat.getPosition() + ". " +
boat.getShortName() + " (Finished)"); boat.getShortName() + " (Finished)");
@@ -399,7 +399,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
} }
} else { } else {
for (Yacht boat : ClientPacketParser.getBoats().values()) { for (Yacht boat : ClientPacketParser.getBoats().values()) {
if (participantIDs.contains(boat.getSourceID())) { // check if the boat is racing if (participantIDs.contains(boat.getSourceId())) { // check if the boat is racing
Text textToAdd = new Text(boat.getPosition() + ". " + Text textToAdd = new Text(boat.getPosition() + ". " +
boat.getShortName() + " "); boat.getShortName() + " ");
textToAdd.setFill(Paint.valueOf("#d3d3d3")); textToAdd.setFill(Paint.valueOf("#d3d3d3"));
@@ -316,7 +316,7 @@ public class BoatGroup extends Group {
* @return An array containing all ID's associated with this RaceObject. * @return An array containing all ID's associated with this RaceObject.
*/ */
public long getRaceId() { public long getRaceId() {
return boat.getSourceID(); return boat.getSourceId();
} }
public Group getWake () { public Group getWake () {
@@ -96,7 +96,7 @@ public class GameServerThread implements Runnable, Observer, ClientConnectionDel
thereAreBoatsNotFinished = true; thereAreBoatsNotFinished = true;
} }
BoatSubMessage m = new BoatSubMessage(y.getSourceID(), boatStatus, y.getLastMarkRounded().getId(), 0, 0, 1234l, 1234l); BoatSubMessage m = new BoatSubMessage(y.getSourceId(), boatStatus, y.getLastMarkRounded().getId(), 0, 0, 1234l, 1234l);
boatSubMessages.add(m); boatSubMessages.add(m);
} }
@@ -8,6 +8,14 @@ import seng302.models.Player;
import seng302.models.Yacht; import seng302.models.Yacht;
import seng302.models.stream.packets.PacketType; import seng302.models.stream.packets.PacketType;
import seng302.models.stream.packets.StreamPacket; import seng302.models.stream.packets.StreamPacket;
import seng302.server.messages.ChatterMessage;
import seng302.server.messages.Heartbeat;
import seng302.server.messages.BoatActionType;
import seng302.server.messages.Message;
import seng302.models.xml.Race;
import seng302.models.xml.Regatta;
import seng302.models.xml.XMLGenerator;
import seng302.server.messages.*;
import seng302.models.xml.XMLGenerator; import seng302.models.xml.XMLGenerator;
import seng302.server.messages.*; import seng302.server.messages.*;
@@ -125,10 +133,22 @@ public class ServerToClientThread extends Thread {
private void sendSetupMessages() { private void sendSetupMessages() {
xml = new XMLGenerator(); xml = new XMLGenerator();
Race race = new Race();
for (Player player : GameState.getPlayers()){
race.addBoat(player.getYacht());
}
//@TODO calculate lat/lng values
xml.setRegatta(new Regatta("RaceVision Test Game", 0d, 0d));
xml.setRace(race);
XMLMessage xmlMessage = new XMLMessage(xml.getRegattaAsXml(), XMLMessageSubType.REGATTA, xml.getRegattaAsXml().length()); XMLMessage xmlMessage = new XMLMessage(xml.getRegattaAsXml(), XMLMessageSubType.REGATTA, xml.getRegattaAsXml().length());
sendMessage(xmlMessage); sendMessage(xmlMessage);
xmlMessage = new XMLMessage(xml.getBoatsAsXml(), XMLMessageSubType.BOAT, xml.getBoatsAsXml().length()); xmlMessage = new XMLMessage(xml.getBoatsAsXml(), XMLMessageSubType.BOAT, xml.getBoatsAsXml().length());
sendMessage(xmlMessage); sendMessage(xmlMessage);
xmlMessage = new XMLMessage(xml.getRaceAsXml(), XMLMessageSubType.RACE, xml.getRaceAsXml().length()); xmlMessage = new XMLMessage(xml.getRaceAsXml(), XMLMessageSubType.RACE, xml.getRaceAsXml().length());
sendMessage(xmlMessage); sendMessage(xmlMessage);
} }
+1
View File
@@ -19,6 +19,7 @@ public class Player {
public Player(Socket socket) { public Player(Socket socket) {
this.socket = socket; this.socket = socket;
yacht = new Yacht("test", 12.2, "asd", 12);
} }
public Socket getSocket() { public Socket getSocket() {
+6 -1
View File
@@ -74,6 +74,7 @@ public class Yacht {
this.velocity = boatVelocity; this.velocity = boatVelocity;
this.shortName = shortName; this.shortName = shortName;
this.sourceID = id; this.sourceID = id;
this.location = new GeoPoint(0.0, 0.0);
} }
public Yacht(String boatType, Integer sourceID, String hullID, String shortName, public Yacht(String boatType, Integer sourceID, String hullID, String shortName,
@@ -126,11 +127,14 @@ public class Yacht {
return boatType; return boatType;
} }
public Integer getSourceID() { public Integer getSourceId() {
//@TODO Remove and merge with Creating Game Loop
if (sourceID == null) return 0;
return sourceID; return sourceID;
} }
public String getHullID() { public String getHullID() {
if (hullID == null) return "";
return hullID; return hullID;
} }
@@ -143,6 +147,7 @@ public class Yacht {
} }
public String getCountry() { public String getCountry() {
if (country == null) return "";
return country; return country;
} }
@@ -558,7 +558,7 @@ public class XMLParser {
getNodeAttributeString(currentBoat, "Country")); getNodeAttributeString(currentBoat, "Country"));
this.boats.add(boat); this.boats.add(boat);
if (boat.getBoatType().equals("Yacht")) { if (boat.getBoatType().equals("Yacht")) {
competingBoats.put(boat.getSourceID(), boat); competingBoats.put(boat.getSourceId(), boat);
} }
} }
} }
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<BoatConfig> <BoatConfig>
<Modified>2012-05-17T07:49:40+0200</Modified> <Modified>2012-05-17T07:49:40+0200</Modified>
@@ -17,11 +16,11 @@
<Boats> <Boats>
<#list boats as boat> <#list boats as boat>
<Boat Type="Yacht" SourceID="${boat.sourceId}" ShapeID="4" HullNum="${boat.hullId}" StoweName="${boat.shortName}" ShortName="${boat.shortName}" <Boat Type="Yacht" SourceID="${boat.sourceId}" ShapeID="4" HullNum="${boat.hullID}" StoweName="${boat.shortName}" ShortName="${boat.shortName}"
BoatName="${boat.boatName}" Country="${boat.country}"> BoatName="${boat.boatName}" Country="${boat.country}">
<GPSposition Z="0" Y="${boat.lat}" X="${boat.lon}" /> <GPSposition Z="0" Y="${boat.location.lat}" X="${boat.location.lng}" />
<MastTop Z="0" Y="${boat.lat}" X="${boat.lon}" /> <MastTop Z="0" Y="${boat.location.lat}" X="${boat.location.lng}" />
</Boat> </Boat>
</#list> </#list>
</Boats> </Boats>