Added a race importer. Added imported races to visualizer. Made it so that the host sets the race. Refactored server to no longer be dependant on a specific race. Tested functionality of map manually. Some bugs found and listed below.

#implement #testmanual #story[1275]

Known bugs:
 * Can't move
 * Map is off center in lobby view.
 * 3D Map is off center
This commit is contained in:
Calum
2017-09-23 22:45:53 +12:00
parent 6ca75b2cac
commit 9b00ba654a
23 changed files with 442 additions and 421 deletions
@@ -0,0 +1,103 @@
package seng302.visualiser;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import javafx.util.Pair;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import seng302.model.stream.xml.parser.RaceXMLData;
import seng302.model.stream.xml.parser.RegattaXMLData;
import seng302.utilities.XMLParser;
/**
* Created by cir27 on 23/09/17.
*/
public class MapMaker {
private List<GameView> gameViews = new ArrayList<>();
private List<RaceXMLData> races = new ArrayList<>();
private List<RegattaXMLData> regattas = new ArrayList<>();
private List<String> filePaths = new ArrayList<>();
private static MapMaker instance;
private int index = 0;
public static MapMaker getInstance() {
if (instance == null) {
instance = new MapMaker();
}
return instance;
}
private MapMaker() {
File dir = new File(MapMaker.class.getResource("/maps/").getPath());
File[] directoryListing = dir.listFiles();
if (directoryListing != null) {
for (File child : directoryListing) {
Pair<String, String> regattaRace = XMLParser.parseRaceDef(
child.getAbsolutePath(), "", 1
);
filePaths.add(child.getAbsolutePath());
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
Document doc = null;
try {
db = dbf.newDocumentBuilder();
doc = db.parse(new InputSource(new StringReader(regattaRace.getKey())));
} catch (ParserConfigurationException | IOException | SAXException e) {
e.printStackTrace();
}
regattas.add(XMLParser.parseRegatta(doc));
try {
db = dbf.newDocumentBuilder();
doc = db.parse(new InputSource(new StringReader(regattaRace.getValue())));
} catch (ParserConfigurationException | IOException | SAXException e) {
e.printStackTrace();
}
RaceXMLData race = XMLParser.parseRace(doc);
GameView gameView = new GameView(
new ArrayList<>(race.getCompoundMarks().values()),
race.getMarkSequence(), race.getCourseLimit()
);
gameViews.add(gameView);
races.add(race);
}
}
}
public void next() {
index += 1;
if (index >= gameViews.size()) {
index = 0;
}
}
public void previous() {
index -= 1;
if (index < 0) {
index = gameViews.size() - 1;
}
}
public GameView getCurrentGameView() {
return gameViews.get(index);
}
public RaceXMLData getCurrentRace() {
return races.get(index);
}
public RegattaXMLData getCurrentRegatta() {
return regattas.get(index);
}
public String getCurrentRacePath() {
return filePaths.get(index);
}
}