dansanderson/picotool

Error trying to call writep8

deadl0ck opened this issue · 4 comments

Hi,
I'm writing a discord bot and I want people to be able to convert Pico8 png files to p8 files.
I'm trying to call the writep8 capability directly.
I was hitting errors, adn I though it was to do with the format of my png files, which i was writing out from the discord bot, so I downloaded a pico8 png directly and am using it as a test.

Here's the code:
args = ["writep8", "C:\Users\Gamer\Downloads\pico8\grapplicious-0.p8.png"]
tool.main(args)

I'm getting this error:

Ignoring exception in command pico8:
Traceback (most recent call last):
File "C:\Users\Gamer\git\discord-bot-v1\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\Gamer\git\discord-bot-v1\admin\admin_commands.py", line 71, in pico8
tool.main(args)
File "C:\Users\Gamer\git\discord-bot-v1\pico8\tool.py", line 596, in main
return args.func(args)
File "C:\Users\Gamer\git\discord-bot-v1\pico8\tool.py", line 398, in do_writep8
return process_game_files(args.filename, writep8, args=args)
File "C:\Users\Gamer\git\discord-bot-v1\pico8\tool.py", line 268, in process_game_files
procfunc(g, out_fname, args=args)
File "C:\Users\Gamer\git\discord-bot-v1\pico8\tool.py", line 288, in writep8
g.to_file(filename=out_fname)
File "C:\Users\Gamer\git\discord-bot-v1\pico8\game\game.py", line 723, in to_file
self.to_p8png_file(outfh, filename=filename, *args, **kwargs)
File "C:\Users\Gamer\git\discord-bot-v1\pico8\game\game.py", line 689, in to_p8png_file
code_bytes = self.get_bytes_from_code(b''.join(cart_lua))
File "C:\Users\Gamer\git\discord-bot-v1\pico8\game\game.py", line 492, in get_bytes_from_code
code_bytes = bytes(code, 'ascii')
TypeError: encoding without a string argument

This should work calling the code like this (as far as I can see) but it does not

As an update - I tried this on a linux box as just the standard out-of-the-box tool and I get the same issue:

/git/picotool$ ls -l
total 104
-rw-r--r-- 1 deadlock deadlock 1081 Nov 1 15:15 LICENSE
-rw-r--r-- 1 deadlock deadlock 22591 Nov 1 15:15 README.md
-rw-r--r-- 1 deadlock deadlock 45334 Nov 1 13:33 fighter_street_ii-1.p8.png
-rwxr-xr-x 1 deadlock deadlock 125 Nov 1 15:15 p8tool
-rwxr-xr-x 1 deadlock deadlock 142 Nov 1 15:15 p8upsidedown
drwxr-xr-x 12 deadlock deadlock 4096 Nov 1 15:20 pico8
-rw-r--r-- 1 deadlock deadlock 21 Nov 1 15:15 requirements.txt
-rw-r--r-- 1 deadlock deadlock 48 Nov 1 15:15 run_tests.py
-rw-r--r-- 1 deadlock deadlock 61 Nov 1 15:15 setup.cfg
drwxr-xr-x 4 deadlock deadlock 4096 Nov 1 15:15 tests
deadlock@BlazeEntCloud:~/git/picotool$ ./p8tool writep8 fighter_street_ii-1.p8.png
fighter_street_ii-1.p8.png -> fighter_street_ii-1_fmt.p8.png
Traceback (most recent call last):
File "./p8tool", line 8, in
sys.exit(tool.main(sys.argv[1:]))
File "/home/deadlock/git/picotool/pico8/tool.py", line 596, in main
return args.func(args)
File "/home/deadlock/git/picotool/pico8/tool.py", line 398, in do_writep8
return process_game_files(args.filename, writep8, args=args)
File "/home/deadlock/git/picotool/pico8/tool.py", line 268, in process_game_files
procfunc(g, out_fname, args=args)
File "/home/deadlock/git/picotool/pico8/tool.py", line 288, in writep8
g.to_file(filename=out_fname)
File "/home/deadlock/git/picotool/pico8/game/game.py", line 723, in to_file
self.to_p8png_file(outfh, filename=filename, *args, **kwargs)
File "/home/deadlock/git/picotool/pico8/game/game.py", line 689, in to_p8png_file
code_bytes = self.get_bytes_from_code(b''.join(cart_lua))
File "/home/deadlock/git/picotool/pico8/game/game.py", line 492, in get_bytes_from_code
code_bytes = bytes(code, 'ascii')
TypeError: encoding without a string argument

fighter_street_ii-1 p8
grapplicious-0 p8
These are the 2 file I was using for testing (the run fine in Pico8)

A bit late, but in my experience it's better to use the zip archive than the repo itself.
And don't forget to apply the writep8 fix #67!

P.S. Looks like picotool is not able to parse code from newer cartridges, like the one you mentioned, but it is still able to parse assets from them.

Cool - I'll try the zip archive when I get back to this (kinda put it on hold since then)