Last active
February 26, 2021 01:55
-
-
Save Perlence/9cb07d87c67399bd5c64 to your computer and use it in GitHub Desktop.
Run all maps from subdirectories (Quake)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import sys | |
import subprocess | |
from os.path import isfile, join, splitext, sep, normpath | |
from glob import glob | |
ENGINE = 'quakespasm\\0.91.0\\quakespasm.exe' | |
GAME = 'sm' | |
QARGS = ['-heapsize', '256000', | |
'-zone', '4096', | |
'-hipnotic', | |
'-game', GAME] | |
def main(): | |
if len(sys.argv) == 1: | |
subprocess.call([ENGINE] + QARGS) | |
return | |
args = sys.argv[1:] | |
maps = [] | |
for arg in args: | |
if arg.endswith('/') or arg.endswith('\\'): | |
files = glob(join(GAME, 'maps', arg, '*.bsp')) | |
for f in files: | |
mapname, _ = splitext(join(*normpath(f).split(sep)[2:])) | |
maps.append(mapname) | |
elif isfile(join(GAME, 'maps', arg + '.bsp')): | |
arg = arg.replace('\\', '/') | |
maps.append(arg) | |
lenmaps = len(maps) | |
if lenmaps == 0: | |
print('no maps found.') | |
sys.exit(1) | |
elif lenmaps == 1: | |
print('1 map found:') | |
else: | |
print('{} maps found:'.format(lenmaps)) | |
print(', '.join(maps)) | |
if '-l' in args or '--list' in args: | |
return | |
for mapname in maps: | |
print('starting {},'.format(mapname), end=' ') | |
response = user_input() | |
if response == 'n': | |
continue | |
subprocess.call([ENGINE] + QARGS + ['+map', mapname]) | |
def user_input(): | |
while True: | |
try: | |
response = raw_input('continue ([y]/n)? ').lower().strip() | |
if response in 'yns': | |
return response | |
except KeyboardInterrupt: | |
print() | |
sys.exit() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment