Replace fromOrdinal() with entries.getOrNull()

Signed-off-by: Graham <gpe@openrs2.org>
master
Graham 2 weeks ago
parent 38a341f8d2
commit 390affb319
  1. 2
      archive/src/main/kotlin/org/openrs2/archive/cache/CrossPollinator.kt
  2. 6
      cache/src/main/kotlin/org/openrs2/cache/Js5Compression.kt
  3. 11
      cache/src/main/kotlin/org/openrs2/cache/Js5CompressionType.kt
  4. 2
      cache/src/main/kotlin/org/openrs2/cache/Js5Pack.kt
  5. 12
      protocol/src/main/kotlin/org/openrs2/protocol/common/AntiAliasingMode.kt
  6. 12
      protocol/src/main/kotlin/org/openrs2/protocol/common/DisplayMode.kt
  7. 4
      protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/GameLoginPayload.kt

@ -197,7 +197,7 @@ public class CrossPollinator @Inject constructor(
}
private fun groupToFile(input: ByteBuf, expectedChecksum: Int): ByteBuf? {
val type = Js5CompressionType.fromOrdinal(input.readUnsignedByte().toInt())
val type = Js5CompressionType.entries.getOrNull(input.readUnsignedByte().toInt())
if (type != Js5CompressionType.GZIP) {
return null
}

@ -115,7 +115,7 @@ public object Js5Compression {
}
val typeId = input.readUnsignedByte().toInt()
val type = Js5CompressionType.fromOrdinal(typeId)
val type = Js5CompressionType.entries.getOrNull(typeId)
?: throw IOException("Invalid compression type: $typeId")
val len = input.readInt()
@ -178,7 +178,7 @@ public object Js5Compression {
}
val typeId = input.readUnsignedByte().toInt()
val type = Js5CompressionType.fromOrdinal(typeId)
val type = Js5CompressionType.entries.getOrNull(typeId)
?: throw IOException("Invalid compression type: $typeId")
val len = input.readInt()
@ -377,7 +377,7 @@ public object Js5Compression {
}
val typeId = buf.readUnsignedByte().toInt()
val type = Js5CompressionType.fromOrdinal(typeId)
val type = Js5CompressionType.entries.getOrNull(typeId)
?: throw IOException("Invalid compression type: $typeId")
val len = buf.readInt()

@ -37,15 +37,4 @@ public enum class Js5CompressionType {
LZMA -> Lzma.createHeaderlessOutputStream(output, Lzma.DEFAULT_COMPRESSION)
}
}
public companion object {
@JvmStatic
public fun fromOrdinal(ordinal: Int): Js5CompressionType? {
return if (ordinal >= 0 && ordinal < entries.size) {
entries[ordinal]
} else {
null
}
}
}
}

@ -151,7 +151,7 @@ public class Js5Pack private constructor(
private fun readCompressed(input: DataInputStream, alloc: ByteBufAllocator): ByteBuf {
val typeId = input.readUnsignedByte()
val type = Js5CompressionType.fromOrdinal(typeId)
val type = Js5CompressionType.entries.getOrNull(typeId)
?: throw IOException("Invalid compression type: $typeId")
val len = input.readInt()

@ -3,15 +3,5 @@ package org.openrs2.protocol.common
public enum class AntiAliasingMode {
NONE,
X2,
X4;
public companion object {
public fun fromOrdinal(ordinal: Int): AntiAliasingMode? {
return if (ordinal >= 0 && ordinal < entries.size) {
entries[ordinal]
} else {
null
}
}
}
X4
}

@ -4,15 +4,5 @@ public enum class DisplayMode {
SD,
HD_SMALL,
HD,
HD_FULLSCREEN;
public companion object {
public fun fromOrdinal(ordinal: Int): DisplayMode? {
return if (ordinal >= 0 && ordinal < entries.size) {
entries[ordinal]
} else {
null
}
}
}
HD_FULLSCREEN
}

@ -84,13 +84,13 @@ public data class GameLoginPayload(
val advertSuppressed = buf.readBoolean()
val clientSigned = buf.readBoolean()
val displayMode = DisplayMode.fromOrdinal(buf.readUnsignedByte().toInt())
val displayMode = DisplayMode.entries.getOrNull(buf.readUnsignedByte().toInt())
?: throw IllegalArgumentException("Invalid DisplayMode")
val canvasWidth = buf.readUnsignedShort()
val canvasHeight = buf.readUnsignedShort()
val antiAliasingMode = AntiAliasingMode.fromOrdinal(buf.readUnsignedByte().toInt())
val antiAliasingMode = AntiAliasingMode.entries.getOrNull(buf.readUnsignedByte().toInt())
?: throw IllegalArgumentException("Invalid AntiAliasingMode")
val uid = Uid.read(buf)

Loading…
Cancel
Save