Example usage for org.jdom2 Element setText

List of usage examples for org.jdom2 Element setText

Introduction

In this page you can find the example usage for org.jdom2 Element setText.

Prototype

public Element setText(final String text) 

Source Link

Document

Sets the content of the element to be the text given.

Usage

From source file:neon.common.resources.loaders.TerrainLoader.java

License:Open Source License

@Override
public void save(Resource resource) throws IOException {
    RTerrain terrain = RTerrain.class.cast(resource);

    Element root = new Element("terrain");
    root.setAttribute("id", terrain.id);
    root.setAttribute("name", terrain.name);

    Element graphics = new Element("graphics");
    graphics.setAttribute("text", Character.toString(terrain.glyph));
    graphics.setAttribute("color", GraphicsUtils.getColorString(terrain.color));
    root.addContent(graphics);//  ww w.j  a v  a2  s .com

    for (Modifier modifier : terrain.getModifiers()) {
        Element mod = new Element("modifier");
        mod.setText(modifier.toString());
        root.addContent(mod);
    }

    files.saveFile(new Document(root), translator, namespace, resource.id + ".xml");
}

From source file:neon.core.GameSaver.java

License:Open Source License

private Element savePlayer(Player player) {
    Element PC = new Element("player");

    PC.setAttribute("name", player.getName());
    PC.setAttribute("race", player.species.id);

    PC.setAttribute("gender", player.getGender().toString().toLowerCase());

    PC.setAttribute("spec", player.getSpecialisation().toString());

    Atlas atlas = Engine.getGame().getAtlas();
    PC.setAttribute("map", Integer.toString(atlas.getCurrentMap().getUID()));
    int l = atlas.getCurrentZoneIndex();
    PC.setAttribute("l", Integer.toString(l));
    Rectangle bounds = player.getShapeComponent();
    PC.setAttribute("x", String.valueOf(bounds.x));
    PC.setAttribute("y", String.valueOf(bounds.y));
    PC.setAttribute("sign", player.getSign());

    Element skills = new Element("skills");
    for (Skill s : Skill.values()) {
        skills.setAttribute(s.toString(), String.valueOf(player.getSkill(s)));
    }/*  w  ww.j a v a  2s  . c o  m*/
    PC.addContent(skills);

    Element stats = new Element("stats");
    stats.setAttribute("str", String.valueOf(player.getStatsComponent().getStr()));
    stats.setAttribute("con", String.valueOf(player.getStatsComponent().getCon()));
    stats.setAttribute("dex", String.valueOf(player.getStatsComponent().getDex()));
    stats.setAttribute("int", String.valueOf(player.getStatsComponent().getInt()));
    stats.setAttribute("wis", String.valueOf(player.getStatsComponent().getWis()));
    stats.setAttribute("cha", String.valueOf(player.getStatsComponent().getCha()));
    PC.addContent(stats);

    Element money = new Element("money");
    money.setText(String.valueOf(player.getInventoryComponent().getMoney()));
    PC.addContent(money);

    for (long uid : player.getInventoryComponent()) {
        Element item = new Element("item");
        item.setAttribute("uid", Long.toString(uid));
        PC.addContent(item);
    }

    for (RSpell s : player.getMagicComponent().getSpells()) {
        Element spell = new Element("spell");
        spell.setText(s.id);
        PC.addContent(spell);
    }

    for (RSpell p : player.getMagicComponent().getPowers()) {
        Element spell = new Element("spell");
        spell.setText(p.id);
        PC.addContent(spell);
    }

    for (Feat f : player.getCharacteristicsComponent().getFeats()) {
        Element feat = new Element("feat");
        feat.setText(f.toString());
        PC.addContent(feat);
    }

    return PC;
}

From source file:neon.core.GameSaver.java

License:Open Source License

private Element saveJournal(Player player) {
    Element journal = new Element("journal");

    for (String q : player.getJournal().getQuests().keySet()) {
        Element quest = new Element("quest");
        quest.setAttribute("id", q);
        quest.setAttribute("stage", String.valueOf(player.getJournal().getQuests().get(q)));
        quest.setText(player.getJournal().getSubjects().get(q));
        journal.addContent(quest);//from   w w w.  jav  a 2s.co m
    }
    return journal;
}

