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

Convert weapon_list to weapons.json #90

Merged
merged 1 commit into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 29 additions & 0 deletions convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Convert weapon_list.xml to weapons.json

import json
import xml.etree.ElementTree as et

weapon_xml = et.parse('weapon_list.xml')
root = weapon_xml.getroot()

string_keys = ["type","name","mountsize","file","soundwav"]
weapons = []
for elem in root:
weapon_dict = {}
weapon_dict['type'] = elem.tag
weapon_dict.update(elem.attrib)

for child in elem:
prefix = child.tag
for key,value in child.attrib.items():
if key in string_keys:
weapon_dict[prefix + '.' + key] = value
else:
weapon_dict[prefix + '.' + key] = float(value)

weapons.append(weapon_dict)

json_object = json.dumps(weapons, indent = 4)
with open("weapons.json", "w") as json_file:
json_file.write(json_object)
print(json_object)
2 changes: 2 additions & 0 deletions units/parser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Convert unit.csv to unit.json

import random
import json
import sys
Expand Down
Loading