Skip to content

Commit

Permalink
Use the Base64 kotlin encoder.
Browse files Browse the repository at this point in the history
Update the example in the sample page and add new games in the showcase part.
  • Loading branch information
dwursteisen committed Jan 15, 2024
1 parent c236227 commit 9aa8d10
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tiny-doc/src/docs/asciidoc/sample/tiny-engine.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tiny-doc/src/docs/asciidoc/sandbox.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ end
- Every examples from xref:index.adoc[the documentation] can be tweaked in this sandbox.
- https://minigdx.github.io/tiny/sandbox.html?game=CiAgCmZ1bmN0aW9uIF9kcmF3KCkKICAgIGdmeC5jbHMoKQoKICAgIHByaW50KCJSZWN0YW5nbGUgbGltaXQiLCA2NCwgNjQgLSA1KQogICAgLS0gZHJhdyB0aGUgYm9yZGVyIGxpbWl0LgogICAgZ2Z4LmRpdGhlcigweEE1QTUpCiAgICBzaGFwZS5yZWN0KDY0LCA2NCwgMjU2IC0gMTI4LCAyNTYgLSAxMjgsIDIpCiAgICBnZnguZGl0aGVyKCkKCiAgICAtLSBkcmF3IHRoZSBtb3VzZSBwb3NpdGlvbi4KICAgIGxvY2FsIHBvcyA9IGN0cmwudG91Y2goKQogICAgc2hhcGUubGluZShwb3MueCAtIDIsIHBvcy55LCBwb3MueCArIDIsIHBvcy55LCAzKQogICAgc2hhcGUubGluZShwb3MueCwgcG9zLnkgLSAyLCBwb3MueCwgcG9zLnkgKyAyLCAzKQoKICAgIC0tIGRyYXcgdGhlIHJlY3RhbmdsZSB0aGF0IGlzIHN0YXlpbmcgd2l0aGluIHRoZSBib3JkZXIgbGltaXQuCiAgICBsb2NhbCB4ID0gbWF0aC5jbGFtcCg2NCwgcG9zLnggLSA0LCAyNTYgLSA2NCAtIDkpCiAgICBsb2NhbCB5ID0gbWF0aC5jbGFtcCg2NCwgcG9zLnkgLSA0LCAyNTYgLSA2NCAtIDkpCiAgICBzaGFwZS5yZWN0KHgsIHksIDksIDksIDgpCmVuZAo=[Tracking the player mouse]
- https://minigdx.github.io/tiny/sandbox.html?game=ZnVuY3Rpb24gX2luaXQoKQogICAgbGV0dGVycyA9IHsiaCIsICJlIiwgImwiLCAibCIsICJvIiwgIiAiLCAidCIsICJpIiwgIm4iLCAieSIsICIhIn0KICAgIHN0YXJ0eCA9ICgyNTYgLSAoI2xldHRlcnMgKiA1KSkgKiAwLjUKZW5kCgpmdW5jdGlvbiBfZHJhdygpCiAgICBnZnguY2xzKCkKICAgIGZvciBpLCBsIGluIGlwYWlycyhsZXR0ZXJzKSBkbwogICAgICAgIHByaW50KAogICAgICAgICAgICBsLCAtLSBsZXR0ZXIgdG8gcHJpbnQKICAgICAgICAgICAgc3RhcnR4ICsgaSAqIDUsIC0tIHggcG9zaXRpb24gcmVnYXJkaW5nIHRoZSBsZXR0ZXIgaW5kZXguCiAgICAgICAgICAgIDEyOCArIG1hdGguY29zKHRpbnkudCAqIDMgKyBpKSAqIDgsIC0tIHkgcG9zaXRpb24gcmVnYXJkaW5nIHRoZSB0aW1lIGVsYXBzZWQgYW5kIHRoZSBsZXR0ZXIgaW5kZXggCiAgICAgICAgICAgIG1hdGguY2VpbCh0aW55LmZyYW1lICogMC4yIC0gaSkgLS0gY29sb3Igb2YgdGhlIGxldHRlciByZWdhcmRpbmcgdGhlIGluZGV4CiAgICAgICAgKQogICAgZW5kCmVuZA==[Waving letters]
- https://minigdx.github.io/tiny/sandbox.html?game=LS0gRnVuY3Rpb24gdG8gY2hlY2sgY29sbGlzaW9uIGJldHdlZW4gdHdvIHJlY3RhbmdsZXMKZnVuY3Rpb24gY2hlY2tDb2xsaXNpb24ocmVjdDEsIHJlY3QyKQogICAgcmV0dXJuIHJlY3QxLnggPCByZWN0Mi54ICsgcmVjdDIud2lkdGggYW5kIHJlY3QxLnggKyByZWN0MS53aWR0aCA+IHJlY3QyLnggYW5kIHJlY3QxLnkgPCByZWN0Mi55ICsgcmVjdDIuaGVpZ2h0IGFuZAogICAgICAgICAgICAgICByZWN0MS55ICsgcmVjdDEuaGVpZ2h0ID4gcmVjdDIueQplbmQKCi0tIEZ1bmN0aW9uIHRvIHJlc29sdmUgY29sbGlzaW9uIGFuZCBzbGlkZQpmdW5jdGlvbiBjb2xsaWRlQW5kU2xpZGUob2JqZWN0LCBvYnN0YWNsZSkKICAgIGlmIGNoZWNrQ29sbGlzaW9uKG9iamVjdCwgb2JzdGFjbGUpIHRoZW4KICAgICAgICBsb2NhbCBvdmVybGFwWCA9IG1hdGgubWluKG9iamVjdC54ICsgb2JqZWN0LndpZHRoLCBvYnN0YWNsZS54ICsgb2JzdGFjbGUud2lkdGgpIC0gbWF0aC5tYXgob2JqZWN0LngsIG9ic3RhY2xlLngpCiAgICAgICAgbG9jYWwgb3ZlcmxhcFkgPSBtYXRoLm1pbihvYmplY3QueSArIG9iamVjdC5oZWlnaHQsIG9ic3RhY2xlLnkgKyBvYnN0YWNsZS5oZWlnaHQpIC0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXRoLm1heChvYmplY3QueSwgb2JzdGFjbGUueSkKCiAgICAgICAgaWYgb3ZlcmxhcFggPCBvdmVybGFwWSB0aGVuCiAgICAgICAgICAgIGlmIG9iamVjdC54IDwgb2JzdGFjbGUueCB0aGVuCiAgICAgICAgICAgICAgICBvYmplY3QueCA9IG9iamVjdC54IC0gb3ZlcmxhcFgKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgb2JqZWN0LnggPSBvYmplY3QueCArIG92ZXJsYXBYCiAgICAgICAgICAgIGVuZAogICAgICAgIGVsc2UKICAgICAgICAgICAgaWYgb2JqZWN0LnkgPCBvYnN0YWNsZS55IHRoZW4KICAgICAgICAgICAgICAgIG9iamVjdC55ID0gb2JqZWN0LnkgLSBvdmVybGFwWQogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBvYmplY3QueSA9IG9iamVjdC55ICsgb3ZlcmxhcFkKICAgICAgICAgICAgZW5kCiAgICAgICAgZW5kCiAgICBlbmQKZW5kCgpmdW5jdGlvbiBfaW5pdCgpCiAgICAtLSBFeGFtcGxlIHVzYWdlOgogICAgcGxheWVyID0gewogICAgICAgIHggPSA1MCwKICAgICAgICB5ID0gNTAsCiAgICAgICAgd2lkdGggPSAyMCwKICAgICAgICBoZWlnaHQgPSAyMAogICAgfQogICAgb2JzID0ge30KCiAgICB0YWJsZS5pbnNlcnQob2JzLCB7CiAgICAgICAgeCA9IDYwLAogICAgICAgIHkgPSA0MCwKICAgICAgICB3aWR0aCA9IDMwLAogICAgICAgIGhlaWdodCA9IDMwCiAgICB9KQoKCiAgICB0YWJsZS5pbnNlcnQob2JzLCB7CiAgICAgICAgeCA9IDgwLAogICAgICAgIHkgPSA2MCwKICAgICAgICB3aWR0aCA9IDMwLAogICAgICAgIGhlaWdodCA9IDMwCiAgICB9KQplbmQKCmZ1bmN0aW9uIF91cGRhdGUoKQogICAgLS0gVXBkYXRlIHBsYXllciBwb3NpdGlvbiBhbmQgaGFuZGxlIGNvbGxpc2lvbnMKICAgIGlmIGN0cmwucHJlc3Npbmcoa2V5cy5sZWZ0KSB0aGVuCiAgICAgICAgcGxheWVyLnggPSBwbGF5ZXIueCAtIDEgLS0gTW92ZSBwbGF5ZXIgaG9yaXpvbnRhbGx5CiAgICBlbHNlaWYgY3RybC5wcmVzc2luZyhrZXlzLnJpZ2h0KSB0aGVuCiAgICAgICAgcGxheWVyLnggPSBwbGF5ZXIueCArIDEgLS0gTW92ZSBwbGF5ZXIgaG9yaXpvbnRhbGx5CiAgICBlbmQKCiAgICBpZiBjdHJsLnByZXNzaW5nKGtleXMudXApIHRoZW4KICAgICAgICBwbGF5ZXIueSA9IHBsYXllci55IC0gMSAtLSBNb3ZlIHBsYXllciBob3Jpem9udGFsbHkKICAgIGVsc2VpZiBjdHJsLnByZXNzaW5nKGtleXMuZG93bikgdGhlbgogICAgICAgIHBsYXllci55ID0gcGxheWVyLnkgKyAxIC0tIE1vdmUgcGxheWVyIGhvcml6b250YWxseQogICAgZW5kCgogICAgZm9yIG8gaW4gYWxsKG9icykgZG8KICAgICAgICBjb2xsaWRlQW5kU2xpZGUocGxheWVyLCBvKQogICAgZW5kCmVuZAoKZnVuY3Rpb24gX2RyYXcoKQogICAgZ2Z4LmNscygpCiAgICBzaGFwZS5yZWN0ZihwbGF5ZXIsIDkpCgogICAgZm9yIG8gaW4gYWxsKG9icykgZG8KICAgICAgICBzaGFwZS5yZWN0KG8sIDgpCiAgICBlbmQKZW5kCgotLSBOb3csIHBsYXllcidzIHBvc2l0aW9uIGlzIGFkanVzdGVkIHRvIHNsaWRlIGFsb25nIHRoZSBvYnN0YWNsZSBpZiBhIGNvbGxpc2lvbiBvY2N1cnJlZAo=[AABB Collision]
- https://minigdx.github.io/tiny/sandbox.html?game=LS0gRnVuY3Rpb24gdG8gY2hlY2sgY29sbGlzaW9uIGJldHdlZW4gdHdvIHJlY3RhbmdsZXMKZnVuY3Rpb24gY2hlY2tDb2xsaXNpb24ocmVjdDEsIHJlY3QyKQogICAgcmV0dXJuIHJlY3QxLnggPCByZWN0Mi54ICsgcmVjdDIud2lkdGggYW5kCiAgICAgICAgICAgcmVjdDEueCArIHJlY3QxLndpZHRoID4gcmVjdDIueCBhbmQKICAgICAgICAgICByZWN0MS55IDwgcmVjdDIueSArIHJlY3QyLmhlaWdodCBhbmQKICAgICAgICAgICByZWN0MS55ICsgcmVjdDEuaGVpZ2h0ID4gcmVjdDIueQplbmQKCi0tIEZ1bmN0aW9uIHRvIHJlc29sdmUgY29sbGlzaW9uIGFuZCBzbGlkZQpmdW5jdGlvbiBjb2xsaWRlQW5kU2xpZGUob2JqZWN0LCBvYnN0YWNsZSkKICAgIGlmIGNoZWNrQ29sbGlzaW9uKG9iamVjdCwgb2JzdGFjbGUpIHRoZW4KICAgICAgICBsb2NhbCBvdmVybGFwWCA9IG1hdGgubWluKG9iamVjdC54ICsgb2JqZWN0LndpZHRoLCBvYnN0YWNsZS54ICsgb2JzdGFjbGUud2lkdGgpIC0gbWF0aC5tYXgob2JqZWN0LngsIG9ic3RhY2xlLngpCiAgICAgICAgbG9jYWwgb3ZlcmxhcFkgPSBtYXRoLm1pbihvYmplY3QueSArIG9iamVjdC5oZWlnaHQsIG9ic3RhY2xlLnkgKyBvYnN0YWNsZS5oZWlnaHQpIC0gbWF0aC5tYXgob2JqZWN0LnksIG9ic3RhY2xlLnkpCgogICAgICAgIGlmIG92ZXJsYXBYIDwgb3ZlcmxhcFkgdGhlbgogICAgICAgICAgICBpZiBvYmplY3QueCA8IG9ic3RhY2xlLnggdGhlbgogICAgICAgICAgICAgICAgb2JqZWN0LnggPSBvYmplY3QueCAtIG92ZXJsYXBYCiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIG9iamVjdC54ID0gb2JqZWN0LnggKyBvdmVybGFwWAogICAgICAgICAgICBlbmQKICAgICAgICBlbHNlCiAgICAgICAgICAgIGlmIG9iamVjdC55IDwgb2JzdGFjbGUueSB0aGVuCiAgICAgICAgICAgICAgICBvYmplY3QueSA9IG9iamVjdC55IC0gb3ZlcmxhcFkKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgb2JqZWN0LnkgPSBvYmplY3QueSArIG92ZXJsYXBZCiAgICAgICAgICAgIGVuZAogICAgICAgIGVuZAogICAgZW5kCmVuZAoKcGxheWVyID0ge3ggPSA1MCwgeSA9IDUwLCB3aWR0aCA9IDIwLCBoZWlnaHQgPSAyMH0Kb2JzdGFjbGVzID0gewogICB7eCA9IDYwLCB5ID0gNDAsIHdpZHRoID0gMzAsIGhlaWdodCA9IDMwfSwKICB7eCA9IDY1LCB5ID0gNjAsIHdpZHRoID0gNDAsIGhlaWdodCA9IDMwfQp9CgpmdW5jdGlvbiBfdXBkYXRlKCkKICAgIGlmKGN0cmwucHJlc3Npbmcoa2V5cy5sZWZ0KSkgdGhlbgogICAgICAgICBwbGF5ZXIueCA9IHBsYXllci54IC0gMQogICAgZWxzZWlmIChjdHJsLnByZXNzaW5nKGtleXMucmlnaHQpKSB0aGVuCiAgICAgICAgIHBsYXllci54ID0gcGxheWVyLnggKyAxCiAgICBlbmQKCiAgICBpZihjdHJsLnByZXNzaW5nKGtleXMudXApKSB0aGVuCiAgICAgICAgIHBsYXllci55ID0gcGxheWVyLnkgLSAxCiAgICBlbHNlaWYgKGN0cmwucHJlc3Npbmcoa2V5cy5kb3duKSkgdGhlbgogICAgICAgICBwbGF5ZXIueSA9IHBsYXllci55ICsgMQogICAgZW5kCgogICAgZm9yIG9ic3RhY2xlIGluIGFsbChvYnN0YWNsZXMpIGRvCiAgICAgICBjb2xsaWRlQW5kU2xpZGUocGxheWVyLCBvYnN0YWNsZSkKICAgIGVuZAplbmQKCgpmdW5jdGlvbiBfZHJhdygpCiAgICBnZnguY2xzKCkKICAgIGZvciBvYnN0YWNsZSBpbiBhbGwob2JzdGFjbGVzKSBkbwogICAgICAgIHNoYXBlLnJlY3Qob2JzdGFjbGUueCwgb2JzdGFjbGUueSwgb2JzdGFjbGUud2lkdGgsIG9ic3RhY2xlLmhlaWdodCwgOSkKICAgIGVuZAoKICAgIHNoYXBlLnJlY3QocGxheWVyLngsIHBsYXllci55LCBwbGF5ZXIud2lkdGgsIHBsYXllci5oZWlnaHQsIDgpCmVuZA==[AABB Collision]
- https://minigdx.github.io/tiny/sandbox.html?game=LS0gVXBkYXRlIHRoZSBjb2RlIHRvIHVwZGF0ZSB0aGUgZ2FtZSEKbG9jYWwgUGxheWVyID0gewogICB4ID0gMTI4IC0gMTYsCiAgIHkgPSAxMjggLSAxNiwKfQpmdW5jdGlvbiBfaW5pdCgpCiAgcGxheWVyID0gbmV3KFBsYXllcikKZW5kCgpmdW5jdGlvbiBfdXBkYXRlKCkKICBpZiBjdHJsLnByZXNzaW5nKGtleXMubGVmdCkgdGhlbgogICAgIHBsYXllci54ID0gbWF0aC5tYXgoMCwgcGxheWVyLnggLSAxKQogIGVsc2VpZiBjdHJsLnByZXNzaW5nKGtleXMucmlnaHQpIHRoZW4KICAgICAgcGxheWVyLnggPSBtYXRoLm1pbigyNDAsIHBsYXllci54ICsgMSkKICBlbmQKCmlmIGN0cmwucHJlc3Npbmcoa2V5cy51cCkgdGhlbgogICAgIHBsYXllci55ID0gbWF0aC5tYXgoMCwgcGxheWVyLnkgLSAxKQogIGVsc2VpZiBjdHJsLnByZXNzaW5nKGtleXMuZG93bikgdGhlbgogICAgICBwbGF5ZXIueSA9IG1hdGgubWluKDI0MCwgcGxheWVyLnkgKyAxKQogIGVuZAplbmQKCmZ1bmN0aW9uIF9kcmF3KCkKICAgZ2Z4LmNscygpCgogICBzaGFwZS5ncmFkaWVudCgwLCAwLCAyNTYsIDI1NiwgMywgNCkKCiAgIHNwci5kcmF3KDk2LCBwbGF5ZXIueCwgcGxheWVyLnkpCiAgIAplbmQK[Control sprite move]
- https://minigdx.github.io/tiny/sandbox.html?game=bG9jYWwgUGxheWVyID0gewogIHggPSAxMjggLSAxNiwKICB5ID0gMTI4IC0gMTYsCiAgZHggPSAwLAogIGR5ID0gMAp9CiAgCmZ1bmN0aW9uIF9pbml0KCkKICAgbG9jYWwgc2VlZCA9IG1hdGgucm5kKCkKICAgcGxheWVyID0gbmV3KFBsYXllciwgewogICAgICAgZHggPSBtYXRoLmNvcyhzZWVkKSAqIDMsIAogICAgICAgZHkgPSBtYXRoLnNpbihzZWVkKSAqIDMKICAgfSkKZW5kCgpmdW5jdGlvbiBfdXBkYXRlKCkKICAgaWYgY3RybC5wcmVzc2VkKGtleXMuc3BhY2UpIHRoZW4KICAgICBfaW5pdCgpCiAgIGVuZAogICBwbGF5ZXIueCA9IHBsYXllci54ICsgcGxheWVyLmR4CiAgIHBsYXllci55ID0gcGxheWVyLnkgKyBwbGF5ZXIuZHkKICAgaWYgcGxheWVyLnggPiAyNDAgb3IgcGxheWVyLnggPCAwIHRoZW4KICAgICAgcGxheWVyLmR4ID0gcGxheWVyLmR4ICogLTEKICAgZW5kCiAgIGlmIHBsYXllci55ID4gMjQwIG9yIHBsYXllci55IDwgMCB0aGVuCiAgICAgIHBsYXllci5keSA9IHBsYXllci5keSAqIC0xCiAgIGVuZAogICBwbGF5ZXIueCA9IG1hdGgubWF4KDAsIG1hdGgubWluKHBsYXllci54LCAyNDApKQogICBwbGF5ZXIueSA9IG1hdGgubWF4KDAsIG1hdGgubWluKHBsYXllci55LCAyNDApKQplbmQKCmZ1bmN0aW9uIF9kcmF3KCkKICBnZnguY2xzKCkKICBzcHIuZHJhdygxMjAsIHBsYXllci54LCBwbGF5ZXIueSkKZW5kCg==[Bouncing Bat]
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 @@ -4,6 +4,8 @@ Here are a fews examples of game created using `🧸 Tiny`.

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[https://dwursteisen.itch.io/memory-pong-trijam-251]
image:sample/connect_me.gif[link=https://dwursteisen.itch.io/connect-me]


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.
8 changes: 6 additions & 2 deletions tiny-web-editor/src/jsMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import org.w3c.dom.HTMLAnchorElement
import org.w3c.dom.HTMLCanvasElement
import org.w3c.dom.HTMLTextAreaElement
import org.w3c.dom.url.URLSearchParams
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi

@OptIn(ExperimentalEncodingApi::class)
fun main() {
val rootPath = getRootPath()

Expand All @@ -34,7 +37,7 @@ fun main() {
val url = URLSearchParams(window.location.search)
val savedCode = url.get("game")
val decodedCode = if (savedCode?.isNotBlank() == true) {
window.atob(savedCode)
Base64.decode(savedCode.encodeToByteArray()).decodeToString()
} else {
null
}
Expand Down Expand Up @@ -75,6 +78,7 @@ fun main() {
}
}

@OptIn(ExperimentalEncodingApi::class)
private fun createGame(
container: Element,
index: Int,
Expand All @@ -101,7 +105,7 @@ private fun createGame(
container.appendChild(textarea)

val link = (document.createElement("a") as HTMLAnchorElement).apply {
val b64 = window.btoa(code)
val b64 = Base64.encode(code.encodeToByteArray())
id = "share-$index"
href = "sandbox.html?game=$b64"
textContent = "\uD83D\uDD17 Share this game!"
Expand Down

0 comments on commit 9aa8d10

Please sign in to comment.