# convert a user-level into a form that can be execute_file'd from oLoadLevel use strict; use warnings; use Win32::Clipboard; my $base = "D:\\Games\\Spelunky\\v0.99.5__b"; my $level = "lem"; my $lvl = "$base\\levels\\$level.lvl"; open FIN, "<$lvl" or die "Unable to load $lvl: $!"; my @accum; push(@accum, 'if (room_get_name(room) != "rLoadLevel") {', ' room_goto(rLoadLevel);', ' show_message("This file should be executed *after* entering the load-map screen");', '} else {', '', '', '// ==== the map that was output by the level editor ====', "global.customLevelName = 'whatever';", ); for (0..31) { my $line = readchomp(); push(@accum, sprintf 'lvl[%02d] = "%s";', $_, $line); #qq{lvl[$_] = "$line";}); } push(@accum, 'oLoadLevel.author = "' . readchomp() . '";'); push(@accum, 'oLoadLevel.music = "' . readchomp() . '";'); push(@accum, 'global.plife = ' . readchomp() . ';'); push(@accum, 'global.bombs = ' . readchomp() . ';'); push(@accum, 'global.rope = ' . readchomp() . ';'); push(@accum, 'global.nextCustomLevel = "' . readchomp() . '";'); push(@accum, ''); push(@accum, ''); push(@accum, "// ==== load the level ===="); push(@accum, "// (this is largely copied from oLoadLevel's constructor)"); push(@accum, "for (j = 0; j < 32; j += 1)", "{", " for (i = 0; i < 40; i += 1)", " {", " scrCreateTileObj(string_char_at(lvl[j], i+1), 16+i*16, 16+j*16);", " }", "}", "global.customLevel = 1;", "instance_activate_all();", "with oMenu instance_destroy();", "with oPageUp instance_destroy();", "with oPageDown instance_destroy();", "with oLoadButton instance_destroy();", "oLoadLevel.levelLoaded = true;", "oLoadLevel.status = 1;", "oLoadLevel.blackOut = false", "global.customLevelAuthor = oLoadLevel.author;", "instance_create(oEntrance.x+8, oEntrance.y+8, oPlayer1);", "instance_create(x+16, y, oLevel);", "instance_create(x+16, y, oGame);"); push(@accum, ""); push(@accum, ""); push(@accum, "// ==== do all the things you can't do with the level editor ===="); #push(@accum, ""); #push(@accum, "} // don't delete this"); #my $out = join("\n", @accum); #Win32::Clipboard()->Set( $out ); #print "Successfully wrote ", length($out), " bytes to the clipboard.\n"; close FIN; open FOUT, ">$base\\$level.txt" or die; print FOUT join("\n", @accum), "\n"; my $custom = "$base\\levels\\$level.custom"; open FIN, "<$custom" or die "unable to read '$custom': $!"; print FOUT ; close FIN; print FOUT "\n}\n"; sub readchomp { my $line = ; $line =~ s/[\n\r]+$//s; # chomp return $line; }