diff --git a/aircraft/javaprop2jsbcpct.py b/aircraft/javaprop2jsbcpct.py index a22ba75..2aa2724 100755 --- a/aircraft/javaprop2jsbcpct.py +++ b/aircraft/javaprop2jsbcpct.py @@ -3,6 +3,7 @@ import argparse import os +import natsort from fgtools.utils.interpolator import Interpolator @@ -93,18 +94,27 @@ if __name__ == "__main__": args = argp.parse_args() - for path in args.input_files: - if not os.path.isfile(path): - print(f"Error: input file {path} not found, exiting") - sys.exit(1) + paths = [] - if len(args.blade_angles) < len(args.input_files): + for path in args.input_files: + if not os.path.exists(path): + print(f"Error: input file / directory {path} not found, exiting") + sys.exit(1) + + if os.path.isfile(path): + paths.append(path) + else: + for file in natsort.realsorted(os.listdir(path)): + paths.append(os.path.join(path, file)) + + if len(args.blade_angles) < len(paths): print("Error: less blade angles than input files") - elif len(args.blade_angles) > len(args.input_files): - args.blade_angles, rest = args.blade_angles[:len(args.input_files) + 1] + elif len(args.blade_angles) > len(paths): + args.blade_angles, rest = args.blade_angles[:len(paths) + 1] print(f"Warning: skipping {len(rest)} blade angles because no corresponding data file was specified") - data = parse_data_files(args.input_files, args.blade_angles) + print(paths) + data = parse_data_files(paths, args.blade_angles) output = make_tables(data, args.max, args.indentation, args.resolution) diff --git a/scenery/create-day-night-xml.py b/scenery/create-day-night-xml.py new file mode 100755 index 0000000..5df6335 --- /dev/null +++ b/scenery/create-day-night-xml.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python + +import os, sys, argparse + +def get_texture_paths(folder="."): + texture_paths = {} + for name in os.listdir(folder): + path = os.path.relpath(os.path.join(folder, name), start=folder) + if name.endswith(".ac"): + with open(path, "r") as f: + if not path in texture_paths: + texture_paths[path] = {} + object = "" + for line in f: + if line.strip().startswith("name"): + object = line.split('"')[1] + if object == "world": + object = "" + continue + + if line.strip().startswith("texture") and object: + texture_path = line.split('"')[1] + if not texture_path in texture_paths[path]: + texture_paths[path][texture_path] = [] + texture_paths[path][texture_path].append(object) + + if not texture_paths[path]: + print(path, "contains no texture, skipping") + + if not texture_paths: + print(os.path.abspath(folder), "does not contain any AC files - exiting") + sys.exit(1) + + return texture_paths + +def write_xml_files(texture_paths, lit_suffix, overwrite): + for ac_path in texture_paths: + xml_path = ac_path.replace(".ac", ".xml") + if os.path.isfile(xml_path) and not overwrite: + print("XML file", xml_path, "already exists - skipping") + continue + + with open(xml_path, "w") as xml_f: + xml_f.write(""" + + %s""" % ac_path) + + for texture_path in texture_paths[ac_path]: + texture_lit_path = texture_path.split(".") + texture_lit_path[-2] += lit_suffix + texture_lit_path = ".".join(texture_lit_path) + + if not os.path.isfile(texture_lit_path): + print("Night texture", texture_lit_path, "does not exist - skipping objects") + break + + xml_f.write(""" + + + + /sim/time/sun-angle-rad + 1.49 + + + material""") + + for object in texture_paths[ac_path][texture_path]: + xml_f.write(" %s" % object) + + xml_f.write(""" + 1 + 1 + 1 + + %s + """ % texture_lit_path) + xml_f.write(""" + + + material + + + /sim/time/sun-angle-rad + 1.49 + + """) + + for object in texture_paths[ac_path][texture_path]: + xml_f.write(" %s" % object) + + xml_f.write(""" + 0 + 0 + 0 + + %s""" % texture_path) + + xml_f.write("") + + xml_f.write("\n") + +def main(): + argp = argparse.ArgumentParser() + + argp.add_argument("-o", "--overwrite", + help="Whether to overwrite XML files if any already exist, defaults to not overwriting", + action="store_true" + ) + + argp.add_argument("-s", "--lit-suffix", + help="What suffix the lit texture has (of the name itself, not the file extension), default is _LIT", + default="_LIT" + ) + + argp.add_argument("folder", + help="Folder / directory where the AC files and textures are in, default is working directory", + default="." + ) + + args = argp.parse_args() + + if not os.path.isdir(args.folder): + print("Folder", args.folder, "does not exist - exiting") + sys.exit(1) + + texture_paths = get_texture_paths(args.folder) + write_xml_files(texture_paths, args.lit_suffix, args.overwrite) + +if __name__ == "__main__": + main() +