Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directional Vehicle Parts for mounted tools, seats, windshields, rams, and doors #40437

Merged
merged 20 commits into from
Jul 5, 2020
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions tools/make_vehicle_parts_directions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import argparse
import json
import os
import subprocess

default_path = "data/json/vehicleparts/rams.json"
default_output = "data/json/vehicleparts/rams2.json"
ids_created_output = "data/json/vehicleparts/new_ids.txt"

ids_to_create_directional_parts_for = []
list_of_created_ids = []

variants = {
"nw" : "y",
"vertical" : "j",
"ne" : "u",
"sw" : "b",
"vertical_2" : "H",
"se" : "n",
"cover" : "^",
"horizontal" : "h",
"horizontal_2" : "=",
"cross" : "c",
"box" : "#"
}

def gen_new(path):
with open(path, "r") as json_file:
json_data = json.load(json_file)
for jo in json_data:
if "id" in jo:
jo["abstract"] = jo["id"]
jo.pop("id")
ids_to_create_directional_parts_for.append(jo["abstract"])

for key, value in variants.items():
for ram in ids_to_create_directional_parts_for:
new_ram_id = ram + "_" + key
new_ram_data = {
"id": new_ram_id,
"copy-from": ram,
"symbol": value,
"type": "vehicle_part"
}
json_data.append(new_ram_data)
list_of_created_ids.append(new_ram_id)
return json_data

path = os.path.join(os.getcwd(), default_path)
output_path = os.path.join(os.getcwd(), default_output)
result = gen_new(path)
print(*ids_to_create_directional_parts_for, sep = "\n")

with open(output_path, "w") as jf:
json.dump(result, jf, ensure_ascii=False, sort_keys=True)
subprocess.Popen(['D:/Cataclysm-DDA/tools/format/json_formatter.exe', output_path], shell=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only going to work on windows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script I based this off, this https://github.com/CleverRaven/Cataclysm-DDA/blob/master/tools/json_tools/pocket_mags.py and it wasn't working for me on Windows. I don't actually expect anyone to be running this script, as I'm committing the transformed JSON along side it. It's more for documentation purposes.


with open(ids_created_output, "w") as jf:
for id in list_of_created_ids:
jf.write(id + "\n")