Skip to content

Commit f9bc6ac

Browse files
chore: Tidy up
1 parent 9671209 commit f9bc6ac

File tree

8 files changed

+109
-86
lines changed

8 files changed

+109
-86
lines changed

.gitignore

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
1-
# sbt
2-
lib_managed
3-
project/project
4-
target
1+
# Log files
2+
*.class
3+
*.log
4+
5+
# sbt specific
6+
.cache
7+
dist/*
8+
lib_managed/
9+
project/**/project
10+
project/activator-sbt*
11+
src_managed/
12+
target/
513

614
# Worksheets (Eclipse or IntelliJ)
715
*.sc
816

9-
# Eclipse
10-
.cache
17+
# Scala-IDE specific
1118
.classpath
1219
.project
1320
.scala_dependencies
1421
.settings
15-
.target
1622
.worksheet
1723

1824
# IntelliJ
19-
.idea
25+
*.iml
26+
*.iws
27+
.idea/
28+
/classes/
29+
/out/
30+
31+
# ScalaTest
32+
exportToHTML
2033

2134
# Mac
2235
.DS_Store
2336

24-
# Log files
25-
*.log
37+
# Windows
38+
desktop.ini
39+
thumbs.db

build.sbt

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,70 @@
1-
name := "FullWindowHtml5Canvas"
2-
version := "0.0"
3-
organization := "nl.amsscala"
4-
organizationName := "Amsterdam.scala Meetup Group"
1+
name := "FullWindowHtml5Canvas"
2+
version := "0.0"
3+
description := "Simple HTML5 Canvas game ported to Scala.js."
4+
organization := "nl.amsscala"
5+
organizationName := "Amsterdam.scala Meetup Group"
56
organizationHomepage := Some(url("http://www.meetup.com/amsterdam-scala/"))
6-
homepage := Some(url("http://github.com/amsterdam-scala/Sjs-Full-Window-HTML5-Canvas"))
7+
homepage := Some(url("http://github.com/amsterdam-scala/Sjs-Full-Window-HTML5-Canvas"))
8+
startYear := Some(2016)
9+
licenses += "EUPL v.1.1" -> url("http://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11")
710

8-
startYear := Some(2016)
11+
// KEEP THIS normalizedName CONSTANTLY THE SAME, otherwise the outputted JS filename will be changed.
12+
normalizedName := "main"
913

10-
description := "Scala.js application using HTML5 canvas to fill the window, repainted on window resize."
11-
12-
licenses += "EUPL v.1.1" -> url("http://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11")
13-
14-
scalaVersion := "2.11.8"
15-
16-
// Keep this normalizedName constantly the same, otherwise the outputted JS filename will be changed.
17-
normalizedName := "main"
14+
// ** Scala dependencies **
15+
scalaVersion in ThisBuild := "2.11.8"
1816

1917
resolvers += Resolver.sonatypeRepo("snapshots")
2018
libraryDependencies ++= Seq(
21-
"be.doeraene" %%% "scalajs-jquery" % "0.9.0",
19+
"be.doeraene" %%% "scalajs-jquery" % "0.9.0",
2220
"com.github.cquiroz" %%% "scala-java-locales" % "0.3.0+29",
23-
"com.github.karasiq" %%% "scalajs-bootstrap" % "1.1.1",
24-
"com.lihaoyi" %%% "scalatags" % "0.6.0",
25-
"com.lihaoyi" %%% "upickle" % "0.4.1",
26-
"com.lihaoyi" %%% "utest" % "0.4.3" % "test",
27-
"io.github.soc" %%% "scala-java-time" % "2.0.0-M2",
28-
"io.surfkit" %%% "scalajs-google-maps" % "0.1-SNAPSHOT",
29-
"org.scala-js" %%% "scalajs-dom" % "0.9.1",
30-
"org.scalatest" %% "scalatest" % "3.0.0" % "test")
31-
32-
//scalaJSStage in Global := FastOptStage
33-
scalaJSUseRhino in Global := false
21+
"com.github.karasiq" %%% "scalajs-bootstrap" % "1.1.1",
22+
"com.lihaoyi" %%% "scalatags" % "0.6.0",
23+
"com.lihaoyi" %%% "upickle" % "0.4.1",
24+
"io.github.soc" %%% "scala-java-time" % "2.0.0-M2",
25+
"io.surfkit" %%% "scalajs-google-maps"% "0.1-SNAPSHOT",
26+
"org.scala-js" %%% "scalajs-dom" % "0.9.1",
27+
"org.scalatest" %% "scalatest" % "3.0.0" % "test")
28+
29+
scalacOptions in (Compile,doc) ++= Seq("-doc-root-content", baseDirectory.value+"/src/main/scala-2.11/root-doc.md",
30+
"-groups", "-implicits")
31+
32+
// ** Scala.js configuration **
33+
// lazy val root = (project in file(".")).
34+
enablePlugins(ScalaJSPlugin)
35+
36+
// Necessary for testing
3437
jsDependencies += RuntimeDOM
38+
scalaJSUseRhino in Global := false
39+
jsEnv := PhantomJSEnv(autoExit = false).value
3540

