Testing out JmonkeyEngine to make a game in Scala with Akka Actors within a pure FP layer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.9 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package wow.doge.mygame.subsystems.scriptsystem
  2. import akka.actor.typed.ActorRef
  3. import akka.actor.typed.Scheduler
  4. import akka.actor.typed.SpawnProtocol
  5. import akka.util.Timeout
  6. import cats.effect.Resource
  7. import monix.bio.Task
  8. import wow.doge.mygame.scriptsystem.ScriptCachingActor
  9. import wow.doge.mygame.utils.AkkaUtils
  10. /**
  11. * Scripts can either be searched and compiled at startup (Eager mode)
  12. * or compiled on demand (Lazy mode)
  13. */
  14. sealed trait ScriptInitMode
  15. object ScriptInitMode {
  16. case object Eager extends ScriptInitMode
  17. case object Lazy extends ScriptInitMode
  18. }
  19. class ScriptSystemResource(
  20. path: os.Path,
  21. spawnProtocol: ActorRef[SpawnProtocol.Command],
  22. mode: ScriptInitMode = ScriptInitMode.Lazy
  23. )(implicit timeout: Timeout, scheduler: Scheduler) {
  24. val make = {
  25. // throw new Exception("boom")
  26. findScriptFiles(os.pwd / "assets" / "scripts")
  27. lazy val scriptCacheActor = AkkaUtils.spawnActorL(
  28. spawnProtocol,
  29. "scriptCachingActor",
  30. ScriptCachingActor()
  31. )
  32. Resource.liftF(scriptCacheActor)
  33. }
  34. // sys.ask(ref => ScriptCachingActor.GetAll(os.pwd/'assets/'scripts/'scala/"hello2.sc",ref, false))
  35. val init = for {
  36. scriptFiles <- Task(findScriptFiles(os.pwd / "assets" / "scripts"))
  37. scriptCacheActor <- AkkaUtils.spawnActorL(
  38. spawnProtocol,
  39. "scriptCachingActor",
  40. ScriptCachingActor()
  41. )
  42. } yield (scriptCacheActor)
  43. def findScriptFiles(wd: os.Path) =
  44. os.walk
  45. .stream(wd)
  46. .filter(p =>
  47. os.isFile(p) &&
  48. (p.ext == "sc" || (p.baseName + "." + p.ext)
  49. .contains(".main.kts") || p.ext == "groovy")
  50. )
  51. .toList
  52. // def findExternalScriptFiles =
  53. // findScriptFiles(os.pwd / "assets" / "scripts")
  54. // def findInternalScriptFiles =
  55. // findScriptFiles((os.resource / "assets" / "scripts"))
  56. // def finalInternalScriptFiles =
  57. }
  58. // pwd / 'src / 'main / 'resources / 'assets / 'scripts