-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
1,359 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
ThisBuild / scalaVersion := "3.3.0" | ||
|
||
wartremoverErrors ++= Warts.unsafe | ||
wartremoverErrors ++= Warts.all | ||
wartremoverWarnings ++= Warts.all | ||
wartremoverWarnings -= Wart.Equals | ||
wartremoverWarnings -= Wart.ImplicitParameter | ||
|
||
lazy val scatan = (project in file(".")) | ||
.enablePlugins(ScalaJSPlugin) | ||
.settings( | ||
name := "Scatan", | ||
scalaVersion := "3.3.0", | ||
libraryDependencies ++= Seq( | ||
// Do not remove or change order | ||
"org.scalatest" %%% "scalatest" % "3.3.0-SNAP4" % Test, | ||
"org.scalatest" %% "scalatest" % "3.3.0-SNAP4" % Test, | ||
"org.scala-js" %%% "scalajs-dom" % "2.6.0", | ||
"com.raquo" %%% "laminar" % "16.0.0" | ||
"com.raquo" %%% "laminar" % "16.0.0", | ||
"org.typelevel" %%% "cats-core" % "2.10.0", | ||
"org.scalatestplus" %%% "scalacheck-1-17" % "3.2.16.0" % Test | ||
), | ||
scalaJSUseMainModuleInitializer := true | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,54 @@ | ||
package scatan | ||
import com.raquo.laminar.api.L.{*, given} | ||
import org.scalajs.dom | ||
import scatan.controllers.home.{HomeController, HomeControllerImpl} | ||
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} | ||
import scatan.controllers.home.{AboutController, AboutControllerImpl} | ||
import scatan.mvc.lib.application.NavigableApplication | ||
import scatan.mvc.lib.page.PageFactory | ||
import scatan.mvc.lib.{Controller, Model, NavigableApplicationManager, ScalaJSView} | ||
|
||
def appElement(): Element = | ||
div( | ||
h1("Hello Laminar!"), | ||
div( | ||
className := "card", | ||
button( | ||
className := "button", | ||
"Click me!", | ||
tpe := "button" | ||
import scala.util.Random | ||
|
||
// Route | ||
enum Pages(val pageFactory: PageFactory[?, ?, ApplicationState]): | ||
case Home | ||
extends Pages( | ||
PageFactory[HomeController, HomeView, ApplicationState]( | ||
viewFactory = new ScalaJsHomeView(_, "root"), | ||
controllerFactory = new HomeControllerImpl(_) | ||
) | ||
) | ||
case Setup | ||
extends Pages( | ||
PageFactory[SetUpController, SetUpView, ApplicationState]( | ||
viewFactory = new ScalaJsSetUpView(_, "root"), | ||
controllerFactory = new SetUpControllerImpl(_) | ||
) | ||
) | ||
case About | ||
extends Pages( | ||
PageFactory[AboutController, AboutView, ApplicationState]( | ||
viewFactory = new ScalaJSAboutView(_, "root"), | ||
controllerFactory = new AboutControllerImpl(_) | ||
) | ||
) | ||
), | ||
p(className := "read-the-docs", "Click on the Vite logo to learn more") | ||
) | ||
@main | ||
def main(): Unit = | ||
val containerNode = dom.document.querySelector("#root") | ||
case Game | ||
extends Pages( | ||
PageFactory[GameController, GameView, ApplicationState]( | ||
viewFactory = new ScalaJsGameView(_, "root"), | ||
controllerFactory = new GameControllerImpl(_) | ||
) | ||
) | ||
|
||
// App | ||
val Application: NavigableApplication[ApplicationState, Pages] = NavigableApplication[ApplicationState, Pages]( | ||
initialState = ApplicationState(), | ||
pagesFactories = Pages.values.map(p => p -> p.pageFactory).toMap | ||
) | ||
|
||
// this is how you render the rootElement in the browser | ||
render(containerNode, appElement()) | ||
@main def main(): Unit = | ||
NavigableApplicationManager.startApplication(Application, Pages.Home) |
17 changes: 17 additions & 0 deletions
17
src/main/scala/scatan/controllers/game/GameController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
29 changes: 29 additions & 0 deletions
29
src/main/scala/scatan/controllers/game/SetUpController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package scatan.controllers.game | ||
|
||
import scatan.mvc.lib.Controller | ||
import scatan.views.game.SetUpView | ||
import scatan.mvc.lib.NavigableApplicationManager | ||
import scatan.Pages | ||
import scatan.model.ApplicationState | ||
|
||
/** This is the controller for the setup page. | ||
*/ | ||
trait SetUpController extends Controller: | ||
/** This method is called when the user clicks on the back button. | ||
*/ | ||
def goToHome(): Unit | ||
|
||
/** This method is called when the user clicks on the start button. | ||
*/ | ||
def goToPlay(): Unit | ||
|
||
/** This is the implementation of the controller for the setup page. | ||
* @param requirements, | ||
* the requirements for the controller. | ||
*/ | ||
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.Game) |
15 changes: 15 additions & 0 deletions
15
src/main/scala/scatan/controllers/home/AboutController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package scatan.controllers.home | ||
import scatan.mvc.lib.Controller | ||
import scatan.model.ApplicationState | ||
import scatan.views.home.AboutView | ||
import scatan.mvc.lib.NavigableApplicationManager | ||
import scatan.Pages | ||
|
||
trait AboutController extends Controller: | ||
def goToHome(): Unit | ||
|
||
class AboutControllerImpl(requirements: Controller.Requirements[AboutView, ApplicationState]) | ||
extends AboutController | ||
with Controller.Dependencies(requirements): | ||
override def goToHome(): Unit = | ||
NavigableApplicationManager.navigateTo(Pages.Home) |
30 changes: 30 additions & 0 deletions
30
src/main/scala/scatan/controllers/home/HomeController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package scatan.controllers.home | ||
|
||
import scatan.mvc.lib.Controller | ||
import scatan.views.home.HomeView | ||
import scatan.Pages | ||
import scatan.mvc.lib.application.NavigableApplication | ||
import scatan.mvc.lib.NavigableApplicationManager | ||
import scatan.model.ApplicationState | ||
|
||
/** This is the controller for the home page. | ||
*/ | ||
trait HomeController extends Controller: | ||
/** This method is called when the user clicks on the settings button. | ||
*/ | ||
def goToSetup(): Unit | ||
|
||
/** This method is called when the user clicks on the about button. | ||
*/ | ||
def goToAbout(): Unit | ||
|
||
/** This is the implementation of the controller for the home page. | ||
* @param requirements, | ||
* the requirements for the controller. | ||
*/ | ||
class HomeControllerImpl(requirements: Controller.Requirements[HomeView, ApplicationState]) extends HomeController: | ||
override def goToSetup(): Unit = | ||
NavigableApplicationManager.navigateTo[Pages](Pages.Setup) | ||
|
||
override def goToAbout(): Unit = | ||
NavigableApplicationManager.navigateTo[Pages](Pages.About) |
14 changes: 14 additions & 0 deletions
14
src/main/scala/scatan/example/controller/AboutController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package scatan.example.controller | ||
|
||
import scatan.example.model.CounterAppState | ||
import scatan.example.view.AboutView | ||
import scatan.mvc.lib.Controller | ||
|
||
trait AboutController extends Controller: | ||
def about(): Unit | ||
|
||
class AboutControllerImpl(requirements: Controller.Requirements[AboutView, CounterAppState]) | ||
extends AboutController | ||
with Controller.Dependencies(requirements): | ||
override def about(): Unit = | ||
println("About") |
7 changes: 7 additions & 0 deletions
7
src/main/scala/scatan/example/controller/HomeController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package scatan.example.controller | ||
|
||
import scatan.mvc.lib.Controller | ||
|
||
trait HomeController extends Controller: | ||
def counter: Int | ||
def increment(): Unit |
17 changes: 17 additions & 0 deletions
17
src/main/scala/scatan/example/controller/HomeControllerImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package scatan.example.controller | ||
|
||
import scatan.example.model.CounterAppState | ||
import scatan.example.view | ||
import scatan.example.view.HomeView | ||
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) |
18 changes: 18 additions & 0 deletions
18
src/main/scala/scatan/example/controller/home/HomeControllerImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package scatan.example.model | ||
|
||
import scatan.mvc.lib.Model | ||
|
||
case class CounterAppState(count: Int) extends Model.State |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package scatan.example.view | ||
|
||
import com.raquo.laminar.api.L.* | ||
import scatan.example.controller.AboutController | ||
import scatan.mvc.lib.{NavigableApplicationManager, ScalaJSView, View} | ||
|
||
trait AboutView extends View: | ||
def about(): Unit | ||
|
||
class ScalaJSAboutView(requirements: View.Requirements[AboutController], container: String) | ||
extends AboutView | ||
with View.Dependencies[AboutController](requirements) | ||
with ScalaJSView(container): | ||
|
||
override def about(): Unit = ??? | ||
|
||
override def element: Element = div( | ||
h1("About"), | ||
p("This is a ScalaJS view"), | ||
button( | ||
"Back", | ||
onClick --> (_ => NavigableApplicationManager.navigateBack()) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package scatan.example.view | ||
|
||
import scatan.mvc.lib.{ScalaJSView, View} | ||
|
||
trait HomeView extends View: | ||
def onCounterUpdated(counter: Int): Unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package scatan.example.view | ||
|
||
import com.raquo.laminar.api.L.* | ||
import scatan.Pages | ||
import scatan.example.controller.HomeController | ||
import scatan.mvc.lib.{NavigableApplicationManager, ScalaJSView, View} | ||
|
||
class ScalaJsHomeView(requirements: View.Requirements[HomeController], container: String) | ||
extends HomeView | ||
with View.Dependencies(requirements) | ||
with ScalaJSView(container): | ||
|
||
private val reactiveCounter = Var(this.controller.counter) | ||
|
||
override def element: Element = | ||
div( | ||
h1("Scala.js Home"), | ||
p("This is a Scala.js view"), | ||
p("The counter is: ", child.text <-- reactiveCounter.signal), | ||
button( | ||
"Increment", | ||
onClick --> (_ => controller.increment()) | ||
), | ||
button( | ||
"Switch to About Page", | ||
onClick --> (_ => NavigableApplicationManager.navigateTo(Pages.About)) | ||
) | ||
) | ||
|
||
override def onCounterUpdated(counter: Int): Unit = | ||
reactiveCounter.set(counter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package scatan.model | ||
|
||
import scatan.mvc.lib.Model | ||
|
||
final case class ApplicationState() extends Model.State |
Oops, something went wrong.