36-
// If true, a launcher script src="../[normalizedName]-launcher.js will
37-
// be generated that always calls the main def indicated by the JSApp.
41+
// If true, a launcher script src="../[normalizedName]-launcher.js will be generated
42+
// that always calls the main def indicated by the used JSApp trait.
3843
persistLauncher in Compile := true
3944
persistLauncher in Test := false
4045

4146
// Will create [normalizedName]-jsdeps.js containing all JavaScript libraries
4247
jsDependencies ++= Seq(
4348
// "org.webjars" % "jquery" % "3.1.0" / "3.1.0/jquery.js",
4449
"org.webjars" % "jstimezonedetect" % "1.0.6" / "1.0.6/jstz.js")
50+
skip in packageJSDependencies := false // All JavaScript dependencies to be concatenated to a single file
51+
52+
// ScalaTest settings //
53+
// testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-oF")
4554

46-
lazy val root = (project in file(".")).enablePlugins(ScalaJSPlugin)
55+
// Workbench settings **
56+
if (sys.env.isDefinedAt("CI")) {
57+
println("Workbench disabled ", sys.env.getOrElse("CI", "?"))
58+
Seq.empty
59+
} else {
60+
println("Workbench enabled")
61+
workbenchSettings
62+
}
4763

48-
// Set the main class for packaging the main in jar, so irrelevant for Scala.js
49-
// mainClass in Compile := Some("nl.amsscala.rembrandt.Main")
50-
workbenchSettings
51-
refreshBrowsers <<= refreshBrowsers.triggeredBy(fastOptJS in Compile)
64+
if (sys.env.isDefinedAt("CI")) normalizedName := normalizedName.value // Dummy
65+
else // Update without refreshing the page every time fastOptJS completes
66+
updateBrowsers <<= updateBrowsers.triggeredBy(fastOptJS in Compile)
5267

53-
// Workbench has to know how to restart your application.
54-
bootSnippet := "Main().main(document.getElementById('canvas'));"
68+
if (sys.env.isDefinedAt("CI")) normalizedName := normalizedName.value
69+
else // Workbench has to know how to restart your application.
70+
bootSnippet := "Main().main(document.getElementById('canvas'));"

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.11")
2-
addSbtPlugin("com.lihaoyi" % "workbench" % "0.2.3")
2+
addSbtPlugin("com.lihaoyi" % "workbench" % "latest.integration")

src/main/resources/index-dev.html

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,15 @@
1111
<meta name=generator content="Scala.js Scalatags">
1212
<meta name=versionId content="2016-08">
1313

14-
<title>Scala.js | Scaffold</title>
14+
<title>Scala.js | Bubbles!</title>
1515
<link rel=apple-touch-icon href="img/apple-touch-icon.png">
16-
<!-- Place favicon.ico in the root directory -->
17-
<link rel=icon href="img/favicon.ico" type="image/x-icon">
18-
19-
<!-- Latest compiled and minified Bootstrap CSS, normalize.css is already included-->
20-
<!--<link rel="stylesheet" media="screen" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
21-
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">-->
16+
<!-- Place favicon.ico in the img directory -->
17+
<link rel=icon type="image/x-icon" href="img/favicon.ico">
2218

2319
<!-- Custom styles for this page -->
2420
<link rel=stylesheet media="screen" href="css/main.css">
2521

26-
<!-- Include JavaScript dependencies e.g. jquery.js -->
27-
<script type="text/javascript" src="../main-jsdeps.js"></script>
28-
<!-- Include Scala.js compiled code -->
29-
<script type="text/javascript" src="../main-fastopt.js"></script>
30-
22+
<!--Workbench for development only -->
3123
<script type="text/javascript" src="/workbench.js"></script>
3224

3325
<!--<style type="text/css"></style>-->
@@ -41,10 +33,15 @@
4133

4234
<!-- Add your site or application content here -->
4335
<div>
44-
<canvas id="canvas">Your browser doesn't support the HTML5 CANVAS tag.</canvas>
36+
<canvas id="canvas main">Your browser doesn't support the HTML5 CANVAS tag.</canvas>
4537
</div>
4638

47-
<!-- Run application. -->
39+
<!-- Include JavaScript dependencies -->
40+
<script type="text/javascript" src="../main-jsdeps.js"></script>
41+
<!-- Include Scala.js compiled code -->
42+
<script type="text/javascript" src="../main-fastopt.js"></script>
43+
<!-- Run JSApp -->
44+
<!-- <script type="text/javascript" src="../main-launcher.js"></script> -->
4845
<script type="text/javascript"> nl.amsscala.rembrandt.Main().main(document.getElementById('canvas'));</script>
4946
</body>
5047
</html>

src/main/resources/index.html

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,12 @@
1313

1414
<title>Scala.js | Bubbles!</title>
1515
<link rel=apple-touch-icon href="img/apple-touch-icon.png">
16-
<!-- Place favicon.ico in the root directory -->
17-
<link rel=icon href="img/favicon.ico" type="image/x-icon">
18-
19-
<!-- Latest compiled and minified Bootstrap CSS, normalize.css is already included-->
20-
<!--<link rel="stylesheet" media="screen" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
21-
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">-->
16+
<!-- Place favicon.ico in the img directory -->
17+
<link rel=icon type="image/x-icon" href="img/favicon.ico">
2218

2319
<!-- Custom styles for this page -->
2420
<link rel=stylesheet media="screen" href="css/main.css">
2521

26-
<!-- Include JavaScript dependencies e.g. jquery.js -->
27-
<script type="text/javascript" src="../main-opt.js"></script>
28-
<!-- Include Scala.js compiled code -->
29-
<script type="text/javascript" src="../main-jsdeps.min.js"></script>
30-
3122
<!--<style type="text/css"></style>-->
3223
</head>
3324

@@ -39,9 +30,14 @@
3930

4031
<!-- Add your site or application content here -->
4132
<div>
42-
<canvas id="canvas">Your browser doesn't support the HTML5 CANVAS tag.</canvas>
33+
<canvas id="canvas main">Your browser doesn't support the HTML5 CANVAS tag.</canvas>
4334
</div>
4435

36+
<!-- Include JavaScript dependencies e.g. jQuery.js -->
37+
<script type="text/javascript" src="../main-jsdeps.min.js"></script>
38+
<!-- Include Scala.js compiled code -->
39+
<script type="text/javascript" src="../main-opt.js"></script>
40+
4541
<!-- Run application. -->
4642
<script type="text/javascript"> nl.amsscala.rembrandt.Main().main(document.getElementById('canvas'));</script>
4743
</body>

src/main/scala-2.11/nl/amsscala/rembrandt/Bubbles.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ trait Bubbles{
3030

3131
waves = waves.map(draw).takeWhile { w => w.time * 8 * speed < canvas.width || w.time * 5 * speed < canvas.height }
3232

33-
canvas.onmousedown = { (e: dom.MouseEvent) => waves +:= Wave(new Point(e.clientX, e.clientY)) }
33+
lazy val runOnce = canvas.onmousedown = { (e: dom.MouseEvent) => waves +:= Wave(new Point(e.clientX, e.clientY)) }
34+
runOnce
3435
}
3536

