Java 类com.badlogic.gdx.utils.XmlWriter 实例源码

项目:fabulae    文件:Quest.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    super.writeToXML(writer);

    variables.writeToXML(writer);

    writer.element(XML_STORY);
    int i = 0;
    for (QuestState state : story) {
        writer.element(XML_STATE);
        writer.attribute(XMLUtil.XML_ATTRIBUTE_ID, state.getId());
        writer.element(XML_TIME);
        storyTimes.get(i).writeToXML(writer);
        writer.pop();
        writer.pop();
        ++i;
    }
    writer.pop();
}
项目:fabulae    文件:GameCharacter.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    super.writeToXML(writer);
    stats.writeToXML(writer);
    survival.writeToXML(writer);

    XMLUtil.writePerks(this, writer);
    XMLUtil.writeSpells(this, writer);
    inventory.writeToXML(writer);

    if (effects.size > 0) {
        writer.element(Effect.XML_PERSISTENT);
        for (PersistentEffect effect : effects.values()) {
            effect.writeToXML(writer);
        }
        writer.pop();
    }

    if (damageQueue.size > 0) {
        writer.element(XML_DAMAGE_QUEUE);
        for (DamageInfo dinfo: damageQueue) {
            dinfo.writeToXML(writer);
        }
        writer.pop();
    }
}
项目:fabulae    文件:GameObjectViewer.java   
public void setGo(GameObject go) {
    if (go == null) {
        goName.setText("");
        goId.setText("");
        goInternalId.setText("");
        goDetails.setText("");
        return;
    }
    StringWriter stringWriter = new StringWriter();
    XmlWriter writer = new XmlWriter(stringWriter);
    String result;
    try {
        go.writeToXML(writer);
        result = stringWriter.toString();
        result = result.replace("\t", "    ");
        stringWriter.close();
    } catch (IOException e) {
        result = "Error: "+e.getMessage();
    }
    goName.setText(go.getName());
    goId.setText(" ("+go.getId()+")");
    goInternalId.setText(" ["+go.getInternalId()+"]");
    goDetails.setText(result);
    pack();
}
项目:fabulae    文件:Theft.java   
@Override
protected void writeTargetToXml(XmlWriter writer) throws IOException {
    InventoryItem item = getCrimeTarget();
    writer.attribute(XMLUtil.XML_ATTRIBUTE_ID, item.getId())
            .attribute(Inventory.XML_ATTRIBUTE_STACK_SIZE,
                    item.getStackSize());
    ItemOwner itemOwner = item.getOwner();
    String ownerId =itemOwner.getOwnerCharacterId();
    if (ownerId != null) {
        writer.attribute(Inventory.XML_ATTRIBUTE_OWNER_CHARACTER, ownerId);
    }
    Faction faction = itemOwner.getOwnerFaction();
    if (faction != null) {
        writer.attribute(Inventory.XML_ATTRIBUTE_OWNER_FACTION, faction);
    }
}
项目:fabulae    文件:UsableGameObject.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    super.writeToXML(writer);
    lock.writeToXML(writer);
    if (trap != null) {
        trap.writeToXML(writer);
    }
    if (ground != null) {
        writer
            .element(XML_GROUND)
                .attribute(XMLUtil.XML_ATTRIBUTE_X, ground.getX())
                .attribute(XMLUtil.XML_ATTRIBUTE_Y, ground.getY())
            .pop();
    }
    inventory.writeToXML(writer);
    writer.element(XML_STATE_MACHINE);
    stateMachine.writeToXML(writer);
    writer.pop();
}
项目:fabulae    文件:GameSaver.java   
private static void writeGlobalToXML(GameState gameState, XmlWriter writer) throws IOException {
    writer.element(XML_GLOBAL);
    writer.element(XMLUtil.XML_PROPERTIES);
    GameMap currentMap = gameState.getCurrentMap();

    if (currentMap != null) {
        writer.attribute(XML_ATTRIBUTE_CURRENT_MAP, currentMap.getId());
        Vector2 tempVector = MathUtil.getVector2().set(currentMap.getCamera().position.x, currentMap.getCamera().position.y);
        currentMap.projectToTiles(tempVector);
        writer.attribute(XML_ATTRIBUTE_CAMERA_POSITION_X, tempVector.x);
        writer.attribute(XML_ATTRIBUTE_CAMERA_POSITION_Y, tempVector.y);
        MathUtil.freeVector2(tempVector);
    } 

    writer.attribute(XML_ATTRIBUTE_GOID, gameState.getCurrentId());
    writer.pop();

    writer.element(XML_ATTRIBUTE_GAME_TIME);
    GameState.getCurrentGameDate().writeToXML(writer);
    writer.pop();

    gameState.variables().writeToXML(writer);
    writer.pop();
}
项目:fabulae    文件:GameSaver.java   
private void writeAllGameObjectsToXML(XmlWriter writer) throws IOException {
    for (GameLocation loc : locations.values()) {
        if (loc instanceof GameMap) {
            writer.element(XML_GAME_OBJECTS).attribute(XML_MAP, loc.getId());
            ((GameMap) loc).writeAllGameObjectsToXML(writer);
            writer.pop();
        }
    }
    if (unassignedLocalGameObjects.size > 0) {
        writer.element(XML_GAME_OBJECTS);
        for (GameObject go : unassignedLocalGameObjects.values()) {
            if (!go.shouldBeSaved()) {
                 continue;
             }
             writer.element(go.getClass().getName());
             go.writeToXML(writer);
             writer.pop();
        }
        writer.pop();
    }
}
项目:XMLLayoutParser    文件:TextFieldParser.java   
@Override
public void save(XmlWriter writer, Actor actor, LayoutParserContext context)
        throws LayoutParseException {
    try {
        TextField textField = (TextField) actor;
        writer.element(getElementName());
        ElementParserHelper.writeDefaultAttributes(writer, actor);

        if (!textField.getText().isEmpty()) {
            writer.text(textField.getText());
        }

        writer.pop();
    } catch (IOException e) {
        throw new LayoutParseException(e);
    }
}
项目:XMLLayoutParser    文件:LayoutParser.java   
/**
 *
 * @param layoutFile
 * @param actors
 * @throws LayoutParseException
 */
