List of usage examples for com.badlogic.gdx.utils IntArray add
public void add(int value)
From source file:com.badlogic.gdx.ai.tests.BehaviorTreeViewer.java
License:Apache License
private void fill(IntArray taskSteps, TaskNode taskNode) { taskSteps.add(taskNode.step); for (Node child : taskNode.getChildren()) { fill(taskSteps, (TaskNode) child); }/* w ww .j a v a2s . com*/ }
From source file:com.betmansmall.game.gameLogic.mapLoader.MapLoader.java
License:Apache License
/** Loads the specified tileset data, adding it to the collection of the specified map, given the XML element, the tmxFile and * an {@link ImageResolver} used to retrieve the tileset Textures. * * <p>/*from ww w. j a v a2 s. com*/ * Default tileset's property keys that are loaded by default are: * </p> * * <ul> * <li><em>firstgid</em>, (int, defaults to 1) the first valid global id used for tile numbering</li> * <li><em>imagesource</em>, (String, defaults to empty string) the tileset source image filename</li> * <li><em>imagewidth</em>, (int, defaults to 0) the tileset source image width</li> * <li><em>imageheight</em>, (int, defaults to 0) the tileset source image height</li> * <li><em>tilewidth</em>, (int, defaults to 0) the tile width</li> * <li><em>tileheight</em>, (int, defaults to 0) the tile height</li> * <li><em>margin</em>, (int, defaults to 0) the tileset margin</li> * <li><em>spacing</em>, (int, defaults to 0) the tileset spacing</li> * </ul> * * <p> * The values are extracted from the specified Tmx file, if a value can't be found then the default is used. * </p> * @param map the Map whose tilesets collection will be populated * @param element the XML element identifying the tileset to load * @param tmxFile the Filehandle of the tmx file * @param imageResolver the {@link ImageResolver} */ protected void loadTileSet(TiledMap map, Element element, FileHandle tmxFile, ImageResolver imageResolver) { if (element.getName().equals("tileset")) { String name = element.get("name", null); int firstgid = element.getIntAttribute("firstgid", 1); int tilewidth = element.getIntAttribute("tilewidth", 0); int tileheight = element.getIntAttribute("tileheight", 0); int spacing = element.getIntAttribute("spacing", 0); int margin = element.getIntAttribute("margin", 0); String source = element.getAttribute("source", null); int offsetX = 0; int offsetY = 0; String imageSource = ""; int imageWidth = 0, imageHeight = 0; FileHandle image = null; if (source != null) { FileHandle tsx = getRelativeFileHandle(tmxFile, source); try { element = xml.parse(tsx); name = element.get("name", null); tilewidth = element.getIntAttribute("tilewidth", 0); tileheight = element.getIntAttribute("tileheight", 0); spacing = element.getIntAttribute("spacing", 0); margin = element.getIntAttribute("margin", 0); Element offset = element.getChildByName("tileoffset"); if (offset != null) { offsetX = offset.getIntAttribute("x", 0); offsetY = offset.getIntAttribute("y", 0); } Element imageElement = element.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandle(tsx, imageSource); } } catch (IOException e) { throw new GdxRuntimeException("Error parsing external tileset."); } } else { Element offset = element.getChildByName("tileoffset"); if (offset != null) { offsetX = offset.getIntAttribute("x", 0); offsetY = offset.getIntAttribute("y", 0); } Element imageElement = element.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandle(tmxFile, imageSource); } } TiledMapTileSet tileset = new TiledMapTileSet(); tileset.setName(name); tileset.getProperties().put("firstgid", firstgid); if (image != null) { TextureRegion texture = imageResolver.getImage(image.path()); MapProperties props = tileset.getProperties(); props.put("imagesource", imageSource); props.put("imagewidth", imageWidth); props.put("imageheight", imageHeight); props.put("tilewidth", tilewidth); props.put("tileheight", tileheight); props.put("margin", margin); props.put("spacing", spacing); int stopWidth = texture.getRegionWidth() - tilewidth; int stopHeight = texture.getRegionHeight() - tileheight; int id = firstgid; for (int y = margin; y <= stopHeight; y += tileheight + spacing) { for (int x = margin; x <= stopWidth; x += tilewidth + spacing) { TextureRegion tileRegion = new TextureRegion(texture, x, y, tilewidth, tileheight); TiledMapTile tile = new StaticTiledMapTile(tileRegion); tile.setId(id); tile.setOffsetX(offsetX); tile.setOffsetY(flipY ? -offsetY : offsetY); tileset.putTile(id++, tile); } } } else { Array<Element> tileElements = element.getChildrenByName("tile"); for (Element tileElement : tileElements) { Element imageElement = tileElement.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandle(tmxFile, imageSource); } TextureRegion texture = imageResolver.getImage(image.path()); TiledMapTile tile = new StaticTiledMapTile(texture); tile.setId(firstgid + tileElement.getIntAttribute("id")); tile.setOffsetX(offsetX); tile.setOffsetY(flipY ? -offsetY : offsetY); tileset.putTile(tile.getId(), tile); } } Array<Element> tileElements = element.getChildrenByName("tile"); Array<AnimatedTiledMapTile> animatedTiles = new Array<AnimatedTiledMapTile>(); for (Element tileElement : tileElements) { int localtid = tileElement.getIntAttribute("id", 0); TiledMapTile tile = tileset.getTile(firstgid + localtid); if (tile != null) { Element animationElement = tileElement.getChildByName("animation"); if (animationElement != null) { Array<StaticTiledMapTile> staticTiles = new Array<StaticTiledMapTile>(); IntArray intervals = new IntArray(); for (Element frameElement : animationElement.getChildrenByName("frame")) { staticTiles.add((StaticTiledMapTile) tileset .getTile(firstgid + frameElement.getIntAttribute("tileid"))); intervals.add(frameElement.getIntAttribute("duration")); } AnimatedTiledMapTile animatedTile = new AnimatedTiledMapTile(intervals, staticTiles); animatedTile.setId(tile.getId()); animatedTiles.add(animatedTile); tile = animatedTile; } String terrain = tileElement.getAttribute("terrain", null); if (terrain != null) { tile.getProperties().put("terrain", terrain); } String probability = tileElement.getAttribute("probability", null); if (probability != null) { tile.getProperties().put("probability", probability); } Element properties = tileElement.getChildByName("properties"); if (properties != null) { loadProperties(tile.getProperties(), properties); } } } for (AnimatedTiledMapTile tile : animatedTiles) { tileset.putTile(tile.getId(), tile); } Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(tileset.getProperties(), properties); } map.getTileSets().addTileSet(tileset); } }
From source file:com.company.minery.utils.spine.SkeletonBinary.java
License:Open Source License
private Attachment readAttachment(DataInput input, Skin skin, String attachmentName, boolean nonessential) throws IOException { float scale = this.scale; String name = input.readString(); if (name == null) name = attachmentName;//from www.ja v a 2 s . co m switch (AttachmentType.values()[input.readByte()]) { case region: { String path = input.readString(); if (path == null) path = name; RegionAttachment region = attachmentLoader.newRegionAttachment(skin, name, path); if (region == null) return null; region.setPath(path); region.setX(input.readFloat() * scale); region.setY(input.readFloat() * scale); region.setScaleX(input.readFloat()); region.setScaleY(input.readFloat()); region.setRotation(input.readFloat()); region.setWidth(input.readFloat() * scale); region.setHeight(input.readFloat() * scale); Color.rgba8888ToColor(region.getColor(), input.readInt()); region.updateOffset(); return region; } case boundingbox: { BoundingBoxAttachment box = attachmentLoader.newBoundingBoxAttachment(skin, name); if (box == null) return null; box.setVertices(readFloatArray(input, scale)); return box; } case mesh: { String path = input.readString(); if (path == null) path = name; MeshAttachment mesh = attachmentLoader.newMeshAttachment(skin, name, path); if (mesh == null) return null; mesh.setPath(path); float[] uvs = readFloatArray(input, 1); short[] triangles = readShortArray(input); float[] vertices = readFloatArray(input, scale); mesh.setVertices(vertices); mesh.setTriangles(triangles); mesh.setRegionUVs(uvs); mesh.updateUVs(); Color.rgba8888ToColor(mesh.getColor(), input.readInt()); mesh.setHullLength(input.readInt(true) * 2); if (nonessential) { mesh.setEdges(readIntArray(input)); mesh.setWidth(input.readFloat() * scale); mesh.setHeight(input.readFloat() * scale); } return mesh; } case skinnedmesh: { String path = input.readString(); if (path == null) path = name; SkinnedMeshAttachment mesh = attachmentLoader.newSkinnedMeshAttachment(skin, name, path); if (mesh == null) return null; mesh.setPath(path); float[] uvs = readFloatArray(input, 1); short[] triangles = readShortArray(input); int vertexCount = input.readInt(true); FloatArray weights = new FloatArray(uvs.length * 3 * 3); IntArray bones = new IntArray(uvs.length * 3); for (int i = 0; i < vertexCount; i++) { int boneCount = (int) input.readFloat(); bones.add(boneCount); for (int nn = i + boneCount * 4; i < nn; i += 4) { bones.add((int) input.readFloat()); weights.add(input.readFloat() * scale); weights.add(input.readFloat() * scale); weights.add(input.readFloat()); } } mesh.setBones(bones.toArray()); mesh.setWeights(weights.toArray()); mesh.setTriangles(triangles); mesh.setRegionUVs(uvs); mesh.updateUVs(); Color.rgba8888ToColor(mesh.getColor(), input.readInt()); mesh.setHullLength(input.readInt(true) * 2); if (nonessential) { mesh.setEdges(readIntArray(input)); mesh.setWidth(input.readFloat() * scale); mesh.setHeight(input.readFloat() * scale); } return mesh; } } return null; }
From source file:com.company.minery.utils.spine.SkeletonJson.java
License:Open Source License
private Attachment readAttachment(Skin skin, String name, JsonValue map) { float scale = this.scale; name = map.getString("name", name); String path = map.getString("path", name); switch (AttachmentType.valueOf(map.getString("type", AttachmentType.region.name()))) { case region: { RegionAttachment region = attachmentLoader.newRegionAttachment(skin, name, path); if (region == null) return null; region.setPath(path);//from w ww . ja v a 2s .c om region.setX(map.getFloat("x", 0) * scale); region.setY(map.getFloat("y", 0) * scale); region.setScaleX(map.getFloat("scaleX", 1)); region.setScaleY(map.getFloat("scaleY", 1)); region.setRotation(map.getFloat("rotation", 0)); region.setWidth(map.getFloat("width") * scale); region.setHeight(map.getFloat("height") * scale); String color = map.getString("color", null); if (color != null) region.getColor().set(Color.valueOf(color)); region.updateOffset(); return region; } case boundingbox: { BoundingBoxAttachment box = attachmentLoader.newBoundingBoxAttachment(skin, name); if (box == null) return null; float[] vertices = map.require("vertices").asFloatArray(); if (scale != 1) { for (int i = 0, n = vertices.length; i < n; i++) vertices[i] *= scale; } box.setVertices(vertices); return box; } case mesh: { MeshAttachment mesh = attachmentLoader.newMeshAttachment(skin, name, path); if (mesh == null) return null; mesh.setPath(path); float[] vertices = map.require("vertices").asFloatArray(); if (scale != 1) { for (int i = 0, n = vertices.length; i < n; i++) vertices[i] *= scale; } mesh.setVertices(vertices); mesh.setTriangles(map.require("triangles").asShortArray()); mesh.setRegionUVs(map.require("uvs").asFloatArray()); mesh.updateUVs(); String color = map.getString("color", null); if (color != null) mesh.getColor().set(Color.valueOf(color)); if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() * 2); if (map.has("edges")) mesh.setEdges(map.require("edges").asIntArray()); mesh.setWidth(map.getFloat("width", 0) * scale); mesh.setHeight(map.getFloat("height", 0) * scale); return mesh; } case skinnedmesh: { SkinnedMeshAttachment mesh = attachmentLoader.newSkinnedMeshAttachment(skin, name, path); if (mesh == null) return null; mesh.setPath(path); float[] uvs = map.require("uvs").asFloatArray(); float[] vertices = map.require("vertices").asFloatArray(); FloatArray weights = new FloatArray(uvs.length * 3 * 3); IntArray bones = new IntArray(uvs.length * 3); for (int i = 0, n = vertices.length; i < n;) { int boneCount = (int) vertices[i++]; bones.add(boneCount); for (int nn = i + boneCount * 4; i < nn;) { bones.add((int) vertices[i]); weights.add(vertices[i + 1] * scale); weights.add(vertices[i + 2] * scale); weights.add(vertices[i + 3]); i += 4; } } mesh.setBones(bones.toArray()); mesh.setWeights(weights.toArray()); mesh.setTriangles(map.require("triangles").asShortArray()); mesh.setRegionUVs(uvs); mesh.updateUVs(); String color = map.getString("color", null); if (color != null) mesh.getColor().set(Color.valueOf(color)); if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() * 2); if (map.has("edges")) mesh.setEdges(map.require("edges").asIntArray()); mesh.setWidth(map.getFloat("width", 0) * scale); mesh.setHeight(map.getFloat("height", 0) * scale); return mesh; } } // RegionSequenceAttachment regionSequenceAttachment = (RegionSequenceAttachment)attachment; // // float fps = map.getFloat("fps"); // regionSequenceAttachment.setFrameTime(fps); // // String modeString = map.getString("mode"); // regionSequenceAttachment.setMode(modeString == null ? Mode.forward : Mode.valueOf(modeString)); return null; }
From source file:com.gdx.extension.ui.list.AdvancedList.java
License:Apache License
public IntArray getSelectedIndexes() { IntArray _indexes = new IntArray(); for (T _item : listRowGroup.getAllChecked()) _indexes.add(listRowGroup.getActors().indexOf(_item, true)); return _indexes; }
From source file:com.kotcrab.vis.editor.proxy.EntityProxy.java
License:Apache License
public void addGroup(int groupId, int parentGroupId) { IntArray groupIds = getGroupComponent().groupIds; if (groupIds.contains(groupId) == false) { if (parentGroupId != -1) groupIds.insert(groupIds.indexOf(parentGroupId), groupId); else//from w w w .j a va 2s . c om groupIds.add(groupId); } }
From source file:com.kotcrab.vis.editor.serializer.cloner.IntArrayCloner.java
License:Apache License
@Override protected IntArray cloneObject(IntArray original, IDeepCloner cloner, Map<Object, Object> clones) { IntArray array = new IntArray(original.size); for (int i = 0; i < original.size; i++) array.add(original.get(i)); return array; }
From source file:com.kotcrab.vis.editor.serializer.json.IntArrayJsonSerializer.java
License:Apache License
@Override public IntArray deserialize(JsonElement j, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonArray json = j.getAsJsonArray(); IntArray intArray = new IntArray(json.size()); for (int i = 0; i < json.size(); i++) { intArray.add(json.get(i).getAsInt()); }/* w w w . j av a2 s. co m*/ return intArray; }
From source file:com.skettios.loader.TmxMapLoaderFixed.java
License:Apache License
/** * Loads the specified tileset data, adding it to the collection of the specified map, given the XML element, the tmxFile and * an {@link ImageResolver} used to retrieve the tileset Textures. * <p/>// w w w . ja v a 2 s. c om * <p> * Default tileset's property keys that are loaded by default are: * </p> * <p/> * <ul> * <li><em>firstgid</em>, (int, defaults to 1) the first valid global id used for tile numbering</li> * <li><em>imagesource</em>, (String, defaults to empty string) the tileset source image filename</li> * <li><em>imagewidth</em>, (int, defaults to 0) the tileset source image width</li> * <li><em>imageheight</em>, (int, defaults to 0) the tileset source image height</li> * <li><em>tilewidth</em>, (int, defaults to 0) the tile width</li> * <li><em>tileheight</em>, (int, defaults to 0) the tile height</li> * <li><em>margin</em>, (int, defaults to 0) the tileset margin</li> * <li><em>spacing</em>, (int, defaults to 0) the tileset spacing</li> * </ul> * <p/> * <p> * The values are extracted from the specified Tmx file, if a value can't be found then the default is used. * </p> * * @param map the Map whose tilesets collection will be populated * @param element the XML element identifying the tileset to load * @param tmxFile the Filehandle of the tmx file * @param imageResolver the {@link ImageResolver} */ protected void loadTileSet(TiledMap map, Element element, FileHandle tmxFile, ImageResolver imageResolver) { if (element.getName().equals("tileset")) { String name = element.get("name", null); int firstgid = element.getIntAttribute("firstgid", 1); int tilewidth = element.getIntAttribute("tilewidth", 0); int tileheight = element.getIntAttribute("tileheight", 0); int spacing = element.getIntAttribute("spacing", 0); int margin = element.getIntAttribute("margin", 0); String source = element.getAttribute("source", null); int offsetX = 0; int offsetY = 0; String imageSource = ""; int imageWidth = 0, imageHeight = 0; FileHandle image = null; if (source != null) { FileHandle tsx = getRelativeFileHandleFixed(tmxFile, source); try { element = xml.parse(tsx); name = element.get("name", null); tilewidth = element.getIntAttribute("tilewidth", 0); tileheight = element.getIntAttribute("tileheight", 0); spacing = element.getIntAttribute("spacing", 0); margin = element.getIntAttribute("margin", 0); Element offset = element.getChildByName("tileoffset"); if (offset != null) { offsetX = offset.getIntAttribute("x", 0); offsetY = offset.getIntAttribute("y", 0); } Element imageElement = element.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandleFixed(tsx, imageSource); } } catch (IOException e) { throw new GdxRuntimeException("Error parsing external tileset."); } } else { Element offset = element.getChildByName("tileoffset"); if (offset != null) { offsetX = offset.getIntAttribute("x", 0); offsetY = offset.getIntAttribute("y", 0); } Element imageElement = element.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandleFixed(tmxFile, imageSource); } } TiledMapTileSet tileset = new TiledMapTileSet(); tileset.setName(name); tileset.getProperties().put("firstgid", firstgid); if (image != null) { TextureRegion texture = imageResolver.getImage(image.path()); MapProperties props = tileset.getProperties(); props.put("imagesource", imageSource); props.put("imagewidth", imageWidth); props.put("imageheight", imageHeight); props.put("tilewidth", tilewidth); props.put("tileheight", tileheight); props.put("margin", margin); props.put("spacing", spacing); int stopWidth = texture.getRegionWidth() - tilewidth; int stopHeight = texture.getRegionHeight() - tileheight; int id = firstgid; for (int y = margin; y <= stopHeight; y += tileheight + spacing) { for (int x = margin; x <= stopWidth; x += tilewidth + spacing) { TextureRegion tileRegion = new TextureRegion(texture, x, y, tilewidth, tileheight); TiledMapTile tile = new StaticTiledMapTile(tileRegion); tile.setId(id); tile.setOffsetX(offsetX); tile.setOffsetY(-offsetY); tileset.putTile(id++, tile); } } } else { Array<Element> tileElements = element.getChildrenByName("tile"); for (Element tileElement : tileElements) { Element imageElement = tileElement.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandleFixed(tmxFile, imageSource); } TextureRegion texture = imageResolver.getImage(image.path()); TiledMapTile tile = new StaticTiledMapTile(texture); tile.setId(firstgid + tileElement.getIntAttribute("id")); tile.setOffsetX(offsetX); tile.setOffsetY(-offsetY); tileset.putTile(tile.getId(), tile); } } Array<Element> tileElements = element.getChildrenByName("tile"); Array<AnimatedTiledMapTile> animatedTiles = new Array<AnimatedTiledMapTile>(); for (Element tileElement : tileElements) { int localtid = tileElement.getIntAttribute("id", 0); TiledMapTile tile = tileset.getTile(firstgid + localtid); if (tile != null) { Element animationElement = tileElement.getChildByName("animation"); if (animationElement != null) { Array<StaticTiledMapTile> staticTiles = new Array<StaticTiledMapTile>(); IntArray intervals = new IntArray(); for (Element frameElement : animationElement.getChildrenByName("frame")) { staticTiles.add((StaticTiledMapTile) tileset .getTile(firstgid + frameElement.getIntAttribute("tileid"))); intervals.add(frameElement.getIntAttribute("duration")); } AnimatedTiledMapTile animatedTile = new AnimatedTiledMapTile(intervals, staticTiles); animatedTile.setId(tile.getId()); animatedTiles.add(animatedTile); tile = animatedTile; } String terrain = tileElement.getAttribute("terrain", null); if (terrain != null) { tile.getProperties().put("terrain", terrain); } String probability = tileElement.getAttribute("probability", null); if (probability != null) { tile.getProperties().put("probability", probability); } Element properties = tileElement.getChildByName("properties"); if (properties != null) { loadProperties(tile.getProperties(), properties); } } } for (AnimatedTiledMapTile tile : animatedTiles) { tileset.putTile(tile.getId(), tile); } Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(tileset.getProperties(), properties); } map.getTileSets().addTileSet(tileset); } }
From source file:com.vlaaad.dice.game.user.Die.java
License:Open Source License
public IntArray getAvailableIndices(Ability ability) { int availableSkill = getTotalSkill() - getUsedSkill(); IntArray res = new IntArray(); for (int i = 0; i < abilities.size; i++) { Ability check = abilities.get(i); if (check == ability) continue; boolean canBePlaced = check == null ? availableSkill >= ability.skill : availableSkill >= ability.skill - check.skill; if (canBePlaced) { res.add(i); }/*from w w w .ja va 2 s . c om*/ } return res; }