Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature gameview #4

Merged
merged 2 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/main/scala/scatan/Main.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package scatan
import com.raquo.laminar.api.L.{*, given}
import scatan.controllers.home.{HomeController, HomeControllerImpl}
import scatan.controllers.game.{SetUpController, SetUpControllerImpl}
import scatan.views.game.{SetUpView, ScalaJsSetUpView}
import scatan.controllers.game.{SetUpController, SetUpControllerImpl, GameController, GameControllerImpl}
import scatan.views.game.{SetUpView, ScalaJsSetUpView, GameView, ScalaJsGameView}
import scatan.views.home.{HomeView, ScalaJsHomeView}
import scatan.model.ApplicationState
import scatan.views.home.{AboutView, ScalaJSAboutView}
Expand Down Expand Up @@ -36,6 +36,13 @@ enum Pages(val pageFactory: PageFactory[?, ?, ApplicationState]):
controllerFactory = new AboutControllerImpl(_)
)
)
case Game
extends Pages(
PageFactory[GameController, GameView, ApplicationState](
viewFactory = new ScalaJsGameView(_, "root"),
controllerFactory = new GameControllerImpl(_)
)
)

// App
val Application: NavigableApplication[ApplicationState, Pages] = NavigableApplication[ApplicationState, Pages](
Expand Down
17 changes: 17 additions & 0 deletions src/main/scala/scatan/controllers/game/GameController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package scatan.controllers.game

import scatan.mvc.lib.Controller.Requirements
import scatan.mvc.lib.NavigableApplicationManager
import scatan.Pages
import scatan.model.ApplicationState
import scatan.mvc.lib.Controller
import scatan.views.game.GameView

trait GameController extends Controller:
def goToHome(): Unit

class GameControllerImpl(requirements: Controller.Requirements[GameView, ApplicationState])
extends GameController
with Controller.Dependencies(requirements):
def goToHome(): Unit =
NavigableApplicationManager.navigateTo(Pages.Home)
10 changes: 6 additions & 4 deletions src/main/scala/scatan/controllers/game/SetUpController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ trait SetUpController extends Controller:
def goToPlay(): Unit

/** This is the implementation of the controller for the setup page.
* @param dependencies,
* the dependencies for the controller.
* @param requirements,
* the requirements for the controller.
*/
class SetUpControllerImpl(dependencies: Controller.Requirements[SetUpView, ApplicationState]) extends SetUpController:
class SetUpControllerImpl(requirements: Controller.Requirements[SetUpView, ApplicationState])
extends SetUpController
with Controller.Dependencies(requirements):
override def goToHome(): Unit = NavigableApplicationManager.navigateTo(Pages.Home)
// TODO: implement goToPlay
override def goToPlay(): Unit = NavigableApplicationManager.navigateTo(Pages.Home)
override def goToPlay(): Unit = NavigableApplicationManager.navigateTo(Pages.Game)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package scatan.example.controller.home

import scatan.example.model.CounterAppState
import scatan.example.view
import scatan.example.view.HomeView
import scatan.example.controller.HomeController
import scatan.mvc.lib.{Controller, Model, ScalaJSView, View}

class HomeControllerImpl(requirements: Controller.Requirements[HomeView, CounterAppState])
extends HomeController
with Controller.Dependencies(requirements):

override def counter: Int = this.model.state.count
override def increment(): Unit =
this.model.update { m =>
m.copy(count = m.count + 1)
}
this.view.onCounterUpdated(this.model.state.count)
24 changes: 24 additions & 0 deletions src/main/scala/scatan/views/game/GameView.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package scatan.views.game

import scatan.controllers.game.GameController

import scatan.Pages
import com.raquo.laminar.api.L.*
import scatan.mvc.lib.{ScalaJSView, View}

trait GameView extends View

class ScalaJsGameView(requirements: View.Requirements[GameController], container: String)
extends GameView
with View.Dependencies(requirements)
with ScalaJSView(container):
val numberOfUsers: Int = 3

override def element: Element = div(
h1("Game"),
p("This is a ScalaJS view"),
button(
"Back",
onClick --> (_ => controller.goToHome())
)
)