From 92057c6ce5f87820cd6770293c7b8992403f6ae5 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Sun, 5 Nov 2023 08:21:44 +0000 Subject: [PATCH] IndigoOptions supports antialiasing flag --- .../src/indigoplugin/IndigoGameMetadata.scala | 16 +++++++++++-- .../indigoplugin/generators/ConfigGen.scala | 2 +- .../indigoplugin/templates/HtmlTemplate.scala | 12 +++++++--- indigo/build.sbt | 24 ++++++++++++------- ...goPhysicsPoc.scala => IndigoPhysics.scala} | 8 ++----- 5 files changed, 42 insertions(+), 20 deletions(-) rename indigo/physics/src/main/scala/example/{IndigoPhysicsPoc.scala => IndigoPhysics.scala} (91%) diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoGameMetadata.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoGameMetadata.scala index ae9731715..6b6f092a7 100644 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoGameMetadata.scala +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/IndigoGameMetadata.scala @@ -12,13 +12,16 @@ package indigoplugin * Initial window width. Default '550'. * @param height * Initial window height. Default '400'. + * @param antiAliasing + * Smooth the rendered view? Defaults to false for pixel art. */ final case class IndigoGameMetadata( title: String, showCursor: Boolean, backgroundColor: String, width: Int, - height: Int + height: Int, + antiAliasing: Boolean ) { /** Sets a new title for your game's window / title bar / tab */ @@ -67,6 +70,14 @@ final case class IndigoGameMetadata( def withWindowSize(w: Int, h: Int): IndigoGameMetadata = this.copy(width = w, height = h) + /** Smooths the image for normal graphics (i.e. not pixel art) */ + def useAntiAliasing: IndigoGameMetadata = + this.copy(antiAliasing = true) + + /** Does not smooth the image for crisp pixel-art. */ + def noAntiAliasing: IndigoGameMetadata = + this.copy(antiAliasing = false) + } object IndigoGameMetadata { @@ -78,6 +89,7 @@ object IndigoGameMetadata { showCursor = true, backgroundColor = "white", width = 550, - height = 400 + height = 400, + antiAliasing = false ) } diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/generators/ConfigGen.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/generators/ConfigGen.scala index 28a2da2c7..415d946a5 100644 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/generators/ConfigGen.scala +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/generators/ConfigGen.scala @@ -35,7 +35,7 @@ object ConfigGen { | resizePolicy = ResizePolicy.Resize, | advanced = AdvancedGameConfig( | renderingTechnology = RenderingTechnology.WebGL2WithFallback, - | antiAliasing = false, + | antiAliasing = ${indigoOptions.metadata.antiAliasing.toString}, | premultipliedAlpha = true, | batchSize = 256, | autoLoadStandardShaders = true, diff --git a/indigo-plugin/indigo-plugin/src/indigoplugin/templates/HtmlTemplate.scala b/indigo-plugin/indigo-plugin/src/indigoplugin/templates/HtmlTemplate.scala index cab544f68..aee5a376e 100644 --- a/indigo-plugin/indigo-plugin/src/indigoplugin/templates/HtmlTemplate.scala +++ b/indigo-plugin/indigo-plugin/src/indigoplugin/templates/HtmlTemplate.scala @@ -2,7 +2,12 @@ package indigoplugin.templates object HtmlTemplate { - def template(title: String, showCursor: Boolean, scriptName: String, backgroundColor: String): String = + def template( + title: String, + showCursor: Boolean, + scriptName: String, + backgroundColor: String + ): String = s""" | | @@ -26,8 +31,9 @@ object HtmlTemplate { | width: 100vw; | height: 100vh; | } - | - | ${if (!showCursor) "canvas { cursor: none }" else ""} + | #indigo-container canvas { + | ${if (!showCursor) "cursor: none;" else ""} + | } | | | diff --git a/indigo/build.sbt b/indigo/build.sbt index 035634e9b..d429b23c6 100644 --- a/indigo/build.sbt +++ b/indigo/build.sbt @@ -1,4 +1,4 @@ -import indigoplugin.IndigoOptions +import indigoplugin._ import scala.language.postfixOps import Misc._ @@ -127,6 +127,14 @@ lazy val shader = .withAssetDirectory("shader/assets/") ) +lazy val physicsOptions = + IndigoOptions.defaults + .withTitle("Physics") + .withBackgroundColor("black") + .withAssetDirectory("physics/assets/") + .withWindowSize(800, 600) + .cursorHidden + lazy val physics = project .enablePlugins(ScalaJSPlugin, SbtIndigo) @@ -135,13 +143,13 @@ lazy val physics = .settings( neverPublish, commonSettings, - name := "physics", - indigoOptions := - IndigoOptions.defaults - .withTitle("Physics") - .withBackgroundColor("black") - .withAssetDirectory("physics/assets/") - .withWindowSize(800, 600) + name := "physics", + indigoOptions := physicsOptions, + Compile / sourceGenerators += Def.task { + IndigoGenerators("example") + .generateConfig("Config", physicsOptions) + .toSourceFiles((Compile / sourceManaged).value) + } ) // Indigo Extensions diff --git a/indigo/physics/src/main/scala/example/IndigoPhysicsPoc.scala b/indigo/physics/src/main/scala/example/IndigoPhysics.scala similarity index 91% rename from indigo/physics/src/main/scala/example/IndigoPhysicsPoc.scala rename to indigo/physics/src/main/scala/example/IndigoPhysics.scala index b69e0cadc..6b02765c8 100644 --- a/indigo/physics/src/main/scala/example/IndigoPhysicsPoc.scala +++ b/indigo/physics/src/main/scala/example/IndigoPhysics.scala @@ -11,7 +11,7 @@ import indigoextras.subsystems.FPSCounter import scala.scalajs.js.annotation.JSExportTopLevel @JSExportTopLevel("IndigoGame") -object IndigoPhysicsPoc extends IndigoGame[Unit, Unit, Model, Unit]: +object IndigoPhysics extends IndigoGame[Unit, Unit, Model, Unit]: def initialScene(bootData: Unit): Option[SceneName] = Some(LoadScene.name) @@ -25,11 +25,7 @@ object IndigoPhysicsPoc extends IndigoGame[Unit, Unit, Model, Unit]: def boot(flags: Map[String, String]): Outcome[BootResult[Unit]] = Outcome( BootResult - .noData( - GameConfig.default - .withViewport(800, 600) - .withFrameRateLimit(60) - ) + .noData(Config.config) .withSubSystems(FPSCounter(Point(10))) )