List<Player> players = new ArrayList<>();
NodeList nl = getSecondLevelElelents("players", "player");
for (int i = 0; i < nl.getLength(); i++) {
Element el = (Element) nl.item(i);
PlayerSlot slot = new PlayerSlot(Integer.parseInt(el.getAttribute("slot")));
Player p = new Player(el.getAttribute("name"), i, slot);
p.setPoints(Integer.parseInt(el.getAttribute("points")));
if (el.hasAttribute("ai-class")) {
String aiClassName = el.getAttribute("ai-class");
slot.setAiClassName(aiClassName);
} else {
if (el.hasAttribute("local")) {
slot.setState(SlotState.OWN);
}
}
NodeList categories = el.getElementsByTagName("point-category");
for (int j = 0; j < categories.getLength(); j++) {
Element catEl = (Element) categories.item(j);
PointCategory cat = PointCategory.valueOf(catEl.getAttribute("name"));
p.setPointsInCategory(cat, Integer.parseInt(catEl.getAttribute("points")));
}
players.add(p);
}
return players;
}