List of usage examples for org.jdom2 Element getChildText
public String getChildText(final String cname)
From source file:neon.client.resource.ConfigurationLoader.java
License:Open Source License
@Override public Resource load(String id) throws IOException { Element root = files.loadFile(translator, namespace, id + ".xml").getRootElement(); String title = root.getAttributeValue("title"); String subtitle = root.getAttributeValue("subtitle"); String intro = root.getChildText("intro"); HashSet<String> playable = new HashSet<>(); for (Element species : root.getChild("playable").getChildren()) { playable.add(species.getAttributeValue("id")); }//w ww . j a va 2 s . c o m return new CClient(title, subtitle, playable, intro); }
From source file:neon.common.resources.loaders.ModuleLoader.java
License:Open Source License
@Override public RModule load(String id) throws IOException { Element root = files.loadFile(translator, id + ".xml").getRootElement(); String title = root.getChildText("title"); String subtitle = root.getChildText("subtitle"); String map = root.getChild("start").getAttributeValue("map"); String intro = root.getChildren("intro").isEmpty() ? "" : root.getChildText("intro"); Element start = root.getChild("start"); int x = Integer.parseInt(start.getAttributeValue("x")); int y = Integer.parseInt(start.getAttributeValue("y")); int money = Integer.parseInt(start.getAttributeValue("money")); RModule.Builder builder = new RModule.Builder(id).setTitle(title).setSubtitle(subtitle).setIntro(intro); builder.setStartMap(map).setStartMoney(money).setStartPosition(x, y); for (Element species : root.getChild("playable").getChildren()) { builder.addPlayableSpecies(species.getText()); }/* w w w . j av a 2 s . co m*/ for (Element parent : root.getChild("parents").getChildren()) { builder.addParentModule(parent.getText()); } for (Element item : start.getChildren("item")) { builder.addStartItem(item.getAttributeValue("id")); } for (Element item : start.getChildren("spell")) { builder.addStartSpell(item.getAttributeValue("id")); } return builder.build(); }
From source file:neon.core.GameLoader.java
License:Open Source License
private void loadPlayer(Element playerData, Atlas atlas) { // player aanmaken RCreature species = (RCreature) Engine.getResources().getResource(playerData.getAttributeValue("race")); Player player = new Player(new RCreature(species.toElement()), playerData.getAttributeValue("name"), Gender.valueOf(playerData.getAttributeValue("gender").toUpperCase()), Player.Specialisation.valueOf(playerData.getAttributeValue("spec")), playerData.getAttributeValue("prof")); engine.startGame(// www .ja v a 2 s . c o m new Game(player, engine.getFileSystem(), engine.getScriptEngine(), engine.getPhysicsEngine())); Rectangle bounds = player.getShapeComponent(); bounds.setLocation(Integer.parseInt(playerData.getAttributeValue("x")), Integer.parseInt(playerData.getAttributeValue("y"))); player.setSign(playerData.getAttributeValue("sign")); player.species.text = "@"; // start map int mapUID = Integer.parseInt(playerData.getAttributeValue("map")); atlas.setMap(atlas.getMap(mapUID)); int level = Integer.parseInt(playerData.getAttributeValue("l")); atlas.setCurrentZone(level); // stats Stats stats = player.getStatsComponent(); stats.addStr(Integer.parseInt(playerData.getChild("stats").getAttributeValue("str")) - stats.getStr()); stats.addCon(Integer.parseInt(playerData.getChild("stats").getAttributeValue("con")) - stats.getCon()); stats.addDex(Integer.parseInt(playerData.getChild("stats").getAttributeValue("dex")) - stats.getDex()); stats.addInt(Integer.parseInt(playerData.getChild("stats").getAttributeValue("int")) - stats.getInt()); stats.addWis(Integer.parseInt(playerData.getChild("stats").getAttributeValue("wis")) - stats.getWis()); stats.addCha(Integer.parseInt(playerData.getChild("stats").getAttributeValue("cha")) - stats.getCha()); // skills for (Attribute skill : (List<Attribute>) playerData.getChild("skills").getAttributes()) { player.setSkill(Skill.valueOf(skill.getName()), Integer.parseInt(skill.getValue())); } // items for (Element e : playerData.getChildren("item")) { long uid = Long.parseLong(e.getAttributeValue("uid")); player.getInventoryComponent().addItem(uid); } // spells for (Element e : playerData.getChildren("spell")) { player.getMagicComponent().addSpell(SpellFactory.getSpell(e.getText())); } // feats for (Element e : playerData.getChildren("feat")) { player.getCharacteristicsComponent().addFeat(Feat.valueOf(e.getText())); } // geld player.getInventoryComponent().addMoney(Integer.parseInt(playerData.getChildText("money"))); }
From source file:neon.resources.CServer.java
License:Open Source License
public CServer(String... path) { super("ini", path); // file inladen Document doc = new Document(); try (FileInputStream in = new FileInputStream(path[0])) { doc = new SAXBuilder().build(in); } catch (Exception e) { e.printStackTrace();//from ww w. j ava 2 s . c o m } Element root = doc.getRootElement(); // mods Element files = root.getChild("files"); for (Element file : files.getChildren("file")) { mods.add(file.getText()); } // logging log = root.getChildText("log").toUpperCase(); // ai range ai = Integer.parseInt(root.getChildText("ai")); }
From source file:neon.resources.quest.Stage.java
License:Open Source License
/** * Initializes a quest stage./*from w ww .j a v a2 s.co m*/ * * @param questID the resouce ID of the quest this stage belongs to */ public Stage(String questID, Element properties) { this.questID = questID; index = Integer.parseInt(properties.getAttributeValue("index")); if (properties.getChild("entry") != null) { entry = properties.getChildText("entry"); } if (properties.getChild("action") != null) { action = properties.getChildText("action"); } }
From source file:neon.resources.quest.Topic.java
License:Open Source License
/** * Initializes a topic from a JDOM {@code Element}. * /*from w ww. j a va2s.c o m*/ * @param topic */ public Topic(String questID, String conversationID, Element topic) { this.questID = questID; this.conversationID = conversationID; // id en phrase moeten altijd bestaan id = topic.getAttributeValue("id"); phrase = topic.getChildText("phrase"); if (topic.getChild("pre") != null) { condition = topic.getChildText("pre"); } else { condition = "true"; } if (topic.getChild("answer") != null) { answer = topic.getChildText("answer"); } if (topic.getChild("action") != null) { action = topic.getChildText("action"); } }
From source file:neon.resources.RMod.java
License:Open Source License
public RMod(Element main, Element cc, String... path) { super(main.getAttributeValue("id"), path); // main.xml/* w ww . j av a 2 s .c o m*/ info.put("id", main.getAttributeValue("id")); info.put("master", main.getChildText("master")); if (main.getChildText("title") != null) { info.put("title", main.getChildText("title")); } if (main.getChild("currency") != null) { info.put("big", main.getChild("currency").getAttributeValue("big")); info.put("small", main.getChild("currency").getAttributeValue("small")); } // cc.xml if (cc != null) { // hier strings, want resources zijn nog niet geladen for (Element race : cc.getChildren("race")) { ccRaces.add(race.getText()); } for (Element item : cc.getChildren("item")) { ccItems.add(item.getText()); } for (Element spell : cc.getChildren("spell")) { ccSpells.add(spell.getText()); } if (cc.getChild("map") != null) { info.put("map", cc.getChild("map").getAttributeValue("path")); info.put("x", cc.getChild("map").getAttributeValue("x")); info.put("y", cc.getChild("map").getAttributeValue("y")); info.put("z", cc.getChild("map").getAttributeValue("z")); } } }
From source file:neon.server.resource.ConfigurationLoader.java
License:Open Source License
public CServer loadServer(Element root) { // LinkedHashSet to preserve module load order and to prevent doubles LinkedHashSet<String> modules = new LinkedHashSet<String>(); for (Element module : root.getChild("modules").getChildren()) { modules.add(module.getText());//from w w w.j a v a 2 s. c o m } // set the correct module uid's in the entity manager if (root.getName().equals("server")) { // in case this was a saved configuration file for (Element module : root.getChild("modules").getChildren()) { entities.setModuleUID(module.getText(), Short.parseShort(module.getAttributeValue("uid"))); } } else { // in case configuration was loaded from neon.ini short index = 1; for (String module : modules) { entities.setModuleUID(module, index++); } } String level = root.getChildText("log").toUpperCase(); return new CServer(modules, level); }
From source file:neon.server.resource.ConfigurationLoader.java
License:Open Source License
private CClient loadClient(Element root) { String title = root.getAttributeValue("title"); String subtitle = root.getAttributeValue("subtitle"); String intro = root.getChildText("intro"); HashSet<String> playable = new HashSet<>(); for (Element species : root.getChild("playable").getChildren()) { playable.add(species.getAttributeValue("id")); }/*w w w . ja va 2 s .c om*/ return new CClient(title, subtitle, playable, intro); }
From source file:neon.systems.conversation.DialogLoader.java
License:Open Source License
private PlayerNode loadPlayerNode(Element node, RDialog dialog) { NodeType type = NodeType.NONE;//ww w .j a v a 2 s . c o m if (node.getAttribute("type") != null) { type = NodeType.valueOf(node.getAttributeValue("type").toUpperCase()); } ArrayList<String> nodes = new ArrayList<>(); if (type == NodeType.LINK) { nodes.add(node.getAttributeValue("link")); } else { for (Element child : node.getChildren("cnode")) { nodes.add(loadCreatureNode(child, dialog).id); } } PlayerNode pnode = new PlayerNode(node.getAttributeValue("id"), node.getChildText("text"), nodes, type); dialog.addNode(pnode); return pnode; }