Skip to content

Commit

Permalink
JSON structure change
Browse files Browse the repository at this point in the history
  • Loading branch information
sylux6 committed Jan 6, 2020
1 parent d15674e commit 5ec89e5
Show file tree
Hide file tree
Showing 4 changed files with 395 additions and 192 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

Versions **< 3.0.0** are **DEPRECATED**

## 3.0.0 (2020-01-06)

### Breaking changes

- **Ship**:
- `buildTime` type change from `String` to `ShipConstruction`.
- `misc.voice` type change from `String` to `Url`.

## 2.0.1 (2019-12-11)

### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data class SkinInfo (
val enClient: String,
val cnClient: String,
val jpClient: String,
val obtainedFrom: String,
val obtainedFrom: String?,
val cost: Int,
val isLive2D: Boolean
)
Expand Down Expand Up @@ -112,6 +112,24 @@ data class Url (
val url: String
)

/**
* Construction info of a ship
* @param constructionTime
* @param light
* @param heavy
* @param aviation
* @param limited
* @param exchange
*/
data class ShipConstruction (
val constructionTime: String,
val light: Boolean,
val heavy: Boolean,
val aviation: Boolean,
val limited: Boolean,
val exchange: Boolean
)

/**
* Miscellaneous info of a ship
* @param voice
Expand All @@ -121,7 +139,7 @@ data class Url (
* @param pixiv
*/
data class Miscellaneous (
val voice: String,
val voice: Url?,
val twitter: Url?,
val artist: String?,
val web: Url?,
Expand Down Expand Up @@ -153,10 +171,11 @@ data class Ship (
val hullType: String,
val thumbnail: String,
val skins: List<Skin>,
val buildTime: String,
val rarity: String,
val stars: Stars?,
val stats: Stats?,
// No construction info for unreleased ships
val construction: ShipConstruction?,
val misc: Miscellaneous?
)

Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ object ShipParser {
}
try {
return SkinInfo(
enClient = json.optString("EN Client"),
cnClient = json.optString("CN Client"),
jpClient = json.optString("JP Client"),
obtainedFrom = json.getString("Obtained From"),
enClient = json.optString("enClient"),
cnClient = json.optString("cnClient"),
jpClient = json.optString("jpClient"),
obtainedFrom = json.optString("obtainedFrom"),
cost = try {
json.optString("Cost").toInt()
json.optString("cost").toInt()
} catch (e: NumberFormatException) {
0
},
isLive2D = json.getString("Live2D Model") == "Yes"
isLive2D = json.getBoolean("live2DModel")
)
} catch (e: JSONException) {
throw e
Expand Down Expand Up @@ -68,20 +68,20 @@ object ShipParser {
private fun jsonToStatsDetails(json: JSONObject): StatsDetails {
try {
return StatsDetails(
speed = json.getInt("Speed"),
accuracy = json.getInt("Accuracy (Hit)"),
antiAir = json.getInt("Anti-air"),
antiSub = json.getInt("Anti-submarine warfare"),
armor = json.getString("Armor"),
aviation = json.getInt("Aviation"),
evasion = json.getInt("Evasion"),
firepower = json.getInt("Firepower"),
health = json.getInt("Health"),
luck = json.getInt("Luck"),
speed = json.getInt("speed"),
accuracy = json.getInt("accuracyHit"),
antiAir = json.getInt("antiair"),
antiSub = json.getInt("antisubmarineWarfare"),
armor = json.getString("armor"),
aviation = json.getInt("aviation"),
evasion = json.getInt("evasion"),
firepower = json.getInt("firepower"),
health = json.getInt("health"),
luck = json.getInt("luck"),
// FIXME: it should be defined
oil = json.optInt("Oil consumption"),
reload = json.getInt("Reload"),
torpedo = json.getInt("Torpedo")
oil = json.optInt("oilConsumption"),
reload = json.getInt("reload"),
torpedo = json.getInt("torpedo")
)
} catch (e: JSONException) {
throw e
Expand All @@ -96,17 +96,17 @@ object ShipParser {
return Stats(
level120 = jsonToStatsDetails(
json.getJSONObject(
"Level 120"
"level120"
)
),
level100 = jsonToStatsDetails(
json.getJSONObject(
"Level 100"
"level100"
)
),
base = jsonToStatsDetails(
json.getJSONObject(
"Base Stats"
"baseStats"
)
)
)
Expand Down Expand Up @@ -143,6 +143,26 @@ object ShipParser {
}
}

private fun jsonToConstruction(json: JSONObject?): ShipConstruction? {
if (json == null) {
return null
}
try {
val availability = json.getJSONObject("availableIn")
// FIXME: not always a boolean
return ShipConstruction(
constructionTime = json.getString("constructionTime"),
light = availability.optBoolean("light", true),
heavy = availability.optBoolean("heavy", true),
aviation = availability.optBoolean("aviation", true),
limited = availability.optBoolean("limited", true),
exchange = availability.optBoolean("exchange", true)
)
} catch (e: JSONException) {
throw e
}
}

private fun jsonToMiscellaneous(json: JSONObject?): Miscellaneous? {
if (json == null) {
return null
Expand All @@ -165,7 +185,11 @@ object ShipParser {
"twitter"
)
),
voice = json.optString("voice")
voice = jsonToUrl(
json.optJSONObject(
"voice"
)
)
)
} catch (e: JSONException) {
throw e
Expand All @@ -177,7 +201,6 @@ object ShipParser {
return Ship(
wikiUrl = json.getString("wikiUrl"),
id = json.getString("id"),
buildTime = json.optString("buildTime"),
hullType = json.getString("hullType"),
nationality = json.getString("nationality"),
rarity = json.getString("rarity"),
Expand All @@ -203,6 +226,11 @@ object ShipParser {
"stars"
)
),
construction = jsonToConstruction(
json.optJSONObject(
"construction"
)
),
misc = jsonToMiscellaneous(
json.optJSONObject(
"misc"
Expand Down
Loading

0 comments on commit 5ec89e5

Please sign in to comment.