nesbox / TIC-80

TIC-80 is a fantasy computer for making, playing and sharing tiny games.
https://tic80.com
MIT License
5.05k stars 491 forks source link

load tiny base64 encoded carts from site URL (feature) #2210

Open runlow opened 1 year ago

runlow commented 1 year ago

Example URL https://tic80.com/play#ECMAAHjaKylKTE5VykjNyclXKM8vyklRCvF0tk2tyCzhAgCMHAmREQ

The proposed feature

Why?

Converting a cart for debug This is one way to extract the cart. First copy the last part of the URL after #, then run these commands in a shell. So from the example earlier:

$ echo "ECMAAHjaKylKTE5VykjNyclXKM8vyklRCvF0tk2tyCzhAgCMHAmREQ==" | base64 -d > foo.tic
$ tic80 foo.tic

Without padding you'll get an error but it will still work. This will run the TIC-80 cart and print the message "hello world". There's a bit of overhead from ZLIB compression in the cart but it's worth it with bigger code.

To do the reverse:

$ base64 -w0 foo.tic
ECMAAHjaKylKTE5VykjNyclXKM8vyklRCvF0tk2tyCzhAgCMHAmREQ==

Then add it to the end of the URL. It's the same as the original string but with padding (the = at the end).

Examples of this in other projects https://twitter.com/Xietanu/status/1569382180505223171 https://twitter.com/nobonoko/status/1517928168535044097 https://exoticorn.github.io/microw8/#examples https://itty.bitty.site/ https://dollchan.net/bytebeat/#v3b64q1ZKzk9JVbJSKrGzM1ErUaoFAA

bztsrc commented 1 year ago

Just my humble opinion, but if this is going to be implemented, I don't think using the "https://tic80.com/play" URL prefix is good, because it is misleading. It would be much better (and more standard compliant) to use the data URI scheme for this. Like

data:application/octet-stream;base64,ECMAAHjaKylKTE5VykjNyclXKM8vyklRCvF0tk2tyCzhAgCMHAmREQ

Here the scheme "data:" replaces the "https:" scheme telling that the URL in itself contains the data, so no network connection needed. The mime part could be something tic specific too, application/octet-stream is a jolly joker for binary. Otherwise this data URI is standardized and widely supported, so you can place these "data:" links on any website just like you would place a "https:" link for example. Both are valid URLs.

Just a thought, bzt

nesbox commented 1 year ago

Let's try, I like the idea Thanks