mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
Fix codegen more
This commit is contained in:
parent
7743bb1a84
commit
68ab3d6524
3 changed files with 26 additions and 22 deletions
|
@ -1,7 +1,8 @@
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
from lib.utils import get_dir_location
|
||||||
|
|
||||||
README_DIR = os.path.join(os.path.dirname(__file__), '../../../README.md')
|
README_DIR = get_dir_location('../README.md')
|
||||||
VERSION_REGEX = r'\*Currently supported Minecraft version: `(.*)`.\*'
|
VERSION_REGEX = r'\*Currently supported Minecraft version: `(.*)`.\*'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,42 +1,40 @@
|
||||||
|
from lib.utils import get_dir_location
|
||||||
from .mappings import Mappings
|
from .mappings import Mappings
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# make sure the downloads directory exists
|
# make sure the downloads directory exists
|
||||||
if not os.path.exists('downloads'):
|
if not os.path.exists(get_dir_location('downloads')):
|
||||||
os.mkdir('downloads')
|
os.mkdir(get_dir_location('downloads'))
|
||||||
|
|
||||||
|
|
||||||
def get_burger():
|
def get_burger():
|
||||||
if not os.path.exists('downloads/Burger'):
|
if not os.path.exists(get_dir_location('downloads/Burger')):
|
||||||
with open('burger.json', 'w') as f:
|
|
||||||
json.dump(requests.get(
|
|
||||||
'https://api.github.com/repos/Burger/Burger/releases/latest').json(), f)
|
|
||||||
print('\033[92mDownloading Burger...\033[m')
|
print('\033[92mDownloading Burger...\033[m')
|
||||||
os.system(
|
os.system(
|
||||||
'cd downloads && git clone https://github.com/pokechu22/Burger && cd Burger && git pull')
|
f'cd {get_dir_location("downloads")} && git clone https://github.com/pokechu22/Burger && cd Burger && git pull')
|
||||||
|
|
||||||
print('\033[92mInstalling dependencies...\033[m')
|
print('\033[92mInstalling dependencies...\033[m')
|
||||||
os.system('cd downloads/Burger && pip install six jawa')
|
os.system('cd downloads/Burger && pip install six jawa')
|
||||||
|
|
||||||
|
|
||||||
def get_version_manifest():
|
def get_version_manifest():
|
||||||
if not os.path.exists(f'downloads/version_manifest.json'):
|
if not os.path.exists(get_dir_location(f'downloads/version_manifest.json')):
|
||||||
print(
|
print(
|
||||||
f'\033[92mDownloading version manifest...\033[m')
|
f'\033[92mDownloading version manifest...\033[m')
|
||||||
version_manifest_data = requests.get(
|
version_manifest_data = requests.get(
|
||||||
'https://launchermeta.mojang.com/mc/game/version_manifest.json').json()
|
'https://launchermeta.mojang.com/mc/game/version_manifest.json').json()
|
||||||
with open(f'downloads/version_manifest.json', 'w') as f:
|
with open(get_dir_location(f'downloads/version_manifest.json'), 'w') as f:
|
||||||
json.dump(version_manifest_data, f)
|
json.dump(version_manifest_data, f)
|
||||||
else:
|
else:
|
||||||
with open(f'downloads/version_manifest.json', 'r') as f:
|
with open(get_dir_location(f'downloads/version_manifest.json'), 'r') as f:
|
||||||
version_manifest_data = json.load(f)
|
version_manifest_data = json.load(f)
|
||||||
return version_manifest_data
|
return version_manifest_data
|
||||||
|
|
||||||
|
|
||||||
def get_version_data(version_id: str):
|
def get_version_data(version_id: str):
|
||||||
if not os.path.exists(f'downloads/{version_id}.json'):
|
if not os.path.exists(get_dir_location(f'downloads/{version_id}.json')):
|
||||||
version_manifest_data = get_version_manifest()
|
version_manifest_data = get_version_manifest()
|
||||||
|
|
||||||
print(
|
print(
|
||||||
|
@ -48,46 +46,46 @@ def get_version_data(version_id: str):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f'No version with id {version_id} found. Maybe delete downloads/version_manifest.json and try again?')
|
f'No version with id {version_id} found. Maybe delete downloads/version_manifest.json and try again?')
|
||||||
package_data = requests.get(package_url).json()
|
package_data = requests.get(package_url).json()
|
||||||
with open(f'downloads/{version_id}.json', 'w') as f:
|
with open(get_dir_location(f'downloads/{version_id}.json'), 'w') as f:
|
||||||
json.dump(package_data, f)
|
json.dump(package_data, f)
|
||||||
else:
|
else:
|
||||||
with open(f'downloads/{version_id}.json', 'r') as f:
|
with open(get_dir_location(f'downloads/{version_id}.json'), 'r') as f:
|
||||||
package_data = json.load(f)
|
package_data = json.load(f)
|
||||||
return package_data
|
return package_data
|
||||||
|
|
||||||
|
|
||||||
def get_client_jar(version_id: str):
|
def get_client_jar(version_id: str):
|
||||||
if not os.path.exists(f'downloads/client-{version_id}.jar'):
|
if not os.path.exists(get_dir_location(f'downloads/client-{version_id}.jar')):
|
||||||
package_data = get_version_data(version_id)
|
package_data = get_version_data(version_id)
|
||||||
print('\033[92mDownloading client jar...\033[m')
|
print('\033[92mDownloading client jar...\033[m')
|
||||||
client_jar_url = package_data['downloads']['client']['url']
|
client_jar_url = package_data['downloads']['client']['url']
|
||||||
with open(f'downloads/client-{version_id}.jar', 'wb') as f:
|
with open(get_dir_location(f'downloads/client-{version_id}.jar'), 'wb') as f:
|
||||||
f.write(requests.get(client_jar_url).content)
|
f.write(requests.get(client_jar_url).content)
|
||||||
|
|
||||||
|
|
||||||
def get_burger_data_for_version(version_id: str):
|
def get_burger_data_for_version(version_id: str):
|
||||||
if not os.path.exists(f'downloads/burger-{version_id}.json'):
|
if not os.path.exists(get_dir_location(f'downloads/burger-{version_id}.json')):
|
||||||
get_burger()
|
get_burger()
|
||||||
get_client_jar(version_id)
|
get_client_jar(version_id)
|
||||||
|
|
||||||
os.system(
|
os.system(
|
||||||
f'cd downloads/Burger && python munch.py ../client-{version_id}.jar --output ../burger-{version_id}.json'
|
f'cd {get_dir_location("downloads/Burger")} && python munch.py ../client-{version_id}.jar --output ../burger-{version_id}.json'
|
||||||
)
|
)
|
||||||
with open(f'downloads/burger-{version_id}.json', 'r') as f:
|
with open(get_dir_location(f'downloads/burger-{version_id}.json'), 'r') as f:
|
||||||
return json.load(f)
|
return json.load(f)
|
||||||
|
|
||||||
|
|
||||||
def get_mappings_for_version(version_id: str):
|
def get_mappings_for_version(version_id: str):
|
||||||
if not os.path.exists(f'downloads/mappings-{version_id}.txt'):
|
if not os.path.exists(get_dir_location(f'downloads/mappings-{version_id}.txt')):
|
||||||
package_data = get_version_data(version_id)
|
package_data = get_version_data(version_id)
|
||||||
|
|
||||||
client_mappings_url = package_data['downloads']['client_mappings']['url']
|
client_mappings_url = package_data['downloads']['client_mappings']['url']
|
||||||
|
|
||||||
mappings_text = requests.get(client_mappings_url).text
|
mappings_text = requests.get(client_mappings_url).text
|
||||||
|
|
||||||
with open(f'downloads/mappings-{version_id}.txt', 'w') as f:
|
with open(get_dir_location(f'downloads/mappings-{version_id}.txt'), 'w') as f:
|
||||||
f.write(mappings_text)
|
f.write(mappings_text)
|
||||||
else:
|
else:
|
||||||
with open(f'downloads/mappings-{version_id}.txt', 'r') as f:
|
with open(get_dir_location(f'downloads/mappings-{version_id}.txt'), 'r') as f:
|
||||||
mappings_text = f.read()
|
mappings_text = f.read()
|
||||||
return Mappings.parse(mappings_text)
|
return Mappings.parse(mappings_text)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import re
|
import re
|
||||||
|
import os
|
||||||
|
|
||||||
# utilities that could be used for things other than codegen
|
# utilities that could be used for things other than codegen
|
||||||
|
|
||||||
|
@ -44,3 +45,7 @@ def group_packets(packets: list[PacketIdentifier]):
|
||||||
packet_groups[key] = []
|
packet_groups[key] = []
|
||||||
packet_groups[key].append(packet.packet_id)
|
packet_groups[key].append(packet.packet_id)
|
||||||
return packet_groups
|
return packet_groups
|
||||||
|
|
||||||
|
|
||||||
|
def get_dir_location(name: str):
|
||||||
|
return os.path.join(os.path.dirname(__file__), '..', name)
|
||||||
|
|
Loading…
Add table
Reference in a new issue