Skip to content

Commit

Permalink
Merge pull request #7 from minigdx/custom-sound
Browse files Browse the repository at this point in the history
Bug fix on the workspace management and all()
  • Loading branch information
dwursteisen authored Feb 18, 2024
2 parents 9c7f5e8 + c8fcfc2 commit 5d1ee3e
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Want to build a game like those? Read the documentation above ⬆️ and start t
[![Type It](./tiny-doc/src/docs/asciidoc/sample/level-up.gif)](https://dwursteisen.itch.io/trijam-220-type-it)
[![Memory Pong](./tiny-doc/src/docs/asciidoc/sample/memory.gif)](https://dwursteisen.itch.io/memory-pong-trijam-251)
[![Connect Me](./tiny-doc/src/docs/asciidoc/sample/connect_me.gif)](https://dwursteisen.itch.io/connect-me)
[![Meiro De Maigo 2](./tiny-doc/src/docs/asciidoc/sample/meiro_de_maigo2.gif)](https://dwursteisen.itch.io/meiro-de)

## Community

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ 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
Expand Down Expand Up @@ -60,6 +62,11 @@ class RunCommand : CliktCommand(name = "run", help = "Run your game.") {
echo("\uD83D\uDC4B See you soon!")
},
)

val data = File("data")
if (data.exists() && data.isDirectory) {
WorkspaceLib.DEFAULT = data.listFiles().map { JvmLocalFile(it.name, data) }
}
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.")
Expand Down
13 changes: 2 additions & 11 deletions tiny-cli/src/jvmMain/resources/sfx/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ function on_active_tab(current, prec)
local data = current.content
bpm.value = data["bpm"]
volume.value = (data["volume"] / 255) * 10
debug.console("stuff")
debug.console(data["volume"])
-- always get the first pattern
active_pattern(1, data)

Expand All @@ -148,7 +146,7 @@ function on_active_tab(current, prec)
for k, f in pairs(faders) do
widgets.resetFaderValue(f)
end
active_tab = { }
active_tab = {}
current.content = sfx.to_table(generate_score())
end

Expand Down Expand Up @@ -457,15 +455,8 @@ function generate_score(played_pattern)
local p = active_tab.content["patterns"]
local v = math.floor((volume.value * 25.5))

debug.console("volume value")
debug.console(volume.value)
debug.console("computed volume")
debug.console(v)
local score = "tiny-sfx " .. #p .. " " .. bpm.value .. " "..v.."\n"
local score = "tiny-sfx " .. #p .. " " .. bpm.value .. " " .. v .. "\n"

debug.console("SCORE ???")
debug.console(score)
debug.console(volume.value)
-- write patterns
for patterns in all(active_tab.content["patterns"]) do
local strip = ""
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions tiny-doc/src/docs/asciidoc/tiny-showcase.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ image:sample/camping.gif[link=https://dwursteisen.itch.io/trijam-camping]
image:sample/level-up.gif[link=https://dwursteisen.itch.io/trijam-220-type-it]
image:sample/memory.gif[link=https://dwursteisen.itch.io/memory-pong-trijam-251]
image:sample/connect_me.gif[link=https://dwursteisen.itch.io/connect-me]
image:sample/only_three_seconds.gif[link=https://dwursteisen.itch.io/one-light-for-three-seconds]
image:sample/meiro_de_maigo2.gif[link=https://dwursteisen.itch.io/meiro-de]


TIP: Want your game to appear here? Create a post about it in https://github.com/minigdx/tiny/discussions/categories/show-and-tell[the Show and tell board] and share all information about it.
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,28 @@ class DebugLib(private val resourceAccess: GameResourceAccess) : TwoArgFunction(

@TinyFunction("Log a message into the console.", example = DEBUG_EXAMPLE)
internal inner class console : OneArgFunction() {

private val recursiveSecurity = mutableSetOf<Int>()

@TinyCall("Log a message into the console.")
override fun call(@TinyArg("str") arg: LuaValue): LuaValue {
val str = formatValue(arg)
println(str)
recursiveSecurity.clear()
println("\uD83D\uDC1B $str")
return NIL
}

private fun formatValue(arg: LuaValue): String = if (arg.istable()) {
val table = arg as LuaTable
val keys = table.keys()
val str = keys.map { it.optjstring("nil") + ":" + formatValue(table.get(it)) }
.joinToString(" ")
"table[$str]"
if (recursiveSecurity.contains(table.hashCode())) {
"table[<${table.hashCode()}>]"
} else {
recursiveSecurity.add(table.hashCode())
val keys = table.keys()
val str = keys.map { it.optjstring("nil") + ":" + formatValue(table.get(it)) }
.joinToString(" ")
"table[$str]"
}
} else {
arg.toString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class SprLib(val gameOptions: GameOptions, val resourceAccess: GameResourceAcces
@TinyFunction(
"Switch to another spritesheet. " +
"The index of the spritesheet is given by it's position in the spritesheets field from the `_tiny.json` file." +
"The first spritesheet is at the index 0.",
"The first spritesheet is at the index 0. It retuns the previous spritesheet.",
)
internal inner class sheet : OneArgFunction() {

Expand All @@ -96,12 +96,13 @@ class SprLib(val gameOptions: GameOptions, val resourceAccess: GameResourceAcces

@TinyCall("Switch to the N spritesheet")
override fun call(@TinyArg("spritesheetN") arg: LuaValue): LuaValue {
val previousSpriteSheet = currentSpritesheet
currentSpritesheet = if (arg.isnil()) {
0
} else {
arg.checkint()
}
return NONE
return valueOf(previousSpriteSheet)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ class StdLib(
return result
}
}
val table = args.checktable(1)!!
// If the expected table is nil, don't iterate.
val table = if (args.isnil(1)) {
LuaTable()
} else {
args.checktable(1)!!
}
// iterator, object to iterate, seed value.
return varargsOf(iterator, table)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class WorkspaceLib(
val (filename, filenameWithExt) = findAvailableName(prefix, ext)

resources = resources + platform.createLocalFile(filenameWithExt)
DEFAULT = resources
return valueOf(filename)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class JvmLocalFile(
}

override fun save(content: ByteArray) {
if (!workingDirectory.exists()) {
workingDirectory.mkdirs()
}
workingDirectory.resolve(file).writeBytes(content)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class GlfwPlatform(
}
}

override fun createLocalFile(name: String): LocalFile = JvmLocalFile(name, workdirectory)
override fun createLocalFile(name: String): LocalFile = JvmLocalFile(name, workdirectory.resolve("data"))

companion object {
private const val FPS = 60
Expand Down

0 comments on commit 5d1ee3e

Please sign in to comment.