diff options
| author | mat <github@matdoes.dev> | 2022-05-25 22:59:05 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-05-25 22:59:05 -0500 |
| commit | 3fbbb61c30f0833dd1e07802419ee91ef6cad8e3 (patch) | |
| tree | 3bec65f06acc301d1f84fc02d6ad87f05d00e1fb /codegen/lib/code | |
| parent | 64eaa63e2368a2d26c5f8d843bd1642539670c70 (diff) | |
| download | azalea-drasl-3fbbb61c30f0833dd1e07802419ee91ef6cad8e3.tar.xz | |
set version ids
Diffstat (limited to 'codegen/lib/code')
| -rw-r--r-- | codegen/lib/code/version.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/codegen/lib/code/version.py b/codegen/lib/code/version.py index b7e5cbcc..77911f16 100644 --- a/codegen/lib/code/version.py +++ b/codegen/lib/code/version.py @@ -29,3 +29,26 @@ def set_version_id(version_id: str) -> None: 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))
\ No newline at end of file |
