|
@@ -60,79 +60,4 @@ object DataParser {
|
|
|
}
|
|
|
return musics
|
|
|
}
|
|
|
-
|
|
|
- fun parseStory(arrayList: ArrayList<JSONObject>): Story {
|
|
|
- val story = Story()
|
|
|
- for (jsonObject in arrayList) {
|
|
|
- val scene = parseScene(jsonObject)
|
|
|
- story.scenes.add(scene)
|
|
|
- }
|
|
|
- return story
|
|
|
- }
|
|
|
-
|
|
|
- private fun parseScene(jsonObject: JSONObject): Scene {
|
|
|
- val scene = Scene()
|
|
|
-
|
|
|
- val layer0 = parseLayer(JSONObject(jsonObject.optString("layer0")))
|
|
|
- val layer1 = parseLayer(JSONObject(jsonObject.optString("layer1")))
|
|
|
- val layer2 = parseLayer(JSONObject(jsonObject.optString("layer2")))
|
|
|
- val layer3 = parseLayer(JSONObject(jsonObject.optString("layer3")))
|
|
|
- val layer4 = parseLayer(JSONObject(jsonObject.optString("layer4")))
|
|
|
-
|
|
|
- scene.layers.add(layer0)
|
|
|
- scene.layers.add(layer1)
|
|
|
- scene.layers.add(layer2)
|
|
|
- scene.layers.add(layer3)
|
|
|
- scene.layers.add(layer4)
|
|
|
-
|
|
|
- scene.record = parseRecord(jsonObject.optJSONObject("record"))
|
|
|
-
|
|
|
- scene.backgroundPath = (Environment.getExternalStorageDirectory().toString()
|
|
|
- + "/Android/yuheng/" + jsonObject.optString("background"))
|
|
|
-
|
|
|
- return scene
|
|
|
- }
|
|
|
-
|
|
|
- private fun parseRecord(jsonObject: JSONObject): Record {
|
|
|
- val record = Record()
|
|
|
- record.period = jsonObject.optLong("period")
|
|
|
- val tracks = jsonObject.optJSONArray("tracks")
|
|
|
- tracks?.let {
|
|
|
- for (i in 0 until it.length()) {
|
|
|
- val track = parseTrack(tracks.optJSONObject(i))
|
|
|
- record.tracks.add(track)
|
|
|
- }
|
|
|
- }
|
|
|
- return record
|
|
|
- }
|
|
|
-
|
|
|
- private fun parseTrack(jsonObject: JSONObject): Track {
|
|
|
- val track = Track()
|
|
|
- track.time = jsonObject.optLong("time")
|
|
|
- track.positionX = jsonObject.optInt("positionX")
|
|
|
- return track
|
|
|
- }
|
|
|
-
|
|
|
- private fun parseLayer(jsonObject: JSONObject): Layer {
|
|
|
- val layer = Layer()
|
|
|
- layer.id = jsonObject.optInt("id")
|
|
|
- layer.name = jsonObject.optString("name")
|
|
|
- val actors = jsonObject.optJSONArray("actor")
|
|
|
- for (i in 0 until actors.length()) {
|
|
|
- val actor = parseActor(actors.optJSONObject(i))
|
|
|
- layer.actors.add(actor)
|
|
|
- }
|
|
|
- return layer
|
|
|
- }
|
|
|
-
|
|
|
- private fun parseActor(jsonObject: JSONObject): Actor {
|
|
|
- val actor = Actor()
|
|
|
- actor.resourcePath = (Environment.getExternalStorageDirectory().toString()
|
|
|
- + "/Android/yuheng/" + jsonObject.optString("resource"))
|
|
|
- actor.positionX = jsonObject.optInt("positionX")
|
|
|
- actor.positionY = jsonObject.optInt("positionY")
|
|
|
- actor.sideLength = jsonObject.optInt("size")
|
|
|
- return actor
|
|
|
- }
|
|
|
-
|
|
|
}
|