mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Boat and race XML now generated dynamically
- Removed course from XML Generator as it was not needed - Boat and race XML added - Method names in Yacht class updated to follow JavaBean standard so they can be read by the template engine Tags: #story[984]
This commit is contained in:
@@ -320,7 +320,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 : StreamParser.getBoatsPos().values()) {
|
||||
if (participantIDs.contains(boat.getSourceID())) {
|
||||
if (participantIDs.contains(boat.getSourceId())) {
|
||||
data.add(boat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +201,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
|
||||
@@ -214,7 +214,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)
|
||||
@@ -244,7 +244,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 (StreamParser.isRaceStarted()) {
|
||||
for (Yacht boat : StreamParser.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 : StreamParser.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"));
|
||||
@@ -613,7 +613,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
|
||||
//We need to iterate over all race groups to get the matching boat group belonging to this boat if we
|
||||
//are to toggle its annotations, there is no other backwards knowledge of a yacht to its boatgroup.
|
||||
if (bg.getBoat().getHullID().equals(yacht.getHullID())) {
|
||||
if (bg.getBoat().getHullId().equals(yacht.getHullId())) {
|
||||
updateLaylines(bg);
|
||||
bg.setIsSelected(true);
|
||||
selectedBoat = yacht;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,15 @@ package seng302.gameServerWithThreading;
|
||||
|
||||
import seng302.gameServer.GameStages;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.models.Yacht;
|
||||
import seng302.models.mark.Mark;
|
||||
import seng302.models.mark.MarkType;
|
||||
import seng302.models.mark.SingleMark;
|
||||
import seng302.models.stream.PacketBufferDelegate;
|
||||
import seng302.models.stream.StreamParser;
|
||||
import seng302.models.stream.packets.StreamPacket;
|
||||
import seng302.models.xml.Boats;
|
||||
import seng302.models.xml.Race;
|
||||
import seng302.models.xml.Regatta;
|
||||
import seng302.models.xml.XMLGenerator;
|
||||
|
||||
@@ -53,8 +57,19 @@ public class MainServerThread extends Thread implements PacketBufferDelegate{
|
||||
|
||||
g.setRegatta(r);
|
||||
|
||||
Race b = new Race();
|
||||
b.addBoat(new Yacht("SomeType", 123, "hid", "NZL",
|
||||
"Emirates Team New Zealand", "NZL"));
|
||||
|
||||
g.setRace(b);
|
||||
|
||||
System.out.println("g.getBoatsAsXml() = " + g.getBoatsAsXml());
|
||||
g.getBoatsAsXml();
|
||||
|
||||
System.out.println("g.getRegattaAsXml() = " + g.getRegattaAsXml());
|
||||
|
||||
System.out.println("g.ragce() = " + g.getRaceAsXml());
|
||||
|
||||
//You should handle interrupts in some way, so that the thread won't keep on forever if you exit the app.
|
||||
while (!isInterrupted()) {
|
||||
try {
|
||||
|
||||
@@ -85,11 +85,11 @@ public class Yacht {
|
||||
return boatType;
|
||||
}
|
||||
|
||||
public Integer getSourceID() {
|
||||
public Integer getSourceId() {
|
||||
return sourceID;
|
||||
}
|
||||
|
||||
public String getHullID() {
|
||||
public String getHullId() {
|
||||
return hullID;
|
||||
}
|
||||
|
||||
@@ -207,6 +207,7 @@ public class Yacht {
|
||||
}
|
||||
|
||||
public Double getLat() {
|
||||
if (lat == null) return 0d;
|
||||
return lat;
|
||||
}
|
||||
|
||||
@@ -215,6 +216,8 @@ public class Yacht {
|
||||
}
|
||||
|
||||
public Double getLon() {
|
||||
|
||||
if (lon == null) return 0d;
|
||||
return lon;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,11 @@
|
||||
package seng302.models.xml;
|
||||
|
||||
import seng302.models.mark.Mark;
|
||||
import seng302.models.Yacht;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Boats {
|
||||
private List<Mark> marks;
|
||||
|
||||
public Boats(){
|
||||
marks = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addMark(Mark m){
|
||||
marks.add(m);
|
||||
}
|
||||
|
||||
public List<Mark> getMarks(){
|
||||
return this.marks;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
package seng302.models.xml;
|
||||
|
||||
public class Race {
|
||||
import seng302.models.Yacht;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Race {
|
||||
private List<Yacht> yachts;
|
||||
|
||||
public Race(){
|
||||
yachts = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addBoat(Yacht yacht){
|
||||
yachts.add(yacht);
|
||||
}
|
||||
|
||||
public List<Yacht> getBoats(){
|
||||
return Collections.unmodifiableList(yachts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,11 @@ import java.net.URISyntaxException;
|
||||
public class XMLGenerator {
|
||||
private static final String XML_TEMPLATE_DIR = "/server_config/xml_templates";
|
||||
private static final String REGATTA_TEMPLATE_NAME = "regatta.ftlh";
|
||||
private static final String BOATS_TEMPLATE_NAME = "boats.ftlh";
|
||||
private static final String RACE_TEMPLATE_NAME = "race.ftlh";
|
||||
private Configuration configuration;
|
||||
private Regatta regatta;
|
||||
private Race race;
|
||||
|
||||
/**
|
||||
* Set up a configuration instance for Apache Freemake
|
||||
@@ -38,6 +41,10 @@ public class XMLGenerator {
|
||||
public void setRegatta(Regatta regatta){
|
||||
this.regatta = regatta;
|
||||
}
|
||||
|
||||
public void setRace(Race race){
|
||||
this.race = race;
|
||||
}
|
||||
|
||||
private String parseToXmlString(String templateName, XMLMessageSubType type) throws IOException, TemplateException {
|
||||
Template template;
|
||||
@@ -52,11 +59,11 @@ public class XMLGenerator {
|
||||
break;
|
||||
|
||||
case BOAT:
|
||||
template.process(regatta, writer);
|
||||
template.process(race, writer);
|
||||
break;
|
||||
|
||||
case RACE:
|
||||
template.process(regatta, writer);
|
||||
template.process(race, writer);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -88,5 +95,35 @@ public class XMLGenerator {
|
||||
}
|
||||
|
||||
|
||||
public String getBoatsAsXml() {
|
||||
String result = null;
|
||||
|
||||
if (race == null) return null;
|
||||
|
||||
try {
|
||||
result = parseToXmlString(BOATS_TEMPLATE_NAME, XMLMessageSubType.BOAT);
|
||||
} catch (TemplateException e) {
|
||||
System.out.println("[FATAL] Error parsing boats");
|
||||
} catch (IOException e) {
|
||||
System.out.println("[FATAL] Error reading boats");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getRaceAsXml() {
|
||||
String result = null;
|
||||
|
||||
if (race == null) return null;
|
||||
|
||||
try {
|
||||
result = parseToXmlString(RACE_TEMPLATE_NAME, XMLMessageSubType.RACE);
|
||||
} catch (TemplateException e) {
|
||||
System.out.println("[FATAL] Error parsing race");
|
||||
} catch (IOException e) {
|
||||
System.out.println("[FATAL] Error reading race");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user