diff --git a/src/main/java/seng302/model/mark/CompoundMark.java b/src/main/java/seng302/model/mark/CompoundMark.java index 8355caa4..b1989845 100644 --- a/src/main/java/seng302/model/mark/CompoundMark.java +++ b/src/main/java/seng302/model/mark/CompoundMark.java @@ -1,6 +1,5 @@ package seng302.model.mark; -import com.sun.deploy.util.StringUtils; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -31,9 +30,13 @@ public class CompoundMark { */ @Override public String toString(){ - String info = String.format("CompoundMark: %d (%s), [", compoundMarkId, name); - info += StringUtils.join(marks, ", ") + "]"; - return info; + String info = String.format( + "CompoundMark: %d (%s), [%s", compoundMarkId, name, marks.get(0).toString() + ); + if (marks.size() > 1) { + info += String.format(", %s", marks.get(1).toString()); + } + return info + "]"; } public int getId() { diff --git a/src/main/java/seng302/model/stream/xml/parser/RaceXMLData.java b/src/main/java/seng302/model/stream/xml/parser/RaceXMLData.java index 6a7e5ca9..13a0bdbc 100644 --- a/src/main/java/seng302/model/stream/xml/parser/RaceXMLData.java +++ b/src/main/java/seng302/model/stream/xml/parser/RaceXMLData.java @@ -43,5 +43,4 @@ public class RaceXMLData { public List getCourseLimit() { return courseLimit; } - } diff --git a/src/main/java/seng302/visualiser/ClientToServerThread.java b/src/main/java/seng302/visualiser/ClientToServerThread.java index 772e08b9..f877d608 100644 --- a/src/main/java/seng302/visualiser/ClientToServerThread.java +++ b/src/main/java/seng302/visualiser/ClientToServerThread.java @@ -147,6 +147,7 @@ public class ClientToServerThread implements Runnable { clientLog(e.getMessage(), 1); return; } + System.out.println("streamPackets.size() = " + streamPackets.size()); } closeSocket(); clientLog("Closed connection to Server", 0); diff --git a/src/main/java/seng302/visualiser/GameClient.java b/src/main/java/seng302/visualiser/GameClient.java index 9b8fc716..87a69843 100644 --- a/src/main/java/seng302/visualiser/GameClient.java +++ b/src/main/java/seng302/visualiser/GameClient.java @@ -1,6 +1,7 @@ package seng302.visualiser; import java.io.IOException; +import java.io.StringWriter; import java.time.ZoneId; import java.time.ZoneOffset; import java.util.Map; @@ -12,6 +13,11 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Node; import javafx.scene.input.KeyEvent; import javafx.scene.layout.Pane; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; import seng302.gameServer.GameState; import seng302.gameServer.MainServerThread; import seng302.model.RaceState; @@ -173,7 +179,18 @@ public class GameClient { break; case RACE_XML: - System.out.println("RACE XML"); + try { + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer transformer = tf.newTransformer(); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + StringWriter writer = new StringWriter(); + transformer.transform(new DOMSource(StreamParser.extractXmlMessage(packet)), + new StreamResult(writer)); +// String output = writer.getBuffer().toString().replaceAll("\n|\r", ""); + System.out.println(writer.getBuffer().toString()); + }catch (Exception e) { + e.printStackTrace(); + } courseData = XMLParser.parseRace( StreamParser.extractXmlMessage(packet) ); diff --git a/src/main/java/seng302/visualiser/GameView.java b/src/main/java/seng302/visualiser/GameView.java index bc55b43e..1965b168 100644 --- a/src/main/java/seng302/visualiser/GameView.java +++ b/src/main/java/seng302/visualiser/GameView.java @@ -59,13 +59,16 @@ public class GameView extends Pane { /* Note that if either of these is null then values for it have not been added and the other should be used as the limits of the map. */ private List borderPoints; - private List course; private Map markerObjects; private Map boatObjects = new HashMap<>(); private Map annotations = new HashMap<>(); - private List markSequence; private ObservableList gameObjects; + private Group annotationsGroup = new Group(); + private Group wakesGroup = new Group(); + private Group boatObjectGroup = new Group(); + private Group trails = new Group(); + private Group markers = new Group(); private ImageView mapImage = new ImageView(); @@ -93,6 +96,7 @@ public class GameView extends Pane { fpsDisplay.setStrokeWidth(2); gameObjects.add(fpsDisplay); gameObjects.add(raceBorder); + gameObjects.add(markers); initializeTimer(); // this.widthProperty().addListener(resize -> { // canvasWidth = this.getWidth(); @@ -182,12 +186,12 @@ public class GameView extends Pane { * @param newCourse the mark objects that make up the course. */ public void updateCourse(List newCourse, List sequence) { - course = newCourse; - this.markSequence = sequence; markerObjects = new HashMap<>(); Paint colour = Color.BLACK; + markers.getChildren().clear(); //Creates new markers - for (CompoundMark cMark : course) { + System.out.println(newCourse.size()); + for (CompoundMark cMark : newCourse) { //Set start and end colour if (cMark.getId() == sequence.get(0).getCompoundMarkID()) { colour = Color.GREEN; @@ -209,6 +213,7 @@ public class GameView extends Pane { } } colour = Color.BLACK; + System.out.println("cMark.toString() = " + cMark.toString()); } //Set X,Y co-ordinates if (borderPoints == null) { @@ -222,6 +227,7 @@ public class GameView extends Pane { marker.setCenterX(p2d.getX()); marker.setCenterY(p2d.getY()); })); + markers.getChildren().addAll(markerObjects.values()); } /** @@ -261,6 +267,7 @@ public class GameView extends Pane { gate.endYProperty().bind( m2.centerYProperty() ); + markers.getChildren().addAll(gate); } /** @@ -293,18 +300,13 @@ public class GameView extends Pane { findMinMaxPoint(limitingCoordinates); double minLonToMaxLon = scaleRaceExtremities(); calculateReferencePointLocation(minLonToMaxLon); - drawGoogleMap(); +// drawGoogleMap(); } /** * Draws all the boats. */ public void setBoats(List yachts) { - Group annotationsGroup = new Group(); - Group wakesGroup = new Group(); - Group boatObjectGroup = new Group(); - Group trails = new Group(); - BoatObject newBoat; for (Yacht yacht : yachts) { newBoat = new BoatObject(); @@ -314,6 +316,7 @@ public class GameView extends Pane { BoatObject bo = boatObjects.get(boat); Point2D p2d = findScaledXY(lat, lon); bo.moveTo(p2d.getX(), p2d.getY(), heading); + annotations.get(boat).setLocation(p2d.getX(), p2d.getY()); bo.setTrajectory( heading, velocity, @@ -331,6 +334,18 @@ public class GameView extends Pane { gameObjects.addAll(boatObjectGroup); } +// private void updateBoatObject (Yacht correspondingYacht) { +// BoatObject bo = boatObjects.get(correspondingYacht); +// Point2D p2d = findScaledXY(lat, lon); +// bo.moveTo(p2d.getX(), p2d.getY(), heading); +// annotations.get(boat).moveTo(p2d.getX(), p2d.getY()); +// bo.setTrajectory( +// heading, +// velocity, +// metersPerPixelX, +// metersPerPixelY); +// } + private void createAndBindAnnotationBox (Yacht yacht) { AnnotationBox newAnnotation; newAnnotation = new AnnotationBox(); @@ -339,7 +354,7 @@ public class GameView extends Pane { newAnnotation.addAnnotation( "velocity", yacht.getVelocityProperty(), - (velocity) -> String.format("%.2f ms", velocity.doubleValue()) + (velocity) -> String.format("Speed: %.2f ms", velocity.doubleValue()) ); newAnnotation.addAnnotation( "nextMark", @@ -477,7 +492,7 @@ public class GameView extends Pane { distanceFromReference = GeoUtility.getDistance( minLatPoint, new GeoPoint(unscaledLat, unscaledLon) ); - System.out.println("distanceFromReference = " + distanceFromReference); +// System.out.println("distanceFromReference = " + distanceFromReference); if (angleFromReference >= 0 && angleFromReference <= Math.PI / 2) { xAxisLocation += Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference); yAxisLocation -= Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference); @@ -497,8 +512,8 @@ public class GameView extends Pane { if(horizontalInversion) { xAxisLocation = canvasWidth - bufferSize - (xAxisLocation - bufferSize); } - System.out.println("yAxisLocation = " + yAxisLocation + " " + unscaledLat); - System.out.println("xAxisLocation = " + xAxisLocation + " " + unscaledLon); +// System.out.println("yAxisLocation = " + yAxisLocation + " " + unscaledLat); +// System.out.println("xAxisLocation = " + xAxisLocation + " " + unscaledLon); return new Point2D(xAxisLocation, yAxisLocation); } diff --git a/src/main/java/seng302/visualiser/fxObjects/AnnotationBox.java b/src/main/java/seng302/visualiser/fxObjects/AnnotationBox.java index 3c257e71..a5591cce 100644 --- a/src/main/java/seng302/visualiser/fxObjects/AnnotationBox.java +++ b/src/main/java/seng302/visualiser/fxObjects/AnnotationBox.java @@ -3,7 +3,6 @@ package seng302.visualiser.fxObjects; import java.util.HashMap; import java.util.Map; import javafx.beans.value.ObservableValue; -import javafx.scene.CacheHint; import javafx.scene.Group; import javafx.scene.paint.Color; import javafx.scene.paint.Paint; @@ -80,7 +79,7 @@ public class AnnotationBox extends Group{ private Map annotationsByName = new HashMap<>(); public AnnotationBox() { - this.setCache(true); +// this.setCache(true); background.setX(BACKGROUND_X); background.setY(BACKGROUND_Y); background.setWidth(backgroundWidth); @@ -90,8 +89,8 @@ public class AnnotationBox extends Group{ background.setFill(new Color(1, 1, 1, 0.75)); background.setStroke(theme); background.setStrokeWidth(2); - background.setCache(true); - background.setCacheHint(CacheHint.SPEED); +// background.setCache(true); +// background.setCacheHint(CacheHint.SPEED); this.getChildren().add(background); } @@ -99,11 +98,15 @@ public class AnnotationBox extends Group{ annotationsByName.put(annotationName, annotation); this.getChildren().add(annotation.getText()); visibleAnnotations++; + update(); } public void addAnnotation (String annotationName, String annotationText) { Text text = getTextObject(); annotationsByName.put(annotationName, new Annotation(text, annotationText)); + this.getChildren().add(text); + visibleAnnotations++; + update(); } public void addAnnotation (String annotationName, ObservableValue observable) { @@ -116,6 +119,7 @@ public class AnnotationBox extends Group{ annotationsByName.put(annotationName, new Annotation<>(newText, observable, formatter)); this.getChildren().add(newText); visibleAnnotations++; + update(); } public void setAnnotationVisibility (String annotationName, boolean visibility) { @@ -144,8 +148,8 @@ public class AnnotationBox extends Group{ } public void setLocation (double x, double y) { - this.setLayoutX(x); - this.setLayoutY(y); + this.setTranslateX(x); + this.setTranslateY(y); } public void setWidth (double width) { @@ -172,8 +176,8 @@ public class AnnotationBox extends Group{ Text text = new Text(); text.setFill(theme); text.setStrokeWidth(2); - text.setCacheHint(CacheHint.SPEED); - text.setCache(true); +// text.setCacheHint(CacheHint.SPEED); +// text.setCache(true); return text; } diff --git a/src/main/java/seng302/visualiser/fxObjects/BoatObject.java b/src/main/java/seng302/visualiser/fxObjects/BoatObject.java index 1cc64956..6452816e 100644 --- a/src/main/java/seng302/visualiser/fxObjects/BoatObject.java +++ b/src/main/java/seng302/visualiser/fxObjects/BoatObject.java @@ -80,8 +80,8 @@ public class BoatObject extends Group { boatPoly.setStroke(Color.BLACK); }); boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected)); - boatPoly.setCache(true); - boatPoly.setCacheHint(CacheHint.SPEED); +// boatPoly.setCache(true); +// boatPoly.setCacheHint(CacheHint.SPEED); // annotationBox = new AnnotationBox(); // annotationBox.setFill(colour); diff --git a/src/main/resources/server_config/race.xml b/src/main/resources/server_config/race.xml index 06f4f626..5798aeb7 100644 --- a/src/main/resources/server_config/race.xml +++ b/src/main/resources/server_config/race.xml @@ -28,30 +28,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -62,13 +38,13 @@ - - - - - - - + + + + + + +