From a587b1b934f3efe7e02ce3f9e684358e8a9a32cd Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 31 Aug 2023 07:50:00 +0100 Subject: [PATCH] Use refactored values --- demos/pirate/build.sbt | 4 +- demos/snake/build.sc | 4 +- examples/build.sbt | 32 +++++++-------- .../src/indigoplugin/core/IndigoCordova.scala | 5 ++- .../src/indigoplugin/core/IndigoRun.scala | 29 ++++++-------- .../templates/ElectronTemplates.scala | 10 +++-- indigo/build.sbt | 8 ++-- .../src/millindigo/MillIndigo.scala | 39 ++++--------------- .../src/main/scala/sbtindigo/SbtIndigo.scala | 39 ++++--------------- 9 files changed, 62 insertions(+), 108 deletions(-) diff --git a/demos/pirate/build.sbt b/demos/pirate/build.sbt index 03d266c9a..7f97fd06f 100644 --- a/demos/pirate/build.sbt +++ b/demos/pirate/build.sbt @@ -29,8 +29,8 @@ lazy val pirate = indigoOptions := IndigoOptions.defaults .withTitle("The Cursed Pirate") - .withWindowStartWidth(1280) - .withWindowStartHeight(720) + .withWindowWidth(1280) + .withWindowHeight(720) .withBackgroundColor("black"), libraryDependencies ++= Seq( "io.indigoengine" %%% "indigo-json-circe" % IndigoVersion.getVersion, // Needed for Aseprite & Tiled support diff --git a/demos/snake/build.sc b/demos/snake/build.sc index 486beff9f..b25cf51ea 100644 --- a/demos/snake/build.sc +++ b/demos/snake/build.sc @@ -17,8 +17,8 @@ object snake extends ScalaJSModule with MillIndigo with ScalafmtModule { val indigoOptions: IndigoOptions = IndigoOptions.defaults .withTitle("Snake - Made with Indigo") - .withWindowStartWidth(720) - .withWindowStartHeight(516) + .withWindowWidth(720) + .withWindowHeight(516) .withBackgroundColor("black") def buildGame() = T.command { diff --git a/examples/build.sbt b/examples/build.sbt index d75f4f13a..37d968009 100644 --- a/examples/build.sbt +++ b/examples/build.sbt @@ -176,8 +176,8 @@ lazy val tiled = .withTitle("Tiled example") .withBackgroundColor("black") .withAssetDirectory("tiled/assets") - .withWindowStartWidth(19 * 32) - .withWindowStartHeight(11 * 32), + .withWindowWidth(19 * 32) + .withWindowHeight(11 * 32), libraryDependencies ++= Seq( "io.indigoengine" %%% "indigo-json-circe" % IndigoVersion.getVersion ) @@ -256,8 +256,8 @@ lazy val fireworks = .withTitle("Fireworks!") .withBackgroundColor("black") .withAssetDirectory("fireworks/assets") - .withWindowStartWidth(1280) - .withWindowStartHeight(720), + .withWindowWidth(1280) + .withWindowHeight(720), libraryDependencies ++= Seq( "org.scalacheck" %%% "scalacheck" % "1.15.3" % "test" ) @@ -290,8 +290,8 @@ lazy val lighting = .withTitle("Lighting") .withBackgroundColor("black") .withAssetDirectory("lighting/assets") - .withWindowStartWidth(684) - .withWindowStartHeight(384) + .withWindowWidth(684) + .withWindowHeight(384) ) .settings( publish := {}, @@ -310,8 +310,8 @@ lazy val distortion = .withTitle("Distortion Example") .withBackgroundColor("black") .withAssetDirectory("distortion/assets") - .withWindowStartWidth(684) - .withWindowStartHeight(384) + .withWindowWidth(684) + .withWindowHeight(384) ) .settings( publish := {}, @@ -382,8 +382,8 @@ lazy val jobs = .withTitle("Job System Example") .withBackgroundColor("black") .withAssetDirectory("jobs/assets") - .withWindowStartWidth(400) - .withWindowStartHeight(400) + .withWindowWidth(400) + .withWindowHeight(400) ) lazy val confetti = @@ -399,8 +399,8 @@ lazy val confetti = .withTitle("Confetti") .withBackgroundColor("black") .withAssetDirectory("confetti/assets") - .withWindowStartWidth(640) - .withWindowStartHeight(480) + .withWindowWidth(640) + .withWindowHeight(480) ) lazy val inputmapper = @@ -416,8 +416,8 @@ lazy val inputmapper = .withTitle("Input Mapper Example") .withBackgroundColor("black") .withAssetDirectory("inputmapper/assets") - .withWindowStartWidth(400) - .withWindowStartHeight(400) + .withWindowWidth(400) + .withWindowHeight(400) ) lazy val mouseevents = @@ -448,8 +448,8 @@ lazy val errors = .withTitle("Error Handling") .withBackgroundColor("black") .withAssetDirectory("errors/assets") - .withWindowStartWidth(800) - .withWindowStartHeight(800) + .withWindowWidth(800) + .withWindowHeight(800) ) // Root diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoCordova.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoCordova.scala index 0a24d5f7e..f96b0e457 100644 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoCordova.scala +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoCordova.scala @@ -5,15 +5,16 @@ import indigoplugin.templates.CordovaTemplates import os._ import indigoplugin.templates.SupportScriptTemplate import indigoplugin.datatypes.FileToWrite +import indigoplugin.IndigoGameMetadata object IndigoCordova { - def run(outputDir: Path, buildDir: Path, title: String, windowWidth: Int, windowHeight: Int): Unit = { + def run(outputDir: Path, buildDir: Path, metadata: IndigoGameMetadata): Unit = { os.remove.all(outputDir) os.makeDir.all(outputDir) - filesToWrite(title, windowWidth, windowHeight).foreach { f => + filesToWrite(metadata.title, metadata.width, metadata.height).foreach { f => os.makeDir.all(outputDir / f.folderPath) os.write.over(outputDir / f.folderPath / f.name, f.contents) } diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoRun.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoRun.scala index 850e75c26..c24637100 100644 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoRun.scala +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoRun.scala @@ -8,6 +8,7 @@ import indigoplugin.templates.SupportScriptTemplate import indigoplugin.datatypes.FileToWrite import indigoplugin.utils.AsciiLogo import indigoplugin.ElectronInstall +import indigoplugin.IndigoOptions object IndigoRun { @@ -20,16 +21,12 @@ object IndigoRun { def run( outputDir: Path, buildDir: Path, - title: String, - windowWidth: Int, - windowHeight: Int, - disableFrameRateLimit: Boolean, - electronInstall: ElectronInstall + indigoOptions: IndigoOptions ): Unit = { os.makeDir.all(outputDir) - filesToWrite(windowWidth, windowHeight, disableFrameRateLimit, electronInstall).foreach { f => + filesToWrite(indigoOptions).foreach { f => os.write.over(outputDir / f.name, f.contents) } @@ -43,11 +40,11 @@ object IndigoRun { os.remove(supportFile) os.write(supportFile, support) - println(s"Starting '$title'") + println(s"Starting '${indigoOptions.metadata.title} title'") sys.props("os.name").toLowerCase match { case x if x contains "windows" => - electronInstall match { + indigoOptions.electron.electronInstall match { case ElectronInstall.Global => IndigoProc.Windows.npmStart(outputDir) @@ -75,7 +72,7 @@ object IndigoRun { } case _ => - electronInstall match { + indigoOptions.electron.electronInstall match { case ElectronInstall.Global => IndigoProc.Nix.npmStart(outputDir) @@ -106,16 +103,14 @@ object IndigoRun { () } - def filesToWrite( - windowWidth: Int, - windowHeight: Int, - disableFrameRateLimit: Boolean, - electronInstall: ElectronInstall - ): List[FileToWrite] = + def filesToWrite(indigoOptions: IndigoOptions): List[FileToWrite] = List( - FileToWrite("main.js", ElectronTemplates.mainFileTemplate(windowWidth, windowHeight)), + FileToWrite( + "main.js", + ElectronTemplates.mainFileTemplate(indigoOptions.metadata.width, indigoOptions.metadata.height) + ), FileToWrite("preload.js", ElectronTemplates.preloadFileTemplate), - FileToWrite("package.json", ElectronTemplates.packageFileTemplate(disableFrameRateLimit, electronInstall)) + FileToWrite("package.json", ElectronTemplates.packageFileTemplate(indigoOptions.electron)) ) } diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/templates/ElectronTemplates.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/templates/ElectronTemplates.scala index 38a816905..3db4142c3 100644 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/templates/ElectronTemplates.scala +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/templates/ElectronTemplates.scala @@ -1,6 +1,7 @@ package indigoplugin.templates import indigoplugin.ElectronInstall +import indigoplugin.IndigoElectronOptions object ElectronTemplates { @@ -53,23 +54,26 @@ app.on('window-all-closed', function () { // code. You can also put them in separate files and require them here. """ - def packageFileTemplate(disableFrameRateLimit: Boolean, electronInstall: ElectronInstall): String = + def packageFileTemplate(electronOptions: IndigoElectronOptions): String = { + val disableFrameLimit = if (electronOptions.disableFrameRateLimit) " --disable-frame-rate-limit" else "" + s"""{ "name": "indigo-runner", "version": "1.0.0", "description": "Indigo Runner", "main": "main.js", "scripts": { - "start": "${electronInstall.executable}${if (disableFrameRateLimit) " --disable-frame-rate-limit" else ""} ." + "start": "${electronOptions.electronInstall.executable}${disableFrameLimit} ." }, "repository": "", "author": "Purple Kingdom Games", "license": "MIT", "devDependencies": { - ${electronInstall.devDependencies} + ${electronOptions.electronInstall.devDependencies} } } """ + } lazy val preloadFileTemplate: String = """// All of the Node.js APIs are available in the preload process. diff --git a/indigo/build.sbt b/indigo/build.sbt index 9029580e3..7d9bb70a5 100644 --- a/indigo/build.sbt +++ b/indigo/build.sbt @@ -104,8 +104,8 @@ lazy val perf = IndigoOptions.defaults .withTitle("Perf") .withBackgroundColor("black") - .withWindowStartWidth(800) - .withWindowStartHeight(600) + .withWindowWidth(800) + .withWindowHeight(600) .withAssetDirectory("perf/assets/") ) @@ -122,8 +122,8 @@ lazy val shader = IndigoOptions.defaults .withTitle("Shader") .withBackgroundColor("black") - .withWindowStartWidth(450) - .withWindowStartHeight(450) + .withWindowWidth(450) + .withWindowHeight(450) .withAssetDirectory("shader/assets/") ) diff --git a/mill-indigo/mill-indigo/src/millindigo/MillIndigo.scala b/mill-indigo/mill-indigo/src/millindigo/MillIndigo.scala index 3485f05ca..2ccc95b6b 100644 --- a/mill-indigo/mill-indigo/src/millindigo/MillIndigo.scala +++ b/mill-indigo/mill-indigo/src/millindigo/MillIndigo.scala @@ -7,7 +7,6 @@ import mill.define.Command import java.io.File import mill.define.Persistent import indigoplugin.core.IndigoBuildMill -import indigoplugin.datatypes.TemplateOptions import indigoplugin.core.IndigoRun import indigoplugin.core.IndigoCordova import indigoplugin.IndigoOptions @@ -38,14 +37,9 @@ trait MillIndigo extends mill.Module { } IndigoBuildMill.build( + scriptPathBase, T.dest, - TemplateOptions( - indigoOptions.title, - indigoOptions.showCursor, - scriptPathBase, - indigoOptions.gameAssetsDirectory, - indigoOptions.backgroundColor - ) + indigoOptions ) T.dest @@ -73,14 +67,9 @@ trait MillIndigo extends mill.Module { } IndigoBuildMill.build( + scriptPathBase, outputDir, - TemplateOptions( - indigoOptions.title, - indigoOptions.showCursor, - scriptPathBase, - indigoOptions.gameAssetsDirectory, - indigoOptions.backgroundColor - ) + indigoOptions ) outputDir @@ -94,11 +83,7 @@ trait MillIndigo extends mill.Module { IndigoRun.run( outputDir, buildDir, - indigoOptions.title, - indigoOptions.windowStartWidth, - indigoOptions.windowStartHeight, - indigoOptions.disableFrameRateLimit, - indigoOptions.electronInstall + indigoOptions ) } @@ -110,11 +95,7 @@ trait MillIndigo extends mill.Module { IndigoRun.run( outputDir, buildDir, - indigoOptions.title, - indigoOptions.windowStartWidth, - indigoOptions.windowStartHeight, - indigoOptions.disableFrameRateLimit, - indigoOptions.electronInstall + indigoOptions ) } @@ -126,9 +107,7 @@ trait MillIndigo extends mill.Module { IndigoCordova.run( outputDir, buildDir, - indigoOptions.title, - indigoOptions.windowStartWidth, - indigoOptions.windowStartHeight + indigoOptions.metadata ) } @@ -140,9 +119,7 @@ trait MillIndigo extends mill.Module { IndigoCordova.run( outputDir, buildDir, - indigoOptions.title, - indigoOptions.windowStartWidth, - indigoOptions.windowStartHeight + indigoOptions.metadata ) } diff --git a/sbt-indigo/src/main/scala/sbtindigo/SbtIndigo.scala b/sbt-indigo/src/main/scala/sbtindigo/SbtIndigo.scala index 56bbd2614..8be32362d 100644 --- a/sbt-indigo/src/main/scala/sbtindigo/SbtIndigo.scala +++ b/sbt-indigo/src/main/scala/sbtindigo/SbtIndigo.scala @@ -5,7 +5,6 @@ import sbt._ import indigoplugin.IndigoOptions import indigoplugin.core.IndigoBuildSBT -import indigoplugin.datatypes.TemplateOptions import indigoplugin.core.IndigoCordova import indigoplugin.core.IndigoRun @@ -73,14 +72,9 @@ object SbtIndigo extends sbt.AutoPlugin { println(scriptPathBase) IndigoBuildSBT.build( + os.Path(scriptPathBase), baseDir, - TemplateOptions( - title = indigoOptions.value.title, - showCursor = indigoOptions.value.showCursor, - scriptPathBase = os.Path(scriptPathBase), - gameAssetsDirectoryPath = indigoOptions.value.gameAssetsDirectory, - backgroundColor = indigoOptions.value.backgroundColor - ), + indigoOptions.value, outputDir, List( "main.js", @@ -106,14 +100,9 @@ object SbtIndigo extends sbt.AutoPlugin { println(scriptPathBase) IndigoBuildSBT.build( + os.Path(scriptPathBase), baseDir, - TemplateOptions( - title = indigoOptions.value.title, - showCursor = indigoOptions.value.showCursor, - scriptPathBase = os.Path(scriptPathBase), - gameAssetsDirectoryPath = indigoOptions.value.gameAssetsDirectory, - backgroundColor = indigoOptions.value.backgroundColor - ), + indigoOptions.value, outputDir, List( "main.js", @@ -133,11 +122,7 @@ object SbtIndigo extends sbt.AutoPlugin { IndigoRun.run( outputDir = outputDir, buildDir = buildDir, - title = indigoOptions.value.title, - windowWidth = indigoOptions.value.windowStartWidth, - windowHeight = indigoOptions.value.windowStartHeight, - disableFrameRateLimit = indigoOptions.value.disableFrameRateLimit, - electronInstall = indigoOptions.value.electronInstall + indigoOptions = indigoOptions.value ) } @@ -150,11 +135,7 @@ object SbtIndigo extends sbt.AutoPlugin { IndigoRun.run( outputDir = outputDir, buildDir = buildDir, - title = indigoOptions.value.title, - windowWidth = indigoOptions.value.windowStartWidth, - windowHeight = indigoOptions.value.windowStartHeight, - disableFrameRateLimit = indigoOptions.value.disableFrameRateLimit, - electronInstall = indigoOptions.value.electronInstall + indigoOptions = indigoOptions.value ) } @@ -167,9 +148,7 @@ object SbtIndigo extends sbt.AutoPlugin { IndigoCordova.run( outputDir = outputDir, buildDir = buildDir, - title = indigoOptions.value.title, - windowWidth = indigoOptions.value.windowStartWidth, - windowHeight = indigoOptions.value.windowStartHeight + metadata = indigoOptions.value.metadata ) } @@ -182,9 +161,7 @@ object SbtIndigo extends sbt.AutoPlugin { IndigoCordova.run( outputDir = outputDir, buildDir = buildDir, - title = indigoOptions.value.title, - windowWidth = indigoOptions.value.windowStartWidth, - windowHeight = indigoOptions.value.windowStartHeight + metadata = indigoOptions.value.metadata ) }