aboutsummaryrefslogtreecommitdiff
path: root/codegen/lib/code/version.py
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2024-11-27 19:31:40 -0600
committerGitHub <noreply@github.com>2024-11-27 19:31:40 -0600
commit08958c2278b15ebeac8a964f392ebb792e479b61 (patch)
tree4ae3664cea38d7fd1a8f1e95ed06fac04ffe519e /codegen/lib/code/version.py
parent139d77d3c2b0922fba5e9d4fa2bd9819d78bd773 (diff)
downloadazalea-drasl-08958c2278b15ebeac8a964f392ebb792e479b61.tar.xz
Refactor azalea-protocol (#190)
* start updating to 1.21.4 * fix block codegen and stop using block data from burger * rename packet related modules and structs to be simpler * ItemSlot -> ItemStack for more consistency with mojmap * .get() -> .into_packet() * simplify declare_state_packets by removing packet ids * rename read_from and write_into to azalea_read and azalea_write * rename McBufReadable and McBufWritable to AzaleaRead and AzaleaWrite * McBuf -> AzBuf * remove most uses of into_variant * update codegen and use resourcelocation names for packets * implement #[limit(i)] attribute for AzBuf derive macro * fixes for 1.21.4 * fix examples * update some physics code and fix ChatType * remove unused imports in codegen * re-add some things to migrate.py and update +mc version numbers automatically * downgrade to 1.21.3 lol
Diffstat (limited to 'codegen/lib/code/version.py')
-rwxr-xr-xcodegen/lib/code/version.py38
1 files changed, 36 insertions, 2 deletions
diff --git a/codegen/lib/code/version.py b/codegen/lib/code/version.py
index c2053da3..d4a37232 100755
--- a/codegen/lib/code/version.py
+++ b/codegen/lib/code/version.py
@@ -31,7 +31,28 @@ def set_version_id(version_id: str) -> None:
with open(README_DIR, 'wb') as f:
f.write(readme_text.encode())
-
+
+ # update the version in all Cargo.toml files
+ # version = "0.10.3+mc1.21.1"
+ for root, _, files in os.walk(get_dir_location('..')):
+ for file in files:
+ if file == 'Cargo.toml':
+ with open(os.path.join(root, file), 'r') as f:
+ cargo_toml = f.read().splitlines()
+ for i, line in enumerate(cargo_toml):
+ if line.strip().startswith('version = '):
+ replaced = re.sub(r'\+mc[^"]+?"', f'+mc{version_id}"', line)
+ cargo_toml[i] = replaced
+ break
+ else:
+ # didn't have a version line
+ continue
+ if cargo_toml[-1] != '':
+ # make sure there's always a trailing newline
+ cargo_toml.append('')
+ with open(os.path.join(root, file), 'w') as f:
+ f.write('\n'.join(cargo_toml))
+ print('Updated version in README.md and Cargo.toml files')
def get_protocol_version() -> str:
# azalea-protocol/src/packets/mod.rs
@@ -49,7 +70,7 @@ def set_protocol_version(protocol_version: str) -> None:
with open(get_dir_location('../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'):
+ if line.strip().startswith('pub const PROTOCOL_VERSION:'):
mod_rs[i] = f'pub const PROTOCOL_VERSION: i32 = {protocol_version};'
break
else:
@@ -58,3 +79,16 @@ def set_protocol_version(protocol_version: str) -> None:
with open(get_dir_location('../azalea-protocol/src/packets/mod.rs'), 'w') as f:
f.write('\n'.join(mod_rs))
+def set_version_name(version_name: str) -> None:
+ with open(get_dir_location('../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 VERSION_NAME:'):
+ mod_rs[i] = f'pub const VERSION_NAME: &str = "{version_name}";'
+ break
+ else:
+ raise Exception(
+ 'Could not find version name in azalea-protocol/src/packets/mod.rs')
+
+ with open(get_dir_location('../azalea-protocol/src/packets/mod.rs'), 'w') as f:
+ f.write('\n'.join(mod_rs))