Skip to content

Commit 5ec89e5

Browse files
committed
JSON structure change
1 parent d15674e commit 5ec89e5

File tree

4 files changed

+395
-192
lines changed

4 files changed

+395
-192
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
Versions **< 3.0.0** are **DEPRECATED**
4+
5+
## 3.0.0 (2020-01-06)
6+
7+
### Breaking changes
8+
9+
- **Ship**:
10+
- `buildTime` type change from `String` to `ShipConstruction`.
11+
- `misc.voice` type change from `String` to `Url`.
12+
313
## 2.0.1 (2019-12-11)
414

515
### Bug fixes

src/main/kotlin/com/github/azurapi/azurapikotlin/internal/entities/Ship.kt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data class SkinInfo (
2323
val enClient: String,
2424
val cnClient: String,
2525
val jpClient: String,
26-
val obtainedFrom: String,
26+
val obtainedFrom: String?,
2727
val cost: Int,
2828
val isLive2D: Boolean
2929
)
@@ -112,6 +112,24 @@ data class Url (
112112
val url: String
113113
)
114114

115+
/**
116+
* Construction info of a ship
117+
* @param constructionTime
118+
* @param light
119+
* @param heavy
120+
* @param aviation
121+
* @param limited
122+
* @param exchange
123+
*/
124+
data class ShipConstruction (
125+
val constructionTime: String,
126+
val light: Boolean,
127+
val heavy: Boolean,
128+
val aviation: Boolean,
129+
val limited: Boolean,
130+
val exchange: Boolean
131+
)
132+
115133
/**
116134
* Miscellaneous info of a ship
117135
* @param voice
@@ -121,7 +139,7 @@ data class Url (
121139
* @param pixiv
122140
*/
123141
data class Miscellaneous (
124-
val voice: String,
142+
val voice: Url?,
125143
val twitter: Url?,
126144
val artist: String?,
127145
val web: Url?,
@@ -153,10 +171,11 @@ data class Ship (
153171
val hullType: String,
154172
val thumbnail: String,
155173
val skins: List<Skin>,
156-
val buildTime: String,
157174
val rarity: String,
158175
val stars: Stars?,
159176
val stats: Stats?,
177+
// No construction info for unreleased ships
178+
val construction: ShipConstruction?,
160179
val misc: Miscellaneous?
161180
)
162181

src/main/kotlin/com/github/azurapi/azurapikotlin/utils/ShipParser.kt

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ object ShipParser {
2828
}
2929
try {
3030
return SkinInfo(
31-
enClient = json.optString("EN Client"),
32-
cnClient = json.optString("CN Client"),
33-
jpClient = json.optString("JP Client"),
34-
obtainedFrom = json.getString("Obtained From"),
31+
enClient = json.optString("enClient"),
32+
cnClient = json.optString("cnClient"),
33+
jpClient = json.optString("jpClient"),
34+
obtainedFrom = json.optString("obtainedFrom"),
3535
cost = try {
36-
json.optString("Cost").toInt()
36+
json.optString("cost").toInt()
3737
} catch (e: NumberFormatException) {
3838
0
3939
},
40-
isLive2D = json.getString("Live2D Model") == "Yes"
40+
isLive2D = json.getBoolean("live2DModel")
4141
)
4242
} catch (e: JSONException) {
4343
throw e
@@ -68,20 +68,20 @@ object ShipParser {
6868
private fun jsonToStatsDetails(json: JSONObject): StatsDetails {
6969
try {
7070
return StatsDetails(
71-
speed = json.getInt("Speed"),
72-
accuracy = json.getInt("Accuracy (Hit)"),
73-
antiAir = json.getInt("Anti-air"),
74-
antiSub = json.getInt("Anti-submarine warfare"),
75-
armor = json.getString("Armor"),
76-
aviation = json.getInt("Aviation"),
77-
evasion = json.getInt("Evasion"),
78-
firepower = json.getInt("Firepower"),
79-
health = json.getInt("Health"),
80-
luck = json.getInt("Luck"),
71+
speed = json.getInt("speed"),
72+
accuracy = json.getInt("accuracyHit"),
73+
antiAir = json.getInt("antiair"),
74+
antiSub = json.getInt("antisubmarineWarfare"),
75+
armor = json.getString("armor"),
76+
aviation = json.getInt("aviation"),
77+
evasion = json.getInt("evasion"),
78+
firepower = json.getInt("firepower"),
79+
health = json.getInt("health"),
80+
luck = json.getInt("luck"),
8181
// FIXME: it should be defined
82-
oil = json.optInt("Oil consumption"),
83-
reload = json.getInt("Reload"),
84-
torpedo = json.getInt("Torpedo")
82+
oil = json.optInt("oilConsumption"),
83+
reload = json.getInt("reload"),
84+
torpedo = json.getInt("torpedo")
8585
)
8686
} catch (e: JSONException) {
8787
throw e
@@ -96,17 +96,17 @@ object ShipParser {
9696
return Stats(
9797
level120 = jsonToStatsDetails(
9898
json.getJSONObject(
99-
"Level 120"
99+
"level120"
100100
)
101101
),
102102
level100 = jsonToStatsDetails(
103103
json.getJSONObject(
104-
"Level 100"
104+
"level100"
105105
)
106106
),
107107
base = jsonToStatsDetails(
108108
json.getJSONObject(
109-
"Base Stats"
109+
"baseStats"
110110
)
111111
)
112112
)
@@ -143,6 +143,26 @@ object ShipParser {
143143
}
144144
}
145145

146+
private fun jsonToConstruction(json: JSONObject?): ShipConstruction? {
147+
if (json == null) {
148+
return null
149+
}
150+
try {
151+
val availability = json.getJSONObject("availableIn")
152+
// FIXME: not always a boolean
153+
return ShipConstruction(
154+
constructionTime = json.getString("constructionTime"),
155+
light = availability.optBoolean("light", true),
156+
heavy = availability.optBoolean("heavy", true),
157+
aviation = availability.optBoolean("aviation", true),
158+
limited = availability.optBoolean("limited", true),
159+
exchange = availability.optBoolean("exchange", true)
160+
)
161+
} catch (e: JSONException) {
162+
throw e
163+
}
164+
}
165+
146166
private fun jsonToMiscellaneous(json: JSONObject?): Miscellaneous? {
147167
if (json == null) {
148168
return null
@@ -165,7 +185,11 @@ object ShipParser {
165185
"twitter"
166186
)
167187
),
168-
voice = json.optString("voice")
188+
voice = jsonToUrl(
189+
json.optJSONObject(
190+
"voice"
191+
)
192+
)
169193
)
170194
} catch (e: JSONException) {
171195
throw e
@@ -177,7 +201,6 @@ object ShipParser {
177201
return Ship(
178202
wikiUrl = json.getString("wikiUrl"),
179203
id = json.getString("id"),
180-
buildTime = json.optString("buildTime"),
181204
hullType = json.getString("hullType"),
182205
nationality = json.getString("nationality"),
183206
rarity = json.getString("rarity"),
@@ -203,6 +226,11 @@ object ShipParser {
203226
"stars"
204227
)
205228
),
229+
construction = jsonToConstruction(
230+
json.optJSONObject(
231+
"construction"
232+
)
233+
),
206234
misc = jsonToMiscellaneous(
207235
json.optJSONObject(
208236
"misc"

0 commit comments

Comments
 (0)