Skip to content

Commit 31392aa

Browse files
refactor: simplify nullable assignments in game setup properties, which gave compiler errors
1 parent a7a543b commit 31392aa

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

gui/src/main/kotlin/dev/robocode/tankroyale/gui/player/LiveBattlePlayer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class LiveBattlePlayer : BattlePlayer {
114114

115115
override fun restart() {
116116
if (isRunning.get()) {
117-
val eventOwner = Object()
117+
val eventOwner = Any()
118118
onGameAborted.subscribe(eventOwner, true) {
119119
startWithLastGameSetup()
120120
}

gui/src/main/kotlin/dev/robocode/tankroyale/gui/ui/config/SetupRulesDialog.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class SetupRulesPanel : JPanel(MigLayout("fill")) {
221221
}
222222
val valid = width != null && width in GameConstants.MIN_ARENA_SIZE..GameConstants.MAX_ARENA_SIZE
223223
if (valid) {
224-
gameSetup.arenaWidth = width!!
224+
gameSetup.arenaWidth = width
225225
} else {
226226
showMessage(
227227
String.format(
@@ -244,7 +244,7 @@ class SetupRulesPanel : JPanel(MigLayout("fill")) {
244244
}
245245
val valid = height != null && height in GameConstants.MIN_ARENA_SIZE..GameConstants.MAX_ARENA_SIZE
246246
if (valid) {
247-
gameSetup.arenaHeight = height!!
247+
gameSetup.arenaHeight = height
248248
} else {
249249
showMessage(
250250
String.format(
@@ -267,7 +267,7 @@ class SetupRulesPanel : JPanel(MigLayout("fill")) {
267267
}
268268
val valid = minNum != null && minNum in GameConstants.MIN_NUM_PARTICIPANTS..GameConstants.MAX_NUM_PARTICIPANTS
269269
if (valid) {
270-
gameSetup.minNumberOfParticipants = minNum!!
270+
gameSetup.minNumberOfParticipants = minNum
271271
} else {
272272
showMessage(
273273
String.format(
@@ -299,7 +299,7 @@ class SetupRulesPanel : JPanel(MigLayout("fill")) {
299299
val valid = minNum != null && maxNum != null &&
300300
(minNum in GameConstants.MIN_NUM_PARTICIPANTS..GameConstants.MAX_NUM_PARTICIPANTS) && (maxNum in minNum..GameConstants.MAX_NUM_PARTICIPANTS)
301301
if (valid) {
302-
gameSetup.maxNumberOfParticipants = maxNum!!
302+
gameSetup.maxNumberOfParticipants = maxNum
303303
} else {
304304
if (maxNum == null || maxNum > GameConstants.MAX_NUM_PARTICIPANTS) {
305305
showMessage(
@@ -325,7 +325,7 @@ class SetupRulesPanel : JPanel(MigLayout("fill")) {
325325
}
326326
val valid = numRounds != null && numRounds in 1..GameConstants.MAX_NUM_ROUNDS
327327
if (valid) {
328-
gameSetup.numberOfRounds = numRounds!!
328+
gameSetup.numberOfRounds = numRounds
329329
} else {
330330
showMessage(String.format(Messages.get("num_rounds_range"), GameConstants.MAX_NUM_ROUNDS))
331331

@@ -342,7 +342,7 @@ class SetupRulesPanel : JPanel(MigLayout("fill")) {
342342
}
343343
val valid = rate != null && rate > 0 && rate <= GameConstants.MAX_GUN_COOLING
344344
if (valid) {
345-
gameSetup.gunCoolingRate = rate!!
345+
gameSetup.gunCoolingRate = rate
346346
} else {
347347
showMessage(
348348
String.format(
@@ -364,7 +364,7 @@ class SetupRulesPanel : JPanel(MigLayout("fill")) {
364364
}
365365
val valid = turns != null && turns in 0..GameConstants.MAX_INACTIVITY_TURNS
366366
if (valid) {
367-
gameSetup.maxInactivityTurns = turns!!
367+
gameSetup.maxInactivityTurns = turns
368368
} else {
369369
showMessage(
370370
String.format(
@@ -386,7 +386,7 @@ class SetupRulesPanel : JPanel(MigLayout("fill")) {
386386
}
387387
val valid = timeout != null && timeout >= 0
388388
if (valid) {
389-
gameSetup.readyTimeout = timeout!!
389+
gameSetup.readyTimeout = timeout
390390
} else {
391391
showMessage(
392392
String.format(
@@ -408,7 +408,7 @@ class SetupRulesPanel : JPanel(MigLayout("fill")) {
408408
}
409409
val valid = timeout != null && timeout >= 0
410410
if (valid) {
411-
gameSetup.turnTimeout = timeout!!
411+
gameSetup.turnTimeout = timeout
412412
} else {
413413
showMessage(
414414
String.format(
@@ -421,4 +421,4 @@ class SetupRulesPanel : JPanel(MigLayout("fill")) {
421421
}
422422
return valid
423423
}
424-
}
424+
}

0 commit comments

Comments
 (0)