List of usage examples for org.jdom2 Element getName
public String getName()
From source file:neon.editor.resources.IObject.java
License:Open Source License
public IObject(Element properties) { super(properties); width = 1;/*from w ww . j a v a2s . c o m*/ height = 1; uid = Integer.parseInt(properties.getAttributeValue("uid")); String id = properties.getAttributeValue("id"); resource = (RData) Editor.resources.getResource(id); if (properties.getName().equals("creature")) { z = Byte.MAX_VALUE - 1; } else { // kan "item", "door" of "container" zijn z = Byte.MAX_VALUE - 2; } }
From source file:neon.editor.resources.RMap.java
License:Open Source License
public RMap(String id, Element properties, String... path) { super(id, path); uid = Short.parseShort(properties.getChild("header").getAttributeValue("uid")); name = properties.getChild("header").getChildText("name"); type = properties.getName().equals("dungeon"); if (type == DUNGEON) { if (properties.getChild("header").getAttribute("theme") != null) { theme = (RDungeonTheme) Editor.resources .getResource(properties.getChild("header").getAttributeValue("theme"), "theme"); } else {//from ww w. j a v a2 s . c o m for (Element zone : properties.getChildren("level")) { zones.put(Integer.parseInt(zone.getAttributeValue("l")), new RZone(zone, this, path)); } } } else { zones.put(0, new RZone(properties, this, path)); } }
From source file:neon.editor.resources.RMap.java
License:Open Source License
public Element toElement() { System.out.println("save map: " + name); Element root = new Element(isDungeon() ? "dungeon" : "world"); Element header = new Element("header"); header.setAttribute("uid", Short.toString(uid)); header.addContent(new Element("name").setText(name)); root.addContent(header);//w w w.j a v a 2s . c o m if (type == DUNGEON) { for (Integer level : zones.keySet()) { root.addContent(zones.get(level).toElement().setAttribute("l", level.toString())); } } else { RZone zone = zones.get(0); Element creatures = new Element("creatures"); Element items = new Element("items"); Element regions = new Element("regions"); for (Renderable r : zone.getScene().getElements()) { Instance i = (Instance) r; Element element = i.toElement(); element.detach(); if (element.getName().equals("region")) { regions.addContent(element); } else if (element.getName().equals("creature")) { creatures.addContent(element); } else if (element.getName().equals("item") || element.getName().equals("door") || element.getName().equals("container")) { items.addContent(element); } } root.addContent(creatures); root.addContent(items); root.addContent(regions); } return root; }
From source file:neon.editor.resources.RMap.java
License:Open Source License
public void load() { if (uids == null) { // vermijden dat map twee keer geladen wordt uids = new ArrayList<Integer>(); try {/*from w ww . ja v a 2 s . c om*/ String file = Editor.getStore().getMod(path[0]).getPath()[0]; Element root = Editor.files.getFile(new XMLTranslator(), file, "maps", id + ".xml") .getRootElement(); if (root.getName().equals("world")) { uids.addAll(zones.get(0).load(root)); } else if (root.getName().equals("dungeon")) { for (Element level : root.getChildren("level")) { uids.addAll(zones.get(Integer.parseInt(level.getAttributeValue("l"))).load(level)); } } else { System.out.println("fout in EditableMap.load(" + id + ")"); } } catch (Exception e) { e.printStackTrace(); } } }
From source file:neon.editor.resources.RZone.java
License:Open Source License
public ArrayList<Integer> load(Element zone) { ArrayList<Integer> uids = new ArrayList<Integer>(); scene = new Scene(); try { // creatures for (Element creature : zone.getChild("creatures").getChildren()) { Instance r = getInstance(creature, this); scene.addElement(r, r.getBounds(), r.z); uids.add(Integer.parseInt(creature.getAttributeValue("uid"))); }//from w ww. j a v a 2s.c o m } catch (NullPointerException e) { } // als map geen creatures bevat try { // regions for (Element region : zone.getChild("regions").getChildren()) { Instance r = new IRegion(region); scene.addElement(r, r.getBounds(), r.z); } } catch (NullPointerException e) { } // als map geen regions bevat try { // items for (Element item : zone.getChild("items").getChildren()) { Instance r = getInstance(item, this); scene.addElement(r, r.getBounds(), r.z); uids.add(Integer.parseInt(item.getAttributeValue("uid"))); if (item.getName().equals("container")) { // container items aan uids toevoegen for (Element e : item.getChildren()) { uids.add(Integer.parseInt(e.getAttributeValue("uid"))); } } } } catch (NullPointerException e) { } // als map geen items bevat return uids; }
From source file:neon.editor.resources.RZone.java
License:Open Source License
public static Instance getInstance(Element e, RZone zone) { if (Editor.resources.getResource(e.getAttributeValue("id")) instanceof RPerson) { return new IPerson(e); } else if (e.getName().equals("door")) { return new IDoor(e, zone); } else if (e.getName().equals("container")) { return new IContainer(e); } else {//w ww.j a va2 s.c o m return new IObject(e); } }
From source file:neon.editor.resources.RZone.java
License:Open Source License
public Element toElement() { Element level = new Element("level"); level.setAttribute("name", name); Element creatures = new Element("creatures"); Element items = new Element("items"); Element regions = new Element("regions"); for (Renderable r : scene.getElements()) { Instance i = (Instance) r;// w ww . ja va2s. c om Element element = i.toElement(); element.detach(); if (element.getName().equals("region")) { regions.addContent(element); } else if (element.getName().equals("creature")) { creatures.addContent(element); } else if (element.getName().equals("item") || element.getName().equals("door") || element.getName().equals("container")) { items.addContent(element); } } level.addContent(creatures); level.addContent(items); level.addContent(regions); return level; }
From source file:neon.maps.MapLoader.java
License:Open Source License
/** * Returns a map described in an xml file with the given name. * //from w ww. ja va 2 s .c o m * @param path the pathname of a map file * @param uid the unique identifier of this map * @return the <code>Map</code> described by the map file */ public static Map loadMap(String[] path, int uid, FileSystem files) { Document doc = files.getFile(new XMLTranslator(), path); Element root = doc.getRootElement(); // System.out.println("loadmap(" + path + ")"); if (root.getName().equals("world")) { return loadWorld(root, uid); } else { return loadDungeon(root, uid); } }
From source file:neon.maps.MapLoader.java
License:Open Source License
private static void loadZone(Element root, Map map, int l, int uid) { for (Element region : root.getChild("regions").getChildren()) { // regions laden map.getZone(l).addRegion(loadRegion(region)); }/*from w ww . j a v a2 s .c o m*/ if (root.getChild("creatures") != null) { // creatures laden for (Element c : root.getChild("creatures").getChildren()) { String species = c.getAttributeValue("id"); int x = Integer.parseInt(c.getAttributeValue("x")); int y = Integer.parseInt(c.getAttributeValue("y")); long creatureUID = UIDStore.getObjectUID(uid, Integer.parseInt(c.getAttributeValue("uid"))); Creature creature = EntityFactory.getCreature(species, x, y, creatureUID); Engine.getGame().getStore().addEntity(creature); map.getZone(l).addCreature(creature); } } if (root.getChild("items") != null) { // items laden for (Element i : root.getChild("items").getChildren()) { long itemUID = UIDStore.getObjectUID(uid, Integer.parseInt(i.getAttributeValue("uid"))); String id = i.getAttributeValue("id"); int x = Integer.parseInt(i.getAttributeValue("x")); int y = Integer.parseInt(i.getAttributeValue("y")); Item item = null; if (i.getName().equals("container")) { item = loadContainer(i, id, x, y, itemUID, uid); // omdat containers lastig zijn } else if (i.getName().equals("door")) { item = loadDoor(i, id, x, y, itemUID, uid); // omdat deuren ook lastig zijn } else { item = EntityFactory.getItem(id, x, y, itemUID); } map.getZone(l).addItem(item); Engine.getGame().getStore().addEntity(item); } } }
From source file:neon.narrative.Resolver.java
License:Open Source License
/** * Resolves variables in a quest resource. Even elements are the original * strings, odd elements are the resolved strings. * /*from w w w . j a v a 2 s.c om*/ * @param vars * @return */ protected List<String> resolveVariables(Element vars) { ArrayList<String> strings = new ArrayList<String>(); if (vars == null) { return strings; } for (Element var : vars.getChildren()) { if (var.getName().equals("item")) { addItem(var, strings); } else if (var.getName().equals("npc")) { addPerson(var, strings); } else if (var.getName().equals("creature")) { addCreature(var, strings); } } return strings; }