Java 类com.badlogic.gdx.utils.XmlReader.Element 实例源码

项目:KyperBox    文件:KyperMapLoader.java   
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle tmxFile,
        com.badlogic.gdx.maps.tiled.AtlasTmxMapLoader.AtlasTiledMapLoaderParameters parameter) {
    Array<AssetDescriptor> dependencies = new Array<AssetDescriptor>();
    try {
        root = xml.parse(tmxFile);

        Element properties = root.getChildByName("properties");
        if (properties != null) {
            for (Element property : properties.getChildrenByName("property")) {
                String name = property.getAttribute("name");
                String value = property.getAttribute("value");
                if (name.startsWith("atlas")) {
                    FileHandle atlasHandle = Gdx.files.internal(value);
                    dependencies.add(new AssetDescriptor(atlasHandle, TextureAtlas.class));
                }
            }
        }
    } catch (IOException e) {
        throw new GdxRuntimeException("Unable to parse .tmx file.");
    }
    return dependencies;
}
项目:KyperBox    文件:KyperMapLoader.java   
/** May return null. */
protected FileHandle loadAtlas(Element root, FileHandle tmxFile) throws IOException {
    Element e = root.getChildByName("properties");

    if (e != null) {
        for (Element property : e.getChildrenByName("property")) {
            String name = property.getAttribute("name", null);
            String value = property.getAttribute("value", null);
            if (name.equals("atlas")) {
                if (value == null) {
                    value = property.getText();
                }

                if (value == null || value.length() == 0) {
                    // keep trying until there are no more atlas properties
                    continue;
                }
                return Gdx.files.internal(value);
            }
        }
    }
    FileHandle atlasFile = tmxFile.sibling(tmxFile.nameWithoutExtension() + ".atlas");
    return atlasFile.exists() ? atlasFile : null;
}
项目:KyperBox    文件:TiledObjectTypes.java   
public TiledObjectTypes(String file) {
    xml_reader = new XmlReader();
    try {
        root = xml_reader.parse(Gdx.files.internal(file));
    } catch (IOException e) {
        e.printStackTrace();
    }
    types = new ObjectMap<String, TiledObjectTypes.TiledObjectType>();

    if(root == null)
        throw new GdxRuntimeException(String.format("Unable to parse file %s. make sure it is the correct path.", file));
    Array<Element> types = root.getChildrenByName("objecttype");
    for (Element element : types) {
        TiledObjectType tot = new TiledObjectType(element.get("name"));
        Array<Element> properties  = element.getChildrenByName("property");
        for (int i = 0; i < properties.size; i++) {
            Element element2 = properties.get(i);
            TypeProperty property = new TypeProperty(element2.get("name"), element2.get("type"), element2.hasAttribute("default")?element2.get("default"):"");
            tot.addProperty(property);
        }
        this.types.put(tot.name, tot);
    }

}
项目:JavityEngine    文件:JXmlUi.java   
private void addList(Table table, Element element) {
    Gdx.app.log("JXmlUi", "addList");
    ObjectMap<String, String> atrributes = element.getAttributes();
    if (atrributes == null)
        atrributes = new ObjectMap<String, String>();

    List<String> list = new List<String>(skin);
    list.getSelection().setMultiple(false);

    ScrollPane scrollPane = new ScrollPane(list, skin);

    Cell<ScrollPane> cell = table.add(scrollPane);
    for (String key : atrributes.keys()) {
        if (key.equalsIgnoreCase("name")) {
            list.setName(atrributes.get(key));
            scrollPane.setName(atrributes.get(key) + "-scroll-panel");
        }
    }
    cellPrepare(cell, atrributes);

    actorsMap.put(list.getName(), list);
    actorsMap.put(scrollPane.getName(), scrollPane);

    addElementsInList(element, list);
}
项目:JavityEngine    文件:JXmlUi.java   
private void addElementsInList(Element element, List list) {
    Array<String> items = new Array<String>();

    int childCount = element.getChildCount();
    for (int x = 0; x < childCount; x++) {
        Element child = element.getChild(x);
        if (!child.getName().equalsIgnoreCase("list-element"))
            continue;
        // Gdx.app.log("JXmlUi", "addListElement");
        String text = child.getAttribute("text");
        items.add(text);

    }

    list.setItems(items);
}
项目:JavityEngine    文件:JXmlUi.java   
private void addButton(Table table, Element element) {
    TextButton button = new TextButton("", skin);
    Cell<TextButton> cell = table.add(button);

    ObjectMap<String, String> atrributes = element.getAttributes();
    for (String key : atrributes.keys()) {
        if (key.equalsIgnoreCase("text")) {
            button.setText(atrributes.get(key));
        } else if (key.equalsIgnoreCase("checked")) {
            button.setChecked(Boolean.parseBoolean(atrributes.get(key)));
        } else if (key.equalsIgnoreCase("visible")) {
            button.setVisible(Boolean.parseBoolean(atrributes.get(key)));
        } else if (key.equalsIgnoreCase("enable")) {
            button.setDisabled(!Boolean.parseBoolean(atrributes.get(key)));
        } else if (key.equalsIgnoreCase("name")) {
            button.setName(atrributes.get(key));
        }
    }
    cellPrepare(cell, atrributes);

    // System.out.println("Dodaje button: " + button.getName());
    actorsMap.put(button.getName(), button);
}
项目:fabulae    文件:StateMachine.java   
private void readStates(Element root) {
    for (int i = 0; i < root.getChildCount(); ++i) {
        Element stateElement = root.getChild(i);
        if (!XML_STATE.equalsIgnoreCase(stateElement.getName())) {
            continue;
        }
        S newState = createState(stateElement);
        newState.loadFromXML(stateElement);
        states.put(newState.getId(), newState);
    }

    String currentStateId = root.get(XML_CURRENT_STATE, null);
    if (currentStateId != null) {
        currentState = getStateForId(currentStateId);
    }
}
项目:fabulae    文件:Effect.java   
@Override
public void loadFromXML(Element root) throws IOException {
    XMLUtil.readPrimitiveMembers(this, root);

    Element dateElement = root.getChildByName(XMLUtil.XML_END_DATE);
    if (dateElement != null) {
        dateToEnd = new GameCalendarDate(GameState.getCurrentGameDate());
        dateToEnd.readFromXML(dateElement);
    }

    Element paramsElement = root.getChildByName(XMLUtil.XML_PARAMETERS);
    parameters = new Array<EffectParameter>();
    for (int i = 0; i < paramsElement.getChildCount(); ++i) {
        parameters.add(new EffectParameter(paramsElement.getChild(i)));
    }

    paramsElement = root.getChildByName(XML_DESCRIPTION_PARAMETERS);
    descriptionParameters= new Object[paramsElement.getChildCount()];
    for (int i = 0; i < paramsElement.getChildCount(); ++i) {
        // this will convert everything into strings, but this should be okay as long 
        // as no special formatting is used in the message format of the description
        descriptionParameters[i] = paramsElement.getChild(i).getText();  
    }
}
项目:fabulae    文件:WeatherProfile.java   
@Override
public void loadFromXMLNoInit(FileHandle file) throws IOException {
    XmlReader xmlReader = new XmlReader();
    Element root = xmlReader.parse(file);
    XMLUtil.handleImports(this, file, root);

    isModifier = root.getName().endsWith(MODIFIER_SUFFIX);
    XMLUtil.readPrimitiveMembers(this,
            root);
    createPools();
    Element weatherEffects = root.getChildByName(XML_WEATHER_EFFECTS);
    if (weatherEffects != null) {
        readAllSounds(weatherEffects.getChildByName(XML_RAIN), continuousSoundsRain, randomSoundsRain);
        readAllSounds(weatherEffects.getChildByName(XML_SNOW), continuousSoundsSnow, randomSoundsSnow);
    }
}
项目:fabulae    文件:Quest.java   
@Override
public void loadFromXML(Element root) throws IOException {
    super.loadFromXML(root);
    story = new Array<QuestState>();
    storyTimes = new Array<GameCalendarDate>();
    if (isFinished()) {
        finishedQuests.add(this);
    } else if (isStarted()) {
        activeQuests.add(this);
    }

    variables = new Variables();
    variables.loadFromXML(root);

    Element storyElement = root.getChildByName(XML_STORY);
    if (storyElement != null) {
        for (int i = 0; i < storyElement.getChildCount(); ++i) {
            Element storyStateElement = storyElement.getChild(i);
            story.add(getStateForId(storyStateElement.getAttribute(XMLUtil.XML_ATTRIBUTE_ID)));
            GameCalendarDate date = new GameCalendarDate(GameState.getCurrentGameDate().getCalendar());
            date.readFromXML(storyStateElement.getChildByName(XML_TIME));
            storyTimes.add(date);
        }
    }
}
项目:fabulae    文件:ProjectileTypeLoader.java   
@SuppressWarnings("rawtypes")
@Override
public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, ProjectileTypeParameter parameter) {
    XmlReader xmlReader = new XmlReader();
    try {
        Array<AssetDescriptor>  returnValue = new Array<AssetDescriptor>();
        Element root = xmlReader.parse(file);
        LoaderUtil.handleImports(this, parameter, returnValue, file, root);
        String animationFile = root.get(ProjectileType.XML_ANIMATION_FILE, null);
        if (animationFile != null) {
            returnValue.add(new AssetDescriptor<Texture>(Configuration.addModulePath(animationFile), Texture.class));
        }
        Element soundsElement = root.getChildByName(XMLUtil.XML_SOUNDS);
        if (soundsElement != null) {
            addSoundDependency(soundsElement, ProjectileType.XML_ON_START, returnValue);
            addSoundDependency(soundsElement, ProjectileType.XML_ON_HIT, returnValue);
            addSoundDependency(soundsElement, ProjectileType.XML_DURING, returnValue);
        }
        if (returnValue.size > 0) {
            return returnValue;
        }
    } catch (IOException e) {
        throw new GdxRuntimeException(e);
    }
    return null;
}
项目:fabulae    文件:XMLUtil.java   
/**
 * Parses the supplied InputStream without closing it at the end using the
 * supplied XmlReader.
 * 
 * @param inStream
 * @return
 */
