Skip to content

Commit e9711cf

Browse files
committed
Fix cleanup of sfx command.
1 parent 6bf3542 commit e9711cf

File tree

21 files changed

+54
-1348
lines changed

21 files changed

+54
-1348
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,9 @@ bin/
4343
/tiny-doc/src/docs/asciidoc/dependencies/
4444
/tiny-doc/src/docs/asciidoc/sample/game-example
4545
/tiny-doc/src/docs/asciidoc/sample/sfx-editor
46+
/tiny-doc/src/docs/asciidoc/sample/home
47+
48+
**/tiny-export.zip
49+
4650

4751
.kotlin

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ docs: install
2222
tiny-cli docs --output tiny-doc/src/docs/asciidoc/dependencies/tiny-cli-commands.adoc
2323
tiny-cli export tiny-samples/breakout
2424
unzip -o -d tiny-doc/src/docs/asciidoc/sample/game-example tiny-samples/breakout/tiny-export.zip
25+
tiny-cli export tiny-samples/home
26+
unzip -o -d tiny-doc/src/docs/asciidoc/sample/home tiny-samples/home/tiny-export.zip
2527
tiny-cli export tiny-cli/src/main/resources/sfx
2628
unzip -o -d tiny-doc/src/docs/asciidoc/sample/sfx-editor tiny-cli/src/main/resources/sfx/tiny-export.zip
2729
./gradlew asciidoctor -Pversion=$(uuidgen)

tiny-cli/src/main/kotlin/com/github/minigdx/tiny/cli/command/AddCommand.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.github.ajalt.clikt.core.Context
66
import com.github.ajalt.clikt.parameters.arguments.argument
77
import com.github.ajalt.clikt.parameters.arguments.multiple
88
import com.github.ajalt.clikt.parameters.options.default
9+
import com.github.ajalt.clikt.parameters.options.flag
910
import com.github.ajalt.clikt.parameters.options.option
1011
import com.github.ajalt.clikt.parameters.options.optionalValue
1112
import com.github.ajalt.clikt.parameters.types.file
@@ -26,6 +27,9 @@ class AddCommand : CliktCommand(name = "add") {
2627

2728
val offset by option("--offset", help = "Pixel offset where the character grid begins (e.g., '8,12'). Auto-detected if omitted.")
2829

30+
val boot by option("--boot", help = "Set a .lua script as the boot script instead of adding it to the scripts list.")
31+
.flag(default = false)
32+
2933
val chars by option("--chars", help = "Characters in the font, in reading order (left-to-right, top-to-bottom). Requires --font.")
3034

3135
val resources by argument(help = "The resource to add to the game. The kind of resource will be deducted from the file extension.")
@@ -48,6 +52,16 @@ class AddCommand : CliktCommand(name = "add") {
4852
echo("⚠️ --size, --chars, and --offset are only used with --font. They will be ignored.")
4953
}
5054

55+
if (boot && resources.any { !it.endsWith("lua") }) {
56+
echo("❌ --boot can only be used with .lua scripts.")
57+
throw Abort()
58+
}
59+
60+
if (boot && resources.size > 1) {
61+
echo("❌ --boot can only be used with a single script.")
62+
throw Abort()
63+
}
64+
5165
// Open the _tiny.json
5266
var gameParameters = GameParameters.read(tiny)
5367

@@ -61,6 +75,10 @@ class AddCommand : CliktCommand(name = "add") {
6175
// Add spritesheet
6276
gameParameters = gameParameters.addSpritesheet(r)
6377
"spritesheet"
78+
} else if (r.endsWith("lua") && boot) {
79+
// Set as boot script
80+
gameParameters = gameParameters.setBootScript(r)
81+
"boot script"
6482
} else if (r.endsWith("lua")) {
6583
// Add script
6684
gameParameters = gameParameters.addScript(r)

tiny-cli/src/main/kotlin/com/github/minigdx/tiny/cli/command/ExportCommand.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,14 @@ class ExportCommand : CliktCommand(name = "export") {
509509

510510
@OptIn(ExperimentalSerializationApi::class)
511511
class GameExporter {
512-
513512
/**
514513
* Resolve a file name relative to the game directory, ensuring the resolved path
515514
* stays within the game directory to prevent path traversal attacks.
516515
*/
517-
private fun safeResolve(gameDirectory: File, name: String): File {
516+
private fun safeResolve(
517+
gameDirectory: File,
518+
name: String,
519+
): File {
518520
val resolved = gameDirectory.resolve(name).canonicalFile
519521
val gameRoot = gameDirectory.canonicalFile
520522
require(resolved.path.startsWith(gameRoot.path + File.separator) || resolved.path == gameRoot.path) {

tiny-cli/src/main/kotlin/com/github/minigdx/tiny/cli/config/GameParameters.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ sealed class GameParameters {
4141

4242
abstract fun addFont(font: GameConfigFont): GameParameters
4343

44+
abstract fun setBootScript(script: String): GameParameters
45+
4446
abstract fun setPalette(colors: List<String>): GameParameters
4547

4648
abstract fun setIcon(icon: String): GameParameters
@@ -192,6 +194,10 @@ data class GameParametersV1(
192194
}
193195
}
194196

197+
override fun setBootScript(script: String): GameParameters {
198+
return copy(bootScript = script)
199+
}
200+
195201
fun setEntryPoint(scriptName: String): GameParametersV1 {
196202
val reordered = listOf(scriptName) + scripts.filter { it != scriptName }
197203
return copy(scripts = reordered)

tiny-cli/src/main/resources/sfx/editor-base.lua

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local widgets = require("widgets")
22
local mouse = require("mouse")
3-
local ModeSwitch = require("widgets/ModeSwitch")
43

54
local EditorBase = {}
65

@@ -35,13 +34,6 @@ EditorBase.init_speakers = function(entities, all_widgets, speaker_widgets)
3534
end
3635
end
3736

38-
-- Widget loading: mode switch
39-
EditorBase.init_mode_switch = function(entities, all_widgets)
40-
for mode in all(entities["ModeSwitch"]) do
41-
local button = new(ModeSwitch, mode)
42-
table.insert(all_widgets, button)
43-
end
44-
end
4537

4638
-- Modal creation from Button entities.
4739
-- config.modal_sizes: optional table of { ModalName = {x, y, width, height} }

0 commit comments

Comments
 (0)