public void save(FileHandle layoutFile, Collection<Actor> actors)
        throws LayoutParseException {
    try {
        XmlWriter writer = new XmlWriter(layoutFile.writer(false));
        LayoutParserContext context = new LayoutParserContext();
        context.setParsers(parsers);

        writer.element("Layout");

        for (Actor i : actors) {
            parsers.getParserByClass(i.getClass()).save(writer, i, context);
        }

        writer.pop();
        writer.close();
    } catch (IOException e) {
        throw new LayoutParseException(e); // TODO More detailed Exception
    }
}
项目:libgdx_ui_editor    文件:FileUtils.java   
public static void createScene(Writer writer,float width,float height,String name) throws IOException {
    XmlWriter xmlWriter= new XmlWriter(writer);
    xmlWriter.element("Stage")
                .attribute("width",width)
                .attribute("height",height)
                .attribute("name",name)
                .pop();
    xmlWriter.flush();
}
项目:libgdx_ui_editor    文件:FileUtils.java   
public static void writeFile(Group group, FileHandle fileHandle) throws IOException {
    FileWriter writer = new FileWriter(fileHandle.file());
    XmlWriter xmlWriter= new XmlWriter(writer);
    writeAttr(xmlWriter,group);
    xmlWriter.flush();
    writer.close();
}
项目:libgdx_ui_editor    文件:FileUtils.java   
public static void writeGenAttr(XmlWriter writer,Actor actor) throws IOException {
    writer.attribute("width",actor.getWidth())
            .attribute("height",actor.getHeight())
            .attribute("x",actor.getX())
            .attribute("y",actor.getY())
            .attribute("originX",actor.getOriginX())
            .attribute("originY",actor.getOriginY())
            .attribute("visible",String.valueOf(actor.isVisible()));
    if (actor.getName()!=null&&!actor.getName().isEmpty()){
        writer.attribute("name",actor.getName());
    }
}
项目:libgdx_ui_editor    文件:FileUtils.java   
public static void writeUqAttr(XmlWriter xmlWriter,Actor actor) throws IOException {
    Object userobject = actor.getUserObject();
    if (userobject!=null&&userobject instanceof HashMap){
        HashMap<String,String> attrMap = (HashMap<String,String>)userobject;
        for (String key : attrMap.keySet()){
            xmlWriter.attribute(key,attrMap.get(key));
        }
    }
}
项目:fabulae    文件:ParticleEffectDescriptor.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    XMLUtil.writePrimitives(this, writer, true);
    writer.element(XML_OFFSET);
    writer.element(XMLUtil.XML_ATTRIBUTE_X, xOffset);
    writer.element(XMLUtil.XML_ATTRIBUTE_Y, yOffset);
    writer.pop();
}
项目:fabulae    文件:GameMap.java   
public void writeAllGameObjectsToXML(XmlWriter writer) throws IOException {
     for (GameObject go : gameObjects) {
         if (!go.shouldBeSaved()) {
             continue;
         }
         writer.element(go.getClass().getName());
         go.writeToXML(writer);
         writer.pop();
     }
}
项目:fabulae    文件:GameMap.java   
public void writeAllLocationsToXML(XmlWriter writer) throws IOException {
     for (GameLocation location: locations) {
         writer.element(location.getClass().getName());
         location.writeToXML(writer);
         writer.pop();
     }
}
项目:fabulae    文件:GameMap.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    super.writeToXML(writer);
    writer.element(XML_FOG_OF_WAR);
    writer.text(fogOfWar.length+" ");
    for (int i = 0; i <fogOfWar.length; ++i) {
        if (fogOfWar[i] == 1) {
            writer.text(i+" ");
        }
    }
    writer.pop();

    writer.element(XML_TRANSITION_LOCKS);
    for (TransitionLock lock : transitionLocks) {
        writer.element(XML_TRANSITION_LOCK);
        lock.writeToXML(writer);
        writer.pop();
    }
    writer.pop();

    writer.element(XML_TRANSITION_TRAPS);
    for (TransitionTrap trap : transitionTraps) {
        writer.element(XML_TRANSITION_TRAP);
        trap.writeToXML(writer);
        writer.pop();
    }
    writer.pop();
}
项目:fabulae    文件:GameLocation.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    writer.element(XML_PROPERTIES);
    XMLUtil.writePrimitives(this, writer);
    writer.pop();
    variables.writeToXML(writer);
}
项目:fabulae    文件:Quest.java   
/**
 * Writes all quests that have been started during the course of the game.
 * 
 * @param writer
 * @throws IOException
 */