From source file:neon.editor.editors.QuestEditor.java

License:Open Source License

protected void save() {
    // algemeen/*from w ww.ja v a2  s.  c o m*/
    quest.initial = initialBox.isSelected();
    quest.repeat = randomBox.isSelected();
    if (randomBox.isSelected()) {
        quest.frequency = Integer.parseInt(freqField.getText());
    }
    quest.name = nameField.getText();

    // condities
    quest.getConditions().clear();
    for (Vector<String> data : (Vector<Vector>) conditionModel.getDataVector()) {
        quest.getConditions().add(data.get(0));
    }

    Element vars = new Element("objects");
    for (Vector<?> data : (Vector<Vector>) varModel.getDataVector()) {
        Element var = new Element(data.get(1).toString());
        var.setText(data.get(0).toString());
        if (data.get(2) != null) {
            var.setAttribute("id", data.get(2).toString());
        }
        if (data.get(3) != null) {
            var.setAttribute("type", data.get(3).toString());
        }
        vars.addContent(var);
    }
    quest.variables = vars;

    //      quest.getTopics().clear();
    for (Vector<?> data : (Vector<Vector>) dialogModel.getDataVector()) {
        String id = data.get(0).toString();
        String condition = (data.get(1) != null ? data.get(1).toString() : null);
        String answer = (data.get(2) != null ? data.get(2).toString() : null);
        String action = (data.get(3) != null ? data.get(3).toString() : null);
        //         quest.getTopics().add(new Topic(id, condition, answer, action));
    }
}

From source file:neon.resources.quest.Topic.java

License:Open Source License

/**
 * @return   a JDOM {@code Element} describing this topic
 *///w  ww. j  a  v a  2  s.  c o m
public Element toElement() {
    Element topic = new Element("topic");
    topic.setAttribute("id", id);
    if (condition != null) {
        Element pre = new Element("pre");
        pre.setText(condition);
        topic.addContent(pre);
    }
    if (answer != null) {
        Element ae = new Element("answer");
        ae.setText(answer);
        topic.addContent(ae);
    }
    if (action != null) {
        Element ae = new Element("action");
        ae.setText(action);
        topic.addContent(ae);
    }
    return topic;
}

From source file:neon.resources.RCreature.java

License:Open Source License

@Override
public Element toElement() {
    Element creature = new Element(type.toString());

    creature.setAttribute("id", id);
    creature.setAttribute("size", size.toString());
    creature.setAttribute("char", text);
    creature.setAttribute("color", color);
    creature.setAttribute("hit", hit);
    creature.setAttribute("speed", Integer.toString(speed));

    if (mana > 0) {
        creature.setAttribute("mana", Integer.toString(mana));
    }/*from w  w w. j av a  2 s  .c o  m*/
    if (name != null && !name.isEmpty()) {
        creature.setAttribute("name", name);
    }
    if (habitat != Habitat.LAND) {
        creature.setAttribute("habitat", habitat.name());
    }

    Element stats = new Element("stats");
    stats.setAttribute("str", Integer.toString((int) str));
    stats.setAttribute("con", Integer.toString((int) con));
    stats.setAttribute("dex", Integer.toString((int) dex));
    stats.setAttribute("int", Integer.toString((int) iq));
    stats.setAttribute("wis", Integer.toString((int) wis));
    stats.setAttribute("cha", Integer.toString((int) cha));
    creature.addContent(stats);

    if (av != null && !av.isEmpty()) {
        Element avElement = new Element("av");
        avElement.setText(av);
        creature.addContent(avElement);
    }
    if (dv > 0) {
        Element dvElement = new Element("dv");
        dvElement.setText(Integer.toString(dv));
        creature.addContent(dvElement);
    }

    if (aiAggr > 0 || aiConf > 0 || aiRange > 0 || aiType != null) {
        Element ai = new Element("ai");
        if (aiType != null) {
            ai.setText(aiType.toString());
        }
        if (aiAggr > 0) {
            ai.setAttribute("a", Integer.toString(aiAggr));
        }
        if (aiConf > 0) {
            ai.setAttribute("c", Integer.toString(aiConf));
        }
        if (aiRange > 0) {
            ai.setAttribute("r", Integer.toString(aiRange));
        }
        creature.addContent(ai);
    }

    return creature;
}

