本文整理汇总了Java中com.badlogic.gdx.utils.XmlReader.Element.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getAttribute方法的具体用法?Java Element.getAttribute怎么用?Java Element.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.utils.XmlReader.Element
的用法示例。
在下文中一共展示了Element.getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDependencies
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
@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;
}
示例2: loadAtlas
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
/** 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;
}
示例3: addElementsInList
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
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);
}
示例4: loadFromXML
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
@Override
public PCSelector loadFromXML(Element element) {
super.loadFromXML(element);
skills = new Array<Skill>();
if (skillsNames != null) {
Array<String> splitSkillNames = StringUtil.arrayFromDelimitedString(skillsNames, ",");
for (String skill : splitSkillNames) {
skills.add(Skill.valueOf(skill.toUpperCase(Locale.ENGLISH)));
}
}
Array<Element> children = element.getChildrenByName(XML_ELEMENT_NPCTTALK);
for (Element npcTalk : children) {
String id = npcTalk.getAttribute(XML_ATTRIBUTE_ID);
NPCTalk talk = getDialogue().getNPCTalk(id);
if (talk == null) {
talk = new NPCTalk(getDialogue());
talk.setId(id);
}
this.npcTalks.add(talk);
getDialogue().addNPCTalk(talk);
}
return this;
}
示例5: readAllGameObjectsFromXML
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
private void readAllGameObjectsFromXML(Element root) {
Array<Element> gosElements = root.getChildrenByName(GameSaver.XML_GAME_OBJECTS);
for (Element gosElement : gosElements) {
String mapId = gosElement.getAttribute(GameSaver.XML_MAP, null);
GameMap map = mapId == null ? null : mapsById.get(mapId);
Array<GameObject> gosForMap = new Array<GameObject>();
if (map != null) {
gosToMaps.put(map, gosForMap);
}
for (int i = 0; i < gosElement.getChildCount(); ++i) {
Element goElement = gosElement.getChild(i);
GameObject go = (GameObject) createFromXML(gameState, goElement);
gosForMap.add(go);
}
}
}
示例6: addTemplate
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
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);
}
}
示例7: loadFromXML
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
public PCTalk loadFromXML(Element element) {
super.loadFromXML(element);
Array<Element> texts = element.getChildrenByName(XML_ELEMENT_TEXT);
roleSpecificTexts = new ObjectMap<String, String>();
for (Element textElement : texts) {
String role = textElement.getAttribute(XML_ATTRIBUTE_ROLE, ROLE_DEFAULT);
roleSpecificTexts.put(role, StringUtil.clearString(textElement.getText()));
}
conversationEnd = Boolean.valueOf(element.getAttribute(XML_ATTRIBUTE_CONVERSATION_END, "false"));
isYes = Boolean.valueOf(element.getAttribute(XML_ATTRIBUTE_IS_YES, "false"));
Array<Element> children = element.getChildrenByName(XML_ELEMENT_NPCTTALK);
for (Element npcTalk : children) {
String id = npcTalk.getAttribute(XML_ATTRIBUTE_ID);
NPCTalk talk = getDialogue().getNPCTalk(id);
if (talk == null) {
talk = new NPCTalk(getDialogue());
talk.setId(id);
}
this.npcTalks.add(talk);
getDialogue().addNPCTalk(talk);
}
return this;
}
示例8: readAndValidateParamateresFromXML
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
@Override
public void readAndValidateParamateresFromXML(Element actionElement) {
targetId = actionElement.getAttribute(XML_ATTRIBUTE_TARGET, null);
if (targetId == null) {
throw new GdxRuntimeException("target must be specified!");
}
}
示例9: readAndValidateParamateresFromXML
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
@Override
public void readAndValidateParamateresFromXML(Element actionElement) {
targetId = actionElement.getAttribute(XML_ATTRIBUTE_TARGET, null);
if (targetId != null) {
GameObject target = GameState.getGameObjectById(targetId);
if (target == null) {
actions = null;
this.actionElement = actionElement;
return;
}
actions = new BasicActionsContainer(target);
}
XMLUtil.readActions(actions, actionElement);
}
示例10: readAndValidateParamateresFromXML
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
@Override
public void readAndValidateParamateresFromXML(Element actionElement) {
text = actionElement.getAttribute(XML_ATTRIBUTE_TEXT, null);
if (text == null) {
throw new GdxRuntimeException("ShoutAction must have attribute text specified! (Character +"+character+")");
}
}
示例11: loadFromXML
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
@Override
public void loadFromXML(Element root) {
s_canBeCast = true;
super.loadFromXML(root);
foci = new ObjectMap<String, Boolean>();
Element fociElement = root.getChildByName(XML_FOCI);
if (fociElement != null) {
for (int i = 0; i < fociElement.getChildCount(); ++i) {
Element focusElement = fociElement.getChild(i);
String itemID = focusElement.getAttribute(XMLUtil.XML_ATTRIBUTE_ID);
boolean consumed = focusElement.getBooleanAttribute(XML_ATTRIBUTE_CONSUMED, false);
foci.put(itemID, consumed);
}
}
}
示例12: load
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public InventoryItem load (AssetManager assetManager, String fileName, FileHandle itemFile, InventoryItemParameter parameter) {
try {
XmlReader xmlReader = new XmlReader();
Element root = xmlReader.parse(itemFile);
InventoryItem newItem = null;
Element properties = root.getChildByName(XMLUtil.XML_PROPERTIES);
if (properties != null) {
String groupNames = properties.getAttribute(Inventory.XML_ATTRIBUTE_GROUPS, "");
String[] groups = groupNames.split(",");
for (String group : groups) {
group = group.trim();
ItemGroup existingGroup = ItemGroup.get(group);
if (existingGroup != null) {
existingGroup.add(itemFile.nameWithoutExtension());
} else {
ItemGroup.add(group, new ItemGroup(group, itemFile.nameWithoutExtension()));
}
}
}
String implementationClassName = root.getName();
implementationClassName = InventoryItem.class.getPackage().getName()+"."+StringUtil.capitalizeFirstLetter(implementationClassName);
Class<? extends InventoryItem> itemClass = (Class<? extends InventoryItem>) Class.forName(implementationClassName);
newItem = itemClass.getConstructor(FileHandle.class).newInstance(resolve(fileName));
return newItem;
} catch (Exception e) {
throw new GdxRuntimeException(e);
}
}
示例13: readScript
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
public static Script readScript(String scriptId, Element scriptElement, Script defaultScript) {
if (scriptElement == null) {
return defaultScript;
}
String id = scriptElement.getAttribute(XML_ATTRIBUTE_ID, null);
if (id != null) {
Script script = GroovyUtil.loadScript(id);
if (script != null) {
return script;
}
}
return GroovyUtil.createScript(scriptId, scriptElement.getText());
}
示例14: readTracks
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
@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;
}
示例15: loadFromXML
import com.badlogic.gdx.utils.XmlReader.Element; //导入方法依赖的package包/类
public void loadFromXML(Element root) throws IOException {
XMLUtil.readPrimitiveMembers(this, root.getChildByName(XMLUtil.XML_PROPERTIES));
variables.loadFromXML(root);
position.loadFromXML(root);
XMLUtil.readActions(this, root.getChildByName(XMLUtil.XML_ACTIONS));
Element forbiddenActionsElement = root.getChildByName(XML_FORBIDDEN_ACTIONS);
if (forbiddenActionsElement != null) {
for (int i = 0; i < forbiddenActionsElement.getChildCount(); ++i) {
Element forbiddenByElement = forbiddenActionsElement.getChild(i);
String forbiddenBy = forbiddenByElement.getAttribute(XMLUtil.XML_ATTRIBUTE_ID);
Array<String> forbidden = new Array<String>();
for (int j = 0; j < forbiddenByElement.getChildCount(); ++j) {
forbidden.add(StringUtil.capitalizeFirstLetter(forbiddenByElement.getChild(j).getName()));
}
forbiddenActions.put(forbiddenBy, forbidden);
}
}
if (isGlobal()) {
gameState.addGameObject(this);
}
if (map == null) {
gameState.addUnassignedGameObject(this);
}
}