public static void writeAllStartedQuests(XmlWriter writer) throws IOException {
    for (String questFile : quests.values()) {
        Quest quest = Assets.get(questFile);
        if (quest.isStarted()) {
            writer.element(quest.getId());
            quest.writeToXML(writer);
            writer.pop();
        }
    }
}
项目:fabulae    文件:GameDate.java   
public void writeToXML(XmlWriter writer) throws IOException {
    writer.attribute(XML_DAY, getDay()+1);
    writer.attribute(XML_MONTH, getMonth()+1);
    writer.attribute(XML_YEAR, getYear());
    writer.attribute(XML_HOUR, getHour());
    writer.attribute(XML_MINUTE, getMinute());
    writer.attribute(XML_SECOND, getSecond());
}
项目:fabulae    文件:ChainAction.java   
@Override
public void writeParametersToXML(XmlWriter writer) throws IOException {
    if (targetId != null) {
        writer.attribute(XML_ATTRIBUTE_TARGET, targetId);
    }
    if (currentAction != null) {
        currentAction.writeToXML(writer);
    }
    if (actions.size() > 0) {
        for (Action action : actions) {
            action.writeToXML(writer);
        }
    }
}
项目:fabulae    文件:WanderAction.java   
@Override
public void writeParametersToXML(XmlWriter writer) throws IOException {
    writer.attribute(XML_ATTRIBUTE_RADIUS, radius)
            .attribute(XML_ATTRIBUTE_CHANCE_TO_MOVE, chanceToMove)
            .attribute(XML_ATTRIBUTE_DURATION, duration)
            .attribute(XML_ATTRIBUTE_TOTAL_TIME, totalTime)
            .attribute(XML_ATTRIBUTE_VISIBLE_ONLY, visibleOnly);
}
项目:fabulae    文件:UsePerkAction.java   
@Override
public void writeParametersToXML(XmlWriter writer) throws IOException {
    writer.attribute(XMLUtil.XML_ATTRIBUTE_ID, perkId);
    if (effectTarget != null) {
        writer.attribute(XML_ATTRIBUTE_X, effectTarget.getTargetX());
        writer.attribute(XML_ATTRIBUTE_Y, effectTarget.getTargetY());
    }
}
项目:fabulae    文件:TweenToAction.java   
@Override
public void writeParametersToXML(XmlWriter writer) throws IOException {
    writer.attribute(XML_ATTRIBUTE_X, targetX)
        .attribute(XML_ATTRIBUTE_Y, targetY)
        .attribute(XML_ATTRIBUTE_SPEED, speed)
        .attribute(XML_ATTRIBUTE_DELAY, delay);
}
项目:fabulae    文件:UseInventoryItemAction.java   
@Override
public void writeParametersToXML(XmlWriter writer) throws IOException {
    writer.attribute(XMLUtil.XML_ATTRIBUTE_ID, itemId);
    if (effectTarget != null) {
        writer.attribute(XML_ATTRIBUTE_X, effectTarget.getTargetX());
        writer.attribute(XML_ATTRIBUTE_Y, effectTarget.getTargetY());
    }
}
项目:fabulae    文件:PlayStateAnimationAction.java   
@Override
public void writeParametersToXML(XmlWriter writer) throws IOException {
    writer.attribute(XML_ATTRIBUTE_STATE, state)
            .attribute(XML_ATTRIBUTE_DURATION, duration)
            .attribute(XML_ATTRIBUTE_RESET_STATE, resetState)
            .attribute(XML_ATTRIBUTE_STATE_TIME, stateTime);
}
项目:fabulae    文件:FadeAction.java   
@Override
public void writeParametersToXML(XmlWriter writer) throws IOException {
    writer.attribute(XML_ATTRIBUTE_LOOP, loop)
        .attribute(XML_ATTRIBUTE_DURATION, duration)
        .attribute(XML_ATTRIBUTE_DELAY, delay)
        .attribute(XML_ATTRIBUTE_TARGET, target);
}
项目:fabulae    文件:BasicAction.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    writer.element(getClass().getSimpleName());
    XMLUtil.writePrimitives(this, writer);
    writeParametersToXML(writer);
    writer.pop();

}
项目:fabulae    文件:Inventory.java   
/**
 * Writes the Inventory into XML using the supplied XmlWriter.
 * 
 * The output XML will look like this:
 * 
 * <pre>
 * &lt;Inventory&gt;
 *  &lt;BagType&gt;
 *      &lt;Item id="itemId" slot="inventorySlot" /&gt;
 *      ...
 *  &lt;/BagType&gt;
 * &lt;/Inventory&gt;
 * </pre>

 */
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    writer.element(Inventory.XML_INVENTORY);

    for (BagType bagType : BagType.values()) {
        IntMap<InventoryItem> bag = getBag(bagType);
        if (bag.size > 0) {
            writer.element(bagType.toString().toLowerCase(Locale.ENGLISH));
            Entries<InventoryItem> bagIterator = bag.entries();
            while (bagIterator.hasNext) {
                Entry<InventoryItem> entry =  bagIterator.next();
                writer.element(Inventory.XML_ITEM)
                        .attribute(XMLUtil.XML_ATTRIBUTE_ID, entry.value.getId())
                        .attribute(XML_ATTRIBUTE_SLOT, entry.key)
                        .attribute(XML_ATTRIBUTE_STACK_SIZE,
                                entry.value.getStackSize());
                ItemOwner itemOwner = entry.value.getOwner();
                String ownerId =itemOwner.getOwnerCharacterId();
                if (ownerId != null) {
                    writer.attribute(XML_ATTRIBUTE_OWNER_CHARACTER, ownerId);
                }
                Faction faction = itemOwner.getOwnerFaction();
                if (faction != null) {
                    writer.attribute(XML_ATTRIBUTE_OWNER_FACTION, faction);
                }
                writer.pop();

            }
            writer.pop();
        }
    }
    writer.pop();
}
项目:fabulae    文件:PlayerCharacterGroup.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    super.writeToXML(writer);
    junkBag.writeToXML(writer);
    variables.writeToXML(writer);
    writeMembers(writer, XML_SELECTED, selectedCharacters);
    writeMembers(writer, XML_PC_MEMBERS, playerCharacters);
    writeMembers(writer, XML_NPC_MEMBERS, nonPlayerCharacters);
    writeMembers(writer, XML_TEMP_REMOVED, tempRemoved);
    writeMembers(writer, XML_CREATED, createdCharacters);
}
项目:fabulae    文件:PlayerCharacterGroup.java   
private void writeMembers(XmlWriter writer, String elementName, Iterable<GameCharacter> iterable) throws IOException {
    writer.element(elementName);
    for (GameCharacter pc : iterable) {
        writer.element(XML_MEMBER).attribute(XMLUtil.XML_ATTRIBUTE_ID, pc.getInternalId()).pop();
    }
    writer.pop();
}
项目:fabulae    文件:Formation.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    writer.element(XML_FORMATION);
    writer.attribute(XML_FORMATION_ORIENTATION, orientation);
    for(Entry<Integer, Tile> entry : formation.entries()) {
        writer.element(CharacterGroup.XML_MEMBER).attribute(XML_ATTRIBUTE_INDEX, entry.key.toString()).attribute(XML_ATTRIBUTE_XOFFSET, entry.value.getX()).attribute(XML_ATTRIBUTE_YOFFSET, entry.value.getY()).pop();
    }
    writer.pop();
}
项目:fabulae    文件:CharacterGroupGameObject.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    super.writeToXML(writer);
    if (group != null) {
        group.writeToXML(writer);
    }
}
项目:fabulae    文件:CharacterGroup.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    writer.element(XMLUtil.XML_PROPERTIES);
    XMLUtil.writePrimitives(this, writer);
    writer.pop();

    writer.element(XML_MEMBERS);
    for (GameCharacter pc : groupMembers) {
        writer.element(XML_MEMBER).attribute(XMLUtil.XML_ATTRIBUTE_ID, pc.getInternalId()).attribute(XMLUtil.XML_ATTRIBUTE_TYPE, pc.getType()).pop();
    }
    writer.pop();

    formation.writeToXML(writer);

}
项目:fabulae    文件:GameCharacterBrain.java   
@Override
public void writeBrainToXML(XmlWriter writer) throws IOException {
    super.writeBrainToXML(writer);
    if (combatEndAction != null) {
        writer.element(XML_COMBAT_END_ACTION);
        combatEndAction.writeToXML(writer);
        writer.pop();
    }
}
项目:fabulae    文件:AbstractGameCharacter.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    super.writeToXML(writer);

    brain.writeToXML(writer);

    if (temporaryHostility.size > 0) {
        writer.element(XML_TEMPORARY_HOSTILITY);
        for(Entry<Faction, Pair<GameCalendarDate, Integer>> hostility : temporaryHostility) {
            writer.element(hostility.key.getId());
            writer.element(XML_START);
            hostility.value.getLeft().writeToXML(writer);
            writer.pop();
            writer.element(XML_DURATION, hostility.value.getRight());
            writer.pop();
        }
        writer.pop();
    }

    if (visitedLocations.size() > 0) {
        writer.element(XML_VISITED);
        StringBuilder text = StringUtil.getFSB();
        int i = 0;
        for (String location : visitedLocations) {
            ++i;
            text.append(location);
            if (i < visitedLocations.size()) {
                text.append(", "); 
            }
        }
        writer.text(text);
        StringUtil.freeFSB(text);
        writer.pop();
    }
}
项目:fabulae    文件:Brain.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    if (aiScript != null) {
        aiScript.writeToXML(writer);
    }

    writer.element(XML_BRAIN);
    writeBrainToXML(writer);
    writer.pop();
}
项目:fabulae    文件:Brain.java   
protected void writeBrainToXML(XmlWriter writer) throws IOException {
    XMLUtil.writePrimitives(this, writer, true);
    if (currentAIAction != null) {
        writer.element(XML_CURRENT_AI_ACTION);
        currentAIAction.writeToXML(writer);
        writer.pop();
    }   

    if (aiScriptBackUp != null) {
        writer.element(XML_AI_BACKUP);
        aiScriptBackUp.writeToXML(writer);
        writer.pop();
    }
}
项目:fabulae    文件:EffectParameter.java   
@Override
public void writeToXML(XmlWriter writer) throws IOException {
    writer.element(name);
    XMLUtil.writePrimitives(this, writer);
    writer.pop();

}
项目:fabulae    文件:WeatherManager.java   
public void writeToXML(XmlWriter writer) throws IOException {
    writer.element(XML_CURRENT_TEMPERATURE).text(currentTemperature).pop();
    writer.element(XML_NEXT_WEATHER_UPDATE).text(nextPossibleWeatherChange)
            .pop();
    if (currentWeather != null) {
        writer.element(XML_CURRENT_WEATHER);
        currentWeather.writeToXML(writer);
        writer.pop();
    }
}