Skip to content

Commit

Permalink
Updated Satellite Reign Tool (v0.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomiejduda committed May 29, 2022
1 parent 2ea8569 commit 12a27a2
Show file tree
Hide file tree
Showing 7 changed files with 779 additions and 10 deletions.
674 changes: 674 additions & 0 deletions NEW Tools/Satellite Reign/Satellite_Reign_Text_Tool/data/LICENSE

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Program created by Bartlomiej Duda (Ikskoks)
https://github.com/bartlomiejduda
53 changes: 44 additions & 9 deletions NEW Tools/Satellite Reign/Satellite_Reign_Text_Tool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Ver Date Author Comment
# v0.1 28.05.2022 Bartlomiej Duda -
# v0.2 29.05.2022 Bartlomiej Duda -


# This program is for converting XML localization file
Expand All @@ -21,6 +22,10 @@

logger = get_logger(__name__)

VERSION_NUM = "v0.2"
EXE_FILE_NAME = "satellite_reign_text_tool_" + VERSION_NUM + ".exe"
PROGRAM_NAME = f'Satellite Reign Text Tool {VERSION_NUM}'


def export_data(in_file_path: str, out_file_path: str) -> Optional[tuple]:
"""
Expand Down Expand Up @@ -60,7 +65,8 @@ def export_data(in_file_path: str, out_file_path: str) -> Optional[tuple]:
if column_name not in ('id', 'cz', 'fr', 'ge', 'it', 'ru', 'sp'):
translation_text = translation_column.get('#text')
if translation_text:
translation_entry = row_name + "_###_" + column_name + "=" + translation_text.replace("\n", "\\n") + "\n"
translation_entry = row_name + "_###_" + column_name + "_###_" + "=" + \
translation_text.replace("\n", "\\n") + "\n"
ini_file.write(translation_entry)

ini_file.close()
Expand All @@ -69,23 +75,52 @@ def export_data(in_file_path: str, out_file_path: str) -> Optional[tuple]:
return "OK", ""


def import_data(in_file_path: str, out_folder_path: str) -> Optional[tuple]:
# TODO - add import
def import_data(xml_file_path: str, ini_file_path: str, new_xml_file_path) -> Optional[tuple]:
"""
Function for importing data to XML files
"""
logger.info("Starting import_data...")

xml_file = open(xml_file_path, 'rt', encoding="utf8")
ini_file = open(ini_file_path, 'rt', encoding="utf8")
new_xml_file = open(new_xml_file_path, 'wt', encoding="utf8")

# old XML parsing
xml_data = xml_file.read()
xml_dict = xmltodict.parse(xml_data)

# INI parsing
line_number = 0
ini_array = []
for line in ini_file:
line_number += 1
line_dict = {}
line_dict['line_number'] = line_number
line_dict['row_name'] = line.split('_###_')[0]
line_dict['column_name'] = line.split('_###_')[1]
line_dict['line_text'] = line.split('=')[-1]
ini_array.append(line_dict)


# xml_dict = None
# xml_out_data = xmltodict.unparse(xml_dict, pretty=True)
# xml_file_out = open("C:\\Users\\Lenovo\\Desktop\\out.xml", 'wt', encoding="utf8")
# xml_file_out.write(xml_out_data)
# xml_file_out.close()
return "IMPORT_NOT_SUPPORTED", "Import is not supported yet!"
# logger.info("Ending import_data...")
return "OK", ""


def main():
"""
Main function of this program.
"""
parser = argparse.ArgumentParser(prog="satellite_reign_text_tool.exe", description='Satellite Reign Text Tool v1.0')
parser.add_argument('-e', '--ext', type=str, nargs="+", required=False, help='Extract data')
parser.add_argument('-i', '--imp', type=str, nargs="+", required=False, help='Import data')
parser = argparse.ArgumentParser(prog=EXE_FILE_NAME,
description=PROGRAM_NAME)
parser.add_argument('-e', '--ext', metavar=('<xml_file_path>', '<ini_file_path>'),
type=str, nargs=2, required=False, help='Extract data (convert XML to INI)')
parser.add_argument('-i', '--imp', metavar=('<xml_file_path>', '<ini_file_path>', '<new_xml_path>'),
type=str, nargs=3, required=False, help='Import data (convert INI to XML)')

if len(sys.argv) == 1:
parser.print_help()
Expand All @@ -99,12 +134,12 @@ def main():
logger.error(f"{export_result[0]}: {export_result[1]}")
sys.exit(-1)
elif args.imp is not None:
import_result = import_data(args.imp[0], args.imp[1])
import_result = import_data(args.imp[0], args.imp[1], args.imp[2])
if import_result[0] != "OK":
logger.error(f"{import_result[0]}: {import_result[1]}")
sys.exit(-2)

logger.info("End of main... Program has been executed successfully.")
logger.info("End of main... Program has been executed successfully!")
sys.exit(0)


Expand Down
20 changes: 20 additions & 0 deletions NEW Tools/Satellite Reign/Satellite_Reign_Text_Tool/make_exe.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

:: BAT script for making exe file
:: Created by Bartlomiej Duda


@ECHO OFF
if exist dist (rd /s /q dist)
if exist build (rd /s /q build)


echo Activating venv...
CALL .\venv\Scripts\activate.bat

echo Executing cxfreeze...
python setup.py build build_exe


if exist __pycache__ (rd /s /q __pycache__)

echo BUILD SUCCESSFUL!
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ black==22.3.0
mypy==0.931
pylint==2.12.2
pytest==7.0.1
xmltodict==0.13.0
xmltodict==0.13.0
cx-Freeze==6.10
37 changes: 37 additions & 0 deletions NEW Tools/Satellite Reign/Satellite_Reign_Text_Tool/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys
from cx_Freeze import setup, Executable
from main import VERSION_NUM, EXE_FILE_NAME, PROGRAM_NAME

base = None
if sys.platform == "win32":
base = "Console"


executables = [
Executable(
"main.py",
copyright="Copyright (C) 2022 Bartlomiej Duda",
base=base,
icon="data/icon_bd.ico",
target_name=EXE_FILE_NAME
)
]

build_exe_options: dict = {
"packages": [],
'includes': [],
"excludes": ["tkinter", "PIL", "PyQt4", "PyQt5"],
'include_files': ['data/LICENSE', 'data/readme.txt'],
}

options: dict = {
'build_exe': build_exe_options
}

setup(
name=PROGRAM_NAME,
version=VERSION_NUM[1:],
description="Tool for modding Satellite Reign",
options=options,
executables=executables,
)

0 comments on commit 12a27a2

Please sign in to comment.