mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-07-14 16:04:41 +00:00
fix enum keyword warnings
This commit is contained in:
parent
0772c27973
commit
b69e13c3ee
11 changed files with 102 additions and 93 deletions
|
|
@ -89,20 +89,20 @@ object PacketHelpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a Codec for an enumeration type that can correctly represent its value
|
/** 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
|
* @param storageCodec the Codec used for actually representing the value
|
||||||
* @tparam E The inferred type
|
* @tparam E The inferred type
|
||||||
* @return Generated codec
|
* @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
|
type Struct = Int :: HNil
|
||||||
val struct: Codec[Struct] = storageCodec.hlist
|
val struct: Codec[Struct] = storageCodec.hlist
|
||||||
val primitiveLimit = Math.pow(2, storageCodec.sizeBound.exact.get.toDouble)
|
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
|
// Assure that the enum will always be able to fit in a N-bit int
|
||||||
assert(
|
assert(
|
||||||
enum.maxId <= primitiveLimit,
|
e.maxId <= primitiveLimit,
|
||||||
enum.getClass.getCanonicalName + s": maxId exceeds primitive type (limit of $primitiveLimit, maxId ${enum.maxId})"
|
e.getClass.getCanonicalName + s": maxId exceeds primitive type (limit of $primitiveLimit, maxId ${e.maxId})"
|
||||||
)
|
)
|
||||||
|
|
||||||
def to(pkt: E#Value): Struct = {
|
def to(pkt: E#Value): Struct = {
|
||||||
|
|
@ -113,13 +113,13 @@ object PacketHelpers {
|
||||||
struct match {
|
struct match {
|
||||||
case enumVal :: HNil =>
|
case enumVal :: HNil =>
|
||||||
// verify that this int can match the enum
|
// verify that this int can match the enum
|
||||||
val first = enum.values.firstKey.id
|
val first = e.values.firstKey.id
|
||||||
val last = enum.maxId - 1
|
val last = e.maxId - 1
|
||||||
|
|
||||||
if (enumVal >= first && enumVal <= last)
|
if (enumVal >= first && enumVal <= last)
|
||||||
Attempt.successful(enum(enumVal))
|
Attempt.successful(e(enumVal))
|
||||||
else
|
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)
|
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.
|
* 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)
|
* 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] = {
|
def createLongEnumerationCodec[E <: Enumeration](e: E, storageCodec: Codec[Long]): Codec[E#Value] = {
|
||||||
createEnumerationCodec(enum, storageCodec.xmap[Int](_.toInt, _.toLong))
|
createEnumerationCodec(e, storageCodec.xmap[Int](_.toInt, _.toLong))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a Codec for enumeratum's IntEnum type */
|
/** 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
|
type Struct = Int :: HNil
|
||||||
val struct: Codec[Struct] = storageCodec.hlist
|
val struct: Codec[Struct] = storageCodec.hlist
|
||||||
|
|
||||||
|
|
@ -146,36 +146,36 @@ object PacketHelpers {
|
||||||
def from(struct: Struct): Attempt[E] =
|
def from(struct: Struct): Attempt[E] =
|
||||||
struct match {
|
struct match {
|
||||||
case enumVal :: HNil =>
|
case enumVal :: HNil =>
|
||||||
enum.withValueOpt(enumVal) match {
|
e.withValueOpt(enumVal) match {
|
||||||
case Some(v) => Attempt.successful(v)
|
case Some(v) => Attempt.successful(v)
|
||||||
case None =>
|
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)
|
struct.narrow[E](from, to)
|
||||||
}
|
}
|
||||||
|
|
||||||
def createLongIntEnumCodec[E <: IntEnumEntry](enum: IntEnum[E], storageCodec: Codec[Long]): Codec[E] = {
|
def createLongIntEnumCodec[E <: IntEnumEntry](e: IntEnum[E], storageCodec: Codec[Long]): Codec[E] = {
|
||||||
createIntEnumCodec(enum, storageCodec.xmap[Int](_.toInt, _.toLong))
|
createIntEnumCodec(e, storageCodec.xmap[Int](_.toInt, _.toLong))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a Codec for enumeratum's Enum type */
|
/** 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
|
type Struct = Int :: HNil
|
||||||
val struct: Codec[Struct] = storageCodec.hlist
|
val struct: Codec[Struct] = storageCodec.hlist
|
||||||
|
|
||||||
def to(pkt: E): Struct = {
|
def to(pkt: E): Struct = {
|
||||||
enum.indexOf(pkt) :: HNil
|
e.indexOf(pkt) :: HNil
|
||||||
}
|
}
|
||||||
|
|
||||||
def from(struct: Struct): Attempt[E] =
|
def from(struct: Struct): Attempt[E] =
|
||||||
struct match {
|
struct match {
|
||||||
case enumVal :: HNil =>
|
case enumVal :: HNil =>
|
||||||
enum.valuesToIndex.find(_._2 == enumVal) match {
|
e.valuesToIndex.find(_._2 == enumVal) match {
|
||||||
case Some((v, _)) => Attempt.successful(v)
|
case Some((v, _)) => Attempt.successful(v)
|
||||||
case None =>
|
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] {
|
object GenericAction extends IntEnum[GenericAction] {
|
||||||
val values: IndexedSeq[GenericAction] = findValues
|
val values: IndexedSeq[GenericAction] = findValues
|
||||||
|
|
||||||
final case object ShowMosquitoRadar extends GenericAction(value = 3)
|
final case object ShowMosquitoRadar extends GenericAction(value = 3)
|
||||||
final case object HideMosquitoRadar extends GenericAction(value = 4)
|
final case object HideMosquitoRadar extends GenericAction(value = 4)
|
||||||
final case object MissileLock extends GenericAction(value = 7)
|
final case object MissileLock extends GenericAction(value = 7)
|
||||||
final case object WaspMissileLock extends GenericAction(value = 8)
|
final case object WaspMissileLock extends GenericAction(value = 8)
|
||||||
final case object TRekLock extends GenericAction(value = 9)
|
final case object TRekLock extends GenericAction(value = 9)
|
||||||
final case object DropSpecialItem extends GenericAction(value = 11)
|
final case object DropSpecialItem extends GenericAction(value = 11)
|
||||||
final case object FacilityCaptureFanfare extends GenericAction(value = 12)
|
final case object FacilityCaptureFanfare extends GenericAction(value = 12)
|
||||||
final case object NewCharacterBasicTrainingPrompt extends GenericAction(value = 14)
|
final case object NewCharacterBasicTrainingPrompt extends GenericAction(value = 14)
|
||||||
final case object MaxAnchorsExtend_RCV extends GenericAction(value = 15)
|
final case object MaxAnchorsExtend_RCV extends GenericAction(value = 15)
|
||||||
final case object MaxAnchorsRelease_RCV extends GenericAction(value = 16)
|
final case object MaxAnchorsRelease_RCV extends GenericAction(value = 16)
|
||||||
final case object MaxSpecialEffect_RCV extends GenericAction(value = 20)
|
final case object MaxSpecialEffect_RCV extends GenericAction(value = 20)
|
||||||
final case object StopMaxSpecialEffect_RCV extends GenericAction(value = 21)
|
final case object StopMaxSpecialEffect_RCV extends GenericAction(value = 21)
|
||||||
final case object CavernFacilityCapture extends GenericAction(value = 22)
|
final case object CavernFacilityCapture extends GenericAction(value = 22)
|
||||||
final case object CavernFacilityKill extends GenericAction(value = 23)
|
final case object CavernFacilityKill extends GenericAction(value = 23)
|
||||||
final case object Imprinted extends GenericAction(value = 24)
|
final case object Imprinted extends GenericAction(value = 24)
|
||||||
final case object NoLongerImprinted extends GenericAction(value = 25)
|
final case object NoLongerImprinted extends GenericAction(value = 25)
|
||||||
final case object PurchaseTimersReset extends GenericAction(value = 27)
|
final case object PurchaseTimersReset extends GenericAction(value = 27)
|
||||||
final case object LeaveWarpQueue_RCV extends GenericAction(value = 28)
|
final case object LeaveWarpQueue_RCV extends GenericAction(value = 28)
|
||||||
final case object AwayFromKeyboard_RCV extends GenericAction(value = 29)
|
final case object AwayFromKeyboard_RCV extends GenericAction(value = 29)
|
||||||
final case object BackInGame_RCV extends GenericAction(value = 30)
|
final case object BackInGame_RCV extends GenericAction(value = 30)
|
||||||
final case object FirstPersonViewWithEffect extends GenericAction(value = 31)
|
final case object FirstPersonViewWithEffect extends GenericAction(value = 31)
|
||||||
final case object FirstPersonViewFailToDeconstruct extends GenericAction(value = 32)
|
final case object FirstPersonViewFailToDeconstruct extends GenericAction(value = 32)
|
||||||
final case object FailToDeconstruct extends GenericAction(value = 33)
|
final case object FailToDeconstruct extends GenericAction(value = 33)
|
||||||
final case object LookingForSquad_RCV extends GenericAction(value = 36)
|
final case object LookingForSquad_RCV extends GenericAction(value = 36)
|
||||||
final case object NotLookingForSquad_RCV extends GenericAction(value = 37)
|
final case object NotLookingForSquad_RCV extends GenericAction(value = 37)
|
||||||
final case object Unknown45 extends GenericAction(value = 45)
|
final case object Unknown45 extends GenericAction(value = 45)
|
||||||
|
|
||||||
final case class Unknown(override val value: Int) extends GenericAction(value)
|
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 = {
|
def apply(i: Int): GenericActionMessage = {
|
||||||
GenericActionMessage(GenericAction.values.find { _.value == i } match {
|
GenericActionMessage(GenericAction.values.find { _.value == i } match {
|
||||||
case Some(enum) => enum
|
case Some(enum) => enum
|
||||||
case None => GenericAction.Unknown(i)
|
case None => GenericAction.Unknown(i)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private val genericActionCodec = uint(bits = 6).xmap[GenericAction]({
|
private val genericActionCodec = uint(bits = 6).xmap[GenericAction](
|
||||||
i => GenericAction.values.find { _.value == i } match {
|
{ i =>
|
||||||
case Some(enum) => enum
|
GenericAction.values.find { _.value == i } match {
|
||||||
case None => GenericAction.Unknown(i)
|
case Some(enum) => enum
|
||||||
}
|
case None => GenericAction.Unknown(i)
|
||||||
}, enum => enum.value)
|
}
|
||||||
|
},
|
||||||
|
e => e.value
|
||||||
|
)
|
||||||
|
|
||||||
implicit val codec: Codec[GenericActionMessage] = ("action" | genericActionCodec).as[GenericActionMessage]
|
implicit val codec: Codec[GenericActionMessage] = ("action" | genericActionCodec).as[GenericActionMessage]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ object TerrainCondition extends Enumeration {
|
||||||
type Type = Value
|
type Type = Value
|
||||||
val Safe, Unsafe = 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
|
* @param pos the vehicle's current position in the game world
|
||||||
*/
|
*/
|
||||||
final case class InvalidTerrainMessage(
|
final case class InvalidTerrainMessage(
|
||||||
player_guid: PlanetSideGUID,
|
player_guid: PlanetSideGUID,
|
||||||
vehicle_guid: PlanetSideGUID,
|
vehicle_guid: PlanetSideGUID,
|
||||||
proximity_alert: TerrainCondition.Value,
|
proximity_alert: TerrainCondition.Value,
|
||||||
pos: Vector3
|
pos: Vector3
|
||||||
) extends PlanetSideGamePacket {
|
) extends PlanetSideGamePacket {
|
||||||
type Packet = InvalidTerrainMessage
|
type Packet = InvalidTerrainMessage
|
||||||
def opcode = GamePacketOpcode.InvalidTerrainMessage
|
def opcode = GamePacketOpcode.InvalidTerrainMessage
|
||||||
def encode = InvalidTerrainMessage.encode(this)
|
def encode = InvalidTerrainMessage.encode(this)
|
||||||
|
|
@ -40,8 +40,7 @@ final case class InvalidTerrainMessage(
|
||||||
|
|
||||||
object InvalidTerrainMessage extends Marshallable[InvalidTerrainMessage] {
|
object InvalidTerrainMessage extends Marshallable[InvalidTerrainMessage] {
|
||||||
|
|
||||||
implicit val codec: Codec[InvalidTerrainMessage] = (
|
implicit val codec: Codec[InvalidTerrainMessage] = (("player_guid" | PlanetSideGUID.codec) ::
|
||||||
("player_guid" | PlanetSideGUID.codec) ::
|
|
||||||
("vehicle_guid" | PlanetSideGUID.codec) ::
|
("vehicle_guid" | PlanetSideGUID.codec) ::
|
||||||
("proximity_alert" | TerrainCondition.codec) ::
|
("proximity_alert" | TerrainCondition.codec) ::
|
||||||
("pos" | floatL :: floatL :: floatL).narrow[Vector3](
|
("pos" | floatL :: floatL :: floatL).narrow[Vector3](
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ object SquadAction {
|
||||||
|
|
||||||
val AnyPositions, AvailablePositions, SomeCertifications, AllCertifications = Value
|
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)
|
final case class DisplaySquad() extends SquadAction(code = 0)
|
||||||
|
|
@ -280,7 +280,7 @@ object SquadAction {
|
||||||
|
|
||||||
val squadListDecoratorCodec = (
|
val squadListDecoratorCodec = (
|
||||||
SquadListDecoration.codec ::
|
SquadListDecoration.codec ::
|
||||||
ignore(size = 3)
|
ignore(size = 3)
|
||||||
).xmap[SquadListDecorator](
|
).xmap[SquadListDecorator](
|
||||||
{
|
{
|
||||||
case value :: _ :: HNil => SquadListDecorator(value)
|
case value :: _ :: HNil => SquadListDecorator(value)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ object MemberEvent extends Enumeration {
|
||||||
|
|
||||||
val Add, Remove, Promote, UpdateZone, Outfit = Value
|
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(
|
final case class SquadMemberEvent(
|
||||||
|
|
@ -58,13 +58,18 @@ object SquadMemberEvent extends Marshallable[SquadMemberEvent] {
|
||||||
("unk2" | uint16L) ::
|
("unk2" | uint16L) ::
|
||||||
("char_id" | uint32L) ::
|
("char_id" | uint32L) ::
|
||||||
("position" | uint4) ::
|
("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)) ::
|
("zone_number" | conditional(action == MemberEvent.Add || action == MemberEvent.UpdateZone, uint16L)) ::
|
||||||
("outfit_id" | conditional(action == MemberEvent.Add || action == MemberEvent.Outfit, uint32L))
|
("outfit_id" | conditional(action == MemberEvent.Add || action == MemberEvent.Outfit, uint32L))
|
||||||
}).exmap[SquadMemberEvent](
|
}).exmap[SquadMemberEvent](
|
||||||
{
|
{
|
||||||
case action :: unk2 :: char_id :: member_position :: player_name :: zone_number :: outfit_id :: HNil =>
|
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(
|
case SquadMemberEvent(
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ object WaypointEventAction extends Enumeration {
|
||||||
val Add, Unknown1, Remove, Unknown3 //unconfirmed
|
val Add, Unknown1, Remove, Unknown3 //unconfirmed
|
||||||
= Value
|
= 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.
|
* Blame the lack of gender dysphoria on the Terran Republic.
|
||||||
*/
|
*/
|
||||||
sealed abstract class CharacterSex(
|
sealed abstract class CharacterSex(
|
||||||
val value: Int,
|
val value: Int,
|
||||||
val pronounSubject: String,
|
val pronounSubject: String,
|
||||||
val pronounObject: String,
|
val pronounObject: String,
|
||||||
val possessive: String
|
val possessive: String
|
||||||
) extends IntEnumEntry {
|
) extends IntEnumEntry {
|
||||||
def possessiveNoObject: String = possessive
|
def possessiveNoObject: String = possessive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,21 +25,23 @@ sealed abstract class CharacterSex(
|
||||||
object CharacterSex extends IntEnum[CharacterSex] {
|
object CharacterSex extends IntEnum[CharacterSex] {
|
||||||
val values = findValues
|
val values = findValues
|
||||||
|
|
||||||
case object Male extends CharacterSex(
|
case object Male
|
||||||
value = 1,
|
extends CharacterSex(
|
||||||
pronounSubject = "he",
|
value = 1,
|
||||||
pronounObject = "him",
|
pronounSubject = "he",
|
||||||
possessive = "his"
|
pronounObject = "him",
|
||||||
)
|
possessive = "his"
|
||||||
|
)
|
||||||
|
|
||||||
case object Female extends CharacterSex(
|
case object Female
|
||||||
value = 2,
|
extends CharacterSex(
|
||||||
pronounSubject = "she",
|
value = 2,
|
||||||
pronounObject = "her",
|
pronounSubject = "she",
|
||||||
possessive = "her"
|
pronounObject = "her",
|
||||||
) {
|
possessive = "her"
|
||||||
|
) {
|
||||||
override def possessiveNoObject: String = "hers"
|
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] {
|
object ExperienceType extends IntEnum[ExperienceType] {
|
||||||
val values: IndexedSeq[ExperienceType] = findValues
|
val values: IndexedSeq[ExperienceType] = findValues
|
||||||
|
|
||||||
case object Normal extends ExperienceType(value = 0)
|
case object Normal extends ExperienceType(value = 0)
|
||||||
case object Support extends ExperienceType(value = 2)
|
case object Support extends ExperienceType(value = 2)
|
||||||
case object RabbitBall extends ExperienceType(value = 4)
|
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 =>
|
case MeritCommendation.None =>
|
||||||
Attempt.successful(0xffffffffL)
|
Attempt.successful(0xffffffffL)
|
||||||
case enum =>
|
case e =>
|
||||||
Attempt.successful(enum.id.toLong)
|
Attempt.successful(e.id.toLong)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,5 +23,5 @@ object OxygenState extends Enum[OxygenState] {
|
||||||
case object Recovery extends OxygenState
|
case object Recovery extends OxygenState
|
||||||
case object Suffocation 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
|
implicit def enumeratumIntConfigConvert[A <: IntEnumEntry](implicit
|
||||||
enum: IntEnum[A],
|
e: IntEnum[A],
|
||||||
ct: ClassTag[A]
|
ct: ClassTag[A]
|
||||||
): ConfigConvert[A] =
|
): ConfigConvert[A] =
|
||||||
viaNonEmptyStringOpt[A](
|
viaNonEmptyStringOpt[A](
|
||||||
v =>
|
v =>
|
||||||
enum.values.toList.collectFirst {
|
e.values.toList.collectFirst {
|
||||||
case e: ServerType if e.name == v => e.asInstanceOf[A]
|
case e: ServerType if e.name == v => e.asInstanceOf[A]
|
||||||
case e: BattleRank if e.value.toString == 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]
|
case e: CommandRank if e.value.toString == v => e.asInstanceOf[A]
|
||||||
|
|
@ -40,12 +40,12 @@ object Config {
|
||||||
)
|
)
|
||||||
|
|
||||||
implicit def enumeratumConfigConvert[A <: EnumEntry](implicit
|
implicit def enumeratumConfigConvert[A <: EnumEntry](implicit
|
||||||
enum: Enum[A],
|
e: Enum[A],
|
||||||
ct: ClassTag[A]
|
ct: ClassTag[A]
|
||||||
): ConfigConvert[A] =
|
): ConfigConvert[A] =
|
||||||
viaNonEmptyStringOpt[A](
|
viaNonEmptyStringOpt[A](
|
||||||
v =>
|
v =>
|
||||||
enum.values.toList.collectFirst {
|
e.values.toList.collectFirst {
|
||||||
case e if e.toString.toLowerCase == v.toLowerCase => e.asInstanceOf[A]
|
case e if e.toString.toLowerCase == v.toLowerCase => e.asInstanceOf[A]
|
||||||
},
|
},
|
||||||
_.toString
|
_.toString
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue