GEM (Good Enough Minifier) for Pico-8
A really hacky code minifier for Pico-8.
Written for my own projects but thought it might come in useful for any other Python-challenged Pico-8 users that couldn't get picotools working.
You can also download the single HTML file as a zip file below and run it locally.
Leave comments or post on Twitter with any feedback.
Comments
Log in with itch.io to leave a comment.
This isn't working for fullcode, just individual functions. I've tried all the various options and combinations. But it generates all sorts of error like function func(..... with unclosed brackets at the start of the code... And it seems to find always find a way to fail should you toss a comment with --[[comment]] anywhere in the code. If you handpick your functions and toss them in here all at once...okay...you can sort of edge out some usage by doing that kind of prep. Fro
m reading the comments and my own fiddling it seems that in general you'll run into problems if you are compressing code that you optimized for tokens.
I really wrote this for my own use but decided to put it out there. Seems to work okay with some code and certainly, at the time, it worked fine for ALL my own pico-8 code (but I do code in a very particular, quite simple, way). Weird that it doesn't cope with block comments though. In saying that, I always end mine "]]--" which my code seems to handle fine. Didn't realise you could omit the "--".
Hi Paul,
the GEM is a great tool and i will used it for the pico1k jam this month. Its really nice.
Today, I found an issue. GEM breaks the code on using the short-hand-print ?"" syntax in if-else. The following code won't work in pico8
The elseif has to be in the next line. Maybe you will fix that issue in the future 😊
quite a list of small things to fix. One day. Maybe!
Great tool! I find it really useful for developing tweet carts. Is there any chance it could give the character counts for the before and after?
Nice - I had tried to setup one of the command line ones but got frustrated. This will work for now when I occasionally max out on characters while adding new features. Unfortunately I'm also reaching the limit on tokens so I might just have to stop adding stuff or start removing stuff at some point... Thanks!
Awesome! This squeezed the single cart version of Mot's Grand Prix down by 15%, enough to fit in a whole 4th track. Thanks for sharing this.
(I always have to untick "Other identifiers" for though. Must be something about my coding style...)
cool. If you want me to look at the other identifiers issue, send me a code sample that breaks it. Haven’t had any issues with that myself and it saves loads of space so I’d like to fix it up if possible!
I've narrowed down a couple of issues.
It appears to be renaming words inside multi-line strings (using [[ ]]):
And ultra-compact mode appears to have difficulty with the short-hand "if" syntax:
wow, didn’t know about multi line string syntax. That going to be useful. I’ll look at trying to fix it.
Awesome work - thanks for building this versatile minifying tool 👏
This may save my bacon while Dan's Picotool is lagging a bit behind atm.
(I may try to tweak it further for my needs - if I do, I'll share with you in case you wish to incorporate any of my mods 🤓)
Thanks. It's been invaluable to me in a couple of larger projects. Feel free to update as much as you like. It's pretty hacky and geared towards my own pico-8 coding style.
One thing I might look at doing in the future is being able to drag/ paste a whole .p8 file so you don't need to go through the hassle of copying all code to a single tab. Probably won't do this until I need to use it again though.
Drag & Drop sounds like a great "quality of life" feature!
(maybe a "save minified file" feature to match also - save needing to copy paste?)
Absolutely!
Odd, the comments are stripped but my local variable names are not minified… Any idea what’s going on? Do I need to format my code in a certain way? I tried with and without the .p8 cartridge header.
no idea, providing you had the correct checkboxes ticked.
If you can replicate it on a few lines of code then post them here and I’ll have a look.
Example:
local averylongname = 10
With default ticked boxes (Comments, Compact, Functions, Other identifiers)
Try the updated version. I wasn't catering for spaces either side of the equals 🤦♂️
It’s working now! It doesn’t seem to work with many spaces though:
local averylongname4 = 100 becomes local averylongname4 = 100
Yes, its pretty hacky. I could easily fix this but due to pico-8's limited number of characters, it seems unlikely that anyone would double-space around symbols such as equals. The reason I missed the spacing the first time was because I've got into the habit (not my usual coding habit at all!) of not putting spaces before and after equals. I'll probably give it a bit of an overhaul the next big project I do and try and sort out stuff like this and also make it a bit easier to use. Thanks for identifying the issue though
Fantastic tool! Got my game from 80% to 56%. Genuinely incredible stuff.
Excellent. Very useful for those of us who over comment out code and use long variable names.
Works like a charm. Thanks for this!
YAH
Hello! couldn't find any info on the license for this tool but I'm using it for minifying my cart and wanted a way to run this from my computer so I did this
https://git.sr.ht/~afk/gem-p8
Mainly what I did is to use the minify function and read a file from the CLI and write the file back, I also split the code into some functions to understand it better and applied some code style rules. Let me know if you have any comments or would like me to change something, or take it down.
Thanks for building this tool!
No problem. Just glad its being used.
You could also "view frame source" in your browser and copy the HTML to a file on your PC. You'd have to remove the last script line after the closing HTML tag that redirects to itch.io. Tested it and it works.
Thanks for the feedback. It's a pretty rough-and-ready utility but it does the job!