diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-06-08 23:37:54 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-08 23:37:54 +0000 |
| commit | 601637bd48fcba826da01725430268f706181449 (patch) | |
| tree | 5b58723b931450d358d7e4387d87cc8e8b9166b2 /codegen/lib/code/version.py | |
| parent | ea7249fb77a8e07d232600081c9c3df5f698d70f (diff) | |
| parent | fb1d419a3d4207a293a1ad6001253192f1b4d12f (diff) | |
| download | azalea-drasl-601637bd48fcba826da01725430268f706181449.tar.xz | |
Merge pull request #7 from mat-1/1.19
1.19
Diffstat (limited to 'codegen/lib/code/version.py')
| -rw-r--r-- | codegen/lib/code/version.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/codegen/lib/code/version.py b/codegen/lib/code/version.py new file mode 100644 index 00000000..e131a598 --- /dev/null +++ b/codegen/lib/code/version.py @@ -0,0 +1,59 @@ +import re +import os + +README_DIR = os.path.join(os.path.dirname(__file__), '../../../README.md') +VERSION_REGEX = r'\*Currently supported Minecraft version: `(.*)`.\*' + + +def get_version_id() -> str: + with open(README_DIR, 'r') as f: + readme_text = f.read() + + version_line_match = re.search(VERSION_REGEX, readme_text) + if version_line_match: + version_id = version_line_match.group(1) + return version_id + else: + raise Exception('Could not find version id in README.md') + + +def set_version_id(version_id: str) -> None: + with open(README_DIR, 'r') as f: + readme_text = f.read() + + version_line_match = re.search(VERSION_REGEX, readme_text) + if version_line_match: + readme_text = readme_text.replace( + version_line_match.group(1), version_id) + else: + raise Exception('Could not find version id in README.md') + + with open(README_DIR, 'w') as f: + f.write(readme_text) + + +def get_protocol_version() -> str: + # azalea-protocol/src/packets/mod.rs + # pub const PROTOCOL_VERSION: u32 = 758; + with open('../azalea-protocol/src/packets/mod.rs', 'r') as f: + mod_rs = f.read().splitlines() + for line in mod_rs: + if line.strip().startswith('pub const PROTOCOL_VERSION'): + return line.strip().split(' ')[-1].strip(';') + raise Exception( + 'Could not find protocol version in azalea-protocol/src/packets/mod.rs') + + +def set_protocol_version(protocol_version: str) -> None: + with open('../azalea-protocol/src/packets/mod.rs', 'r') as f: + mod_rs = f.read().splitlines() + for i, line in enumerate(mod_rs): + if line.strip().startswith('pub const PROTOCOL_VERSION'): + mod_rs[i] = f'pub const PROTOCOL_VERSION: u32 = {protocol_version};' + break + else: + raise Exception( + 'Could not find protocol version in azalea-protocol/src/packets/mod.rs') + + with open('../azalea-protocol/src/packets/mod.rs', 'w') as f: + f.write('\n'.join(mod_rs)) |
