Last active
March 23, 2021 15:10
-
-
Save jakobhellermann/1ed6b0d10203c86de40de695c6e82a3e to your computer and use it in GitHub Desktop.
Does the easily automatable part of updating bevy 0.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $(git diff --stat) != '' ]]; then | |
echo 'git has uncommit changes, please commit as this tool can break stuff' | |
exit | |
fi | |
echo "warning: this code isn't very well tested" | |
read -p "Press enter to continue: " | |
files=$(find . -name "*.rs") | |
for file in $files; do | |
sed -i 's/\(\w\+\): &mut Commands/mut \1: Commands/' "$file" | |
sed -i 's/&mut Commands/Commands/' "$file" | |
sed -i 's/\.spawn(/.spawn_bundle(/' "$file" | |
sed -i 's/\.with(/.insert(/' "$file" | |
sed -i 's/\.with_bundle(/.insert_bundle(/' "$file" | |
sed -i 's/FromResources/FromWorld/' "$file" | |
sed -i 's/from_resources(resources: &Resources)/from_world(world: \&mut World)/' "$file" | |
sed -i 's/\bresources\.get/world.get_resource/' "$file" | |
sed -i 's/\bresources\.get_mut/world.get_resource_mut/' "$file" | |
sed -i 's/add_resource/insert_resource/' "$file" | |
sed -i 's/Camera3dBundle/PerspectiveCameraBundle/' "$file" | |
sed -i 's/Camera2dBundle::default()/OrthographicCameraBundle::new_2d()/' "$file" | |
sed -i 's/CameraUiBundle::default()/UiCameraBundle::default()/' "$file" | |
sed -i 's/transform.forward()/transform.local_z()/' "$file" | |
sed -i 's/ResMut<Events<\(\w\+\)>>/EventWriter<\1>/' "$file" | |
# glam | |
sed -i 's/Vec3::unit_x()/Vec3::X/' "$file" | |
sed -i 's/Vec3::unit_y()/Vec3::Y/' "$file" | |
sed -i 's/Vec3::unit_z()/Vec3::Z/' "$file" | |
sed -i 's/Vec3::zero()/Vec3::ZERO/' "$file" | |
sed -i 's/Vec3::one()/Vec3::ONE/' "$file" | |
sed -i 's/Vec2::unit_x()/Vec2::X/' "$file" | |
sed -i 's/Vec2::unit_y()/Vec2::Y/' "$file" | |
sed -i 's/Vec2::zero()/Vec2::ZERO/' "$file" | |
sed -i 's/Vec2::one()/Vec2::ONE/' "$file" | |
sed -i 's/.transform_point3()/.project_point3()/' "$file" | |
done | |
echo 'Done 🎉' | |
echo '' | |
echo '# Some more tips' | |
echo 'If you get errors about not being able to borrow `world` mutable, try `let world = world.cell();`' | |
echo 'Chains of `commands.spawn(..).spawn()` will have to be manually changed to `commands.spawn(..); commands.spawn(..);`' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Suggestion:
Also, for any macos users out there, I'd recommend just doing
brew install gnu-sed
and replacing all instances ofsed
in this script withgsed
. I don't think there's actually a portable way to use sed to do inline replacements without generating a bunch of backup file garbage.