3637
}

src/main/scala-2.11/nl/amsscala/rembrandt/Main.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package nl.amsscala.rembrandt
1+
package nl.amsscala
2+
package rembrandt
23

34
import org.scalajs.dom
45

@@ -9,16 +10,14 @@ import scala.scalajs.js.annotation.JSExport
910
* Use this code as a template for resizeable full-window canvas applications. In index.html, replace %main application
1011
* class% with the application's main class name (whatever packaged name you give to the copy of this file).
1112
*/
12-
@JSExport
13-
object Main extends js.JSApp with Resizeable with Fancy with Clock with Bubbles{
13+
object Main extends js.JSApp with Resizeable/* with Fancy*/ with Clock with Bubbles{
1414
lazy val timezone = js.Dynamic.global.jstz.determine().name().toString
1515

1616
/**
1717
* Alternative method is enforced by JSApp which is necessary for the parameterless main call of the sbt
1818
* generated launcher when generation is set in build.sbt as: `persistLauncher in Compile := true`
1919
*/
20-
@JSExport
21-
def main(): Unit = main(dom.document.getElementById("canvas").asInstanceOf[dom.html.Canvas])
20+
def main(): Unit = main(dom.document.getElementById("canvas main").asInstanceOf[dom.html.Canvas])
2221

2322
/**
2423
* The method initially called when the HTML page is loaded typically by its `Main().main(...)`
@@ -28,14 +27,14 @@ object Main extends js.JSApp with Resizeable with Fancy with Clock with Bubbles{
2827
*
2928
* @param canvas The HTML element, the container for graphics
3029
*/
31-
@JSExport
3230
def main(canvas: dom.html.Canvas): Unit = {
3331

34-
println(s"Main started at ${dateTimeStringOfPattern("d-MMM-yyyy HH:mm:ss")}.")
32+
def run() = intialResize(canvas, List(successiveResize, fancy, clock, bubbles), timezone)
3533

36-
intialResize(canvas, List(successiveResize, fancy, clock, bubbles), timezone)
34+
println(s"Main started at ${dateTimeStringOfPattern("d-MMM-yyyy HH:mm:ss")}.")
35+
run()
3736
// Initialize the canvas and refresh continuously.
38-
dom.window.setInterval(() => intialResize(canvas, List(successiveResize, fancy, clock, bubbles), timezone), 40)
37+
dom.window.setInterval(() => run(), 40)
3938

4039
// ... rest of the application logic
4140
}

src/main/scala-2.11/nl/amsscala/rembrandt/Resizeable.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import org.scalajs.dom
66
trait Resizeable {
77
type painterList = List[(dom.html.Canvas, dom.CanvasRenderingContext2D, => String) => Unit]
88

9-
private var painters: Option[painterList] = None
9+
private var painters: painterList = List.empty
1010

1111
def successiveResize(canvas: dom.html.Canvas, renderer: dom.CanvasRenderingContext2D, dummy: => String) = {
1212
canvas.width = dom.window.innerWidth.toInt
1313
canvas.height = dom.window.innerHeight.toInt
1414
}
1515

1616
protected def intialResize(canvas: dom.html.Canvas, _painters: painterList, context: => String): Unit = {
17-
painters = Option(_painters)
17+
painters = _painters
1818
val renderer = canvas.getContext("2d").asInstanceOf[dom.CanvasRenderingContext2D]
1919

20-
painters.get.foreach(_ (canvas, renderer, context))
21-
dom.window.onresize = (event: dom.Event) => painters.get.foreach(_ (canvas, renderer, context))
20+
painters.foreach(_ (canvas, renderer, context))
21+
dom.window.onresize = (event: dom.Event) => painters.foreach(_ (canvas, renderer, context))
2222
}
2323
}

0 commit comments

Comments
 (0)