Skip to content

Commit

Permalink
endwalker support
Browse files Browse the repository at this point in the history
* added sge and rpr
* changed way to define savage gear
* libraries update
  • Loading branch information
arcan1s committed Dec 19, 2021
1 parent 08f7f45 commit 1866a1b
Show file tree
Hide file tree
Showing 21 changed files with 95 additions and 81 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "ffxivbis"

scalaVersion := "2.13.1"
scalaVersion := "2.13.6"

scalacOptions ++= Seq("-deprecation", "-feature")

Expand Down
22 changes: 11 additions & 11 deletions libraries.sbt
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
val AkkaVersion = "2.6.10"
val AkkaHttpVersion = "10.2.1"
val AkkaVersion = "2.6.17"
val AkkaHttpVersion = "10.2.7"
val SlickVersion = "3.3.3"

libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3"
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.2"
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.9"
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.4"

libraryDependencies += "com.typesafe.akka" %% "akka-http" % AkkaHttpVersion
libraryDependencies += "com.typesafe.akka" %% "akka-http-spray-json" % AkkaHttpVersion
libraryDependencies += "com.typesafe.akka" %% "akka-actor-typed" % AkkaVersion
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % AkkaVersion
libraryDependencies += "com.github.swagger-akka-http" %% "swagger-akka-http" % "2.3.0"
libraryDependencies += "com.github.swagger-akka-http" %% "swagger-akka-http" % "2.6.0"
libraryDependencies += "javax.ws.rs" % "javax.ws.rs-api" % "2.1.1"

libraryDependencies += "io.spray" %% "spray-json" % "1.3.6"
libraryDependencies += "com.lihaoyi" %% "scalatags" % "0.9.2"

libraryDependencies += "com.typesafe.slick" %% "slick" % SlickVersion
libraryDependencies += "com.typesafe.slick" %% "slick-hikaricp" % SlickVersion
libraryDependencies += "org.flywaydb" % "flyway-core" % "6.0.6"
libraryDependencies += "org.xerial" % "sqlite-jdbc" % "3.32.3.2"
libraryDependencies += "org.postgresql" % "postgresql" % "42.2.18"
libraryDependencies += "org.flywaydb" % "flyway-core" % "8.2.2"
libraryDependencies += "org.xerial" % "sqlite-jdbc" % "3.36.0.3"
libraryDependencies += "org.postgresql" % "postgresql" % "42.3.1"

libraryDependencies += "org.mindrot" % "jbcrypt" % "0.3m"
libraryDependencies += "org.mindrot" % "jbcrypt" % "0.4"


// testing
libraryDependencies += "org.scalactic" %% "scalactic" % "3.1.4" % "test"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.4" % "test"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.2.10" % "test"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.10" % "test"

libraryDependencies += "com.typesafe.akka" %% "akka-actor-testkit-typed" % AkkaVersion % "test"
libraryDependencies += "com.typesafe.akka" %% "akka-stream-testkit" % AkkaVersion % "test"
Expand Down
20 changes: 14 additions & 6 deletions src/main/scala/me/arcanis/ffxivbis/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package me.arcanis.ffxivbis
import akka.actor.typed.{Behavior, PostStop, Signal}
import akka.actor.typed.scaladsl.{AbstractBehavior, ActorContext, Behaviors}
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Route
import akka.stream.Materializer
import com.typesafe.scalalogging.StrictLogging
import me.arcanis.ffxivbis.http.RootEndpoint
Expand All @@ -19,6 +20,7 @@ import me.arcanis.ffxivbis.service.{Database, PartyService}
import me.arcanis.ffxivbis.storage.Migration

import scala.concurrent.ExecutionContext
import scala.util.{Failure, Success}

class Application(context: ActorContext[Nothing])
extends AbstractBehavior[Nothing](context) with StrictLogging {
Expand All @@ -42,14 +44,20 @@ class Application(context: ActorContext[Nothing])
implicit val executionContext: ExecutionContext = context.system.executionContext
implicit val materializer: Materializer = Materializer(context)

Migration(config)
Migration(config) match {
case Success(_) =>
val bisProvider = context.spawn(BisProvider(), "bis-provider")
val storage = context.spawn(Database(), "storage")
val party = context.spawn(PartyService(storage), "party")
val http = new RootEndpoint(context.system, party, bisProvider)

val bisProvider = context.spawn(BisProvider(), "bis-provider")
val storage = context.spawn(Database(), "storage")
val party = context.spawn(PartyService(storage), "party")
val http = new RootEndpoint(context.system, party, bisProvider)
val flow = Route.toFlow(http.route)(context.system)
Http(context.system).newServerAt(host, port).bindFlow(flow)

Http()(context.system).newServerAt(host, port).bindFlow(http.route)
case Failure(exception) =>
logger.error("exception during migration", exception)
context.system.terminate()
}
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/main/scala/me/arcanis/ffxivbis/models/Job.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ object Job {
val leftSide: LeftSide = BodyMnks
val rightSide: RightSide = AccessoriesStr
}
trait Drgs extends Job {
val leftSide: LeftSide = BodyDrgs
val rightSide: RightSide = AccessoriesStr
}
trait Tanks extends Job {
val leftSide: LeftSide = BodyTanks
val rightSide: RightSide = AccessoriesVit
Expand All @@ -79,12 +83,11 @@ object Job {
case object WHM extends Healers
case object SCH extends Healers
case object AST extends Healers
case object SGE extends Healers

case object MNK extends Mnks
case object DRG extends Job {
val leftSide: LeftSide = BodyDrgs
val rightSide: RightSide = AccessoriesStr
}
case object DRG extends Drgs
case object RPR extends Drgs
case object NIN extends Job {
val leftSide: LeftSide = BodyNins
val rightSide: RightSide = AccessoriesDex
Expand All @@ -100,7 +103,7 @@ object Job {
case object RDM extends Casters

lazy val available: Seq[Job] =
Seq(PLD, WAR, DRK, GNB, WHM, SCH, AST, MNK, DRG, NIN, SAM, BRD, MCH, DNC, BLM, SMN, RDM)
Seq(PLD, WAR, DRK, GNB, WHM, SCH, AST, SGE, MNK, DRG, RPR, NIN, SAM, BRD, MCH, DNC, BLM, SMN, RDM)
lazy val availableWithAnyJob: Seq[Job] = available.prepended(AnyJob)

def withName(job: String): Job.Job =
Expand Down
20 changes: 8 additions & 12 deletions src/main/scala/me/arcanis/ffxivbis/models/Piece.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ sealed trait Piece extends Equals {

def withJob(other: Job.Job): Piece

def upgrade: Option[PieceUpgrade] = this match {
case _ if pieceType != PieceType.Tome => None
case _: Waist => Some(AccessoryUpgrade)
case _: PieceAccessory => Some(AccessoryUpgrade)
case _: PieceBody => Some(BodyUpgrade)
case _: PieceWeapon => Some(WeaponUpgrade)
def upgrade: Option[PieceUpgrade] = {
val isTome = pieceType == PieceType.Tome
Some(this).collect {
case _: PieceAccessory if isTome => AccessoryUpgrade
case _: PieceBody if isTome => BodyUpgrade
case _: PieceWeapon if isTome => WeaponUpgrade
}
}

// used for ring comparison
Expand Down Expand Up @@ -54,10 +55,6 @@ case class Hands(override val pieceType: PieceType.PieceType, override val job:
val piece: String = "hands"
def withJob(other: Job.Job): Piece = copy(job = other)
}
case class Waist(override val pieceType: PieceType.PieceType, override val job: Job.Job) extends PieceBody {
val piece: String = "waist"
def withJob(other: Job.Job): Piece = copy(job = other)
}
case class Legs(override val pieceType: PieceType.PieceType, override val job: Job.Job) extends PieceBody {
val piece: String = "legs"
def withJob(other: Job.Job): Piece = copy(job = other)
Expand Down Expand Up @@ -111,7 +108,6 @@ object Piece {
case "head" => Head(pieceType, job)
case "body" => Body(pieceType, job)
case "hands" => Hands(pieceType, job)
case "waist" => Waist(pieceType, job)
case "legs" => Legs(pieceType, job)
case "feet" => Feet(pieceType, job)
case "ears" => Ears(pieceType, job)
Expand All @@ -125,7 +121,7 @@ object Piece {
}

lazy val available: Seq[String] = Seq("weapon",
"head", "body", "hands", "waist", "legs", "feet",
"head", "body", "hands", "legs", "feet",
"ears", "neck", "wrist", "left ring", "right ring",
"accessory upgrade", "body upgrade", "weapon upgrade")
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object BisProvider {
case "chest" => Some("body")
case "ringLeft" | "fingerL" => Some("left ring")
case "ringRight" | "fingerR" => Some("right ring")
case "weapon" | "head" | "body" | "hands" | "waist" | "legs" | "feet" | "ears" | "neck" | "wrist" | "wrists" => Some(key)
case "weapon" | "head" | "body" | "hands" | "legs" | "feet" | "ears" | "neck" | "wrist" | "wrists" => Some(key)
case _ => None
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ object XivApi {
.getOrElse(throw new Exception(s"${shopMap(shopId).fields(s"ItemCost$index")}, $index"))
.getFields("IsUnique", "StackSize") match {
case Seq(JsNumber(isUnique), JsNumber(stackSize)) =>
if (isUnique == 1 || stackSize.toLong == 2000) PieceType.Tome // either upgraded gear or tomes found
if (isUnique == 1 || stackSize.toLong != 999) PieceType.Tome // either upgraded gear or tomes found
else PieceType.Savage
case other => throw deserializationError(s"Could not parse $other")
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/me/arcanis/ffxivbis/storage/Migration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import org.flywaydb.core.Flyway
import org.flywaydb.core.api.configuration.ClassicConfiguration

import scala.concurrent.Future
import scala.util.Try

class Migration(config: Config) {

def performMigration(): Future[Int] = {
def performMigration(): Try[Boolean] = {
val section = DatabaseProfile.getSection(config)

val url = section.getString("db.url")
Expand All @@ -33,11 +34,11 @@ class Migration(config: Config) {
flywayConfiguration.setDataSource(url, username, password)
val flyway = new Flyway(flywayConfiguration)

Future.successful(flyway.migrate())
Try(flyway.migrate().success)
}
}

object Migration {

def apply(config: Config): Future[Int] = new Migration(config).performMigration()
def apply(config: Config): Try[Boolean] = new Migration(config).performMigration()
}
3 changes: 0 additions & 3 deletions src/test/scala/me/arcanis/ffxivbis/Fixtures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ object Fixtures {
Head(pieceType = PieceType.Savage, Job.DNC),
Body(pieceType = PieceType.Savage, Job.DNC),
Hands(pieceType = PieceType.Tome, Job.DNC),
Waist(pieceType = PieceType.Tome, Job.DNC),
Legs(pieceType = PieceType.Tome, Job.DNC),
Feet(pieceType = PieceType.Savage, Job.DNC),
Ears(pieceType = PieceType.Savage, Job.DNC),
Expand All @@ -25,7 +24,6 @@ object Fixtures {
Head(pieceType = PieceType.Tome, Job.DNC),
Body(pieceType = PieceType.Savage, Job.DNC),
Hands(pieceType = PieceType.Tome, Job.DNC),
Waist(pieceType = PieceType.Tome, Job.DNC),
Legs(pieceType = PieceType.Savage, Job.DNC),
Feet(pieceType = PieceType.Tome, Job.DNC),
Ears(pieceType = PieceType.Savage, Job.DNC),
Expand All @@ -45,7 +43,6 @@ object Fixtures {
lazy val lootBody: Piece = Body(pieceType = PieceType.Savage, Job.AnyJob)
lazy val lootBodyCrafted: Piece = Body(pieceType = PieceType.Crafted, Job.AnyJob)
lazy val lootHands: Piece = Hands(pieceType = PieceType.Tome, Job.AnyJob)
lazy val lootWaist: Piece = Waist(pieceType = PieceType.Tome, Job.AnyJob)
lazy val lootLegs: Piece = Legs(pieceType = PieceType.Savage, Job.AnyJob)
lazy val lootEars: Piece = Ears(pieceType = PieceType.Savage, Job.AnyJob)
lazy val lootRing: Piece = Ring(pieceType = PieceType.Tome, Job.AnyJob)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ class BiSEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRouteT
private val party = testKit.spawn(PartyService(storage))
private val route = new BiSEndpoint(party, provider)(askTimeout, testKit.scheduler).route

override def beforeAll: Unit = {
Await.result(Migration(testConfig), askTimeout)
override def beforeAll(): Unit = {
super.beforeAll()
Migration(testConfig)
Await.result(storage.ask(AddUser(Fixtures.userAdmin, isHashedPassword = true, _))(askTimeout, testKit.scheduler), askTimeout)
Await.result(storage.ask(AddPlayer(Fixtures.playerEmpty, _))(askTimeout, testKit.scheduler), askTimeout)
}

override def afterAll: Unit = {
super.afterAll()
override def afterAll(): Unit = {
Settings.clearDatabase(testConfig)
TestKit.shutdownActorSystem(system)
testKit.shutdownTestKit()
super.afterAll()
}

private def compareBiSResponse(actual: PlayerResponse, expected: PlayerResponse): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ class LootEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRoute
private val party = testKit.spawn(PartyService(storage))
private val route = new LootEndpoint(party)(askTimeout, testKit.scheduler).route

override def beforeAll: Unit = {
Await.result(Migration(testConfig), askTimeout)
override def beforeAll(): Unit = {
super.beforeAll()
Migration(testConfig)
Await.result(storage.ask(AddUser(Fixtures.userAdmin, isHashedPassword = true, _))(askTimeout, testKit.scheduler), askTimeout)
Await.result(storage.ask(AddPlayer(Fixtures.playerEmpty, _))(askTimeout, testKit.scheduler), askTimeout)
}

override def afterAll: Unit = {
super.afterAll()
override def afterAll(): Unit = {
Settings.clearDatabase(testConfig)
TestKit.shutdownActorSystem(system)
testKit.shutdownTestKit()
super.afterAll()
}

"api v1 loot endpoint" must {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ class PartyEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRout
private val party = testKit.spawn(PartyService(storage))
private val route = new PartyEndpoint(party, provider)(askTimeout, testKit.scheduler).route

override def beforeAll: Unit = {
Await.result(Migration(testConfig), askTimeout)
override def beforeAll(): Unit = {
super.beforeAll()
Migration(testConfig)
Await.result(storage.ask(AddUser(Fixtures.userAdmin, isHashedPassword = true, _))(askTimeout, testKit.scheduler), askTimeout)
}

override def afterAll: Unit = {
super.afterAll()
override def afterAll(): Unit = {
Settings.clearDatabase(testConfig)
TestKit.shutdownActorSystem(system)
testKit.shutdownTestKit()
super.afterAll()
}

"api v1 party endpoint" must {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ class PlayerEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRou
private val party = testKit.spawn(PartyService(storage))
private val route = new PlayerEndpoint(party, provider)(askTimeout, testKit.scheduler).route

override def beforeAll: Unit = {
Await.result(Migration(testConfig), askTimeout)
override def beforeAll(): Unit = {
super.beforeAll()
Migration(testConfig)
Await.result(storage.ask(AddUser(Fixtures.userAdmin, isHashedPassword = true, _))(askTimeout, testKit.scheduler), askTimeout)
Await.result(storage.ask(AddPlayer(Fixtures.playerEmpty, _))(askTimeout, testKit.scheduler), askTimeout)
}

override def afterAll: Unit = {
super.afterAll()
override def afterAll(): Unit = {
Settings.clearDatabase(testConfig)
TestKit.shutdownActorSystem(system)
testKit.shutdownTestKit()
super.afterAll()
}

"api v1 player endpoint" must {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ class UserEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRoute
private val party = testKit.spawn(PartyService(storage))
private val route = new UserEndpoint(party)(askTimeout, testKit.scheduler).route

override def beforeAll: Unit = {
Await.result(Migration(testConfig), askTimeout)
override def beforeAll(): Unit = {
super.beforeAll()
Migration(testConfig)
}

override def afterAll: Unit = {
super.afterAll()
override def afterAll(): Unit = {
Settings.clearDatabase(testConfig)
TestKit.shutdownActorSystem(system)
testKit.shutdownTestKit()
super.afterAll()
}

"api v1 users endpoint" must {
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/me/arcanis/ffxivbis/models/BiSTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BiSTest extends AnyWordSpecLike with Matchers {
}

"return upgrade list" in {
Compare.mapEquals(Fixtures.bis.upgrades, Map[PieceUpgrade, Int](BodyUpgrade -> 2, AccessoryUpgrade -> 4)) shouldEqual true
Compare.mapEquals(Fixtures.bis.upgrades, Map[PieceUpgrade, Int](BodyUpgrade -> 2, AccessoryUpgrade -> 3)) shouldEqual true
}

}
Expand Down
1 change: 0 additions & 1 deletion src/test/scala/me/arcanis/ffxivbis/models/PieceTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class PieceTest extends AnyWordSpecLike with Matchers {
Fixtures.lootWeapon.upgrade shouldEqual Some(WeaponUpgrade)
Fixtures.lootBody.upgrade shouldEqual None
Fixtures.lootHands.upgrade shouldEqual Some(BodyUpgrade)
Fixtures.lootWaist.upgrade shouldEqual Some(AccessoryUpgrade)
Fixtures.lootLegs.upgrade shouldEqual None
Fixtures.lootEars.upgrade shouldEqual None
Fixtures.lootLeftRing.upgrade shouldEqual Some(AccessoryUpgrade)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ class DatabaseBiSHandlerTest extends ScalaTestWithActorTestKit(Settings.withRand
private val database = testKit.spawn(Database())
private val askTimeout: FiniteDuration = 60 seconds

override def beforeAll: Unit = {
Await.result(Migration(testKit.system.settings.config), askTimeout)
override def beforeAll(): Unit = {
super.beforeAll()
Migration(testKit.system.settings.config)
Await.result(database.ask(AddPlayer(Fixtures.playerEmpty, _))(askTimeout, testKit.scheduler), askTimeout)
}

override def afterAll: Unit = {
super.afterAll()
override def afterAll(): Unit = {
Settings.clearDatabase(testKit.system.settings.config)
super.afterAll()
}

"database bis handler" must {
Expand Down
Loading

0 comments on commit 1866a1b

Please sign in to comment.