Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
manuandru committed Sep 18, 2023
2 parents 647ca82 + 6c5bce7 commit 3836f61
Show file tree
Hide file tree
Showing 47 changed files with 1,359 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Test
on:
push:
branches-ignore: [ 'doc' ]
branches-ignore: [ 'doc', 'develop' ]
pull_request:
branches: [ 'develop' ]

Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# mdbook compiled book
book
.bloop/
.metals/
.vscode/
project/.bloop/
project/metals.sbt
project/project/

.DS_Store
.idea/*
Expand Down
10 changes: 7 additions & 3 deletions build.sbt
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
)
Binary file added res/img/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/img/backgroundBlurred.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions scatan.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<title>Scatan</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div id="root"></div>
Expand Down
67 changes: 49 additions & 18 deletions src/main/scala/scatan/Main.scala
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 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)
29 changes: 29 additions & 0 deletions src/main/scala/scatan/controllers/game/SetUpController.scala
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 src/main/scala/scatan/controllers/home/AboutController.scala
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 src/main/scala/scatan/controllers/home/HomeController.scala
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 src/main/scala/scatan/example/controller/AboutController.scala
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 src/main/scala/scatan/example/controller/HomeController.scala
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 src/main/scala/scatan/example/controller/HomeControllerImpl.scala
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)
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)
5 changes: 5 additions & 0 deletions src/main/scala/scatan/example/model/CounterAppState.scala
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
24 changes: 24 additions & 0 deletions src/main/scala/scatan/example/view/AboutView.scala
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())
)
)
6 changes: 6 additions & 0 deletions src/main/scala/scatan/example/view/HomeView.scala
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
31 changes: 31 additions & 0 deletions src/main/scala/scatan/example/view/ScalaJsHomeView.scala
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)
5 changes: 5 additions & 0 deletions src/main/scala/scatan/model/ApplicationState.scala
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
Loading

0 comments on commit 3836f61

Please sign in to comment.