Myriad changes
This commit is contained in:
parent
f0ae3625bf
commit
1b9bb4265f
@ -34,7 +34,6 @@ import monix.bio.Task
|
|||||||
import monix.bio.UIO
|
import monix.bio.UIO
|
||||||
import monix.eval.Coeval
|
import monix.eval.Coeval
|
||||||
import monix.execution.cancelables.CompositeCancelable
|
import monix.execution.cancelables.CompositeCancelable
|
||||||
import monix.execution.exceptions.DummyException
|
|
||||||
import monix.reactive.Observable
|
import monix.reactive.Observable
|
||||||
import monix.{eval => me}
|
import monix.{eval => me}
|
||||||
import scalafx.scene.control.Label
|
import scalafx.scene.control.Label
|
||||||
@ -83,6 +82,7 @@ import wow.doge.mygame.utils.MonixDirectoryWatcher.ModifyEvent
|
|||||||
import wow.doge.mygame.utils.controls.JFXProgressBar
|
import wow.doge.mygame.utils.controls.JFXProgressBar
|
||||||
import wow.doge.mygame.utils.wrappers.jme.AssetManager
|
import wow.doge.mygame.utils.wrappers.jme.AssetManager
|
||||||
import wow.doge.mygame.utils.wrappers.jme.PhysicsSpace
|
import wow.doge.mygame.utils.wrappers.jme.PhysicsSpace
|
||||||
|
|
||||||
class MainApp(
|
class MainApp(
|
||||||
logger: Logger[Task],
|
logger: Logger[Task],
|
||||||
jmeThread: JmeScheduler,
|
jmeThread: JmeScheduler,
|
||||||
@ -151,22 +151,18 @@ class MainApp(
|
|||||||
.executeOn(gameApp.scheduler.value)
|
.executeOn(gameApp.scheduler.value)
|
||||||
} yield fib
|
} yield fib
|
||||||
|
|
||||||
// val k = new FunctionK[Task, UIO] {
|
|
||||||
|
|
||||||
// override def apply[A](fa: monix.bio.Task[A]): monix.bio.UIO[A] =
|
|
||||||
// fa.hideErrors
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
def gameInit(
|
def gameInit(
|
||||||
tickEventBus: GameEventBus[TickEvent]
|
tickEventBus: GameEventBus[TickEvent]
|
||||||
): Resource[UIO, Either[AppError, Fiber[Nothing, Unit]]] =
|
): Resource[UIO, Either[AppError, Fiber[Nothing, Unit]]] =
|
||||||
for {
|
for {
|
||||||
r1 <- wire[GameAppResource].resource.evalMap {
|
r1 <- wire[GameAppResource].resource.evalMap(e =>
|
||||||
case Right(gameApp -> gameAppFib) =>
|
IO.fromEither(e)
|
||||||
eval(tickEventBus, gameApp, gameAppFib).attempt
|
.flatMap {
|
||||||
case Left(error) => IO.terminate(new Exception(error.toString))
|
case (gameApp -> gameAppFib) =>
|
||||||
|
eval(tickEventBus, gameApp, gameAppFib)
|
||||||
}
|
}
|
||||||
|
.attempt
|
||||||
|
)
|
||||||
dirWatcher <- Resource.liftF(
|
dirWatcher <- Resource.liftF(
|
||||||
MonixDirectoryWatcher(
|
MonixDirectoryWatcher(
|
||||||
os.pwd / "assets" / "scripts"
|
os.pwd / "assets" / "scripts"
|
||||||
|
@ -144,28 +144,28 @@ object GameInputHandler {
|
|||||||
case PlayerMovementInput.WalkLeft =>
|
case PlayerMovementInput.WalkLeft =>
|
||||||
me.Task(
|
me.Task(
|
||||||
playerEventBus ! EventBus.Publish(
|
playerEventBus ! EventBus.Publish(
|
||||||
PlayerMovementEvent.PlayerMovedLeft(pressed = action.value),
|
PlayerMovementEvent.PlayerMovedLeft(action.value),
|
||||||
name
|
name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
case PlayerMovementInput.WalkRight =>
|
case PlayerMovementInput.WalkRight =>
|
||||||
me.Task(
|
me.Task(
|
||||||
playerEventBus ! EventBus.Publish(
|
playerEventBus ! EventBus.Publish(
|
||||||
PlayerMovementEvent.PlayerMovedRight(pressed = action.value),
|
PlayerMovementEvent.PlayerMovedRight(action.value),
|
||||||
name
|
name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
case PlayerMovementInput.WalkForward =>
|
case PlayerMovementInput.WalkForward =>
|
||||||
me.Task(
|
me.Task(
|
||||||
playerEventBus ! EventBus.Publish(
|
playerEventBus ! EventBus.Publish(
|
||||||
PlayerMovementEvent.PlayerMovedForward(pressed = action.value),
|
PlayerMovementEvent.PlayerMovedForward(action.value),
|
||||||
name
|
name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
case PlayerMovementInput.WalkBackward =>
|
case PlayerMovementInput.WalkBackward =>
|
||||||
me.Task(
|
me.Task(
|
||||||
playerEventBus ! EventBus.Publish(
|
playerEventBus ! EventBus.Publish(
|
||||||
PlayerMovementEvent.PlayerMovedBackward(pressed = action.value),
|
PlayerMovementEvent.PlayerMovedBackward(action.value),
|
||||||
name
|
name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -44,7 +44,7 @@ object ModdingSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def readPluginsList(dir: os.Path): IO[Error, ArraySeq[Plugin]] =
|
def readPluginsList(dir: os.Path): IO[Error, ArraySeq[Plugin]] =
|
||||||
IO(parse(os.read(dir / "plugins.json")))
|
IO(os.read(dir / "plugins.json"))
|
||||||
.onErrorHandleWith {
|
.onErrorHandleWith {
|
||||||
case _: FileNotFoundException =>
|
case _: FileNotFoundException =>
|
||||||
IO.raiseError(FileNotFound(dir / "plugins.json"))
|
IO.raiseError(FileNotFound(dir / "plugins.json"))
|
||||||
@ -52,16 +52,16 @@ object ModdingSystem {
|
|||||||
IO.raiseError(FileNotFound(dir / "plugins.json"))
|
IO.raiseError(FileNotFound(dir / "plugins.json"))
|
||||||
}
|
}
|
||||||
.flatMap(files =>
|
.flatMap(files =>
|
||||||
IO.fromEither(files)
|
IO.fromEither(parse(files))
|
||||||
.map(_.as[ArraySeq[Plugin]])
|
|
||||||
.mapError(ParseFailure)
|
.mapError(ParseFailure)
|
||||||
|
.map(_.as[ArraySeq[Plugin]])
|
||||||
)
|
)
|
||||||
.flatMap(result => IO.fromEither(result).mapError(DecodingFailure))
|
.flatMap(result => IO.fromEither(result).mapError(DecodingFailure))
|
||||||
|
|
||||||
def findPluginFiles(dir: os.Path): View[os.Path] =
|
// def findPluginFiles(dir: os.Path): View[os.Path] =
|
||||||
os.list(dir)
|
// os.list(dir)
|
||||||
.view
|
// .view
|
||||||
.filter(f => f.ext === "json" && f.baseName.endsWith("plugin"))
|
// .filter(f => f.ext === "json" && f.baseName.endsWith("plugin"))
|
||||||
|
|
||||||
def findAndReadPluginFiles(
|
def findAndReadPluginFiles(
|
||||||
dir: os.Path,
|
dir: os.Path,
|
||||||
|
@ -44,6 +44,19 @@ trait Requestable[A] {
|
|||||||
_ <- queue.offer(req)
|
_ <- queue.offer(req)
|
||||||
res <- d.get.timeout(timeout).map(_.get)
|
res <- d.get.timeout(timeout).map(_.get)
|
||||||
} yield res
|
} yield res
|
||||||
|
|
||||||
|
// def request[T](
|
||||||
|
// compileRequest: Deferred[Task, T] => A
|
||||||
|
// )(implicit timeout: FiniteDuration): IO[AppError, T] =
|
||||||
|
// for {
|
||||||
|
// d <- Deferred[Task, T].hideErrors
|
||||||
|
// req = compileRequest(d)
|
||||||
|
// _ <- queue.offer(req).hideErrors
|
||||||
|
// res <-
|
||||||
|
// d.get.hideErrors
|
||||||
|
// .timeout(timeout)
|
||||||
|
// .flatMap(o => IO.fromOption(o, AppError.TimeoutError("Timed out")))
|
||||||
|
// } yield res
|
||||||
}
|
}
|
||||||
|
|
||||||
class ScriptCompiler private (
|
class ScriptCompiler private (
|
||||||
|
@ -7,6 +7,8 @@ import sttp.client3.asynchttpclient.monix._
|
|||||||
import monix.eval.Task
|
import monix.eval.Task
|
||||||
import monix.reactive.Observable
|
import monix.reactive.Observable
|
||||||
import scala.concurrent.duration.Duration
|
import scala.concurrent.duration.Duration
|
||||||
|
import scala.collection.immutable.ArraySeq
|
||||||
|
import monix.reactive.Consumer
|
||||||
|
|
||||||
class WebsocketTest {
|
class WebsocketTest {
|
||||||
// : Task[Response[Either[String, Observable[Array[Byte]]]]]
|
// : Task[Response[Either[String, Observable[Array[Byte]]]]]
|
||||||
@ -15,13 +17,25 @@ class WebsocketTest {
|
|||||||
val response =
|
val response =
|
||||||
basicRequest
|
basicRequest
|
||||||
.post(uri"...")
|
.post(uri"...")
|
||||||
.response(
|
.response(asStreamUnsafe(MonixStreams))
|
||||||
asStream(MonixStreams)(
|
|
||||||
_.doOnNext(i => Task(println(s"$i"))).completedL
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.readTimeout(Duration.Inf)
|
.readTimeout(Duration.Inf)
|
||||||
.send(backend)
|
.send(backend)
|
||||||
response
|
response.map(_.body.map(_.map(ArraySeq.unsafeWrapArray)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val MB = 1024 * 1024
|
||||||
|
def consumer(contentLength: Long): Consumer[ArraySeq[Byte], Long] =
|
||||||
|
Consumer.foldLeftEval(0L) {
|
||||||
|
case (sum, data) =>
|
||||||
|
val newSum = sum + data.length
|
||||||
|
for {
|
||||||
|
_ <- Task(
|
||||||
|
pprint.log(
|
||||||
|
s"Bytes downloaded = ${newSum * 1f / MB}MB . Percent done = ${(newSum * 100f / contentLength)
|
||||||
|
.formatted("%.2f")}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} yield newSum
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user