Esempio n. 1
0
def build_maps_for(bsp_dir, wad):
    global needed_quake_wad  # only used if wad is 'quake'
    used_cached_maps = False

    use_repo_bins(Build.base)
    use_repo_wads(Build.base)
    bsp_dir.mkdir(exist_ok=True)

    if not have_needed_tools():
        raise Exception('Quake map tools missing')

    maps = list(Build.dir_maps_source.glob('*.map'))
    maps.remove(Build.dir_maps_source / 'agdm02l.map')  # TODO: it is borked
    maps_to_build = list(maps)

    for mapfile in maps:
        bsp_name = bsp_maybe_hc(wad, mapfile)
        this_wad_mapfile = (bsp_dir / bsp_name).with_suffix('.map')
        this_wad_bspfile = this_wad_mapfile.with_suffix('.bsp')

        if force_map_build or not this_wad_bspfile.is_file() \
         or not this_wad_mapfile.is_file() \
         or this_wad_mapfile.stat().st_mtime < mapfile.stat().st_mtime:

            if not have_wad(wad, quiet=True):
                continue

            map_string = mapfile.read_text()
            map_string = swap_wad(map_string, wad)

            if wad != WADs.QUAKE:
                map_string = swap_textures(map_string, wad)
                throw_errors = True
            else:
                throw_errors = False

            if wad == WADs.PROTOTYPE:
                map_string = high_contrast(map_string)

            this_wad_mapfile.write_text(map_string)
            build(this_wad_mapfile, throw=throw_errors, quiet=True)
        else:
            used_cached_maps = True

        maps_to_build.remove(mapfile)

    if len(maps_to_build) > 0:
        print(len(maps_to_build), 'maps left to build (may need WAD file)')
    elif used_cached_maps:
        print('all maps were retrieved from the cache or built')
    else:
        print('all maps were built')

    if wad == WADs.QUAKE and len(maps_to_build) > 0:
        needed_quake_wad = True
Esempio n. 2
0
def handle_core(args, mode):
	if mode >= Mode.BUILD and not have_needed_tools():
		sys.exit(42)

	if mode >= Mode.BUILD and not have_wad(args.wad):
		sys.exit(42)

	# We only loop over the basenames of the files passed in, because the user
	# could have various temporary files in the directory, and we want to go
	# from the XML by default.

	files = [Path(filename) for filename in args.files]
	bases = [filepath.with_suffix('') for filepath in files]

	for basename in bases:
		xmlfile = basename.with_suffix('.xml')
		mapfile = basename.with_suffix('.map')
		bspfile = bsp_maybe_hc(args.wad, basename)

		if xmlfile in files:
			try:
				if mode >= Mode.CONVERT:
					convert(
						xmlfile,
						wad=args.wad,
						verbose=args.verbose,
						keep_intermediate=args.keep)
					if mode >= Mode.BUILD:
						build(mapfile, bspfile, verbose=args.verbose)
						if mode == Mode.PLAY:
							play(bspfile, verbose=args.verbose)
			except (LDLError, FileNotFoundError):
				print_exception()

		elif mapfile in files:
			try:
				if mode >= Mode.BUILD:
					build(mapfile, verbose=args.verbose)
					if mode == Mode.PLAY:
						play(bspfile, verbose=args.verbose)
			except (LDLError, FileNotFoundError):
				print_exception()

		elif bspfile in files:
			try:
				if mode == Mode.PLAY:
					play(bspfile, verbose=args.verbose)
			except LDLError:
				print_exception()

		else:
			if args.verbose:
				print("Can't", mode, basename, '-- skipping')
Esempio n. 3
0
File: map.py Progetto: matatk/agrip
    def build_and_copy(xmlfile, wad, dest_dirs):
        mapfile = xmlfile.with_suffix('.map')
        bspfile = bsp_maybe_hc(wad, xmlfile)

        convert(xmlfile, wad=wad)
        build(mapfile, bsp_file=bspfile, quiet=True, throw=True)

        for dest_dir in dest_dirs:
            full_dest = dirs.data / dest_dir / 'maps' / bspfile
            shutil.copy(bspfile, full_dest)

        bspfile.unlink()
        mapfile.unlink()