diff --git a/demos/pirate/build.sbt b/demos/pirate/build.sbt index 598bf045d..03d266c9a 100644 --- a/demos/pirate/build.sbt +++ b/demos/pirate/build.sbt @@ -1,4 +1,4 @@ -import indigoplugin.ElectronInstall +import indigoplugin.IndigoOptions Global / onChangedBuildSource := ReloadOnSourceChanges @@ -26,14 +26,12 @@ lazy val pirate = Test / scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) } ) .settings( // Indigo specific settings - showCursor := true, - title := "The Cursed Pirate", - gameAssetsDirectory := "assets", - windowStartWidth := 1280, - windowStartHeight := 720, - disableFrameRateLimit := false, - electronInstall := ElectronInstall.Latest, - backgroundColor := "black", + indigoOptions := + IndigoOptions.defaults + .withTitle("The Cursed Pirate") + .withWindowStartWidth(1280) + .withWindowStartHeight(720) + .withBackgroundColor("black"), libraryDependencies ++= Seq( "io.indigoengine" %%% "indigo-json-circe" % IndigoVersion.getVersion, // Needed for Aseprite & Tiled support "io.indigoengine" %%% "indigo" % IndigoVersion.getVersion, // Important! :-) diff --git a/demos/snake/build.sc b/demos/snake/build.sc index 4a100ff45..486beff9f 100644 --- a/demos/snake/build.sc +++ b/demos/snake/build.sc @@ -8,20 +8,18 @@ import mill.scalajslib.api._ import mill.scalalib.scalafmt._ import coursier.maven.MavenRepository -import $ivy.`io.indigoengine::mill-indigo:0.15.0-RC3`, millindigo._ +import $ivy.`io.indigoengine::mill-indigo:0.15.0-RC4`, millindigo._ object snake extends ScalaJSModule with MillIndigo with ScalafmtModule { def scalaVersion = "3.3.0" def scalaJSVersion = "1.13.1" - val gameAssetsDirectory: os.Path = os.pwd / "assets" - val showCursor: Boolean = true - val title: String = "Snake - Made with Indigo" - val windowStartWidth: Int = 720 - val windowStartHeight: Int = 516 - val disableFrameRateLimit: Boolean = false - val electronInstall: ElectronInstall = ElectronInstall.Latest - val backgroundColor: String = "black" + val indigoOptions: IndigoOptions = + IndigoOptions.defaults + .withTitle("Snake - Made with Indigo") + .withWindowStartWidth(720) + .withWindowStartHeight(516) + .withBackgroundColor("black") def buildGame() = T.command { T { diff --git a/examples/build.sbt b/examples/build.sbt index 77906d128..d75f4f13a 100644 --- a/examples/build.sbt +++ b/examples/build.sbt @@ -1,3 +1,4 @@ +import indigoplugin.IndigoOptions import scala.sys.process._ import scala.language.postfixOps @@ -26,22 +27,6 @@ lazy val commonSettings = Seq( semanticdbVersion := scalafixSemanticdb.revision ) -lazy val commonGameSettings = Seq( - disableFrameRateLimit := (sys.props("os.name").toLowerCase match { - case x if x contains "windows" => false - case _ => false - }), - electronInstall := (sys.props("os.name").toLowerCase match { - case x if x.contains("windows") || x.contains("linux") => - indigoplugin.ElectronInstall.Version("^23.0.0") - - case _ => - indigoplugin.ElectronInstall.Global - }), - showCursor := true, - gameAssetsDirectory := "assets" -) - // Examples lazy val basicSetup = project @@ -50,10 +35,13 @@ lazy val basicSetup = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "basic-setup", - title := "Basic Setup" + name := "basic-setup", + indigoOptions := + IndigoOptions.defaults + .withTitle("Basic Setup") + .withBackgroundColor("black") + .withAssetDirectory("basic-setup/assets") ) - .settings(commonGameSettings: _*) lazy val blending = project @@ -62,10 +50,13 @@ lazy val blending = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "blending-example", - title := "Blending example" + name := "blending-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Blending example") + .withBackgroundColor("black") + .withAssetDirectory("blending/assets") ) - .settings(commonGameSettings: _*) lazy val subSystems = project @@ -74,10 +65,13 @@ lazy val subSystems = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "subsystems", - title := "SubSystems Example" + name := "subsystems", + indigoOptions := + IndigoOptions.defaults + .withTitle("SubSystems Example") + .withBackgroundColor("black") + .withAssetDirectory("subsystems/assets") ) - .settings(commonGameSettings: _*) lazy val scenesSetup = project @@ -86,10 +80,13 @@ lazy val scenesSetup = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "scenes-setup", - title := "Scene Manager Setup" + name := "scenes-setup", + indigoOptions := + IndigoOptions.defaults + .withTitle("Scene Manager Setup") + .withBackgroundColor("black") + .withAssetDirectory("scenes-setup/assets") ) - .settings(commonGameSettings: _*) lazy val text = project @@ -98,10 +95,13 @@ lazy val text = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "text-example", - title := "Text example" + name := "text-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Text example") + .withBackgroundColor("black") + .withAssetDirectory("text/assets") ) - .settings(commonGameSettings: _*) lazy val inputfield = project @@ -110,10 +110,13 @@ lazy val inputfield = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "input-field-example", - title := "Input field example" + name := "input-field-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Input field example") + .withBackgroundColor("black") + .withAssetDirectory("inputfield/assets") ) - .settings(commonGameSettings: _*) lazy val button = project @@ -122,10 +125,13 @@ lazy val button = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "button-example", - title := "Button example" + name := "button-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Button example") + .withBackgroundColor("black") + .withAssetDirectory("button/assets") ) - .settings(commonGameSettings: _*) lazy val graphic = project @@ -134,10 +140,13 @@ lazy val graphic = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "graphic-example", - title := "Graphic example" + name := "graphic-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Graphic example") + .withBackgroundColor("black") + .withAssetDirectory("graphic/assets") ) - .settings(commonGameSettings: _*) lazy val group = project @@ -146,10 +155,13 @@ lazy val group = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "group-example", - title := "Group example" + name := "group-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Group example") + .withBackgroundColor("black") + .withAssetDirectory("group/assets") ) - .settings(commonGameSettings: _*) lazy val tiled = project @@ -158,15 +170,18 @@ lazy val tiled = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "tiled-example", - title := "Tiled example", - windowStartWidth := 19 * 32, - windowStartHeight := 11 * 32, + name := "tiled-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Tiled example") + .withBackgroundColor("black") + .withAssetDirectory("tiled/assets") + .withWindowStartWidth(19 * 32) + .withWindowStartHeight(11 * 32), libraryDependencies ++= Seq( "io.indigoengine" %%% "indigo-json-circe" % IndigoVersion.getVersion ) ) - .settings(commonGameSettings: _*) lazy val sprite = project @@ -175,10 +190,13 @@ lazy val sprite = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "sprite-example", - title := "Sprite example" + name := "sprite-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Sprite example") + .withBackgroundColor("black") + .withAssetDirectory("sprite/assets") ) - .settings(commonGameSettings: _*) lazy val http = project @@ -187,10 +205,13 @@ lazy val http = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "http-example", - title := "Http example" + name := "http-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Http example") + .withBackgroundColor("black") + .withAssetDirectory("http/assets") ) - .settings(commonGameSettings: _*) lazy val websocket = project @@ -199,10 +220,13 @@ lazy val websocket = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "websocket-example", - title := "WebSocket example" + name := "websocket-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("WebSocket example") + .withBackgroundColor("black") + .withAssetDirectory("websocket/assets") ) - .settings(commonGameSettings: _*) lazy val automata = project @@ -211,10 +235,13 @@ lazy val automata = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "automata-example", - title := "Automata example" + name := "automata-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Automata example") + .withBackgroundColor("black") + .withAssetDirectory("automata/assets") ) - .settings(commonGameSettings: _*) lazy val fireworks = project @@ -223,15 +250,18 @@ lazy val fireworks = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "fireworks-example", - title := "Fireworks!", - windowStartWidth := 1280, - windowStartHeight := 720, + name := "fireworks-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Fireworks!") + .withBackgroundColor("black") + .withAssetDirectory("fireworks/assets") + .withWindowStartWidth(1280) + .withWindowStartHeight(720), libraryDependencies ++= Seq( "org.scalacheck" %%% "scalacheck" % "1.15.3" % "test" ) ) - .settings(commonGameSettings: _*) lazy val audio = project @@ -241,9 +271,12 @@ lazy val audio = .enablePlugins(ScalaJSPlugin) .settings( name := "audio-example", - title := "Audio example" + indigoOptions := + IndigoOptions.defaults + .withTitle("Audio example") + .withBackgroundColor("black") + .withAssetDirectory("audio/assets") ) - .settings(commonGameSettings: _*) lazy val lighting = project @@ -251,16 +284,19 @@ lazy val lighting = .enablePlugins(ScalaJSPlugin) .settings(commonSettings: _*) .settings( - name := "lighting Example", - title := "Lighting", - windowStartWidth := 684, - windowStartHeight := 384 + name := "lighting Example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Lighting") + .withBackgroundColor("black") + .withAssetDirectory("lighting/assets") + .withWindowStartWidth(684) + .withWindowStartHeight(384) ) .settings( publish := {}, publishLocal := {} ) - .settings(commonGameSettings: _*) lazy val distortion = project @@ -268,16 +304,19 @@ lazy val distortion = .enablePlugins(ScalaJSPlugin) .settings(commonSettings: _*) .settings( - name := "distortion", - title := "Distortion Example", - windowStartWidth := 684, - windowStartHeight := 384 + name := "distortion", + indigoOptions := + IndigoOptions.defaults + .withTitle("Distortion Example") + .withBackgroundColor("black") + .withAssetDirectory("distortion/assets") + .withWindowStartWidth(684) + .withWindowStartHeight(384) ) .settings( publish := {}, publishLocal := {} ) - .settings(commonGameSettings: _*) lazy val assetLoading = project @@ -285,14 +324,17 @@ lazy val assetLoading = .enablePlugins(ScalaJSPlugin) .settings(commonSettings: _*) .settings( - name := "assetLoading", - title := "Asset Loading Example" + name := "assetLoading", + indigoOptions := + IndigoOptions.defaults + .withTitle("Asset Loading Example") + .withBackgroundColor("black") + .withAssetDirectory("assetLoading/assets") ) .settings( publish := {}, publishLocal := {} ) - .settings(commonGameSettings: _*) lazy val effects = project @@ -300,16 +342,17 @@ lazy val effects = .enablePlugins(ScalaJSPlugin) .settings(commonSettings: _*) .settings( - name := "effects", - title := "Effects Example", - windowStartWidth := 550, - windowStartHeight := 400 + name := "effects", + indigoOptions := + IndigoOptions.defaults + .withTitle("Effects Example") + .withBackgroundColor("black") + .withAssetDirectory("effects/assets") ) .settings( publish := {}, publishLocal := {} ) - .settings(commonGameSettings: _*) lazy val radio = project @@ -319,9 +362,12 @@ lazy val radio = .enablePlugins(ScalaJSPlugin) .settings( name := "radio-example", - title := "Radio button example" + indigoOptions := + IndigoOptions.defaults + .withTitle("Radio button example") + .withBackgroundColor("black") + .withAssetDirectory("radio/assets") ) - .settings(commonGameSettings: _*) lazy val jobs = project @@ -330,12 +376,15 @@ lazy val jobs = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "jobs-example", - title := "Job System Example", - windowStartWidth := 400, - windowStartHeight := 400 + name := "jobs-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Job System Example") + .withBackgroundColor("black") + .withAssetDirectory("jobs/assets") + .withWindowStartWidth(400) + .withWindowStartHeight(400) ) - .settings(commonGameSettings: _*) lazy val confetti = project @@ -344,12 +393,15 @@ lazy val confetti = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "confetti", - title := "Confetti", - windowStartWidth := 640, - windowStartHeight := 480 + name := "confetti", + indigoOptions := + IndigoOptions.defaults + .withTitle("Confetti") + .withBackgroundColor("black") + .withAssetDirectory("confetti/assets") + .withWindowStartWidth(640) + .withWindowStartHeight(480) ) - .settings(commonGameSettings: _*) lazy val inputmapper = project @@ -358,12 +410,15 @@ lazy val inputmapper = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "inputmapper-example", - title := "Input Mapper Example", - windowStartWidth := 400, - windowStartHeight := 400 + name := "inputmapper-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Input Mapper Example") + .withBackgroundColor("black") + .withAssetDirectory("inputmapper/assets") + .withWindowStartWidth(400) + .withWindowStartHeight(400) ) - .settings(commonGameSettings: _*) lazy val mouseevents = project @@ -372,12 +427,13 @@ lazy val mouseevents = .enablePlugins(SbtIndigo) .enablePlugins(ScalaJSPlugin) .settings( - name := "mouseevents-example", - title := "Mouse Events Example", - windowStartWidth := 550, - windowStartHeight := 400 + name := "mouseevents-example", + indigoOptions := + IndigoOptions.defaults + .withTitle("Mouse Events Example") + .withBackgroundColor("black") + .withAssetDirectory("mouseevents/assets") ) - .settings(commonGameSettings: _*) lazy val errors = project @@ -386,12 +442,15 @@ lazy val errors = .enablePlugins(ScalaJSPlugin) .enablePlugins(SbtIndigo) .settings( - name := "errors", - title := "Error Handling", - windowStartWidth := 800, - windowStartHeight := 800 + name := "errors", + indigoOptions := + IndigoOptions.defaults + .withTitle("Error Handling") + .withBackgroundColor("black") + .withAssetDirectory("errors/assets") + .withWindowStartWidth(800) + .withWindowStartHeight(800) ) - .settings(commonGameSettings: _*) // Root lazy val examplesProject = diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoOptions.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoOptions.scala new file mode 100644 index 000000000..e9bfd7f8b --- /dev/null +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoOptions.scala @@ -0,0 +1,137 @@ +package indigoplugin + +/** Represents the various options that go into an Indigo game build. + * + * @param title + * Title of your game. Default 'Made with Indigo'. + * @param showCursor + * Show the cursor? Default 'true'. + * @param backgroundColor + * HTML page background color Default 'white'. + * @param gameAssetsDirectory + * Project relative path to a directory that contains all of the assets the game needs to load. Default './assets'. + * @param windowStartWidth + * Initial window width. Default '550'. + * @param windowStartHeight + * Initial window height. Default '400'. + * @param disableFrameRateLimit + * If possible, disables the runtime's frame rate limit, recommended to be `false`. Default 'false'. + * @param electronInstall + * How should electron be run? ElectronInstall.Global | ElectronInstall.Version(version: String) | + * ElectronInstall.Latest | ElectronInstall.PathToExecutable(path: String). Default 'ElectronInstall.Latest'. + */ +final case class IndigoOptions( + title: String, + showCursor: Boolean, + backgroundColor: String, + gameAssetsDirectory: os.Path, + windowStartWidth: Int, + windowStartHeight: Int, + disableFrameRateLimit: Boolean, + electronInstall: ElectronInstall +) { + + /** Sets a new title for your game's window / title bar / tab */ + def withTitle(newTitle: String): IndigoOptions = + this.copy(title = newTitle) + + /** Make the cursor visible */ + def cursorVisible: IndigoOptions = + this.copy(showCursor = true) + + /** Hide the cursor */ + def cursorHidden: IndigoOptions = + this.copy(showCursor = false) + + /** Sets the background color, any valid CSS color representation acceptable, e.g. 'black' or '#000000' */ + def withBackgroundColor(cssColorValue: String): IndigoOptions = + this.copy(backgroundColor = cssColorValue) + + /** Set the background color from RGBA values */ + def withBackgroundColor(r: Double, g: Double, b: Double, a: Double): IndigoOptions = { + val convert: Double => String = d => { + val hex = Integer.toHexString((Math.min(1, Math.max(0, d)) * 255).toInt) + if (hex.length == 1) "0" + hex else hex + } + withBackgroundColor("#" + convert(r) + convert(g) + convert(b) + convert(a)) + } + + /** Set the background color from RGB values */ + def withBackgroundColor(r: Double, g: Double, b: Double): IndigoOptions = { + val convert: Double => String = d => { + val hex = Integer.toHexString((Math.min(1, Math.max(0, d)) * 255).toInt) + if (hex.length == 1) "0" + hex else hex + } + withBackgroundColor("#" + convert(r) + convert(g) + convert(b)) + } + + /** Sets the asset directory path */ + def withAssetDirectory(path: String): IndigoOptions = + this.copy( + gameAssetsDirectory = + if (path.startsWith("/")) os.Path(path) + else os.RelPath(path).resolveFrom(os.pwd) + ) + def withAssetDirectory(path: os.Path): IndigoOptions = + this.copy(gameAssetsDirectory = path) + + /** Set the window start width */ + def withWindowStartWidth(value: Int): IndigoOptions = + this.copy(windowStartWidth = value) + + /** Set the window start height */ + def withWindowStartHeight(value: Int): IndigoOptions = + this.copy(windowStartHeight = value) + + /** Electron will limit the frame rate using the default browser refresh rate, typically it will sync with your + * monitor's refresh rate. It is recommended that you do this, and set your indigo config to limit the framerate too. + */ + def electronLimitsFrameRate: IndigoOptions = + this.copy(disableFrameRateLimit = false) + + /** Electron will not limit the frame rate. */ + def electronUnlimitedFrameRate: IndigoOptions = + this.copy(disableFrameRateLimit = true) + + /** Sets the electron installation type. It is recommended that, during development at least, you set this to + * `ElectronInstall.Latest` to take advantage of performance improvements. + */ + def withElectronInstallType(value: ElectronInstall): IndigoOptions = + this.copy(electronInstall = value) + + /** Use the latest version of Electron with the `indigoRun` command, which will be installed with NPM. */ + def useLatestElectron: IndigoOptions = + withElectronInstallType(ElectronInstall.Latest) + + /** Use a globally installed version of Electron with the `indigoRun` command. Global installs of Electron have the + * advantage of a slightly faster `indigoRun` startup time, however, global Electron installs can be of dubious + * quality, and suffer from poor performance or limited features. Not recommended. + */ + def useGlobalElectron: IndigoOptions = + withElectronInstallType(ElectronInstall.Global) + + /** Use a specific version of Electron, follows normal NPM version formats. */ + def useElectronVersion(version: String): IndigoOptions = + withElectronInstallType(ElectronInstall.Version(version)) + + /** Use an Electron install at the specified path with the `indigoRun` command. */ + def useElectronExecutable(path: String): IndigoOptions = + withElectronInstallType(ElectronInstall.PathToExecutable(path)) + +} + +object IndigoOptions { + + val defaults: IndigoOptions = + IndigoOptions( + title = "Made with Indigo", + showCursor = true, + backgroundColor = "white", + gameAssetsDirectory = os.pwd / "assets", + windowStartWidth = 550, + windowStartHeight = 400, + disableFrameRateLimit = false, + electronInstall = indigoplugin.ElectronInstall.Latest + ) + +} diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/Utils.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/Utils.scala deleted file mode 100644 index 816d4c8ed..000000000 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/Utils.scala +++ /dev/null @@ -1,27 +0,0 @@ -package indigoplugin - -import os._ - -final case class TemplateOptions( - title: String, - showCursor: Boolean, - scriptPathBase: Path, - gameAssetsDirectoryPath: Path, - backgroundColor: String = "white" -) - -object Utils { - - def ensureDirectoryAt(path: Path): Path = { - os.remove.all(path) - os.makeDir.all(path) - - path - } - -} - -final case class DirectoryStructure(base: Path, assets: Path, artefacts: Path) - -@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments")) -final case class FileToWrite(name: String, contents: String, folderPath: RelPath = RelPath.rel) diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoBuild.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoBuild.scala similarity index 95% rename from indigo-plugin/indigo-plugin/src/indigoplugin/IndigoBuild.scala rename to indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoBuild.scala index 39f751a04..275664651 100644 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoBuild.scala +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoBuild.scala @@ -1,8 +1,11 @@ -package indigoplugin +package indigoplugin.core import os._ import indigoplugin.templates.HtmlTemplate import indigoplugin.templates.SupportScriptTemplate +import indigoplugin.datatypes.TemplateOptions +import indigoplugin.datatypes.DirectoryStructure +import indigoplugin.utils.Utils object IndigoBuild { diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoBuildMill.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoBuildMill.scala similarity index 72% rename from indigo-plugin/indigo-plugin/src/indigoplugin/IndigoBuildMill.scala rename to indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoBuildMill.scala index c3ef8f358..b50eb0660 100644 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoBuildMill.scala +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoBuildMill.scala @@ -1,6 +1,8 @@ -package indigoplugin +package indigoplugin.core import os._ +import indigoplugin.datatypes.TemplateOptions +import indigoplugin.utils.AsciiLogo object IndigoBuildMill { diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoBuildSBT.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoBuildSBT.scala similarity index 78% rename from indigo-plugin/indigo-plugin/src/indigoplugin/IndigoBuildSBT.scala rename to indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoBuildSBT.scala index 558e3c642..3b6d6af45 100644 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoBuildSBT.scala +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoBuildSBT.scala @@ -1,6 +1,8 @@ -package indigoplugin +package indigoplugin.core import os._ +import indigoplugin.datatypes.TemplateOptions +import indigoplugin.utils.AsciiLogo object IndigoBuildSBT { diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoCordova.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoCordova.scala similarity index 95% rename from indigo-plugin/indigo-plugin/src/indigoplugin/IndigoCordova.scala rename to indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoCordova.scala index 53027cb8e..0a24d5f7e 100644 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoCordova.scala +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoCordova.scala @@ -1,9 +1,10 @@ -package indigoplugin +package indigoplugin.core import indigoplugin.templates.CordovaTemplates import os._ import indigoplugin.templates.SupportScriptTemplate +import indigoplugin.datatypes.FileToWrite object IndigoCordova { diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoRun.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoRun.scala similarity index 97% rename from indigo-plugin/indigo-plugin/src/indigoplugin/IndigoRun.scala rename to indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoRun.scala index 6707b595e..850e75c26 100644 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoRun.scala +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoRun.scala @@ -1,10 +1,13 @@ -package indigoplugin +package indigoplugin.core import indigoplugin.templates.ElectronTemplates import scala.sys.process._ import os._ import indigoplugin.templates.SupportScriptTemplate +import indigoplugin.datatypes.FileToWrite +import indigoplugin.utils.AsciiLogo +import indigoplugin.ElectronInstall object IndigoRun { diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/datatypes/DirectoryStructure.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/datatypes/DirectoryStructure.scala new file mode 100644 index 000000000..d315f7a27 --- /dev/null +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/datatypes/DirectoryStructure.scala @@ -0,0 +1,5 @@ +package indigoplugin.datatypes + +import os._ + +final case class DirectoryStructure(base: Path, assets: Path, artefacts: Path) diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/datatypes/FileToWrite.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/datatypes/FileToWrite.scala new file mode 100644 index 000000000..dd7006eb3 --- /dev/null +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/datatypes/FileToWrite.scala @@ -0,0 +1,6 @@ +package indigoplugin.datatypes + +import os._ + +@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments")) +final case class FileToWrite(name: String, contents: String, folderPath: RelPath = RelPath.rel) diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/datatypes/TemplateOptions.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/datatypes/TemplateOptions.scala new file mode 100644 index 000000000..4d98e0ff2 --- /dev/null +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/datatypes/TemplateOptions.scala @@ -0,0 +1,11 @@ +package indigoplugin.datatypes + +import os._ + +final case class TemplateOptions( + title: String, + showCursor: Boolean, + scriptPathBase: Path, + gameAssetsDirectoryPath: Path, + backgroundColor: String = "white" +) diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/AsciiLogo.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/utils/AsciiLogo.scala similarity index 95% rename from indigo-plugin/indigo-plugin/src/indigoplugin/AsciiLogo.scala rename to indigo-plugin/indigo-plugin/src/indigoplugin/utils/AsciiLogo.scala index d5bf8db40..600b43838 100644 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/AsciiLogo.scala +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/utils/AsciiLogo.scala @@ -1,4 +1,4 @@ -package indigoplugin +package indigoplugin.utils object AsciiLogo { diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/utils/Utils.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/utils/Utils.scala new file mode 100644 index 000000000..5f4f04439 --- /dev/null +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/utils/Utils.scala @@ -0,0 +1,14 @@ +package indigoplugin.utils + +import os._ + +object Utils { + + def ensureDirectoryAt(path: Path): Path = { + os.remove.all(path) + os.makeDir.all(path) + + path + } + +} diff --git a/indigo/build.sbt b/indigo/build.sbt index a0f3bf0fb..9029580e3 100644 --- a/indigo/build.sbt +++ b/indigo/build.sbt @@ -1,3 +1,4 @@ +import indigoplugin.IndigoOptions import scala.language.postfixOps import Misc._ @@ -82,13 +83,12 @@ lazy val sandbox = .settings( neverPublish, commonSettings, - name := "sandbox", - showCursor := true, - title := "Sandbox", - gameAssetsDirectory := "assets", - disableFrameRateLimit := false, - backgroundColor := "black", - electronInstall := indigoplugin.ElectronInstall.Latest + name := "sandbox", + indigoOptions := + IndigoOptions.defaults + .withTitle("Sandbox") + .withBackgroundColor("black") + .withAssetDirectory("sandbox/assets/") ) lazy val perf = @@ -99,17 +99,14 @@ lazy val perf = .settings( neverPublish, commonSettings, - name := "indigo-perf", - showCursor := true, - title := "Perf", - gameAssetsDirectory := "assets", - windowStartWidth := 800, - windowStartHeight := 600, - disableFrameRateLimit := (sys.props("os.name").toLowerCase match { - case x if x contains "windows" => false - case _ => true - }), - electronInstall := indigoplugin.ElectronInstall.Latest + name := "indigo-perf", + indigoOptions := + IndigoOptions.defaults + .withTitle("Perf") + .withBackgroundColor("black") + .withWindowStartWidth(800) + .withWindowStartHeight(600) + .withAssetDirectory("perf/assets/") ) lazy val shader = @@ -120,18 +117,14 @@ lazy val shader = .settings( neverPublish, commonSettings, - name := "indigo-shader", - showCursor := true, - title := "Shader", - gameAssetsDirectory := "assets", - windowStartWidth := 450, - windowStartHeight := 450, - backgroundColor := "black", - disableFrameRateLimit := (sys.props("os.name").toLowerCase match { - case x if x contains "windows" => false - case _ => true - }), - electronInstall := indigoplugin.ElectronInstall.Latest + name := "indigo-shader", + indigoOptions := + IndigoOptions.defaults + .withTitle("Shader") + .withBackgroundColor("black") + .withWindowStartWidth(450) + .withWindowStartHeight(450) + .withAssetDirectory("shader/assets/") ) // Indigo Extensions @@ -191,10 +184,10 @@ lazy val jsdocs = project organization := "io.indigoengine", libraryDependencies ++= Dependencies.jsDocs.value, libraryDependencies ++= Seq( - "io.indigoengine" %%% "indigo-json-circe" % indigoDocsVersion, - "io.indigoengine" %%% "indigo" % indigoDocsVersion, - "io.indigoengine" %%% "indigo-extras" % indigoDocsVersion, - "io.indigoengine" %%% "tyrian-io" % tyrianDocsVersion//, + "io.indigoengine" %%% "indigo-json-circe" % indigoDocsVersion, + "io.indigoengine" %%% "indigo" % indigoDocsVersion, + "io.indigoengine" %%% "indigo-extras" % indigoDocsVersion, + "io.indigoengine" %%% "tyrian-io" % tyrianDocsVersion // , // "io.indigoengine" %%% "tyrian-indigo-bridge" % tyrianDocsVersion ) ) diff --git a/mill-indigo/mill-indigo/src/millindigo/MillIndigo.scala b/mill-indigo/mill-indigo/src/millindigo/MillIndigo.scala index c5c21ccac..3485f05ca 100644 --- a/mill-indigo/mill-indigo/src/millindigo/MillIndigo.scala +++ b/mill-indigo/mill-indigo/src/millindigo/MillIndigo.scala @@ -6,43 +6,16 @@ import os.Path import mill.define.Command import java.io.File import mill.define.Persistent -import indigoplugin.{IndigoRun, IndigoBuildMill, TemplateOptions} -import indigoplugin.IndigoCordova +import indigoplugin.core.IndigoBuildMill +import indigoplugin.datatypes.TemplateOptions +import indigoplugin.core.IndigoRun +import indigoplugin.core.IndigoCordova +import indigoplugin.IndigoOptions trait MillIndigo extends mill.Module { - /** Title of your game. - */ - def title: String - - /** Show the cursor? - */ - def showCursor: Boolean - - /** HTML page background color - */ - def backgroundColor: String - - /** Project relative path to a directory that contains all of the assets the game needs to load. - */ - def gameAssetsDirectory: Path - - /** Initial window width. - */ - def windowStartWidth: Int - - /** Initial window height. - */ - def windowStartHeight: Int - - /** If possible, disables the runtime's frame rate limit, recommended to be `false`. - */ - def disableFrameRateLimit: Boolean - - /** How should electron be run? ElectronInstall.Global | ElectronInstall.Version(version: String) | - * ElectronInstall.Latest | ElectronInstall.PathToExecutable(path: String) - */ - def electronInstall: ElectronInstall + /** Configuration options for your Indigo game. */ + def indigoOptions: IndigoOptions def indigoBuild(): Command[Path] = T.command { @@ -67,11 +40,11 @@ trait MillIndigo extends mill.Module { IndigoBuildMill.build( T.dest, TemplateOptions( - title, - showCursor, + indigoOptions.title, + indigoOptions.showCursor, scriptPathBase, - gameAssetsDirectory, - backgroundColor + indigoOptions.gameAssetsDirectory, + indigoOptions.backgroundColor ) ) @@ -102,11 +75,11 @@ trait MillIndigo extends mill.Module { IndigoBuildMill.build( outputDir, TemplateOptions( - title, - showCursor, + indigoOptions.title, + indigoOptions.showCursor, scriptPathBase, - gameAssetsDirectory, - backgroundColor + indigoOptions.gameAssetsDirectory, + indigoOptions.backgroundColor ) ) @@ -121,11 +94,11 @@ trait MillIndigo extends mill.Module { IndigoRun.run( outputDir, buildDir, - title, - windowStartWidth, - windowStartHeight, - disableFrameRateLimit, - electronInstall + indigoOptions.title, + indigoOptions.windowStartWidth, + indigoOptions.windowStartHeight, + indigoOptions.disableFrameRateLimit, + indigoOptions.electronInstall ) } @@ -137,11 +110,11 @@ trait MillIndigo extends mill.Module { IndigoRun.run( outputDir, buildDir, - title, - windowStartWidth, - windowStartHeight, - disableFrameRateLimit, - electronInstall + indigoOptions.title, + indigoOptions.windowStartWidth, + indigoOptions.windowStartHeight, + indigoOptions.disableFrameRateLimit, + indigoOptions.electronInstall ) } @@ -150,7 +123,13 @@ trait MillIndigo extends mill.Module { val outputDir: Path = T.dest val buildDir: Path = indigoBuild()() - IndigoCordova.run(outputDir, buildDir, title, windowStartWidth, windowStartHeight) + IndigoCordova.run( + outputDir, + buildDir, + indigoOptions.title, + indigoOptions.windowStartWidth, + indigoOptions.windowStartHeight + ) } def indigoCordovaBuildFull(): Command[Unit] = @@ -158,7 +137,13 @@ trait MillIndigo extends mill.Module { val outputDir: Path = T.dest val buildDir: Path = indigoBuildFull()() - IndigoCordova.run(outputDir, buildDir, title, windowStartWidth, windowStartHeight) + IndigoCordova.run( + outputDir, + buildDir, + indigoOptions.title, + indigoOptions.windowStartWidth, + indigoOptions.windowStartHeight + ) } } diff --git a/mill-indigo/mill-indigo/src/millindigo/package.scala b/mill-indigo/mill-indigo/src/millindigo/package.scala index 92e9f28bd..7bf726e6c 100644 --- a/mill-indigo/mill-indigo/src/millindigo/package.scala +++ b/mill-indigo/mill-indigo/src/millindigo/package.scala @@ -3,4 +3,7 @@ package object millindigo { type ElectronInstall = indigoplugin.ElectronInstall val ElectronInstall: indigoplugin.ElectronInstall.type = indigoplugin.ElectronInstall + type IndigoOptions = indigoplugin.IndigoOptions + val IndigoOptions: indigoplugin.IndigoOptions.type = indigoplugin.IndigoOptions + } diff --git a/sbt-indigo/src/main/scala/sbtindigo/SbtIndigo.scala b/sbt-indigo/src/main/scala/sbtindigo/SbtIndigo.scala index 2ceee6c4d..56bbd2614 100644 --- a/sbt-indigo/src/main/scala/sbtindigo/SbtIndigo.scala +++ b/sbt-indigo/src/main/scala/sbtindigo/SbtIndigo.scala @@ -3,8 +3,11 @@ package sbtindigo import sbt.plugins.JvmPlugin import sbt._ -import indigoplugin.{IndigoRun, IndigoBuildSBT, TemplateOptions} -import indigoplugin.IndigoCordova +import indigoplugin.IndigoOptions +import indigoplugin.core.IndigoBuildSBT +import indigoplugin.datatypes.TemplateOptions +import indigoplugin.core.IndigoCordova +import indigoplugin.core.IndigoRun object SbtIndigo extends sbt.AutoPlugin { @@ -12,6 +15,8 @@ object SbtIndigo extends sbt.AutoPlugin { override def trigger: PluginTrigger = allRequirements object autoImport { + + // Build and Run tasks val indigoBuild: TaskKey[Unit] = taskKey[Unit]("Build an Indigo game.") val indigoBuildFull: TaskKey[Unit] = taskKey[Unit]("Build an Indigo game using full compression.") val indigoRun: TaskKey[Unit] = taskKey[Unit]("Run an Indigo game.") @@ -19,19 +24,10 @@ object SbtIndigo extends sbt.AutoPlugin { val indigoCordovaBuild: TaskKey[Unit] = taskKey[Unit]("Build an Indigo game Cordova template.") val indigoCordovaBuildFull: TaskKey[Unit] = taskKey[Unit]("Build an Indigo game Cordova template that has been compressed.") - val gameAssetsDirectory: SettingKey[String] = - settingKey[String]("Project relative path to a directory that contains all of the assets the game needs to load.") - val showCursor: SettingKey[Boolean] = settingKey[Boolean]("Show the cursor? True by default.") - val title: SettingKey[String] = settingKey[String]("Title of your game. Defaults to 'Made with Indigo'.") - val backgroundColor: SettingKey[String] = - settingKey[String]("HTML page background color CSS property. Defaults to 'initial'.") - val windowStartWidth: SettingKey[Int] = settingKey[Int]("Initial window width. Defaults to 550 pixels.") - val windowStartHeight: SettingKey[Int] = settingKey[Int]("Initial window height. Defaults to 400 pixels.") - val disableFrameRateLimit: SettingKey[Boolean] = - settingKey[Boolean]("If possible, disables the runtime's frame rate limit. Defaults to false.") - val electronInstall: SettingKey[ElectronInstall] = settingKey[ElectronInstall]( - "How should electron be run? `ElectronInstall.Global | ElectronInstall.Version(version: String) | ElectronInstall.Latest | ElectronInstall.PathToExecutable(path: String)`. Defaults to ElectronInstall.Global." - ) + + // Config options + val indigoOptions: SettingKey[IndigoOptions] = + settingKey[IndigoOptions]("Config options for your Indigo game.") } import autoImport._ @@ -43,14 +39,7 @@ object SbtIndigo extends sbt.AutoPlugin { indigoRunFull := indigoRunFullTask.value, indigoCordovaBuild := indigoCordovaBuildTask.value, indigoCordovaBuildFull := indigoCordovaBuildFullTask.value, - showCursor := true, - title := "Made with Indigo", - backgroundColor := "white", - gameAssetsDirectory := ".", - windowStartWidth := 550, - windowStartHeight := 400, - disableFrameRateLimit := false, - electronInstall := indigoplugin.ElectronInstall.Global + indigoOptions := IndigoOptions.defaults ) def giveScriptBasePath(baseDir: String, scalaVersion: String, projectName: String): String = { @@ -86,15 +75,11 @@ object SbtIndigo extends sbt.AutoPlugin { IndigoBuildSBT.build( baseDir, TemplateOptions( - title = title.value, - showCursor = showCursor.value, + title = indigoOptions.value.title, + showCursor = indigoOptions.value.showCursor, scriptPathBase = os.Path(scriptPathBase), - gameAssetsDirectoryPath = os.Path( - if (gameAssetsDirectory.value.startsWith("/")) - gameAssetsDirectory.value - else baseDir.replace("/.js", "") + "/" + gameAssetsDirectory.value - ), - backgroundColor = backgroundColor.value + gameAssetsDirectoryPath = indigoOptions.value.gameAssetsDirectory, + backgroundColor = indigoOptions.value.backgroundColor ), outputDir, List( @@ -123,15 +108,11 @@ object SbtIndigo extends sbt.AutoPlugin { IndigoBuildSBT.build( baseDir, TemplateOptions( - title = title.value, - showCursor = showCursor.value, + title = indigoOptions.value.title, + showCursor = indigoOptions.value.showCursor, scriptPathBase = os.Path(scriptPathBase), - gameAssetsDirectoryPath = os.Path( - if (gameAssetsDirectory.value.startsWith("/")) - gameAssetsDirectory.value - else baseDir + "/" + gameAssetsDirectory.value - ), - backgroundColor = backgroundColor.value + gameAssetsDirectoryPath = indigoOptions.value.gameAssetsDirectory, + backgroundColor = indigoOptions.value.backgroundColor ), outputDir, List( @@ -152,11 +133,11 @@ object SbtIndigo extends sbt.AutoPlugin { IndigoRun.run( outputDir = outputDir, buildDir = buildDir, - title = title.value, - windowWidth = windowStartWidth.value, - windowHeight = windowStartHeight.value, - disableFrameRateLimit = disableFrameRateLimit.value, - electronInstall = electronInstall.value + title = indigoOptions.value.title, + windowWidth = indigoOptions.value.windowStartWidth, + windowHeight = indigoOptions.value.windowStartHeight, + disableFrameRateLimit = indigoOptions.value.disableFrameRateLimit, + electronInstall = indigoOptions.value.electronInstall ) } @@ -169,11 +150,11 @@ object SbtIndigo extends sbt.AutoPlugin { IndigoRun.run( outputDir = outputDir, buildDir = buildDir, - title = title.value, - windowWidth = windowStartWidth.value, - windowHeight = windowStartHeight.value, - disableFrameRateLimit = disableFrameRateLimit.value, - electronInstall = electronInstall.value + title = indigoOptions.value.title, + windowWidth = indigoOptions.value.windowStartWidth, + windowHeight = indigoOptions.value.windowStartHeight, + disableFrameRateLimit = indigoOptions.value.disableFrameRateLimit, + electronInstall = indigoOptions.value.electronInstall ) } @@ -186,9 +167,9 @@ object SbtIndigo extends sbt.AutoPlugin { IndigoCordova.run( outputDir = outputDir, buildDir = buildDir, - title = title.value, - windowWidth = windowStartWidth.value, - windowHeight = windowStartHeight.value + title = indigoOptions.value.title, + windowWidth = indigoOptions.value.windowStartWidth, + windowHeight = indigoOptions.value.windowStartHeight ) } @@ -201,9 +182,9 @@ object SbtIndigo extends sbt.AutoPlugin { IndigoCordova.run( outputDir = outputDir, buildDir = buildDir, - title = title.value, - windowWidth = windowStartWidth.value, - windowHeight = windowStartHeight.value + title = indigoOptions.value.title, + windowWidth = indigoOptions.value.windowStartWidth, + windowHeight = indigoOptions.value.windowStartHeight ) }