Skip to content

Commit

Permalink
Merge pull request #5 from minigdx/custom-sound
Browse files Browse the repository at this point in the history
Improve sound part.
  • Loading branch information
dwursteisen authored Feb 8, 2024
2 parents 76bca30 + dcf27cb commit 14555c9
Show file tree
Hide file tree
Showing 45 changed files with 2,689 additions and 75 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
run: ./gradlew asciidoctor -Pversion="${{github.ref_name}}"
- name: Copy generated content into gh-pages.
uses: peaceiris/actions-gh-pages@v3
if: startsWith(github.ref, 'refs/tags/')
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./tiny-doc/build/docs/asciidoc
Expand Down
Binary file added tiny-cli/sfx.aseprite
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AddCommand : CliktCommand(name = "add", help = "Add a resource to your gam
// Add script
gameParameters = gameParameters.addScript(r)
"script"
} else if (r.endsWith("mid") || r.endsWith("midi")) {
} else if (r.endsWith("mid") || r.endsWith("midi") || r.endsWith("sfx")) {
// Add midi
gameParameters = gameParameters.addSound(r)
"sound"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MainCommand : CliktCommand(invokeWithoutSubcommand = true) {
ServeCommand(),
LibCommand(),
PaletteCommand(),
SfxCommand(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,19 @@ class RunCommand : CliktCommand(name = "run", help = "Run your game.") {
val logger = StdOutLogger("tiny-cli")
val vfs = CommonVirtualFileSystem()
val gameOption = gameParameters.toGameOptions()
GameEngine(
val gameEngine = GameEngine(
gameOptions = gameOption,
platform = GlfwPlatform(gameOption, logger, vfs, gameDirectory, LwjglGLRender(logger, gameOption)),
vfs = vfs,
logger = logger,
).main()
)
Runtime.getRuntime().addShutdownHook(
Thread {
gameEngine.end()
echo("\uD83D\uDC4B See you soon!")
},
)
gameEngine.main()
} catch (ex: Exception) {
echo("\uD83E\uDDE8 An unexpected exception occurred. The application will stop. It might be a bug in Tiny. If so, please report it.")
when (ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ class ServeCommand : CliktCommand(name = "serve", help = "Run your game as a web
val server = embeddedServer(Netty, port = port, module = method)

echo("\uD83D\uDE80 Try your game on http://localhost:$port with your browser.")

Runtime.getRuntime().addShutdownHook(
Thread {
server.stop()
echo("\uD83D\uDC4B See you soon!")
},
)
// Starts the server and waits for the engine to stop and exits.
server.start(wait = true)
// start a browser to the address
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.github.minigdx.tiny.cli.command

import com.github.ajalt.clikt.core.Abort
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.default
import com.github.ajalt.clikt.parameters.types.file
import com.github.minigdx.tiny.cli.config.GameParameters
import com.github.minigdx.tiny.engine.GameEngine
import com.github.minigdx.tiny.file.CommonVirtualFileSystem
import com.github.minigdx.tiny.file.JvmLocalFile
import com.github.minigdx.tiny.log.StdOutLogger
import com.github.minigdx.tiny.lua.WorkspaceLib
import com.github.minigdx.tiny.lua.errorLine
import com.github.minigdx.tiny.platform.glfw.GlfwPlatform
import com.github.minigdx.tiny.render.LwjglGLRender
import kotlinx.serialization.json.decodeFromStream
import org.luaj.vm2.LuaError
import java.io.File

class SfxCommand : CliktCommand(name = "sfx", help = "Start the SFX Editor") {

val gameDirectory by argument(help = "The directory containing all game information")
.file(mustExist = true, canBeDir = true, canBeFile = false)
.default(File("."))

fun isOracleOrOpenJDK(): Boolean {
val vendor = System.getProperty("java.vendor")?.lowercase()
return vendor?.contains("oracle") == true || vendor?.contains("eclipse") == true || vendor?.contains("openjdk") == true
}

fun isMacOS(): Boolean {
val os = System.getProperty("os.name").lowercase()
return os.contains("mac") || os.contains("darwin")
}

override fun run() {
if (isMacOS() && isOracleOrOpenJDK()) {
echo("\uD83D\uDEA7 === The Tiny CLI on Mac with require a special option.")
echo("\uD83D\uDEA7 === If the application crash ➡ use the command 'tiny-cli-mac' instead.")
}

try {
val configFile = SfxCommand::class.java.getResourceAsStream("/sfx/_tiny.json")
if (configFile == null) {
echo(
"\uD83D\uDE2D No _tiny.json found! Can't run the game without. " +
"The tiny-cli command doesn't seems to be bundled correctly. You might want to report an issue.",
)
throw Abort()
}
val commandParameters = GameParameters.JSON.decodeFromStream<GameParameters>(configFile)

val gameConfig = gameDirectory.resolve("_tiny.json")
if (gameConfig.exists()) {
val parameters = GameParameters.read(gameConfig)
WorkspaceLib.DEFAULT = parameters.toGameOptions().sounds.map {
JvmLocalFile(it, gameDirectory)
}
} else {
WorkspaceLib.DEFAULT = listOf(JvmLocalFile("sfx1.sfx", workingDirectory = gameDirectory))
}

val logger = StdOutLogger("tiny-cli")
val vfs = CommonVirtualFileSystem()
val commandOptions = commandParameters.toGameOptions()
val gameEngine = GameEngine(
gameOptions = commandOptions,
platform = GlfwPlatform(
commandOptions,
logger,
vfs,
File("."),
LwjglGLRender(logger, commandOptions),
jarResourcePrefix = "/sfx",
),
vfs = vfs,
logger = logger,
)
Runtime.getRuntime().addShutdownHook(
Thread {
gameEngine.end()
echo("\uD83D\uDC4B See you soon!")
},
)
gameEngine.main()
} catch (ex: Exception) {
echo(
"\uD83E\uDDE8 An unexpected exception occurred. " +
"The application will stop. " +
"It might be a bug in Tiny. " +
"If so, please report it.",
)
when (ex) {
is LuaError -> {
val (nb, line) = ex.errorLine() ?: (null to null)
echo("Error found line $nb:$line")
}
}
echo()
ex.printStackTrace()
}
}
}
40 changes: 40 additions & 0 deletions tiny-cli/src/jvmMain/resources/sfx/_tiny.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"version": "V1",
"name": "Tiny SFX Sequencer",
"resolution": {
"width": 512,
"height": 288
},
"sprites": {
"width": 16,
"height": 16
},
"zoom": 2,
"colors": [
"#000000",
"#1D2B53",
"#7E2553",
"#008751",
"#AB5236",
"#5F574F",
"#C2C3C7",
"#FFF1E8",
"#FF004D",
"#FFA300",
"#FFEC27",
"#00E436",
"#29ADFF",
"#83769C",
"#FF77A8",
"#FFCCAA"
],
"scripts": [
"game.lua",
"mouse.lua",
"widgets.lua"
],
"spritesheets": [
"sfx.png"
],
"hideMouseCursor": true
}
Loading

0 comments on commit 14555c9

Please sign in to comment.