Skip to content

Instantly share code, notes, and snippets.

@Caaz
Created December 24, 2017 21:55
Show Gist options
  • Save Caaz/21dc2f3c1d0062bd71bfef788ba5ceed to your computer and use it in GitHub Desktop.
Save Caaz/21dc2f3c1d0062bd71bfef788ba5ceed to your computer and use it in GitHub Desktop.
Compile pico-8 carts into one file!
#!/usr/bin/perl
use warnings;
use strict;
use v5.10;
no warnings 'experimental::smartmatch';
die("No argument provided for file\n") unless($ARGV[0]);
die("No file at $ARGV[0]\n") unless(-e $ARGV[0]);
unless($ARGV[1]) {
my $cart_name = $ARGV[0];
$cart_name =~ s/.*\///gs;
$ARGV[1] = 'build/'.$cart_name;
}
my $cart = $ARGV[0];
my $output = $ARGV[1];
my @required = ();
sub parse;
sub parse($ $) {
my ($code, $out) = @_;
while(my $row = <$code>) {
if($row =~ /\-\- require (.*?)$/i) {
my $require = $1;
if($require ~~ @required) {
print "$require already required, skipping.\n";
$row = ''
} else {
push(@required,$require);
print "requiring $require\n";
my $importing;
open($importing, '<:encoding(Windows-1252)', $require)
or die "Could not open file '$require' for reading. $!";
open my ($out), '>', \$row;
parse($importing, $out);
close $out;
}
}
print $out $row;
}
}
open(my $base_cart, '<:encoding(Windows-1252)', $cart)
or die "Could not open file '$cart' for reading. $!";
open(my $compiled_cart, '>:encoding(Windows-1252)', $output)
or die "Could not open file '$output' for writing. $!";
parse($base_cart,$compiled_cart);
close $base_cart;
close $compiled_cart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment