QPong / planning

For planning purposes
0 stars 0 forks source link

Make a PICO-8 demo of sharing something #16

Open HuangJunye opened 2 years ago

HuangJunye commented 2 years ago

Based on the research done in #1, we have decided to focus on PICO-8 version.

This task is to make a brand new PICO-8 demo to share some text. Note this should not be built on top of QPong PICO-8 version.

@Unathi-Skosana can you please break this down to smaller actionable items?

Unathi-Skosana commented 1 year ago

Tasks

To the second check list item; Alternatively, one could instead build a pico-8 in JS/TS https://jspicl.github.io/ and leave the sharing (which I presume in such a scenario, TS/JS would be managing the game state to certain extant) to TS/JS.

Unathi-Skosana commented 1 year ago

It appears as if global libraries such as os and io that are within scope in vanilla Lua, are intentionally disabled in pico-8 for obvious security reasons, which I think would make copying text to the OS's clipboard or opening a url link (as in the comment on issue #15, for posting on twitter) from a pico-8 impossible, if not very difficult to achieve. See gist:

-- attempts to open a given url in the system default browser, regardless of operating system.
local open_cmd -- this needs to stay outside the function, or it'll re-sniff every time...
function _open_url(url)
 if not open_cmd then
     if package.config:sub(1,1) == '\\' then -- windows
         open_cmd = function(url)
             -- should work on anything since (and including) win'95
             os.execute(string.format('start "%s"', url))
         end
     -- the only systems left should understand uname...
     elseif (io.popen("uname -s"):read'*a') == "darwin" then -- osx/darwin ? (i can not test.)
         open_cmd = function(url)
             -- i cannot test, but this should work on modern macs.
             os.execute(string.format('open "%s"', url))
         end
     else -- that ought to only leave linux
         open_cmd = function(url)
             -- should work on x-based distros.
             os.execute(string.format('xdg-open "%s"', url))
         end
     end
 end

 open_cmd(url)
end

This code excerpt works on vanilla Lua, but not on pico-8 :(

Unathi-Skosana commented 1 year ago

As an alternative, I think we should consider QPong writing QPong in a web-based language like JS/TS, in the future, this would make QPong's codebase a little more malleable for adding features such as multi-player, score sharing, analytics, etc. To this end, a game framework like phaser.io immediately comes to mind.

HuangJunye commented 1 year ago
Unathi-Skosana commented 1 year ago

As discussed during #33 , the best (or only possible way) way to implement such a feature for a pico8 game is to send the data (score, player ids, and etc) to the frontend (JS), where opening/sharing URL links will be done. This can be achieved by encoding data in bytes and populating the pico8_gpio array with the said data, and retrieving from the client by reading pico8_gpio array (as done here).

However, to proceed with the above requires purchasing pico8 for exporting games to html and more importantly the JS for testing changes that implement the just described feature (on pico-edu export is not supported). Alternatively, one could locally editing the once-off exported JS (thanks @HuangJunye) to reflect the changes made in the pico8 game source code (see source here), but this is pulling teeth since much of the pico-8 game source code (as far as I can tell) is compiled down to a large JS with a lot of moving parts even for a basic demo, which is hard to read and it is not yet clear to me where to start (see gist)

tula3and commented 1 year ago

Good source to send data to apply for server

It is found by Unathi. Thanks again!

tula3and commented 1 year ago

Using p8modem; checked it works well.

Image

However, sending an array is not working.