From source file:neon.resources.RPerson.java

License:Open Source License

public Element toElement() {
    Element npc = new Element("npc");
    npc.setAttribute("race", species);
    npc.setAttribute("id", id);

    for (Element service : services) {
        service.detach(); // anders fout bij 2de keer saven
        npc.addContent(service);/*from  w  w  w  .  j a  v a 2 s.  co m*/
    }

    if (!factions.isEmpty()) {
        Element factionList = new Element("factions");
        for (String f : factions.keySet()) {
            Element faction = new Element("faction");
            faction.setAttribute("id", f);
            faction.setAttribute("rank", Integer.toString(factions.get(f)));
            factionList.addContent(faction);
        }
        npc.addContent(factionList);
    }

    if (!items.isEmpty()) {
        Element itemList = new Element("items");
        for (String ri : items) {
            Element item = new Element("item");
            item.setAttribute("id", ri);
            itemList.addContent(item);
        }
        npc.addContent(itemList);
    }

    if (!spells.isEmpty()) {
        Element spellList = new Element("spells");
        for (String rs : spells) {
            Element spell = new Element("spell");
            spell.setAttribute("id", rs);
            spellList.addContent(spell);
        }
        npc.addContent(spellList);
    }

    if (aiAggr > -1 || aiConf > -1 || aiRange > -1 || aiType != null) {
        Element ai = new Element("ai");
        if (aiType != null) {
            ai.setText(aiType.toString());
        }
        if (aiAggr > -1) {
            ai.setAttribute("a", Integer.toString(aiAggr));
        }
        if (aiConf > -1) {
            ai.setAttribute("c", Integer.toString(aiConf));
        }
        if (aiRange > -1) {
            ai.setAttribute("r", Integer.toString(aiRange));
        }
        npc.addContent(ai);
    }

    return npc;
}

From source file:neon.resources.RRegionTheme.java

License:Open Source License

public Element toElement() {
    Element theme = new Element("region");
    theme.setAttribute("id", id);

    if (floor != null) {
        theme.setAttribute("floor", floor);
    }/*  ww  w.  j  a v  a 2  s  . co  m*/

    for (Map.Entry<String, Integer> entry : creatures.entrySet()) {
        Element creature = new Element("creature");
        creature.setText(entry.getKey());
        creature.setAttribute("n", Integer.toString(entry.getValue()));
        theme.addContent(creature);
    }

    for (Map.Entry<String, Integer> plant : vegetation.entrySet()) {
        Element veg = new Element("plant");
        veg.setText(plant.getKey());
        veg.setAttribute("a", Integer.toString(plant.getValue()));
        theme.addContent(veg);
    }

    String random = type.toString() + ";";
    switch (type) {
    case town:
    case town_big:
    case town_small:
        random += (wall + ";" + door.toString());
        break;
    default:
        break;
    }
    theme.setAttribute("random", random);
    return theme;
}

From source file:neon.resources.RSpell.java

License:Open Source License

public Element toElement() {
    Element spell = new Element(type.toString());
    spell.setAttribute("id", id);
    spell.setAttribute("effect", effect.name());

    if (script != null && !script.isEmpty()) {
        spell.setText(script);
    }//from w  w  w  .j a  va  2  s.c o m
    if (size > 0) {
        spell.setAttribute("size", Integer.toString(size));
    }
    if (range > 0) {
        spell.setAttribute("range", Integer.toString(range));
    }
    if (duration > 0) {
        spell.setAttribute("duration", Integer.toString(duration));
    }
    if (radius > 0) {
        spell.setAttribute("area", Integer.toString(radius));
    }

    return spell;
}

From source file:neon.resources.RTerrain.java

License:Open Source License

public Element toElement() {
    Element terrain = new Element("type");
    terrain.setAttribute("id", id);
    terrain.setAttribute("char", text);
    terrain.setAttribute("color", color);
    if (modifier != Modifier.NONE) {
        terrain.setAttribute("mod", modifier.toString());
    }//from  w  w w  .  j  ava 2s.  c  o  m
    if (description != null && !description.isEmpty()) {
        terrain.setText(description);
    }
    if (type != Subtype.NONE) {
        terrain.setAttribute("sub", type.toString());
    }
    return terrain;
}