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.eval.Coeval
|
||||
import monix.execution.cancelables.CompositeCancelable
|
||||
import monix.execution.exceptions.DummyException
|
||||
import monix.reactive.Observable
|
||||
import monix.{eval => me}
|
||||
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.wrappers.jme.AssetManager
|
||||
import wow.doge.mygame.utils.wrappers.jme.PhysicsSpace
|
||||
|
||||
class MainApp(
|
||||
logger: Logger[Task],
|
||||
jmeThread: JmeScheduler,
|
||||
@ -151,22 +151,18 @@ class MainApp(
|
||||
.executeOn(gameApp.scheduler.value)
|
||||
} 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(
|
||||
tickEventBus: GameEventBus[TickEvent]
|
||||
): Resource[UIO, Either[AppError, Fiber[Nothing, Unit]]] =
|
||||
for {
|
||||
r1 <- wire[GameAppResource].resource.evalMap {
|
||||
case Right(gameApp -> gameAppFib) =>
|
||||
eval(tickEventBus, gameApp, gameAppFib).attempt
|
||||
case Left(error) => IO.terminate(new Exception(error.toString))
|
||||
r1 <- wire[GameAppResource].resource.evalMap(e =>
|
||||
IO.fromEither(e)
|
||||
.flatMap {
|
||||
case (gameApp -> gameAppFib) =>
|
||||
eval(tickEventBus, gameApp, gameAppFib)
|
||||
}
|
||||
.attempt
|
||||
)
|
||||
dirWatcher <- Resource.liftF(
|
||||
MonixDirectoryWatcher(
|
||||
os.pwd / "assets" / "scripts"
|
||||
|
@ -144,28 +144,28 @@ object GameInputHandler {
|
||||
case PlayerMovementInput.WalkLeft =>
|
||||
me.Task(
|
||||
playerEventBus ! EventBus.Publish(
|
||||
PlayerMovementEvent.PlayerMovedLeft(pressed = action.value),
|
||||
PlayerMovementEvent.PlayerMovedLeft(action.value),
|
||||
name
|
||||
)
|
||||
)
|
||||
case PlayerMovementInput.WalkRight =>
|
||||
me.Task(
|
||||
playerEventBus ! EventBus.Publish(
|
||||
PlayerMovementEvent.PlayerMovedRight(pressed = action.value),
|
||||
PlayerMovementEvent.PlayerMovedRight(action.value),
|
||||
name
|
||||
)
|
||||
)
|
||||
case PlayerMovementInput.WalkForward =>
|
||||
me.Task(
|
||||
playerEventBus ! EventBus.Publish(
|
||||
PlayerMovementEvent.PlayerMovedForward(pressed = action.value),
|
||||
PlayerMovementEvent.PlayerMovedForward(action.value),
|
||||
name
|
||||
)
|
||||
)
|
||||
case PlayerMovementInput.WalkBackward =>
|
||||
me.Task(
|
||||
playerEventBus ! EventBus.Publish(
|
||||
PlayerMovementEvent.PlayerMovedBackward(pressed = action.value),
|
||||
PlayerMovementEvent.PlayerMovedBackward(action.value),
|
||||
name
|
||||
)
|
||||
)
|
||||
|
@ -44,7 +44,7 @@ object ModdingSystem {
|
||||
}
|
||||
|
||||
def readPluginsList(dir: os.Path): IO[Error, ArraySeq[Plugin]] =
|
||||
IO(parse(os.read(dir / "plugins.json")))
|
||||
IO(os.read(dir / "plugins.json"))
|
||||
.onErrorHandleWith {
|
||||
case _: FileNotFoundException =>
|
||||
IO.raiseError(FileNotFound(dir / "plugins.json"))
|
||||
@ -52,16 +52,16 @@ object ModdingSystem {
|
||||
IO.raiseError(FileNotFound(dir / "plugins.json"))
|
||||
}
|
||||
.flatMap(files =>
|
||||
IO.fromEither(files)
|
||||
.map(_.as[ArraySeq[Plugin]])
|
||||
IO.fromEither(parse(files))
|
||||
.mapError(ParseFailure)
|
||||
.map(_.as[ArraySeq[Plugin]])
|
||||
)
|
||||
.flatMap(result => IO.fromEither(result).mapError(DecodingFailure))
|
||||
|
||||
def findPluginFiles(dir: os.Path): View[os.Path] =
|
||||
os.list(dir)
|
||||
.view
|
||||
.filter(f => f.ext === "json" && f.baseName.endsWith("plugin"))
|
||||
// def findPluginFiles(dir: os.Path): View[os.Path] =
|
||||
// os.list(dir)
|
||||
// .view
|
||||
// .filter(f => f.ext === "json" && f.baseName.endsWith("plugin"))
|
||||
|
||||
def findAndReadPluginFiles(
|
||||
dir: os.Path,
|
||||
|
@ -44,6 +44,19 @@ trait Requestable[A] {
|
||||
_ <- queue.offer(req)
|
||||
res <- d.get.timeout(timeout).map(_.get)
|
||||
} 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 (
|
||||
|
@ -7,6 +7,8 @@ import sttp.client3.asynchttpclient.monix._
|
||||
import monix.eval.Task
|
||||
import monix.reactive.Observable
|
||||
import scala.concurrent.duration.Duration
|
||||
import scala.collection.immutable.ArraySeq
|
||||
import monix.reactive.Consumer
|
||||
|
||||
class WebsocketTest {
|
||||
// : Task[Response[Either[String, Observable[Array[Byte]]]]]
|
||||
@ -15,13 +17,25 @@ class WebsocketTest {
|
||||
val response =
|
||||
basicRequest
|
||||
.post(uri"...")
|
||||
.response(
|
||||
asStream(MonixStreams)(
|
||||
_.doOnNext(i => Task(println(s"$i"))).completedL
|
||||
)
|
||||
)
|
||||
.response(asStreamUnsafe(MonixStreams))
|
||||
.readTimeout(Duration.Inf)
|
||||
.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