Skip to content

Commit

Permalink
IndigoOptions supports antialiasing flag
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Nov 5, 2023
1 parent 915ea24 commit 95ef833
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 {
Expand All @@ -78,6 +89,7 @@ object IndigoGameMetadata {
showCursor = true,
backgroundColor = "white",
width = 550,
height = 400
height = 400,
antiAliasing = false
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""<!DOCTYPE html>
|<html>
| <head>
Expand All @@ -26,8 +31,9 @@ object HtmlTemplate {
| width: 100vw;
| height: 100vh;
| }
|
| ${if (!showCursor) "canvas { cursor: none }" else ""}
| #indigo-container canvas {
| ${if (!showCursor) "cursor: none;" else ""}
| }
| </style>
| </head>
| <body>
Expand Down
24 changes: 16 additions & 8 deletions indigo/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import indigoplugin.IndigoOptions
import indigoplugin._
import scala.language.postfixOps
import Misc._

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)))
)

Expand Down

0 comments on commit 95ef833

Please sign in to comment.