mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Added race start time to race XML
- Added race start time to race XML - Added documentation - Removed test code in MainServerThread Tags: #story[984]
This commit is contained in:
@@ -2,17 +2,9 @@ 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
@@ -48,28 +40,6 @@ public class MainServerThread extends Thread implements PacketBufferDelegate{
|
||||
|
||||
|
||||
public void run() {
|
||||
// @TODO remove before commit
|
||||
XMLGenerator g = new XMLGenerator();
|
||||
|
||||
Regatta r = new Regatta("Test regatta", 1.123, 4.456);
|
||||
r.setMagneticVariation(12.1);
|
||||
r.setUtcOffset(12);
|
||||
|
||||
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 {
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package seng302.models.xml;
|
||||
|
||||
import seng302.models.Yacht;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Boats {
|
||||
|
||||
}
|
||||
@@ -2,22 +2,52 @@ package seng302.models.xml;
|
||||
|
||||
import seng302.models.Yacht;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A Race object that can be parsed into XML
|
||||
*/
|
||||
public class Race {
|
||||
private List<Yacht> yachts;
|
||||
private LocalDateTime startTime;
|
||||
|
||||
public Race(){
|
||||
yachts = new ArrayList<>();
|
||||
startTime = LocalDateTime.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a boat to the race
|
||||
* @param yacht The boat to add
|
||||
*/
|
||||
public void addBoat(Yacht yacht){
|
||||
yachts.add(yacht);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of boats in the race
|
||||
* @return A List of boats
|
||||
*/
|
||||
public List<Yacht> getBoats(){
|
||||
return Collections.unmodifiableList(yachts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the time until the race starts
|
||||
* @param seconds The time in seconds until the race starts
|
||||
*/
|
||||
public void setRaceStartDelay(Integer seconds){
|
||||
startTime = startTime.plusMinutes(seconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time the race starts
|
||||
* @return The time the race starts
|
||||
*/
|
||||
public String getRaceStartTime(){
|
||||
return startTime.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package seng302.models.xml;
|
||||
|
||||
/**
|
||||
* A Race regatta that can be parsed into XML
|
||||
*/
|
||||
public class Regatta {
|
||||
private final Double DEFAULT_ALTITUDE = 0d;
|
||||
private final Integer DEFAULT_REGATTA_ID = 0;
|
||||
|
||||
@@ -8,6 +8,9 @@ import seng302.server.messages.XMLMessageSubType;
|
||||
import java.io.*;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* An XML generator to generate the Race, Boat, and Regatta XML dynamically
|
||||
*/
|
||||
public class XMLGenerator {
|
||||
private static final String XML_TEMPLATE_DIR = "/server_config/xml_templates";
|
||||
private static final String REGATTA_TEMPLATE_NAME = "regatta.ftlh";
|
||||
@@ -34,18 +37,36 @@ public class XMLGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the XML Generator
|
||||
*/
|
||||
public XMLGenerator(){
|
||||
setupConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the race regatta to send to players
|
||||
* Note: This must be set before a regatta message can be generated
|
||||
* @param regatta The race regatta
|
||||
*/
|
||||
public void setRegatta(Regatta regatta){
|
||||
this.regatta = regatta;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the race to send to players
|
||||
* Note: This must be set before a boat or race message can be generated
|
||||
* @param race The race
|
||||
*/
|
||||
public void setRace(Race race){
|
||||
this.race = race;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an XML template and generate the output as a string
|
||||
* @param templateName The templates file name
|
||||
* @param type The XML message sub type
|
||||
*/
|
||||
private String parseToXmlString(String templateName, XMLMessageSubType type) throws IOException, TemplateException {
|
||||
Template template;
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
@@ -78,6 +99,11 @@ public class XMLGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the race regatta as a string
|
||||
* Note: Regatta must be set before calling this
|
||||
* @return String containing the regatta XML, null if there was an error
|
||||
*/
|
||||
public String getRegattaAsXml(){
|
||||
String result = null;
|
||||
|
||||
@@ -94,7 +120,11 @@ public class XMLGenerator {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the boats XML as a string
|
||||
* Note: Race must be set before calling this
|
||||
* @return String containing the boats XML, null if there was an error
|
||||
*/
|
||||
public String getBoatsAsXml() {
|
||||
String result = null;
|
||||
|
||||
@@ -111,6 +141,11 @@ public class XMLGenerator {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the race XML as a string
|
||||
* Note: Race must be set before calling this
|
||||
* @return String containing the race XML, null if there was an error
|
||||
*/
|
||||
public String getRaceAsXml() {
|
||||
String result = null;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Race>
|
||||
<CreationTimeDate>2015-08-29T11:27:15+02:00</CreationTimeDate>
|
||||
<RaceStartTime Start="2015-08-29T13:10:00+02:00" Postpone="False" />
|
||||
<CreationTimeDate>${raceStartTime}</CreationTimeDate>
|
||||
<RaceStartTime Start="${raceStartTime}" Postpone="False" />
|
||||
<RaceID>15082901</RaceID>
|
||||
<RaceType>Fleet</RaceType>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user