Skip to content

Commit

Permalink
feat: Upgrade both package.json and migrate pong from 14 to 15
Browse files Browse the repository at this point in the history
  • Loading branch information
batleforc committed Jan 21, 2025
1 parent c718706 commit 2a30c4c
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 213 deletions.
2 changes: 1 addition & 1 deletion apps/pong/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"


[dependencies]
bevy = "0.14.2"
bevy = "0.15.1"


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
12 changes: 2 additions & 10 deletions apps/pong/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use bevy::{
app::{App, Startup, Update},
prelude::{
default, Camera, Camera2dBundle, Commands, IntoSystemConfigs, PluginGroup, Query, Transform,
},
prelude::{default, Camera2d, Commands, IntoSystemConfigs, PluginGroup, Query, Transform},
window::{Window, WindowPlugin},
DefaultPlugins,
};
Expand All @@ -18,13 +16,7 @@ use pong::model::{

fn add_cam(mut commands: Commands) {
println!("Spawning Camera");
commands.spawn(Camera2dBundle {
camera: Camera {
hdr: true,
..default()
},
..default()
});
commands.spawn(Camera2d);
}

fn project_positions(mut positionables: Query<(&mut Transform, &Position)>) {
Expand Down
11 changes: 4 additions & 7 deletions apps/pong/src/model/ball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use bevy::{
asset::Assets,
color::Color,
math::Vec2,
prelude::{default, Bundle, Circle, Commands, Component, Mesh, Query, ResMut, With},
sprite::{ColorMaterial, MaterialMesh2dBundle},
prelude::{Bundle, Circle, Commands, Component, Mesh, Mesh2d, Query, ResMut, With},
sprite::{ColorMaterial, MeshMaterial2d},
};

use super::{Position, Shape, Velocity};
Expand Down Expand Up @@ -47,11 +47,8 @@ pub fn spawn_ball(

commands.spawn((
BallBundle::new(1., 1.),
MaterialMesh2dBundle {
mesh: mesh_handle.into(),
material: material_handle,
..default()
},
Mesh2d(mesh_handle.clone()),
MeshMaterial2d(material_handle.clone()),
));
}

Expand Down
18 changes: 6 additions & 12 deletions apps/pong/src/model/gutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use bevy::{
asset::Assets,
color::Color,
math::Vec2,
prelude::{default, Bundle, Commands, Component, Mesh, Query, Rectangle, ResMut},
sprite::{ColorMaterial, MaterialMesh2dBundle},
prelude::{Bundle, Commands, Component, Mesh, Mesh2d, Query, Rectangle, ResMut},
sprite::{ColorMaterial, MeshMaterial2d},
window::Window,
};

Expand Down Expand Up @@ -55,20 +55,14 @@ pub fn spawn_gutters(

commands.spawn((
top_gutter,
MaterialMesh2dBundle {
mesh: mesh_handle.clone().into(),
material: material_handle.clone(),
..default()
},
Mesh2d(mesh_handle.clone()),
MeshMaterial2d(material_handle.clone()),
));

commands.spawn((
bottom_gutter,
MaterialMesh2dBundle {
mesh: mesh_handle.into(),
material: material_handle.clone(),
..default()
},
Mesh2d(mesh_handle.clone()),
MeshMaterial2d(material_handle.clone()),
));
}
}
104 changes: 45 additions & 59 deletions apps/pong/src/model/scoreboard.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use bevy::{
color::Color,
prelude::{default, Commands, Component, DetectChanges, Query, Res, TextBundle, With, Without},
text::{JustifyText, Text, TextStyle},
ui::{PositionType, Style, Val},
prelude::{default, Commands, Component, DetectChanges, Query, Res, Text, With, Without},
text::{JustifyText, TextColor, TextFont, TextLayout},
ui::{Node, PositionType, Val},
};

use super::score::Score;
Expand All @@ -20,93 +20,79 @@ pub fn update_scoreboard(
) {
if score.is_changed() {
if let Ok(mut player_score) = player_score.get_single_mut() {
player_score.sections[0].value = score.player1.to_string();
player_score.0 = score.player1.to_string();
}

if let Ok(mut ai_score) = player2_score.get_single_mut() {
ai_score.sections[0].value = score.player2.to_string();
ai_score.0 = score.player2.to_string();
}
}
}

pub fn spawn_scoreboard(mut commands: Commands) {
commands.spawn((
// Create a TextBundle that has a Text with a
// single section.
TextBundle::from_section(
// Accepts a `String` or any type that converts
// into a `String`, such as `&str`
"0",
TextStyle {
font_size: 72.0,
color: Color::WHITE,
..default()
},
) // Set the alignment of the Text
.with_text_justify(JustifyText::Center)
// Set the style of the TextBundle itself.
.with_style(Style {
Text::new("0"),
TextLayout::new_with_justify(JustifyText::Center),
TextColor(Color::WHITE),
TextFont {
font_size: 72.0,
..default()
},
Node {
position_type: PositionType::Absolute,
top: Val::Px(5.0),
right: Val::Px(15.0),
..default()
}),
},
Player1Scoreboard,
));

commands.spawn(
TextBundle::from_section(
"Z/S - Player 1",
TextStyle {
font_size: 31.0,
color: Color::WHITE,
..default()
},
)
.with_text_justify(JustifyText::Center)
.with_style(Style {
commands.spawn((
Text::new("Z/S - Player 1"),
TextLayout::new_with_justify(JustifyText::Center),
TextColor(Color::WHITE),
TextFont {
font_size: 31.0,
..default()
},
Node {
position_type: PositionType::Absolute,
top: Val::Px(75.0),
left: Val::Px(15.0),
..default()
}),
);
},
));

commands.spawn(
TextBundle::from_section(
"UP/DOWN - Player 2",
TextStyle {
font_size: 31.0,
color: Color::WHITE,
..default()
},
)
.with_text_justify(JustifyText::Center)
.with_style(Style {
commands.spawn((
Text::new("UP/DOWN - Player 2"),
TextLayout::new_with_justify(JustifyText::Center),
TextColor(Color::WHITE),
TextFont {
font_size: 31.0,
..default()
},
Node {
position_type: PositionType::Absolute,
top: Val::Px(75.0),
right: Val::Px(15.0),
..default()
}),
);
},
));

// Then we do it again for the AI score
commands.spawn((
TextBundle::from_section(
"0",
TextStyle {
font_size: 72.0,
color: Color::WHITE,
..default()
},
)
.with_text_justify(JustifyText::Center)
.with_style(Style {
Text::new("0"),
TextLayout::new_with_justify(JustifyText::Center),
TextColor(Color::WHITE),
TextFont {
font_size: 72.0,
..default()
},
Node {
position_type: PositionType::Absolute,
top: Val::Px(5.0),
left: Val::Px(15.0),
..default()
}),
},
Player2Scoreboard,
));
}
20 changes: 8 additions & 12 deletions apps/pong/src/model/user_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use bevy::{
color::Color,
input::ButtonInput,
math::Vec2,
prelude::{Bundle, Commands, Component, KeyCode, Mesh, Query, Rectangle, Res, ResMut, With},
sprite::{ColorMaterial, MaterialMesh2dBundle},
prelude::{
Bundle, Commands, Component, KeyCode, Mesh, Mesh2d, Query, Rectangle, Res, ResMut, With,
},
sprite::{ColorMaterial, MeshMaterial2d},
window::Window,
};

Expand Down Expand Up @@ -57,20 +59,14 @@ pub fn spawn_user_row(

commands.spawn((
UserRowBundle::new(Scorer::Player1, right_paddle_x, 0.),
MaterialMesh2dBundle {
mesh: mesh_handle.clone().into(),
material: materials.add(ColorMaterial::from(Color::srgb(0., 1., 0.))),
..Default::default()
},
Mesh2d(mesh_handle.clone()),
MeshMaterial2d(materials.add(ColorMaterial::from(Color::srgb(0., 1., 0.)))),
));

commands.spawn((
UserRowBundle::new(Scorer::Player2, left_paddle_x, 0.),
MaterialMesh2dBundle {
mesh: mesh_handle.into(),
material: materials.add(ColorMaterial::from(Color::srgb(0., 0., 1.))),
..Default::default()
},
Mesh2d(mesh_handle.clone()),
MeshMaterial2d(materials.add(ColorMaterial::from(Color::srgb(0., 0., 1.)))),
));
}
}
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@highlightjs/vue-plugin": "^2.1.0",
"@primevue/themes": "^4.2.5",
"highlight.js": "^11.10.0",
"pinia": "^2.3.0",
"pinia": "^2.3.1",
"primevue": "^4.2.5",
"tslib": "^2.7.0",
"vue": "^3.5.8",
Expand All @@ -42,16 +42,16 @@
"@primevue/auto-import-resolver": "^4.0.4",
"@swc-node/register": "^1.10.9",
"@swc/cli": "~0.5.0",
"@swc/core": "~1.7.22",
"@swc/core": "~1.10.8",
"@swc/helpers": "~0.5.11",
"@types/jest": "29.5.14",
"@types/node": "22.9.0",
"@types/node": "^22.10.7",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
"@vitejs/plugin-vue": "^5.2.1",
"@vitest/coverage-v8": "^2.1.1",
"@vitest/ui": "^2.1.1",
"@vue/eslint-config-prettier": "9.0.0",
"@vue/eslint-config-prettier": "10.2.0",
"@vue/eslint-config-typescript": "^13.0.0",
"@vue/test-utils": "^2.4.1",
"autoprefixer": "^10.4.20",
Expand All @@ -72,7 +72,7 @@
"ts-jest": "^29.1.0",
"ts-node": "^10.9.2",
"typescript": "5.7.3",
"unplugin-vue-components": "^0.27.3",
"unplugin-vue-components": "^0.28.0",
"vite": "^5.4.6",
"vitest": "^2.1.1",
"vue-tsc": "^2.0.29"
Expand Down
Loading

0 comments on commit 2a30c4c

Please sign in to comment.