private Attachment readAttachment(Skin skin, String name, JsonValue map) { name = map.getString("name", name); AttachmentType type = AttachmentType.valueOf(map.getString("type", AttachmentType.region.name())); Attachment attachment = attachmentLoader.newAttachment(skin, type, name); if (attachment instanceof RegionSequenceAttachment) { 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)); } if (attachment instanceof RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment) attachment; regionAttachment.setX(map.getFloat("x", 0) * scale); regionAttachment.setY(map.getFloat("y", 0) * scale); regionAttachment.setScaleX(map.getFloat("scaleX", 1)); regionAttachment.setScaleY(map.getFloat("scaleY", 1)); regionAttachment.setRotation(map.getFloat("rotation", 0)); regionAttachment.setWidth(map.getFloat("width", 32) * scale); regionAttachment.setHeight(map.getFloat("height", 32) * scale); regionAttachment.updateOffset(); } return attachment; }
public SpaceEnvConfig(JsonValue json, TextureManager textureManager, FileHandle configFile) { String junkTexDirStr = json.getString("junkTexs"); junkTexs = textureManager.getPack(junkTexDirStr, configFile); junkDensity = json.getFloat("junkDensity"); String farJunkTexDirStr = json.getString("farJunkTexs"); farJunkTexs = textureManager.getPack(farJunkTexDirStr, configFile); farJunkDensity = json.getFloat("farJunkDensity"); }
@Override public TreeJson read(Json json, JsonValue jv, Class arg2) { TreeJson label = new TreeJson(); label.setName(jv.getString("name")); label.setX(jv.getFloat("x")); label.setY(jv.getFloat("y")); label.setWidth(jv.getFloat("width")); label.setHeight(jv.getFloat("height")); label.setColor(Color.valueOf(jv.getString("color"))); return label; }
public static ShipConfig load( HullConfigManager hullConfigs, JsonValue shipNode, ItemManager itemManager) { if (shipNode == null) return null; String hullName = shipNode.getString("hull"); HullConfig hull = hullConfigs.getConfig(hullName); String items = shipNode.getString("items"); int money = shipNode.getInt("money", 0); float density = shipNode.getFloat("density", -1); ShipConfig guard; if (shipNode.hasChild("guard")) { guard = load(hullConfigs, shipNode.get("guard"), itemManager); } else { guard = null; } return new ShipConfig(hull, items, money, density, guard, itemManager); }
private RigidBodyModel readRigidBody(JsonValue bodyElem) { RigidBodyModel rbModel = new RigidBodyModel(); rbModel.name = bodyElem.getString("name"); rbModel.imagePath = bodyElem.getString("imagePath"); JsonValue originElem = bodyElem.get("origin"); rbModel.origin.x = originElem.getFloat("x"); rbModel.origin.y = originElem.getFloat("y"); // polygons JsonValue polygonsElem = bodyElem.getChild("polygons"); for (; polygonsElem != null; polygonsElem = polygonsElem.next()) { PolygonModel polygon = new PolygonModel(); rbModel.polygons.add(polygon); JsonValue vertexElem = polygonsElem.child(); for (; vertexElem != null; vertexElem = vertexElem.next()) { float x = vertexElem.getFloat("x"); float y = vertexElem.getFloat("y"); polygon.vertices.add(new Vector2(x, y)); } polygon.buffer = new Vector2[polygon.vertices.size()]; } // circles JsonValue circleElem = bodyElem.getChild("circles"); for (; circleElem != null; circleElem = circleElem.next()) { CircleModel circle = new CircleModel(); rbModel.circles.add(circle); circle.center.x = circleElem.getFloat("cx"); circle.center.y = circleElem.getFloat("cy"); circle.radius = circleElem.getFloat("r"); } return rbModel; }
public void addHighScore(int level, String name, float score) { JsonValue root; try { root = new JsonReader().parse(new FileReader(FilePath.highscoreTemp)); } catch (FileNotFoundException e) { try { FileWriter f = new FileWriter(FilePath.highscoreTemp); f.write("[]"); f.close(); root = new JsonReader().parse(new FileReader(FilePath.highscoreTemp)); } catch (IOException e1) { return; } } if (root == null) root = new JsonValue(false); root.setType(ValueType.array); JsonValue entry = new JsonValue(false); entry.setType(ValueType.array); entry.child = new JsonValue(level); entry.child.next = new JsonValue(name); entry.child.next.next = new JsonValue(score); if (root.child == null) root.child = entry; else { JsonValue last = root.child; while (last.next() != null) last = last.next(); last.next = entry; } try { FileWriter f = new FileWriter(FilePath.highscoreTemp); JsonWriter j = new JsonWriter(f); j.array(); for (JsonValue p = root.child; p != null; p = p.next) { j.array(); j.value(p.getInt(0)); j.value(p.getString(1)); j.value(p.getFloat(2)); j.pop(); } j.close(); f.close(); } catch (IOException e) { return; } }
public void tryUpload() { JsonValue root; try { root = new JsonReader().parse(new FileReader(FilePath.highscoreTemp)); } catch (FileNotFoundException e) { return; } if (!isConnected()) return; for (JsonValue p = root.child; p != null; p = p.next) { try { HttpURLConnection c = (HttpURLConnection) new URL( // "http://" + addr + "/Eintragen.php?Index=" + p.getInt(0) // + "&Name=" + p.getString(1) // + "&Score=" + p.getFloat(2) // ) .openConnection(); c.setRequestMethod("GET"); c.setConnectTimeout(1000); c.setReadTimeout(5000); if (c.getInputStream().read() != '1') return; } catch (IOException e) { return; } } try { FileWriter f = new FileWriter(FilePath.highscoreTemp); f.close(); File fl = new File(FilePath.highscoreTemp); fl.delete(); } catch (IOException e) { return; } }
// Rules are just parameters the player can't see and have no control over. public ArrayList<GameModeParameter> getRulesForMode(String gameMode) { if (true) // fake out the compiler return null; // this isn't used currently JsonValue obg = rootValue.get("gamemode"); do { if (obg.child().asString().equals(gameMode)) { obg = obg.child(); break; } } while ((obg = obg.next()) != null); // next = parameters obg = obg.next(); // next = rules obg = obg.next(); // child = rule 1 // from child, next = rule i ArrayList<GameModeParameter> params = new ArrayList<GameModeParameter>(); obg = obg.child(); do { String s = obg.getString("type"); if (s.equals("int")) { params.add(new GameModeParameter.IntParameter(obg)); } else if (s.equals("string")) { } else if (s.equals("spawnables")) { } else if (s.equals("powerups")) { } else if (s.equals("component")) { params.add(new GameModeParameter.ComponentParameter(obg)); } else if (s.equals("conditions")) { } else { System.out.println("Unknown type: " + s); } } while ((obg = obg.next()) != null); return params; }
public ArrayList<GameModeParameter> getParametersForMode(String gameMode) { JsonValue obg = rootValue.get("gamemode"); do { if (obg.child().asString().equals(gameMode)) { obg = obg.child(); break; } } while ((obg = obg.next()) != null); // next = parameters obg = obg.next(); // child = param 1 // from child, next = param i ArrayList<GameModeParameter> params = new ArrayList<GameModeParameter>(); obg = obg.child(); do { String s = obg.getString("type"); if (s.equals("int")) { params.add(new GameModeParameter.IntParameter(obg)); } else if (s.equals("string")) { } else if (s.equals("spawnables")) { } else if (s.equals("powerups")) { } else if (s.equals("meh")) { } else if (s.equals("nu-huh")) { } else { System.out.println("Unknown type: " + s); } } while ((obg = obg.next()) != null); return params; }
public ProjectileConfigs( TextureManager textureManager, SoundManager soundManager, EffectTypes effectTypes, GameCols cols) { myConfigs = new HashMap<String, ProjectileConfig>(); JsonReader r = new JsonReader(); FileHandle configFile = FileManager.getInstance().getConfigDirectory().child("projectiles.json"); JsonValue parsed = r.parse(configFile); for (JsonValue sh : parsed) { String texName = "smallGameObjs/projectiles/" + sh.getString("texName"); TextureAtlas.AtlasRegion tex = textureManager.getTex(texName, configFile); float texSz = sh.getFloat("texSz"); float spdLen = sh.getFloat("spdLen"); float physSize = sh.getFloat("physSize", 0); boolean stretch = sh.getBoolean("stretch", false); DmgType dmgType = DmgType.forName(sh.getString("dmgType")); String collisionSoundPath = sh.getString("collisionSound", ""); SolSound collisionSound = collisionSoundPath.isEmpty() ? null : soundManager.getSound(collisionSoundPath, configFile); float lightSz = sh.getFloat("lightSz", 0); EffectConfig trailEffect = EffectConfig.load(sh.get("trailEffect"), effectTypes, textureManager, configFile, cols); EffectConfig bodyEffect = EffectConfig.load(sh.get("bodyEffect"), effectTypes, textureManager, configFile, cols); EffectConfig collisionEffect = EffectConfig.load( sh.get("collisionEffect"), effectTypes, textureManager, configFile, cols); EffectConfig collisionEffectBg = EffectConfig.load( sh.get("collisionEffectBg"), effectTypes, textureManager, configFile, cols); float guideRotSpd = sh.getFloat("guideRotSpd", 0); boolean zeroAbsSpd = sh.getBoolean("zeroAbsSpd", false); Vector2 origin = SolMath.readV2(sh.getString("texOrig", "0 0")); float acc = sh.getFloat("acceleration", 0); String workSoundDir = sh.getString("workSound", ""); SolSound workSound = workSoundDir.isEmpty() ? null : soundManager.getLoopedSound(workSoundDir, configFile); boolean bodyless = sh.getBoolean("massless", false); float density = sh.getFloat("density", -1); float dmg = sh.getFloat("dmg"); float emTime = sh.getFloat("emTime", 0); ProjectileConfig c = new ProjectileConfig( tex, texSz, spdLen, stretch, physSize, dmgType, collisionSound, lightSz, trailEffect, bodyEffect, collisionEffect, collisionEffectBg, zeroAbsSpd, origin, acc, workSound, bodyless, density, guideRotSpd, dmg, emTime); myConfigs.put(sh.name, c); } }
public SkeletonData readSkeletonData(FileHandle file) { if (file == null) throw new IllegalArgumentException("file cannot be null."); SkeletonData skeletonData = new SkeletonData(); skeletonData.setName(file.nameWithoutExtension()); JsonValue root = new JsonReader().parse(file); // Bones. for (JsonValue boneMap = root.getChild("bones"); boneMap != null; boneMap = boneMap.next()) { BoneData parent = null; String parentName = boneMap.getString("parent", null); if (parentName != null) { parent = skeletonData.findBone(parentName); if (parent == null) throw new SerializationException("Parent bone not found: " + parentName); } BoneData boneData = new BoneData(boneMap.getString("name"), parent); boneData.length = boneMap.getFloat("length", 0) * scale; boneData.x = boneMap.getFloat("x", 0) * scale; boneData.y = boneMap.getFloat("y", 0) * scale; boneData.rotation = boneMap.getFloat("rotation", 0); boneData.scaleX = boneMap.getFloat("scaleX", 1); boneData.scaleY = boneMap.getFloat("scaleY", 1); boneData.inheritScale = boneMap.getBoolean("inheritScale", true); boneData.inheritRotation = boneMap.getBoolean("inheritRotation", true); skeletonData.addBone(boneData); } // Slots. for (JsonValue slotMap = root.getChild("slots"); slotMap != null; slotMap = slotMap.next()) { String slotName = slotMap.getString("name"); String boneName = slotMap.getString("bone"); BoneData boneData = skeletonData.findBone(boneName); if (boneData == null) throw new SerializationException("Slot bone not found: " + boneName); SlotData slotData = new SlotData(slotName, boneData); String color = slotMap.getString("color", null); if (color != null) slotData.getColor().set(Color.valueOf(color)); slotData.setAttachmentName(slotMap.getString("attachment", null)); slotData.additiveBlending = slotMap.getBoolean("additive", false); skeletonData.addSlot(slotData); } // Skins. for (JsonValue skinMap = root.getChild("skins"); skinMap != null; skinMap = skinMap.next()) { Skin skin = new Skin(skinMap.name()); for (JsonValue slotEntry = skinMap.child(); slotEntry != null; slotEntry = slotEntry.next()) { int slotIndex = skeletonData.findSlotIndex(slotEntry.name()); for (JsonValue entry = slotEntry.child(); entry != null; entry = entry.next()) { Attachment attachment = readAttachment(skin, entry.name(), entry); if (attachment != null) skin.addAttachment(slotIndex, entry.name(), attachment); } } skeletonData.addSkin(skin); if (skin.name.equals("default")) skeletonData.setDefaultSkin(skin); } // Animations. for (JsonValue animationMap = root.getChild("animations"); animationMap != null; animationMap = animationMap.next()) readAnimation(animationMap.name(), animationMap, skeletonData); skeletonData.bones.shrink(); skeletonData.slots.shrink(); skeletonData.skins.shrink(); skeletonData.animations.shrink(); return skeletonData; }
private void readAnimation(String name, JsonValue map, SkeletonData skeletonData) { Array<Timeline> timelines = new Array(); float duration = 0; for (JsonValue boneMap = map.getChild("bones"); boneMap != null; boneMap = boneMap.next()) { int boneIndex = skeletonData.findBoneIndex(boneMap.name()); if (boneIndex == -1) throw new SerializationException("Bone not found: " + boneMap.name()); for (JsonValue timelineMap = boneMap.child(); timelineMap != null; timelineMap = timelineMap.next()) { String timelineName = timelineMap.name(); if (timelineName.equals(TIMELINE_ROTATE)) { RotateTimeline timeline = new RotateTimeline(timelineMap.size()); timeline.setBoneIndex(boneIndex); int frameIndex = 0; for (JsonValue valueMap = timelineMap.child(); valueMap != null; valueMap = valueMap.next()) { float time = valueMap.getFloat("time"); timeline.setFrame(frameIndex, time, valueMap.getFloat("angle")); readCurve(timeline, frameIndex, valueMap); frameIndex++; } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 2 - 2]); } else if (timelineName.equals(TIMELINE_TRANSLATE) || timelineName.equals(TIMELINE_SCALE)) { TranslateTimeline timeline; float timelineScale = 1; if (timelineName.equals(TIMELINE_SCALE)) timeline = new ScaleTimeline(timelineMap.size()); else { timeline = new TranslateTimeline(timelineMap.size()); timelineScale = scale; } timeline.setBoneIndex(boneIndex); int frameIndex = 0; for (JsonValue valueMap = timelineMap.child(); valueMap != null; valueMap = valueMap.next()) { float time = valueMap.getFloat("time"); float x = valueMap.getFloat("x", 0), y = valueMap.getFloat("y", 0); timeline.setFrame(frameIndex, time, x * timelineScale, y * timelineScale); readCurve(timeline, frameIndex, valueMap); frameIndex++; } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 3 - 3]); } else throw new RuntimeException( "Invalid timeline type for a bone: " + timelineName + " (" + boneMap.name() + ")"); } } for (JsonValue slotMap = map.getChild("slots"); slotMap != null; slotMap = slotMap.next()) { int slotIndex = skeletonData.findSlotIndex(slotMap.name()); for (JsonValue timelineMap = slotMap.child(); timelineMap != null; timelineMap = timelineMap.next()) { String timelineName = timelineMap.name(); if (timelineName.equals(TIMELINE_COLOR)) { ColorTimeline timeline = new ColorTimeline(timelineMap.size()); timeline.setSlotIndex(slotIndex); int frameIndex = 0; for (JsonValue valueMap = timelineMap.child(); valueMap != null; valueMap = valueMap.next()) { float time = valueMap.getFloat("time"); Color color = Color.valueOf(valueMap.getString("color")); timeline.setFrame(frameIndex, time, color.r, color.g, color.b, color.a); readCurve(timeline, frameIndex, valueMap); frameIndex++; } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 5 - 5]); } else if (timelineName.equals(TIMELINE_ATTACHMENT)) { AttachmentTimeline timeline = new AttachmentTimeline(timelineMap.size()); timeline.setSlotIndex(slotIndex); int frameIndex = 0; for (JsonValue valueMap = timelineMap.child(); valueMap != null; valueMap = valueMap.next()) { float time = valueMap.getFloat("time"); timeline.setFrame(frameIndex++, time, valueMap.getString("name")); } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]); } else throw new RuntimeException( "Invalid timeline type for a slot: " + timelineName + " (" + slotMap.name() + ")"); } } timelines.shrink(); skeletonData.addAnimation(new Animation(name, timelines, duration)); }