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()) {
if (participantIDs.contains(boat.getSourceID())) {
if (participantIDs.contains(boat.getSourceId())) {
boat.setColour(Colors.getColor());
BoatGroup boatGroup = new BoatGroup(boat, boat.getColour());
boatGroups.add(boatGroup);
@@ -68,7 +68,7 @@ public class FinishScreenViewController implements Initializable {
// add data to table
for (Yacht boat : ClientPacketParser.getBoatsPos().values()) {
if (participantIDs.contains(boat.getSourceID())) {
if (participantIDs.contains(boat.getSourceId())) {
data.add(boat);
}
}
@@ -199,7 +199,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
*/
void updateSparkLine(){
// 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));
// 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<>();
yachtData.setName(yacht.getBoatName());
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)
@@ -242,7 +242,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
* @param legNumber the leg number that the position will be assigned to
*/
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())));
}
@@ -381,7 +381,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
if (ClientPacketParser.isRaceStarted()) {
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
Text textToAdd = new Text(boat.getPosition() + ". " +
boat.getShortName() + " (Finished)");
@@ -399,7 +399,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
}
} else {
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() + ". " +
boat.getShortName() + " ");
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.
*/
public long getRaceId() {
return boat.getSourceID();
return boat.getSourceId();
}
public Group getWake () {
@@ -96,7 +96,7 @@ public class GameServerThread implements Runnable, Observer, ClientConnectionDel
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);
}
@@ -8,6 +8,14 @@ import seng302.models.Player;
import seng302.models.Yacht;
import seng302.models.stream.packets.PacketType;
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.server.messages.*;
@@ -125,10 +133,22 @@ public class ServerToClientThread extends Thread {
private void sendSetupMessages() {
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());
sendMessage(xmlMessage);
xmlMessage = new XMLMessage(xml.getBoatsAsXml(), XMLMessageSubType.BOAT, xml.getBoatsAsXml().length());
sendMessage(xmlMessage);
xmlMessage = new XMLMessage(xml.getRaceAsXml(), XMLMessageSubType.RACE, xml.getRaceAsXml().length());
sendMessage(xmlMessage);
}
+1
View File
@@ -19,6 +19,7 @@ public class Player {
public Player(Socket socket) {
this.socket = socket;
yacht = new Yacht("test", 12.2, "asd", 12);
}
public Socket getSocket() {
+6 -1
View File
@@ -74,6 +74,7 @@ public class Yacht {
this.velocity = boatVelocity;
this.shortName = shortName;
this.sourceID = id;
this.location = new GeoPoint(0.0, 0.0);
}
public Yacht(String boatType, Integer sourceID, String hullID, String shortName,
@@ -126,11 +127,14 @@ public class Yacht {
return boatType;
}
public Integer getSourceID() {
public Integer getSourceId() {
//@TODO Remove and merge with Creating Game Loop
if (sourceID == null) return 0;
return sourceID;
}
public String getHullID() {
if (hullID == null) return "";
return hullID;
}
@@ -143,6 +147,7 @@ public class Yacht {
}
public String getCountry() {
if (country == null) return "";
return country;
}
@@ -558,7 +558,7 @@ public class XMLParser {
getNodeAttributeString(currentBoat, "Country"));
this.boats.add(boat);
if (boat.getBoatType().equals("Yacht")) {
competingBoats.put(boat.getSourceID(), boat);
competingBoats.put(boat.getSourceId(), boat);
}
}
}