public static Element parseNonCLosing(XmlReader parser, InputStream inStream) {
    try {
        InputStreamReader inReader = new InputStreamReader(inStream, "UTF-8");
        char[] data = new char[1024];
        int offset = 0;
        while (true) {
            int length = inReader.read(data, offset, data.length - offset);
            if (length == -1)
                break;
            if (length == 0) {
                char[] newData = new char[data.length * 2];
                System.arraycopy(data, 0, newData, 0, data.length);
                data = newData;
            } else
                offset += length;
        }
        return parser.parse(data, 0, offset);
    } catch (IOException ex) {
        throw new SerializationException(ex);
    }
}
项目:fabulae    文件:ProjectileType.java   
public void loadFromXML(Element root) throws IOException {
    XMLUtil.readPrimitiveMembers(this, root);

    Element soundsElement = root.getChildByName(XMLUtil.XML_SOUNDS);
    if (soundsElement != null) {
        onStartSounds = XMLUtil.readSounds(soundsElement, ProjectileType.XML_ON_START);
        onHitSounds = XMLUtil.readSounds(soundsElement, ProjectileType.XML_ON_HIT);
        duringSounds = XMLUtil.readSounds(soundsElement, ProjectileType.XML_DURING);
    } else {
        onStartSounds = new Array<Sound>();
        onHitSounds = new Array<Sound>();
        duringSounds = new Array<Sound>();
    }

    try {
        if (s_animationFile != null && s_animationInfoFile != null) {
            s_animationFile = Configuration.addModulePath(s_animationFile);
            s_animationInfoFile = Configuration.addModulePath(s_animationInfoFile);
            animations = new OrientationAnimationMap(s_animationFile,
                    Gdx.files.internal(s_animationInfoFile));
        }
    } catch (IOException e) {
        throw new GdxRuntimeException("Problem loading animation for projectile type "+getId(),e);
    }
}
项目:fabulae    文件:Formation.java   
@Override
public void loadFromXML(Element root) throws IOException {
    Element formationElement = root.getChildByName(XML_FORMATION);
    if (formationElement == null) {
        return;
    }
    orientation = Orientation.valueOf(formationElement.getAttribute(XML_FORMATION_ORIENTATION, "UP"));
    for (int i = 0; i <formationElement.getChildCount(); ++i) {
        Element memberElement = formationElement.getChild(i);
        Integer index = Integer.valueOf(memberElement.getAttribute(XML_ATTRIBUTE_INDEX));
        int xOffset = Integer.parseInt(memberElement.getAttribute(XML_ATTRIBUTE_XOFFSET, "0"));
        int yOffset = Integer.parseInt(memberElement.getAttribute(XML_ATTRIBUTE_YOFFSET, "0"));
        formation.put(index, new Tile(xOffset,yOffset));
    }
    recalculateOrthoFormation();
    recalculateIsoFormation();
}
项目:fabulae    文件:WeatherProfileLoader.java   
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, WeatherProfileParameter parameter) {
    Array<AssetDescriptor> returnValue = new Array<AssetDescriptor>();
    try {
        XmlReader xmlReader = new XmlReader();
        Element root = xmlReader.parse(file);
        LoaderUtil.handleImports(this, parameter, returnValue, file, root);
        Array<Element> trackElements = root.getChildrenByNameRecursively(WeatherProfile.XML_TRACK);
        for (Element trackElement : trackElements) {
            String trackFileName = Configuration.addModulePath(trackElement.get(XMLUtil.XML_ATTRIBUTE_FILENAME));
            returnValue.add(new AssetDescriptor(trackFileName, WeatherProfile.XML_CONTINOUS.equalsIgnoreCase(trackElement.getParent().getName()) ? Music.class : Sound.class)); 
        }
    } catch (IOException e) {
        throw new GdxRuntimeException(e);
    }

    return returnValue;
}
项目:KyperBox    文件:TiledTemplates.java   
public void addTemplate(String template) {
    XmlReader xml = types.getXmlReader();
    Element root = null;
    try {
        root = xml.parse(Gdx.files.internal(template_folder+template));
    } catch (IOException e) {
        e.printStackTrace();
    }
    if(root == null) {
        throw new GdxRuntimeException("Unable to parse template ["+template+"]. Make sure it exists or that you have the correct template folder set.");
    }
    Element object = root.getChildByName("object");
    if(object!=null) {
        String parent_type = object.getAttribute("type");
        TiledTemplate t = new TiledTemplate(template,object.getAttribute("name"), types.get(parent_type));
        t.setWidth(object.getInt("width", 0));
        t.setHeight(object.getInt("height",0));
        t.setGid(object.getAttribute("gid",null));
        t.setRotation(object.getFloat("rotation",0f));

        if(object.hasChild("properties")) {
            Array<Element> properties = object.getChildByName("properties").getChildrenByName("property");
            for (Element property : properties) {
                t.getTemplateType().addProperty(property.get("name"), property.hasAttribute("type")?property.get("type"):TypeProperty.STRING, property.get("value"));
            }
        }

        Gdx.app.log(getClass().getName(), "template ["+template+"] has been added");
        templates.put(template, t);
    }
}
项目:JavityEngine    文件:JXmlUi.java   
private void addChildrens(Element element, Table table) {
    int childCount = element.getChildCount();
    for (int x = 0; x < childCount; x++) {
        Element child = element.getChild(x);
        if (child.getName().equalsIgnoreCase("button")) {
            addButton(table, child);
        } else if (child.getName().equalsIgnoreCase("row")) {
            addRow(table);
        } else if (child.getName().equalsIgnoreCase("list")) {
            addList(table, child);
        } else if (child.getName().equalsIgnoreCase("scroll-panel")) {
            addScrollPanel(table, child);
        } else if (child.getName().equalsIgnoreCase("image")) {
            addImage(table, child);
        } else if (child.getName().equalsIgnoreCase("label")) {
            addLabel(table, child);
        } else if (child.getName().equalsIgnoreCase("text-area")) {
            addTextArea(table, child);
        } else if (child.getName().equalsIgnoreCase("table")) {
            addTable(table, child);
        } else if (child.getName().equalsIgnoreCase("text-field")) {
            addTextField(table, child);
        } else if (child.getName().equalsIgnoreCase("window")) {
            addWindow(table, child);
        } else if (child.getName().equalsIgnoreCase("vertical-group")) {
            addVerticalGroup(table, child);
        } else if (child.getName().equalsIgnoreCase("horizontal-group")) {
            addHorizontalGroup(table, child);
        }

    }
}
项目:fabulae    文件:AudioProfile.java   
@Override
public void loadFromXMLNoInit(FileHandle file) throws IOException {
    XmlReader xmlReader = new XmlReader();
    Element root = xmlReader.parse(file);
    XMLUtil.handleImports(this, file, root);
    XMLUtil.readPrimitiveMembers(this, root);
    XMLUtil.readTracks(this, root.getChildByName(XML_AUDIO));
}
项目:fabulae    文件:GameLoader.java   
private void readAllLocationsFromXML(Element root) throws IOException {
    Array<Element> locationsElements = root.getChildrenByName(GameSaver.XML_LOCATIONS);
    for (Element locationsElement : locationsElements) {
        String mapId = locationsElement.getAttribute(GameSaver.XML_MAP, null);
        if (mapId == null) {
            continue;
        }
        GameMap map = null;
        for (int i = 0; i < locationsElement.getChildCount(); ++i) {
            Element locElement = locationsElement.getChild(i);
            GameLocation loc = (GameLocation) createFromXML(gameState, locElement);
            // the first location is the map itself, the others are those that belong to it
            // its okay if this dies on a class cast, since if this is not true, then everything is terrible
            if (i == 0) {
                map = (GameMap) loc;
            } else {
                loc.setMap(map);
                // load any "master data" from the xml file
                loc.loadFromXML(Gdx.files.internal(Configuration
                        .getFolderLocations() + loc.getType() + ".xml"));
                // and then reload it from the savegame to override any changes
                // TODO this currently means the savegame element is read twice, this should be optimized
                loc.loadFromXML(locElement);
            }
            gameState.addLocation(loc);
        }
    }
}
项目:JavityEngine    文件:JXmlUi.java   
private void addImage(Table table, Element element) {
    Image image = new Image(new Texture(element.get("path")));
    Cell<Image> cell = table.add(image);

    ObjectMap<String, String> atrributes = element.getAttributes();
    for (String key : atrributes.keys()) {
        if (key.equalsIgnoreCase("name")) {
            image.setName(atrributes.get(key));
        }
    }
    cellPrepare(cell, atrributes);
    actorsMap.put(image.getName(), image);
}
项目:JavityEngine    文件:JXmlUi.java   
private void addLabel(Table table, Element element) {
    ObjectMap<String, String> atrributes = element.getAttributes();

    Label label = new Label(element.get("text", ""), skin);
    Cell<Label> cell = table.add(label);

    for (String key : atrributes.keys()) {
        if (key.equalsIgnoreCase("name")) {
            label.setName(atrributes.get(key));
        }
    }
    cellPrepare(cell, atrributes);
    actorsMap.put(label.getName(), label);

}
项目:fabulae    文件:XMLUtil.java   
public static void handleImports(XMLLoadable importable, FileHandle parentFile, Element root) throws IOException {
    Array<Element> imports = root.getChildrenByName(XMLUtil.XML_IMPORT);
    for (Element singleImport : imports) {
        String filename = singleImport.get(XMLUtil.XML_FILENAME);
        FileHandle file = parentFile.parent().child(filename);
        if (!file.exists()) {
            throw new GdxRuntimeException("Import " + file.path() + " from import for " + importable
                    + " does not exist.");
        }
        importable.loadFromXMLNoInit(file);
    }
}
项目:fabulae    文件:KnowsSpell.java   
@Override
public void validateAndLoadFromXML(Element conditionElement) {
    String spellId = conditionElement.get(XML_SPELL_ID, null);
    if (spellId == null) {
        throw new GdxRuntimeException(XML_SPELL_ID+" must be set for condition KnowsSpell in element: \n\n"+conditionElement);
    }
    if (!Spell.spellExists(spellId)) {
        throw new GdxRuntimeException(XML_SPELL_ID+" contains invalid value "+spellId+", which is not an existing spell in condition KnowsSpell in element: \n\n"+conditionElement);
    }
}
项目:fabulae    文件:SwitchToCombatMap.java   
@Override
public void validateAndLoadFromXML(Element conditionElement) {
    if (conditionElement.get(XML_ENEMY_GROUP, null) == null) {
        throw new GdxRuntimeException(XML_ENEMY_GROUP
                + " must be set for action SwitchToCombatMap in element: \n\n" + conditionElement);
    }
}
项目:fabulae    文件:Stats.java   
@Override
public void loadFromXML(Element root) throws IOException {
    super.loadFromXML(root);
    skills.loadFromXML(root);
    readSkillIncreasesThisLevel(root.getChildByName(XML_SKILL_INCREASES_THIS_LEVEL));
    XMLUtil.readModifiers(this, root.getChildByName(XMLUtil.XML_MODIFIERS));
}
项目:fabulae    文件:QuestVariableFalse.java   
@Override
public void validateAndLoadFromXML(Element conditionElement) {
    super.validateAndLoadFromXML(conditionElement);
    if (conditionElement.get(XML_QUEST, null) == null) {
        throw new GdxRuntimeException(XML_QUEST+" must be set for condition QuestVariableFalse in element: \n\n"+conditionElement);
    }
}
项目:fabulae    文件:Dialogue.java   
@Override
public void loadFromXMLNoInit(FileHandle file) throws IOException {
    XmlReader xmlReader = new XmlReader();
    Element root = xmlReader.parse(file);
    XMLUtil.handleImports(this, file, root);
    loadFromXML(root);
}
项目:fabulae    文件:QuestWasInState.java   
@Override
public void validateAndLoadFromXML(Element conditionElement) {
    if (conditionElement.get(XML_QUEST, null) == null) {
        throw new GdxRuntimeException(XML_QUEST+" must be set for condition QuestWasInState in element: \n\n"+conditionElement);
    }
    if (conditionElement.get(XML_STATE, null) == null) {
        throw new GdxRuntimeException(XML_STATE+" must be set for condition QuestWasInState in element: \n\n"+conditionElement);
    }
}
项目:fabulae    文件:GameLocation.java   
@Override
public void loadFromXMLNoInit(FileHandle locationFile) throws IOException {
    // if there is no xml, we just create an empty location and we are done
    if (!locationFile.exists()) {
        return;
    }
    XmlReader xmlReader = new XmlReader();
    Element root = xmlReader.parse(locationFile);
    XMLUtil.handleImports(this, locationFile, root);
    loadFromXML(root);
}
项目:fabulae    文件:Stats.java   
private void readSkillIncreasesThisLevel(Element skillIncreasesElement) {
    if (skillIncreasesElement != null) {
        for (int i = 0; i< skillIncreasesElement.getChildCount(); ++i) {
            Element variable = skillIncreasesElement.getChild(i);
            skillIncreasesThisLevel.put(Skill.valueOf(variable.getAttribute(XMLUtil.XML_ATTRIBUTE_NAME).toUpperCase(Locale.ENGLISH)),Integer.valueOf(variable.getAttribute(XMLUtil.XML_ATTRIBUTE_VALUE)));
        }
    }
}
项目:fabulae    文件:WeatherProfile.java   
private void readAllSounds (Element element, ObjectMap<PrecipitationAmount, Array<AudioTrack<?>>> continuous, ObjectMap<PrecipitationAmount, Array<AudioTrack<?>>> random) {
    if (element == null) {
        return;
    }
    for (PrecipitationAmount amount : PrecipitationAmount.values()) {
        Element amountElement = element.getChildByName(amount.toString().toLowerCase(Locale.ENGLISH));
        if (amountElement != null) {
            Element soundsElement =  amountElement.getChildByName(XML_SOUNDS);
            if (soundsElement != null) {
                readTracks(soundsElement.getChildByName(XML_CONTINOUS), continuous, amount, StreamingSound.class);
                readTracks(soundsElement.getChildByName(XML_RANDOM), random, amount, Sound.class);
            }
        }
    }
}
项目:fabulae    文件:And.java   
@Override
public void validateAndLoadFromXML(Element actionElement) {
    for (int i = 0; i < actionElement.getChildCount(); ++i) {
        Element childActionElement = actionElement.getChild(i);
        actions.add(Action.getAction(childActionElement));  
    }
    if (actions.size < 1) {
        throw new GdxRuntimeException("Action And must have at least one child action in element "+actionElement);
    }
}
项目:fabulae    文件:Brain.java   
protected void readBrainFromXML(Element brainElement) throws IOException {
    XMLUtil.readPrimitiveMembers(this, brainElement);
    Element currentAIActionElement = brainElement.getChildByName(XML_CURRENT_AI_ACTION);
    if (currentAIActionElement != null && currentAIActionElement.getChildCount() > 0) {
        currentAIAction = Action.readFromXML(currentAIActionElement.getChild(0), go);
        go.addAction(currentAIAction, false);
    }

    Element aiBackup = brainElement.getChildByName(XML_AI_BACKUP);
    if (aiBackup != null) {
        aiScriptBackUp = new AIScriptPackage(aiBackup);
    } else {
        aiScriptBackUp = aiScript;
    }
}
项目:fabulae    文件:GameDate.java   
public void readFromXML(Element dateElement) {
    if (dateElement == null) {
        return;
    }

    setDay(dateElement.getInt(XML_DAY, 1)-1);
    setMonth(dateElement.getInt(XML_MONTH, 1)-1);
    setYear(dateElement.getInt(XML_YEAR, 0));
    setHour(dateElement.getInt(XML_HOUR, 0));
    setMinute(dateElement.getInt(XML_MINUTE, 0));
    setSecond(dateElement.getFloat(XML_SECOND, 0));
}
项目:fabulae    文件:GameCalendar.java   
public void loadFromXML(FileHandle calendarFile) throws IOException {
    XmlReader xmlReader = new XmlReader();
    Element root = xmlReader.parse(calendarFile);
    XMLUtil.readPrimitiveMembers(this, root.getChildByName(XMLUtil.XML_PROPERTIES));
    readNames(root.getChildByName(XML_DAYS), dayNames);
    readYearNames(root.getChildByName(XML_YEARS));
    startDate.readFromXML(root.getChildByName(XML_START_DATE));
    readMonthInfos(root.getChildByName(XML_MONTHS));
}
项目:fabulae    文件:LogMessage.java   
@Override
public void validateAndLoadFromXML(Element conditionElement) {
    if (conditionElement.get(XML_MESSAGE, null) == null) {
        throw new GdxRuntimeException(XML_MESSAGE+" must be set for action LogMessage in element: \n\n"+conditionElement);
    }
    if (conditionElement.get(XML_LOG_TYPE, null) == null) {
        throw new GdxRuntimeException(XML_LOG_TYPE+" must be set for action LogMessage in element: \n\n"+conditionElement);
    }
}
项目:fabulae    文件:PickUpAction.java   
@Override
public void readAndValidateParamateresFromXML(Element actionElement) {
    targetId = actionElement.getAttribute(XML_ATTRIBUTE_TARGET, null);
    if (targetId == null) {
        throw new GdxRuntimeException("target must be specified!");
    }
}
项目:fabulae    文件:HasMeleeWeaponEquipped.java   
@Override
public void validateAndLoadFromXML(Element conditionElement) {
    String skillName = conditionElement.get(XML_WEAPON_SKILL, null);
    if (skillName != null) {
        try {
            Skill.valueOf(skillName.toUpperCase(Locale.ENGLISH));
        } catch (IllegalArgumentException e){
            throw new GdxRuntimeException(XML_WEAPON_SKILL+" contains invalid value "+skillName+", which is not an existing skill in condition "+this.getClass().getSimpleName()+" in element: \n\n"+conditionElement);
        }
    }
}
项目:fabulae    文件:XMLUtil.java   
@SuppressWarnings("unchecked")
private static <T extends AudioTrack<?>> Array<AudioTrack<?>> readTracks(Element typeElement, Class<T> trackType,
        AudioContainer ao, String type) throws InstantiationException, IllegalAccessException,
        IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ReflectionException {
    Array<AudioTrack<?>> returnValue = new Array<AudioTrack<?>>();
    if (typeElement == null) {
        return returnValue;
    }
    String chanceToPlayString = typeElement.getAttribute(XML_ATTRIBUTE_CHANCE_TO_PLAY, null);
    Integer chanceToPlay = chanceToPlayString != null ? Integer.valueOf(chanceToPlayString) : null;

    String volumeModString = typeElement.getAttribute(XML_ATTRIBUTE_VOLUME_MOD, null);
    Float volumeMod = volumeModString != null ? Float.valueOf(volumeModString) : null;
    for (int i = 0; i < typeElement.getChildCount(); ++i) {
        Element trackElement = typeElement.getChild(i);
        Class<T> clazz = trackType; 
        if (clazz == null) {
            String className = StringUtil.capitalizeFirstLetter(trackElement.getName());
            clazz = ClassReflection.forName(AudioTrack.class.getPackage().getName()+"."+className);
        }
        T newTrack = clazz.getConstructor().newInstance();

        if (chanceToPlay != null) {
            newTrack.setChanceToPlay(chanceToPlay);
        }
        if (volumeMod != null) {
            newTrack.setVolumeModifier(volumeMod);
        }
        newTrack.loadFromXML(trackElement);
        if (ao != null) {
            ao.addTrack(newTrack, type);
        }
        returnValue.add(newTrack);
    }
    return returnValue;
}
项目:fabulae    文件:LockpickAction.java   
@Override
public void readAndValidateParamateresFromXML(Element actionElement) {
    targetX = actionElement.getFloatAttribute(XML_ATTRIBUTE_X, -1);
    if (targetX == -1) {
        throw new GdxRuntimeException("x must be specified!");
    }

    targetY = actionElement.getFloatAttribute(XML_ATTRIBUTE_Y, -1);
    if (targetY == -1) {
        throw new GdxRuntimeException("y must be specified!");
    }
}