Skip to content

Commit

Permalink
loadFromXml is throwing IOException now
Browse files Browse the repository at this point in the history
  • Loading branch information
ssenegas committed May 1, 2018
1 parent 9a6600b commit 84c06e8
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions core/src/com/senegas/kickoff/tactics/Tactic.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ public Tactic(Team team, String fileName) {
this.regions = new Array<Rectangle>();

createRegions();
loadFromXml(fileName);
try {
loadFromXml(fileName);
} catch (IOException e) {
e.printStackTrace();
}
}

/**
Expand All @@ -113,36 +117,33 @@ private void createRegions() {
}

/**
* Load player locations from tatic xml file
* Load player locations from tactic xml file
* @param fileName
* @throws IOException
*/
private void loadFromXml(String fileName) {
try {
Element root = new XmlReader().parse(Gdx.files.internal(fileName));

this.name = root.get("name");
Gdx.app.log("Tactic", "Loading " + name + "...");

Array<Element> players = root.getChildrenByName("player");
int playerIndex = 0;
for (Element player : players) {
//int shirt = player.getInt("shirt"); // shirt number
//Gdx.app.log("Tactic", "Location for player number " + shirt);

// regions
Array<Element> regions = player.getChildrenByName("region");
for (Element region : regions) {
String regionName = region.get("name"); // region name

this.locations[playerIndex][Location.valueOf(regionName).ordinal()] = new Vector2(region.getFloat("x"), region.getFloat("y"));

//Gdx.app.log("Tactic", locationId + " read");
}
playerIndex++;
}
} catch (IOException e) {
e.printStackTrace();
}
private void loadFromXml(String fileName) throws IOException {
Element root = new XmlReader().parse(Gdx.files.internal(fileName));

this.name = root.get("name");
Gdx.app.log("Tactic", "Loading " + name + "...");

Array<Element> players = root.getChildrenByName("player");
int playerIndex = 0;
for (Element player : players) {
//int shirt = player.getInt("shirt"); // shirt number
//Gdx.app.log("Tactic", "Location for player number " + shirt);

// regions
Array<Element> regions = player.getChildrenByName("region");
for (Element region : regions) {
String regionName = region.get("name"); // region name

this.locations[playerIndex][Location.valueOf(regionName).ordinal()] = new Vector2(region.getFloat("x"), region.getFloat("y"));

//Gdx.app.log("Tactic", locationId + " read");
}
playerIndex++;
}
}

/**
Expand All @@ -156,7 +157,7 @@ public String getName() {
public void update(Ball ball)
{
int regionIndex = getRegionIndex(ball, this.team);
Gdx.app.log("Tactic", "region index: " + regionIndex);
//Gdx.app.log("Tactic", "region index: " + regionIndex);
for (int playerIndex = 0; playerIndex < 10; playerIndex++) {
Vector2 playerLocation = PitchUtils.pitchToGlobal(
team.getDirection() == Direction.NORTH ? locations[playerIndex][regionIndex].x : (float)Pitch.PITCH_WIDTH_IN_PX - locations[playerIndex][regionIndex].x,
Expand Down

0 comments on commit 84c06e8

Please sign in to comment.