Skip to content

Commit

Permalink
Use refactored values
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Aug 31, 2023
1 parent 37a9995 commit a587b1b
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 108 deletions.
4 changes: 2 additions & 2 deletions demos/pirate/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions demos/snake/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 16 additions & 16 deletions examples/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -290,8 +290,8 @@ lazy val lighting =
.withTitle("Lighting")
.withBackgroundColor("black")
.withAssetDirectory("lighting/assets")
.withWindowStartWidth(684)
.withWindowStartHeight(384)
.withWindowWidth(684)
.withWindowHeight(384)
)
.settings(
publish := {},
Expand All @@ -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 := {},
Expand Down Expand Up @@ -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 =
Expand All @@ -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 =
Expand All @@ -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 =
Expand Down Expand Up @@ -448,8 +448,8 @@ lazy val errors =
.withTitle("Error Handling")
.withBackgroundColor("black")
.withAssetDirectory("errors/assets")
.withWindowStartWidth(800)
.withWindowStartHeight(800)
.withWindowWidth(800)
.withWindowHeight(800)
)

// Root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
29 changes: 12 additions & 17 deletions indigo-plugin/indigo-plugin/src/indigoplugin/core/IndigoRun.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import indigoplugin.templates.SupportScriptTemplate
import indigoplugin.datatypes.FileToWrite
import indigoplugin.utils.AsciiLogo
import indigoplugin.ElectronInstall
import indigoplugin.IndigoOptions

object IndigoRun {

Expand All @@ -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)
}

Expand All @@ -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)

Expand Down Expand Up @@ -75,7 +72,7 @@ object IndigoRun {
}

case _ =>
electronInstall match {
indigoOptions.electron.electronInstall match {
case ElectronInstall.Global =>
IndigoProc.Nix.npmStart(outputDir)

Expand Down Expand Up @@ -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))
)

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package indigoplugin.templates

import indigoplugin.ElectronInstall
import indigoplugin.IndigoElectronOptions

object ElectronTemplates {

Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions indigo/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ lazy val perf =
IndigoOptions.defaults
.withTitle("Perf")
.withBackgroundColor("black")
.withWindowStartWidth(800)
.withWindowStartHeight(600)
.withWindowWidth(800)
.withWindowHeight(600)
.withAssetDirectory("perf/assets/")
)

Expand All @@ -122,8 +122,8 @@ lazy val shader =
IndigoOptions.defaults
.withTitle("Shader")
.withBackgroundColor("black")
.withWindowStartWidth(450)
.withWindowStartHeight(450)
.withWindowWidth(450)
.withWindowHeight(450)
.withAssetDirectory("shader/assets/")
)

Expand Down
39 changes: 8 additions & 31 deletions mill-indigo/mill-indigo/src/millindigo/MillIndigo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -94,11 +83,7 @@ trait MillIndigo extends mill.Module {
IndigoRun.run(
outputDir,
buildDir,
indigoOptions.title,
indigoOptions.windowStartWidth,
indigoOptions.windowStartHeight,
indigoOptions.disableFrameRateLimit,
indigoOptions.electronInstall
indigoOptions
)
}

Expand All @@ -110,11 +95,7 @@ trait MillIndigo extends mill.Module {
IndigoRun.run(
outputDir,
buildDir,
indigoOptions.title,
indigoOptions.windowStartWidth,
indigoOptions.windowStartHeight,
indigoOptions.disableFrameRateLimit,
indigoOptions.electronInstall
indigoOptions
)
}

Expand All @@ -126,9 +107,7 @@ trait MillIndigo extends mill.Module {
IndigoCordova.run(
outputDir,
buildDir,
indigoOptions.title,
indigoOptions.windowStartWidth,
indigoOptions.windowStartHeight
indigoOptions.metadata
)
}

Expand All @@ -140,9 +119,7 @@ trait MillIndigo extends mill.Module {
IndigoCordova.run(
outputDir,
buildDir,
indigoOptions.title,
indigoOptions.windowStartWidth,
indigoOptions.windowStartHeight
indigoOptions.metadata
)
}

Expand Down
Loading

0 comments on commit a587b1b

Please sign in to comment.