Skip to content
Snippets Groups Projects
Commit 274592dd authored by Florian Schröder's avatar Florian Schröder
Browse files

Add argparse for CLI in simulator script

An argparse has been added to the overcooked simulator script for better configuration of the command line interface. This allows the user to input the state file, visualization configuration and output filename when executing the script. As a result, the need to manually update these parameters in the script has been mitigated.
parent 181d8ae2
No related branches found
No related tags found
No related merge requests found
Pipeline #45141 passed
import argparse
import colorsys import colorsys
import json import json
import math import math
...@@ -523,9 +524,32 @@ def save_screenshot(state: dict, config: dict, filename: str | Path) -> None: ...@@ -523,9 +524,32 @@ def save_screenshot(state: dict, config: dict, filename: str | Path) -> None:
if __name__ == "__main__": if __name__ == "__main__":
with open(ROOT_DIR / "gui_2d_vis" / "visualization.yaml", "r") as conf_file: parser = argparse.ArgumentParser(
viz_config = yaml.safe_load(conf_file) prog="Overcooked Simulator Image Generation",
with open(ROOT_DIR / "gui_2d_vis" / "sample_state.json", "r") as jsonf: description="Generate images for a state in json.",
sample_state = json.load(jsonf) epilog="For further information, see https://scs.pages.ub.uni-bielefeld.de/cocosy/overcooked-simulator/overcooked_simulator.html",
screenshot_filename = ROOT_DIR / "gui_2d_vis" / "screenshot.jpg" )
save_screenshot(sample_state, viz_config, screenshot_filename) parser.add_argument(
"-s",
"--state",
type=argparse.FileType("r", encoding="UTF-8"),
default=ROOT_DIR / "gui_2d_vis" / "sample_state.json",
)
parser.add_argument(
"-v",
"--visualization_config",
type=argparse.FileType("r", encoding="UTF-8"),
default=ROOT_DIR / "gui_2d_vis" / "visualization.yaml",
)
parser.add_argument(
"-o",
"--output_filename",
type=str,
default="screenshot.jpg",
)
args = parser.parse_args()
with open(args.visualization_config, "r") as f:
viz_config = yaml.safe_load(f)
with open(args.state, "r") as f:
state = json.load(f)
save_screenshot(state, viz_config, args.output_filename)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment