Skip to content

Commit

Permalink
feat: online rematch
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeder committed Jun 23, 2023
1 parent f92d24b commit c6232f2
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "turtle_time"
version = "0.8.0"
version = "0.9.0"
publish = false
authors = ["Mike Eder <[email protected]>"]
edition = "2021"
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ Try it out here: https://mikeder.net/turtletime
2. Scoreboard and Leaderboard for game stats, pickups, wins, loses, etc.
3. More game modes, COOP survival, PVE.
4. Controller support.


2 changes: 1 addition & 1 deletion src/menu/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn create_matchbox_socket(mut commands: Commands, connect_data: Res<ConnectD
commands.remove_resource::<MatchboxSocket<SingleChannel>>();
// insert new socket resource for next session
commands.insert_resource(MatchboxSocket::new_reliable(room_url));
commands.remove_resource::<ConnectData>();
// commands.remove_resource::<ConnectData>();
}

pub fn lobby_system(
Expand Down
5 changes: 4 additions & 1 deletion src/menu/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::connect::LocalHandle;
use super::connect::{ConnectData, LocalHandle};
use super::online::PlayerCount;
use super::plugin::{BUTTON_TEXT, HOVERED_BUTTON, NORMAL_BUTTON, PRESSED_BUTTON, VERSION};
use crate::loading::{FontAssets, TextureAssets};
Expand Down Expand Up @@ -244,6 +244,9 @@ pub fn btn_listeners(
app_state.set(AppState::MenuOnline);
}
MainMenuBtn::LocalMatch => {
// remove any lingering online connect data
commands.remove_resource::<ConnectData>();

create_synctest_session(&mut commands, player_count.0);
app_state.set(AppState::RoundLocal);
game_state.set(GameState::Playing);
Expand Down
58 changes: 46 additions & 12 deletions src/menu/win.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::connect::ConnectData;
use super::plugin::{BUTTON_TEXT, HOVERED_BUTTON, NORMAL_BUTTON, PRESSED_BUTTON};
use crate::loading::FontAssets;
use crate::AppState;
Expand All @@ -9,14 +10,25 @@ pub struct WinUI;
#[derive(Component)]
pub enum MenuWinBtn {
Back,
Rematch,
}

#[derive(Resource)]
pub struct MatchData {
pub result: String,
}

pub fn setup_ui(mut commands: Commands, match_data: Res<MatchData>, font_assets: Res<FontAssets>) {
pub fn setup_ui(
mut commands: Commands,
match_data: Res<MatchData>,
font_assets: Res<FontAssets>,
connect_data: Option<Res<ConnectData>>,
) {
let mut rematch_vis = Visibility::Hidden;
if connect_data.is_some() {
rematch_vis = Visibility::Visible;
}

// ui camera
commands.spawn(Camera2dBundle::default()).insert(WinUI);

Expand Down Expand Up @@ -54,6 +66,36 @@ pub fn setup_ui(mut commands: Commands, match_data: Res<MatchData>, font_assets:
),
..Default::default()
});
// rematch button
parent
.spawn(ButtonBundle {
style: Style {
size: Size::new(Val::Px(250.0), Val::Px(65.0)),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
margin: UiRect::all(Val::Px(16.)),
padding: UiRect::all(Val::Px(16.)),

..Default::default()
},
visibility: rematch_vis,
background_color: NORMAL_BUTTON.into(),
..Default::default()
})
.with_children(|parent| {
parent.spawn(TextBundle {
text: Text::from_section(
"Rematch",
TextStyle {
font: font_assets.fira_sans.clone(),
font_size: 40.0,
color: BUTTON_TEXT,
},
),
..Default::default()
});
})
.insert(MenuWinBtn::Rematch);
// back to menu button
parent
.spawn(ButtonBundle {
Expand Down Expand Up @@ -82,17 +124,6 @@ pub fn setup_ui(mut commands: Commands, match_data: Res<MatchData>, font_assets:
});
})
.insert(MenuWinBtn::Back);
parent.spawn(TextBundle {
text: Text::from_section(
"This state is bugged...\nIf the button doesn't work, refresh the page.",
TextStyle {
font: font_assets.fira_sans.clone(),
font_size: 20.0,
color: Color::BLACK,
},
),
..Default::default()
});
})
.insert(WinUI);

Expand Down Expand Up @@ -130,6 +161,9 @@ pub fn btn_listeners(
MenuWinBtn::Back => {
app_state.set(AppState::MenuMain);
}
MenuWinBtn::Rematch => {
app_state.set(AppState::MenuConnect);
}
}
}
}
Expand Down

0 comments on commit c6232f2

Please sign in to comment.