mirror of
https://github.com/psforever/PSF-LoginServer.git
synced 2026-01-19 18:44:45 +00:00
fix enum keyword warnings
This commit is contained in:
parent
0772c27973
commit
b69e13c3ee
|
|
@ -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()}'"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,12 +59,15 @@ object GenericActionMessage extends Marshallable[GenericActionMessage] {
|
|||
})
|
||||
}
|
||||
|
||||
private val genericActionCodec = uint(bits = 6).xmap[GenericAction]({
|
||||
i => GenericAction.values.find { _.value == i } match {
|
||||
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)
|
||||
},
|
||||
e => e.value
|
||||
)
|
||||
|
||||
implicit val codec: Codec[GenericActionMessage] = ("action" | genericActionCodec).as[GenericActionMessage]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -32,7 +32,7 @@ final case class InvalidTerrainMessage(
|
|||
vehicle_guid: PlanetSideGUID,
|
||||
proximity_alert: TerrainCondition.Value,
|
||||
pos: Vector3
|
||||
) extends PlanetSideGamePacket {
|
||||
) 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](
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ sealed abstract class CharacterSex(
|
|||
val pronounSubject: String,
|
||||
val pronounObject: String,
|
||||
val possessive: String
|
||||
) extends IntEnumEntry {
|
||||
) extends IntEnumEntry {
|
||||
def possessiveNoObject: String = possessive
|
||||
}
|
||||
|
||||
|
|
@ -25,14 +25,16 @@ sealed abstract class CharacterSex(
|
|||
object CharacterSex extends IntEnum[CharacterSex] {
|
||||
val values = findValues
|
||||
|
||||
case object Male extends CharacterSex(
|
||||
case object Male
|
||||
extends CharacterSex(
|
||||
value = 1,
|
||||
pronounSubject = "he",
|
||||
pronounObject = "him",
|
||||
possessive = "his"
|
||||
)
|
||||
|
||||
case object Female extends CharacterSex(
|
||||
case object Female
|
||||
extends CharacterSex(
|
||||
value = 2,
|
||||
pronounSubject = "she",
|
||||
pronounObject = "her",
|
||||
|
|
@ -41,5 +43,5 @@ object CharacterSex extends IntEnum[CharacterSex] {
|
|||
override def possessiveNoObject: String = "hers"
|
||||
}
|
||||
|
||||
implicit val codec = PacketHelpers.createIntEnumCodec(enum = this, uint2L)
|
||||
implicit val codec = PacketHelpers.createIntEnumCodec(e = this, uint2L)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,5 +15,5 @@ object ExperienceType extends IntEnum[ExperienceType] {
|
|||
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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue