Added scripts for automatic pack generation

This commit is contained in:
Stijn Bannink 2024-08-04 15:45:50 +02:00
parent 1598270436
commit 70bc481145
Signed by: SBDeveloper
GPG key ID: B730712F2C3A9D7A
72 changed files with 283 additions and 0 deletions

15
.gitignore vendored Normal file
View file

@ -0,0 +1,15 @@
# Jetbrains IDE
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
.idea/artifacts
.idea/compiler.xml
.idea/jarRepositories.xml
.idea/modules.xml
.idea/*.iml
.idea/modules
*.iml
*.ipr
.internal/Tools/*

8
.idea/.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

7
.idea/discord.xml Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
<option name="description" value="" />
</component>
</project>

View file

@ -0,0 +1,19 @@
<component name="libraryTable">
<library name="Examples-v2">
<CLASSES>
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v2/VPExample-1.16.2-1.16.4.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v2/VPExample-1.20.2-1.20.4.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v2/VPExample-1.15.2-1.16.1.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v2/VPExample-1.17.x.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v2/VPExample-1.19.3.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v2/VPExample-1.20-1.20.1.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v2/VPExample-1.19-1.19.2.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v2/VPExample-1.12.2.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v2/VPExample-1.19.4.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v2/VPExample-1.18.x.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v2/VPExample-1.13.2-1.14.4.zip!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View file

@ -0,0 +1,18 @@
<component name="libraryTable">
<library name="Examples-v3">
<CLASSES>
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v3/VPExampleNew-1.17.x.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v3/VPExampleNew-1.19-1.19.2.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v3/VPExampleNew-1.16.x.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v3/VPExampleNew-1.19.4.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v3/VPExampleNew-1.19.3.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v3/VPExampleNew-1.14.x.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v3/VPExampleNew-1.15.x.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v3/VPExampleNew-1.18.x.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v3/VPExampleNew-1.20.2-1.20.4.zip!/" />
<root url="jar://$PROJECT_DIR$/Resource Packs/Examples-v3/VPExampleNew-1.20-1.20.1.zip!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

9
.idea/misc.xml Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.10 (VehiclesPlus-v3)" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View file

@ -0,0 +1,26 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Build v2 packs" type="PythonConfigurationType" factoryName="Python">
<module name="VehiclesPlus" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="SDK_NAME" value="Python 3.10 (VehiclesPlus-v3)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.internal/Sources" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/.internal/Sources/convert.py" />
<option name="PARAMETERS" value="v2" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>

View file

@ -0,0 +1,26 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Build v3 packs" type="PythonConfigurationType" factoryName="Python">
<module name="VehiclesPlus" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="SDK_NAME" value="Python 3.10 (VehiclesPlus-v3)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.internal/Sources" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/.internal/Sources/convert.py" />
<option name="PARAMETERS" value="v3" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>

6
.idea/vcs.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View file

@ -0,0 +1,4 @@
# Converter scripts
This directory contains scripts that are used to convert the data from the original format to the format used in the project.
The VPExample.zip files are for version 1.20, which is the source.

View file

@ -0,0 +1,118 @@
import os
import shutil
import subprocess
import requests
def parse_versions(file_path):
versions = []
with open(file_path, 'r') as file:
for line in file:
parts = line.strip().split('#')
version_description = parts[1]
versions.append(version_description)
return versions
def download_latest_jar(repo_url, jar_directory, jar_name="ResourcePackConverter.jar"):
api_url = f"https://api.github.com/repos/{repo_url}/releases"
response = requests.get(api_url)
response.raise_for_status()
releases = response.json()
jar_url = None
for release in releases:
if release['assets']:
for asset in release['assets']:
if asset['name'] == jar_name:
jar_url = asset['browser_download_url']
break
if jar_url:
break
if not jar_url:
raise FileNotFoundError(f"No JAR file named {jar_name} found in the releases.")
jar_path = os.path.join(jar_directory, jar_name)
os.makedirs(jar_directory, exist_ok=True)
response = requests.get(jar_url)
response.raise_for_status()
with open(jar_path, 'wb') as file:
file.write(response.content)
return jar_path
def copy_zip_file(src, dst):
if not os.path.exists(dst):
os.makedirs(dst)
shutil.copy(src, dst)
def run_java_command(version, jar_file, input_zip):
command = f"java -jar {jar_file} --from 1.20 --to {version} -i {input_zip}"
print(f"Executing: {command}")
subprocess.run(command, shell=True)
def main(version_type):
if version_type not in ['v2', 'v3']:
raise ValueError("Invalid version type. Choose 'v2' or 'v3'.")
versions_file = f'versions_{version_type}.txt'
jar_directory = '../Tools/'
jar_name = "ResourcePackConverter.jar"
src_zip = f'Examples-{version_type}/VPExample.zip'
output_dir = f'../../ResourcePacks/Examples-{version_type}/'
repo_url = "agentdid127/ResourcePackConverter"
output_zip_name = "VPExample_converted.zip"
# Remove all zip files in the output directory
for file in os.listdir(output_dir):
if file.endswith(".zip"):
os.remove(os.path.join(output_dir, file))
# Parse versions from the file
versions = parse_versions(versions_file)
# Download the latest JAR file from GitHub
latest_jar = os.path.join(jar_directory, jar_name)
# TODO Re-enable
# latest_jar = download_latest_jar(repo_url, jar_directory, jar_name)
# Copy the zip file to the tools directory
copy_zip_file(src_zip, jar_directory)
try:
for version_description in versions:
# Run the Java command
run_java_command(version_description.split('-')[-1], latest_jar, jar_directory)
# Define the destination path with the new name
final_output_path = os.path.join(output_dir, f"VPExample-{version_type}-{version_description}.zip")
# Move and rename the output zip file to the destination
output_zip_path = os.path.join(jar_directory, output_zip_name)
shutil.move(output_zip_path, final_output_path)
print(f"Moved {output_zip_path} to {final_output_path}")
# Add the file to git
os.system(f"git add {final_output_path}")
finally:
# Remove the JAR file and the input zip file
run_path_folder = os.path.join(jar_directory, "VPExample_converted")
if os.path.exists(run_path_folder):
shutil.rmtree(run_path_folder)
# if os.path.exists(latest_jar):
# os.remove(latest_jar)
input_zip_path = os.path.join(jar_directory, os.path.basename(src_zip))
if os.path.exists(input_zip_path):
os.remove(input_zip_path)
print("Conversion completed.")
if __name__ == '__main__':
import sys
if len(sys.argv) != 2:
print("Usage: python convert_versions.py [v2|v3]")
sys.exit(1)
version_type = sys.argv[1]
main(version_type)

View file

@ -0,0 +1,14 @@
3#1.12.2
4#1.13.2-1.14.4
5#1.15.2-1.16.1
6#1.16.2-1.16.5
7#1.17-1.17.1
8#1.18-1.18.2
9#1.19-1.19.2
11#1.19.3
13#1.19.4
15#1.20-1.20.1
18#1.20.2
22#1.20.3-1.20.4
32#1.20.5-1.20.6
34#1.21

View file

@ -0,0 +1,13 @@
4#1.14-1.14.4
5#1.15.2-1.16.1
6#1.16.2-1.16.5
7#1.17-1.17.1
8#1.18-1.18.2
9#1.19-1.19.2
11#1.19.3
13#1.19.4
15#1.20-1.20.1
18#1.20.2
22#1.20.3-1.20.4
32#1.20.5-1.20.6
34#1.21

0
.internal/Tools/.gitkeep Normal file
View file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.