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

Sketch JSON mappings #10

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
35 changes: 35 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: coh3_modding
channels:
- anaconda
- defaults
dependencies:
- bzip2=1.0.8
- ca-certificates=2023.01.10
- certifi=2022.12.7
- freetype=2.12.1
- jpeg=9e
- lerc=3.0
- libdeflate=1.8
- libffi=3.4.2
- libpng=1.6.37
- libtiff=4.5.0
- libwebp=1.2.4
- libwebp-base=1.2.4
- lz4-c=1.9.4
- openssl=1.1.1t
- pillow=9.3.0
- pip=23.0.1
- python=3.10.9
- setuptools=65.6.3
- sqlite=3.41.1
- tk=8.6.12
- tzdata=2022g
- vc=14.2
- vs2015_runtime=14.27.29016
- wheel=0.38.4
- wincertstore=0.2
- xz=5.2.10
- zlib=1.2.13
- zstd=1.5.2
- pip:
- texture2ddecoder==1.0.4
95 changes: 59 additions & 36 deletions scripts/xml-to-json/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os

from mappingSbps import parseSquadBlueprintXML
from scriptUtils import get_nth_level_parent, build_files_dictionary, save_dict_to_json, get_path_as_string, resolve_dict_value_by_path, create_locstring_dictionary
from weapons import parse_weapon_xml_data

Expand All @@ -13,49 +15,63 @@



# create locstring dictionary
locstring_path = os.path.abspath(os.path.join(xml_data_dir, 'loc_english\locale.txt'))
locstring = create_locstring_dictionary(locstring_path)
# export to json
locstring_export_path = os.path.join(script_root_dir, f'{CONST_EXPORT_DIR}')
save_dict_to_json(locstring, locstring_export_path, "locstring.json")
def exportLocstrings():
# create locstring dictionary
locstring_path = os.path.abspath(os.path.join(xml_data_dir, 'loc_english\locale.txt'))
locstring = create_locstring_dictionary(locstring_path)
# export to json
locstring_export_path = os.path.join(script_root_dir, f'{CONST_EXPORT_DIR}')
save_dict_to_json(locstring, locstring_export_path, "locstring.json")


def exportWeapons():
print('## Started processing weapons....')
# navigate to weapon XMLs and build a dictionary
weapons_src_dir = os.path.abspath(os.path.join(xml_data_dir, 'attrib\instances\weapon'))
result = build_files_dictionary(weapons_src_dir, parse_weapon_xml_data)
weapons = resolve_dict_value_by_path(result, get_path_as_string(weapons_src_dir))
# export to json
exported_weapons_dir = os.path.join(script_root_dir, f'{CONST_EXPORT_DIR}')
save_dict_to_json(weapons, exported_weapons_dir, "weapon.json")
print('## Started processing weapons....')

# navigate to weapon XMLs and build a dictionary
weapons_src_dir = os.path.abspath(os.path.join(xml_data_dir, 'attrib\instances\weapon'))
result = build_files_dictionary(weapons_src_dir, parse_weapon_xml_data)
weapons = resolve_dict_value_by_path(result, get_path_as_string(weapons_src_dir))
# export to json
exported_weapons_dir = os.path.join(script_root_dir, f'{CONST_EXPORT_DIR}')
save_dict_to_json(weapons, exported_weapons_dir, "weapon.json")


def exportEntityBlueprints():
print('## Started processing ebps....')
# navigate to ebps XMLs and build a dictionary
ebps_src_dir = os.path.abspath(os.path.join(xml_data_dir, 'attrib\instances\ebps'))
result = build_files_dictionary(ebps_src_dir, parse_weapon_xml_data)
ebps = resolve_dict_value_by_path(result, get_path_as_string(ebps_src_dir))
# export to json
exported_ebps_dir = os.path.join(script_root_dir, f'{CONST_EXPORT_DIR}')
save_dict_to_json(ebps, exported_ebps_dir, "ebps.json")
print('## Finished processing ebps....')

# navigate to ebps XMLs and build a dictionary
ebps_src_dir = os.path.abspath(os.path.join(xml_data_dir, 'attrib\instances\ebps'))
result = build_files_dictionary(ebps_src_dir, parse_weapon_xml_data)
ebps = resolve_dict_value_by_path(result, get_path_as_string(ebps_src_dir))
# export to json
exported_ebps_dir = os.path.join(script_root_dir, f'{CONST_EXPORT_DIR}')
save_dict_to_json(ebps, exported_ebps_dir, "ebps.json")


def exportSquadBlueprints():
print('## Started processing sbps....')
# navigate to sbps XMLs and build a dictionary
sbps_src_dir = os.path.abspath(os.path.join(xml_data_dir, 'attrib\instances\sbps'))
result = build_files_dictionary(sbps_src_dir, parse_weapon_xml_data)
sbps = resolve_dict_value_by_path(result, get_path_as_string(sbps_src_dir))
# export to json
exported_sbps_dir = os.path.join(script_root_dir, f'{CONST_EXPORT_DIR}')
save_dict_to_json(sbps, exported_sbps_dir, "sbps.json")
print('## Finished processing sbps....')

# navigate to sbps XMLs and build a dictionary
sbps_src_dir = os.path.abspath(os.path.join(xml_data_dir, 'attrib\instances\sbps'))
result = build_files_dictionary(sbps_src_dir, parse_weapon_xml_data)
sbps = resolve_dict_value_by_path(result, get_path_as_string(sbps_src_dir))
# export to json
exported_sbps_dir = os.path.join(script_root_dir, f'{CONST_EXPORT_DIR}')
save_dict_to_json(sbps, exported_sbps_dir, "sbps.json")

# navigate to upgrade XMLs and build a dictionary
upgrade_src_dir = os.path.abspath(os.path.join(xml_data_dir, 'attrib\instances\\upgrade'))
result = build_files_dictionary(upgrade_src_dir, parse_weapon_xml_data)
upgrade = resolve_dict_value_by_path(result, get_path_as_string(upgrade_src_dir))
# export to json
exported_upgrade_dir = os.path.join(script_root_dir, f'{CONST_EXPORT_DIR}')
save_dict_to_json(upgrade, exported_upgrade_dir, "upgrade.json")
def exportUpgrades():
print('## Started processing upgrades....')
# navigate to upgrade XMLs and build a dictionary
upgrade_src_dir = os.path.abspath(os.path.join(xml_data_dir, 'attrib\instances\\upgrade'))
result = build_files_dictionary(upgrade_src_dir, parse_weapon_xml_data)
upgrade = resolve_dict_value_by_path(result, get_path_as_string(upgrade_src_dir))
# export to json
exported_upgrade_dir = os.path.join(script_root_dir, f'{CONST_EXPORT_DIR}')
save_dict_to_json(upgrade, exported_upgrade_dir, "upgrade.json")
print('## Finished processing upgrades....')

# Use a function to easily spot each xml-to-json execution.
def exportBattlegroups():
Expand All @@ -81,7 +97,14 @@ def exportAbilities():
print('## Finished processing abilities....')


exportBattlegroups()
exportAbilities()
# exportLocstrings()
# exportWeapons()
# exportEntityBlueprints()
# exportSquadBlueprints()
# exportUpgrades()
# exportBattlegroups()
# exportAbilities()

parseSquadBlueprintXML()

print('Parsing done. View this folder for results: \n"'+ get_path_as_string(script_root_dir)+f'\{CONST_EXPORT_DIR}"')
Loading