From b69e13c3ee79575db9244741672824ba8506eea2 Mon Sep 17 00:00:00 2001 From: Jakob Gillich Date: Sun, 26 Mar 2023 16:01:33 +0000 Subject: [PATCH] fix enum keyword warnings --- .../scala/net/psforever/packet/PSPacket.scala | 38 +++++------ .../packet/game/GenericActionMessage.scala | 67 ++++++++++--------- .../packet/game/InvalidTerrainMessage.scala | 15 ++--- .../game/SquadDefinitionActionMessage.scala | 4 +- .../packet/game/SquadMemberEvent.scala | 11 ++- .../packet/game/SquadWaypointRequest.scala | 2 +- .../net/psforever/types/CharacterSex.scala | 38 ++++++----- .../net/psforever/types/ExperienceType.scala | 6 +- .../psforever/types/MeritCommendation.scala | 4 +- .../net/psforever/types/OxygenState.scala | 2 +- .../scala/net/psforever/util/Config.scala | 8 +-- 11 files changed, 102 insertions(+), 93 deletions(-) diff --git a/src/main/scala/net/psforever/packet/PSPacket.scala b/src/main/scala/net/psforever/packet/PSPacket.scala index b03be3dde..1a5c9037b 100644 --- a/src/main/scala/net/psforever/packet/PSPacket.scala +++ b/src/main/scala/net/psforever/packet/PSPacket.scala @@ -89,20 +89,20 @@ object PacketHelpers { } /** Create a Codec for an enumeration type that can correctly represent its value - * @param enum the enumeration type to create a codec for + * @param e the enumeration type to create a codec for * @param storageCodec the Codec used for actually representing the value * @tparam E The inferred type * @return Generated codec */ - def createEnumerationCodec[E <: Enumeration](enum: E, storageCodec: Codec[Int]): Codec[E#Value] = { + def createEnumerationCodec[E <: Enumeration](e: E, storageCodec: Codec[Int]): Codec[E#Value] = { type Struct = Int :: HNil val struct: Codec[Struct] = storageCodec.hlist val primitiveLimit = Math.pow(2, storageCodec.sizeBound.exact.get.toDouble) // Assure that the enum will always be able to fit in a N-bit int assert( - enum.maxId <= primitiveLimit, - enum.getClass.getCanonicalName + s": maxId exceeds primitive type (limit of $primitiveLimit, maxId ${enum.maxId})" + e.maxId <= primitiveLimit, + e.getClass.getCanonicalName + s": maxId exceeds primitive type (limit of $primitiveLimit, maxId ${e.maxId})" ) def to(pkt: E#Value): Struct = { @@ -113,13 +113,13 @@ object PacketHelpers { struct match { case enumVal :: HNil => // verify that this int can match the enum - val first = enum.values.firstKey.id - val last = enum.maxId - 1 + val first = e.values.firstKey.id + val last = e.maxId - 1 if (enumVal >= first && enumVal <= last) - Attempt.successful(enum(enumVal)) + Attempt.successful(e(enumVal)) else - Attempt.failure(Err(s"Expected ${enum} with ID between [${first}, ${last}], but got '${enumVal}'")) + Attempt.failure(Err(s"Expected ${e} with ID between [${first}, ${last}], but got '${enumVal}'")) } struct.narrow[E#Value](from, to) @@ -130,12 +130,12 @@ object PacketHelpers { * NOTE: enumerations in scala can't be represented by more than an Int anyways, so this conversion shouldn't matter. * This is only to overload createEnumerationCodec to work with uint32[L] codecs (which are Long) */ - def createLongEnumerationCodec[E <: Enumeration](enum: E, storageCodec: Codec[Long]): Codec[E#Value] = { - createEnumerationCodec(enum, storageCodec.xmap[Int](_.toInt, _.toLong)) + def createLongEnumerationCodec[E <: Enumeration](e: E, storageCodec: Codec[Long]): Codec[E#Value] = { + createEnumerationCodec(e, storageCodec.xmap[Int](_.toInt, _.toLong)) } /** Create a Codec for enumeratum's IntEnum type */ - def createIntEnumCodec[E <: IntEnumEntry](enum: IntEnum[E], storageCodec: Codec[Int]): Codec[E] = { + def createIntEnumCodec[E <: IntEnumEntry](e: IntEnum[E], storageCodec: Codec[Int]): Codec[E] = { type Struct = Int :: HNil val struct: Codec[Struct] = storageCodec.hlist @@ -146,36 +146,36 @@ object PacketHelpers { def from(struct: Struct): Attempt[E] = struct match { case enumVal :: HNil => - enum.withValueOpt(enumVal) match { + e.withValueOpt(enumVal) match { case Some(v) => Attempt.successful(v) case None => - Attempt.failure(Err(s"Enum value '${enumVal}' not found in values '${enum.values.toString()}'")) + Attempt.failure(Err(s"Enum value '${enumVal}' not found in values '${e.values.toString()}'")) } } struct.narrow[E](from, to) } - def createLongIntEnumCodec[E <: IntEnumEntry](enum: IntEnum[E], storageCodec: Codec[Long]): Codec[E] = { - createIntEnumCodec(enum, storageCodec.xmap[Int](_.toInt, _.toLong)) + def createLongIntEnumCodec[E <: IntEnumEntry](e: IntEnum[E], storageCodec: Codec[Long]): Codec[E] = { + createIntEnumCodec(e, storageCodec.xmap[Int](_.toInt, _.toLong)) } /** Create a Codec for enumeratum's Enum type */ - def createEnumCodec[E <: EnumEntry](enum: Enum[E], storageCodec: Codec[Int]): Codec[E] = { + def createEnumCodec[E <: EnumEntry](e: Enum[E], storageCodec: Codec[Int]): Codec[E] = { type Struct = Int :: HNil val struct: Codec[Struct] = storageCodec.hlist def to(pkt: E): Struct = { - enum.indexOf(pkt) :: HNil + e.indexOf(pkt) :: HNil } def from(struct: Struct): Attempt[E] = struct match { case enumVal :: HNil => - enum.valuesToIndex.find(_._2 == enumVal) match { + e.valuesToIndex.find(_._2 == enumVal) match { case Some((v, _)) => Attempt.successful(v) case None => - Attempt.failure(Err(s"Enum index '${enumVal}' not found in values '${enum.valuesToIndex.toString()}'")) + Attempt.failure(Err(s"Enum index '${enumVal}' not found in values '${e.valuesToIndex.toString()}'")) } } diff --git a/src/main/scala/net/psforever/packet/game/GenericActionMessage.scala b/src/main/scala/net/psforever/packet/game/GenericActionMessage.scala index d1230be72..39111f51a 100644 --- a/src/main/scala/net/psforever/packet/game/GenericActionMessage.scala +++ b/src/main/scala/net/psforever/packet/game/GenericActionMessage.scala @@ -11,32 +11,32 @@ sealed abstract class GenericAction(val value: Int) extends IntEnumEntry object GenericAction extends IntEnum[GenericAction] { val values: IndexedSeq[GenericAction] = findValues - final case object ShowMosquitoRadar extends GenericAction(value = 3) - final case object HideMosquitoRadar extends GenericAction(value = 4) - final case object MissileLock extends GenericAction(value = 7) - final case object WaspMissileLock extends GenericAction(value = 8) - final case object TRekLock extends GenericAction(value = 9) - final case object DropSpecialItem extends GenericAction(value = 11) - final case object FacilityCaptureFanfare extends GenericAction(value = 12) - final case object NewCharacterBasicTrainingPrompt extends GenericAction(value = 14) - final case object MaxAnchorsExtend_RCV extends GenericAction(value = 15) - final case object MaxAnchorsRelease_RCV extends GenericAction(value = 16) - final case object MaxSpecialEffect_RCV extends GenericAction(value = 20) - final case object StopMaxSpecialEffect_RCV extends GenericAction(value = 21) - final case object CavernFacilityCapture extends GenericAction(value = 22) - final case object CavernFacilityKill extends GenericAction(value = 23) - final case object Imprinted extends GenericAction(value = 24) - final case object NoLongerImprinted extends GenericAction(value = 25) - final case object PurchaseTimersReset extends GenericAction(value = 27) - final case object LeaveWarpQueue_RCV extends GenericAction(value = 28) - final case object AwayFromKeyboard_RCV extends GenericAction(value = 29) - final case object BackInGame_RCV extends GenericAction(value = 30) - final case object FirstPersonViewWithEffect extends GenericAction(value = 31) + final case object ShowMosquitoRadar extends GenericAction(value = 3) + final case object HideMosquitoRadar extends GenericAction(value = 4) + final case object MissileLock extends GenericAction(value = 7) + final case object WaspMissileLock extends GenericAction(value = 8) + final case object TRekLock extends GenericAction(value = 9) + final case object DropSpecialItem extends GenericAction(value = 11) + final case object FacilityCaptureFanfare extends GenericAction(value = 12) + final case object NewCharacterBasicTrainingPrompt extends GenericAction(value = 14) + final case object MaxAnchorsExtend_RCV extends GenericAction(value = 15) + final case object MaxAnchorsRelease_RCV extends GenericAction(value = 16) + final case object MaxSpecialEffect_RCV extends GenericAction(value = 20) + final case object StopMaxSpecialEffect_RCV extends GenericAction(value = 21) + final case object CavernFacilityCapture extends GenericAction(value = 22) + final case object CavernFacilityKill extends GenericAction(value = 23) + final case object Imprinted extends GenericAction(value = 24) + final case object NoLongerImprinted extends GenericAction(value = 25) + final case object PurchaseTimersReset extends GenericAction(value = 27) + final case object LeaveWarpQueue_RCV extends GenericAction(value = 28) + final case object AwayFromKeyboard_RCV extends GenericAction(value = 29) + final case object BackInGame_RCV extends GenericAction(value = 30) + final case object FirstPersonViewWithEffect extends GenericAction(value = 31) final case object FirstPersonViewFailToDeconstruct extends GenericAction(value = 32) - final case object FailToDeconstruct extends GenericAction(value = 33) - final case object LookingForSquad_RCV extends GenericAction(value = 36) - final case object NotLookingForSquad_RCV extends GenericAction(value = 37) - final case object Unknown45 extends GenericAction(value = 45) + final case object FailToDeconstruct extends GenericAction(value = 33) + final case object LookingForSquad_RCV extends GenericAction(value = 36) + final case object NotLookingForSquad_RCV extends GenericAction(value = 37) + final case object Unknown45 extends GenericAction(value = 45) final case class Unknown(override val value: Int) extends GenericAction(value) } @@ -55,16 +55,19 @@ object GenericActionMessage extends Marshallable[GenericActionMessage] { def apply(i: Int): GenericActionMessage = { GenericActionMessage(GenericAction.values.find { _.value == i } match { case Some(enum) => enum - case None => GenericAction.Unknown(i) + case None => GenericAction.Unknown(i) }) } - private val genericActionCodec = uint(bits = 6).xmap[GenericAction]({ - i => GenericAction.values.find { _.value == i } match { - case Some(enum) => enum - case None => GenericAction.Unknown(i) - } - }, enum => enum.value) + private val genericActionCodec = uint(bits = 6).xmap[GenericAction]( + { i => + GenericAction.values.find { _.value == i } match { + case Some(enum) => enum + case None => GenericAction.Unknown(i) + } + }, + e => e.value + ) implicit val codec: Codec[GenericActionMessage] = ("action" | genericActionCodec).as[GenericActionMessage] } diff --git a/src/main/scala/net/psforever/packet/game/InvalidTerrainMessage.scala b/src/main/scala/net/psforever/packet/game/InvalidTerrainMessage.scala index a252d2ab1..383836426 100644 --- a/src/main/scala/net/psforever/packet/game/InvalidTerrainMessage.scala +++ b/src/main/scala/net/psforever/packet/game/InvalidTerrainMessage.scala @@ -15,7 +15,7 @@ object TerrainCondition extends Enumeration { type Type = Value val Safe, Unsafe = Value - implicit val codec = PacketHelpers.createEnumerationCodec(enum = this, uint(bits = 1)) + implicit val codec = PacketHelpers.createEnumerationCodec(e = this, uint(bits = 1)) } /** @@ -28,11 +28,11 @@ object TerrainCondition extends Enumeration { * @param pos the vehicle's current position in the game world */ final case class InvalidTerrainMessage( - player_guid: PlanetSideGUID, - vehicle_guid: PlanetSideGUID, - proximity_alert: TerrainCondition.Value, - pos: Vector3 - ) extends PlanetSideGamePacket { + player_guid: PlanetSideGUID, + vehicle_guid: PlanetSideGUID, + proximity_alert: TerrainCondition.Value, + pos: Vector3 +) extends PlanetSideGamePacket { type Packet = InvalidTerrainMessage def opcode = GamePacketOpcode.InvalidTerrainMessage def encode = InvalidTerrainMessage.encode(this) @@ -40,8 +40,7 @@ final case class InvalidTerrainMessage( object InvalidTerrainMessage extends Marshallable[InvalidTerrainMessage] { - implicit val codec: Codec[InvalidTerrainMessage] = ( - ("player_guid" | PlanetSideGUID.codec) :: + implicit val codec: Codec[InvalidTerrainMessage] = (("player_guid" | PlanetSideGUID.codec) :: ("vehicle_guid" | PlanetSideGUID.codec) :: ("proximity_alert" | TerrainCondition.codec) :: ("pos" | floatL :: floatL :: floatL).narrow[Vector3]( diff --git a/src/main/scala/net/psforever/packet/game/SquadDefinitionActionMessage.scala b/src/main/scala/net/psforever/packet/game/SquadDefinitionActionMessage.scala index 14358c0b6..abc7e790a 100644 --- a/src/main/scala/net/psforever/packet/game/SquadDefinitionActionMessage.scala +++ b/src/main/scala/net/psforever/packet/game/SquadDefinitionActionMessage.scala @@ -22,7 +22,7 @@ object SquadAction { val AnyPositions, AvailablePositions, SomeCertifications, AllCertifications = Value - implicit val codec: Codec[SearchMode.Value] = PacketHelpers.createEnumerationCodec(enum = this, uint(bits = 3)) + implicit val codec: Codec[SearchMode.Value] = PacketHelpers.createEnumerationCodec(e = this, uint(bits = 3)) } final case class DisplaySquad() extends SquadAction(code = 0) @@ -280,7 +280,7 @@ object SquadAction { val squadListDecoratorCodec = ( SquadListDecoration.codec :: - ignore(size = 3) + ignore(size = 3) ).xmap[SquadListDecorator]( { case value :: _ :: HNil => SquadListDecorator(value) diff --git a/src/main/scala/net/psforever/packet/game/SquadMemberEvent.scala b/src/main/scala/net/psforever/packet/game/SquadMemberEvent.scala index 3bd5c9490..69117ced1 100644 --- a/src/main/scala/net/psforever/packet/game/SquadMemberEvent.scala +++ b/src/main/scala/net/psforever/packet/game/SquadMemberEvent.scala @@ -11,7 +11,7 @@ object MemberEvent extends Enumeration { val Add, Remove, Promote, UpdateZone, Outfit = Value - implicit val codec = PacketHelpers.createEnumerationCodec(enum = this, uint(bits = 3)) + implicit val codec = PacketHelpers.createEnumerationCodec(e = this, uint(bits = 3)) } final case class SquadMemberEvent( @@ -58,13 +58,18 @@ object SquadMemberEvent extends Marshallable[SquadMemberEvent] { ("unk2" | uint16L) :: ("char_id" | uint32L) :: ("position" | uint4) :: - ("player_name" | conditional(action == MemberEvent.Add, PacketHelpers.encodedWideStringAligned(adjustment = 1))) :: + ("player_name" | conditional( + action == MemberEvent.Add, + PacketHelpers.encodedWideStringAligned(adjustment = 1) + )) :: ("zone_number" | conditional(action == MemberEvent.Add || action == MemberEvent.UpdateZone, uint16L)) :: ("outfit_id" | conditional(action == MemberEvent.Add || action == MemberEvent.Outfit, uint32L)) }).exmap[SquadMemberEvent]( { case action :: unk2 :: char_id :: member_position :: player_name :: zone_number :: outfit_id :: HNil => - Attempt.Successful(SquadMemberEvent(action, unk2, char_id, member_position, player_name, zone_number, outfit_id)) + Attempt.Successful( + SquadMemberEvent(action, unk2, char_id, member_position, player_name, zone_number, outfit_id) + ) }, { case SquadMemberEvent( diff --git a/src/main/scala/net/psforever/packet/game/SquadWaypointRequest.scala b/src/main/scala/net/psforever/packet/game/SquadWaypointRequest.scala index 77637cae7..5ba9109f5 100644 --- a/src/main/scala/net/psforever/packet/game/SquadWaypointRequest.scala +++ b/src/main/scala/net/psforever/packet/game/SquadWaypointRequest.scala @@ -16,7 +16,7 @@ object WaypointEventAction extends Enumeration { val Add, Unknown1, Remove, Unknown3 //unconfirmed = Value - implicit val codec: Codec[WaypointEventAction.Value] = PacketHelpers.createEnumerationCodec(enum = this, uint2) + implicit val codec: Codec[WaypointEventAction.Value] = PacketHelpers.createEnumerationCodec(e = this, uint2) } /** diff --git a/src/main/scala/net/psforever/types/CharacterSex.scala b/src/main/scala/net/psforever/types/CharacterSex.scala index 28b8d237f..e19a2bc49 100644 --- a/src/main/scala/net/psforever/types/CharacterSex.scala +++ b/src/main/scala/net/psforever/types/CharacterSex.scala @@ -11,11 +11,11 @@ import scodec.codecs.uint2L * Blame the lack of gender dysphoria on the Terran Republic. */ sealed abstract class CharacterSex( - val value: Int, - val pronounSubject: String, - val pronounObject: String, - val possessive: String - ) extends IntEnumEntry { + val value: Int, + val pronounSubject: String, + val pronounObject: String, + val possessive: String +) extends IntEnumEntry { def possessiveNoObject: String = possessive } @@ -25,21 +25,23 @@ sealed abstract class CharacterSex( object CharacterSex extends IntEnum[CharacterSex] { val values = findValues - case object Male extends CharacterSex( - value = 1, - pronounSubject = "he", - pronounObject = "him", - possessive = "his" - ) + case object Male + extends CharacterSex( + value = 1, + pronounSubject = "he", + pronounObject = "him", + possessive = "his" + ) - case object Female extends CharacterSex( - value = 2, - pronounSubject = "she", - pronounObject = "her", - possessive = "her" - ) { + case object Female + extends CharacterSex( + value = 2, + pronounSubject = "she", + pronounObject = "her", + possessive = "her" + ) { override def possessiveNoObject: String = "hers" } - implicit val codec = PacketHelpers.createIntEnumCodec(enum = this, uint2L) + implicit val codec = PacketHelpers.createIntEnumCodec(e = this, uint2L) } diff --git a/src/main/scala/net/psforever/types/ExperienceType.scala b/src/main/scala/net/psforever/types/ExperienceType.scala index 204135030..4f6b94209 100644 --- a/src/main/scala/net/psforever/types/ExperienceType.scala +++ b/src/main/scala/net/psforever/types/ExperienceType.scala @@ -11,9 +11,9 @@ sealed abstract class ExperienceType(val value: Int) extends IntEnumEntry object ExperienceType extends IntEnum[ExperienceType] { val values: IndexedSeq[ExperienceType] = findValues - case object Normal extends ExperienceType(value = 0) - case object Support extends ExperienceType(value = 2) + case object Normal extends ExperienceType(value = 0) + case object Support extends ExperienceType(value = 2) case object RabbitBall extends ExperienceType(value = 4) - implicit val codec: Codec[ExperienceType] = PacketHelpers.createIntEnumCodec(enum = this, uint(bits = 3)) + implicit val codec: Codec[ExperienceType] = PacketHelpers.createIntEnumCodec(e = this, uint(bits = 3)) } diff --git a/src/main/scala/net/psforever/types/MeritCommendation.scala b/src/main/scala/net/psforever/types/MeritCommendation.scala index 869dce7fa..99c8ccb49 100644 --- a/src/main/scala/net/psforever/types/MeritCommendation.scala +++ b/src/main/scala/net/psforever/types/MeritCommendation.scala @@ -165,8 +165,8 @@ object MeritCommendation extends Enumeration { { case MeritCommendation.None => Attempt.successful(0xffffffffL) - case enum => - Attempt.successful(enum.id.toLong) + case e => + Attempt.successful(e.id.toLong) } ) } diff --git a/src/main/scala/net/psforever/types/OxygenState.scala b/src/main/scala/net/psforever/types/OxygenState.scala index be272f0fe..56f27166a 100644 --- a/src/main/scala/net/psforever/types/OxygenState.scala +++ b/src/main/scala/net/psforever/types/OxygenState.scala @@ -23,5 +23,5 @@ object OxygenState extends Enum[OxygenState] { case object Recovery extends OxygenState case object Suffocation extends OxygenState - implicit val codec: Codec[OxygenState] = PacketHelpers.createEnumCodec(enum = this, uint(bits = 1)) + implicit val codec: Codec[OxygenState] = PacketHelpers.createEnumCodec(e = this, uint(bits = 1)) } diff --git a/src/main/scala/net/psforever/util/Config.scala b/src/main/scala/net/psforever/util/Config.scala index bd2d1c718..a3e3335f4 100644 --- a/src/main/scala/net/psforever/util/Config.scala +++ b/src/main/scala/net/psforever/util/Config.scala @@ -25,12 +25,12 @@ object Config { } implicit def enumeratumIntConfigConvert[A <: IntEnumEntry](implicit - enum: IntEnum[A], + e: IntEnum[A], ct: ClassTag[A] ): ConfigConvert[A] = viaNonEmptyStringOpt[A]( v => - enum.values.toList.collectFirst { + e.values.toList.collectFirst { case e: ServerType if e.name == v => e.asInstanceOf[A] case e: BattleRank if e.value.toString == v => e.asInstanceOf[A] case e: CommandRank if e.value.toString == v => e.asInstanceOf[A] @@ -40,12 +40,12 @@ object Config { ) implicit def enumeratumConfigConvert[A <: EnumEntry](implicit - enum: Enum[A], + e: Enum[A], ct: ClassTag[A] ): ConfigConvert[A] = viaNonEmptyStringOpt[A]( v => - enum.values.toList.collectFirst { + e.values.toList.collectFirst { case e if e.toString.toLowerCase == v.toLowerCase => e.asInstanceOf[A] }, _.toString