package wow.doge.mygame.events import akka.actor.typed.ActorRef import akka.actor.typed.SpawnProtocol import wow.doge.mygame.implicits._ import akka.actor.typed.scaladsl.AskPattern._ import akka.actor.typed.Props import akka.util.Timeout import akka.actor.typed.Scheduler import akka.actor.typed.LogOptions import com.typesafe.scalalogging.{Logger => SLLogger} import wow.doge.mygame.events.EventBus import akka.actor.typed.scaladsl.Behaviors import wow.doge.mygame.subsystems.events.EntityMovementEvent.PlayerMovementEvent import akka.actor.typed.SupervisorStrategy trait EventsModule { def spawnProtocol: ActorRef[SpawnProtocol.Command] implicit def akkaScheduler: Scheduler implicit def timeout: Timeout def eventBusLogger = SLLogger[EventBus[_]] lazy val tickEventBusTask = createEventBus[Events.Tick]("tickEventBus") lazy val playerMovementEventBusTask = createEventBus[PlayerMovementEvent]("movementEventBus") def createEventBus[T](busName: String) = spawnProtocol.askL( SpawnProtocol.Spawn[EventBus.Command[T]]( Behaviors.logMessages( logOptions = LogOptions().withLogger(eventBusLogger.underlying), Behaviors .supervise(EventBus[T]()) .onFailure[Exception](SupervisorStrategy.restart) ), busName, Props.empty, _ ) ) } object EventTypes { type EventBus[T] = ActorRef[EventBus.Command[T]] } // val subscribingActor = // spawnProtocol.askT( // SpawnProtocol.Spawn[Events.PhysicsTick.type]( // SubscribingActor(), // "subscriber-1", // Props.empty, // _ // ) // )