package wow.doge.mygame.game

import cats.effect.Resource
import com.jme3.app.StatsAppState
import com.jme3.system.AppSettings
import io.odin.Logger
import monix.bio.Task
import monix.execution.Scheduler
import wow.doge.mygame.executors.Schedulers
class GameAppResource(
    logger: Logger[Task],
    jmeScheduler: Scheduler,
    schedulers: Schedulers
) {

  def get: Resource[Task, GameApp] =
    Resource.make(
      for {
        _ <- logger.info("Creating game app")
        appExt <- Task(new SimpleAppExt(schedulers, new StatsAppState()))
        app <- Task {
          val settings = new AppSettings(true)
          settings.setVSync(true)

          /**
            * disables the launcher
            * We'll be making our own launcher anyway
            */
          appExt.setShowSettings(false)
          appExt.setSettings(settings)
          // JMERunner.runner = app
          new GameApp(logger, appExt)
        }
      } yield (app)
    )(_ => logger.info("Closing game app"))
}
