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()}'"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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](
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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