Skip to content

Commit ef6d9f5

Browse files
authored
Remove example plugins (#465)
Just define directly in main. Doesn't make much sense to create a plugin for an example.
1 parent 998fd6b commit ef6d9f5

2 files changed

Lines changed: 45 additions & 61 deletions

File tree

bevy_replicon_example_backend/examples/simple_box.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,18 @@ fn main() {
2828
DefaultPlugins,
2929
RepliconPlugins,
3030
RepliconExampleBackendPlugins,
31-
SimpleBoxPlugin,
3231
))
32+
.replicate::<BoxPosition>()
33+
.replicate::<PlayerBox>()
34+
.add_client_trigger::<MoveBox>(Channel::Ordered)
35+
.add_observer(spawn_clients)
36+
.add_observer(despawn_clients)
37+
.add_observer(apply_movement)
38+
.add_systems(Startup, (read_cli.map(Result::unwrap), spawn_camera))
39+
.add_systems(Update, (read_input, draw_boxes))
3340
.run();
3441
}
3542

36-
struct SimpleBoxPlugin;
37-
38-
impl Plugin for SimpleBoxPlugin {
39-
fn build(&self, app: &mut App) {
40-
app.replicate::<BoxPosition>()
41-
.replicate::<PlayerBox>()
42-
.add_client_trigger::<MoveBox>(Channel::Ordered)
43-
.add_observer(spawn_clients)
44-
.add_observer(despawn_clients)
45-
.add_observer(apply_movement)
46-
.add_systems(Startup, (read_cli.map(Result::unwrap), spawn_camera))
47-
.add_systems(Update, (read_input, draw_boxes));
48-
}
49-
}
50-
5143
fn read_cli(mut commands: Commands, cli: Res<Cli>) -> io::Result<()> {
5244
match *cli {
5345
Cli::SinglePlayer => {

bevy_replicon_example_backend/examples/tic_tac_toe.rs

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,53 +30,45 @@ fn main() {
3030
..Default::default()
3131
}),
3232
RepliconExampleBackendPlugins,
33-
TicTacToePlugin,
3433
))
35-
.run();
36-
}
37-
38-
struct TicTacToePlugin;
39-
40-
impl Plugin for TicTacToePlugin {
41-
fn build(&self, app: &mut App) {
42-
app.init_state::<GameState>()
43-
.init_resource::<SymbolFont>()
44-
.init_resource::<TurnSymbol>()
45-
.replicate::<Symbol>()
46-
.add_client_trigger::<CellPick>(Channel::Ordered)
47-
.add_client_trigger::<MapCells>(Channel::Ordered)
48-
.add_server_trigger::<MakeLocal>(Channel::Ordered)
49-
.insert_resource(ClearColor(BACKGROUND_COLOR))
50-
.add_observer(disconnect_by_client)
51-
.add_observer(init_client)
52-
.add_observer(make_local)
53-
.add_observer(apply_pick)
54-
.add_observer(init_symbols)
55-
.add_observer(advance_turn)
56-
.add_systems(Startup, (setup_ui, read_cli.map(Result::unwrap)))
57-
.add_systems(
58-
OnEnter(GameState::InGame),
59-
(show_turn_text, show_turn_symbol),
60-
)
61-
.add_systems(OnEnter(GameState::Disconnected), show_disconnected_text)
62-
.add_systems(OnEnter(GameState::Winner), show_winner_text)
63-
.add_systems(OnEnter(GameState::Tie), show_tie_text)
64-
.add_systems(OnEnter(GameState::Disconnected), stop_networking)
65-
.add_systems(
66-
Update,
34+
.init_state::<GameState>()
35+
.init_resource::<SymbolFont>()
36+
.init_resource::<TurnSymbol>()
37+
.replicate::<Symbol>()
38+
.add_client_trigger::<CellPick>(Channel::Ordered)
39+
.add_client_trigger::<MapCells>(Channel::Ordered)
40+
.add_server_trigger::<MakeLocal>(Channel::Ordered)
41+
.insert_resource(ClearColor(BACKGROUND_COLOR))
42+
.add_observer(disconnect_by_client)
43+
.add_observer(init_client)
44+
.add_observer(make_local)
45+
.add_observer(apply_pick)
46+
.add_observer(init_symbols)
47+
.add_observer(advance_turn)
48+
.add_systems(Startup, (setup_ui, read_cli.map(Result::unwrap)))
49+
.add_systems(
50+
OnEnter(GameState::InGame),
51+
(show_turn_text, show_turn_symbol),
52+
)
53+
.add_systems(OnEnter(GameState::Disconnected), show_disconnected_text)
54+
.add_systems(OnEnter(GameState::Winner), show_winner_text)
55+
.add_systems(OnEnter(GameState::Tie), show_tie_text)
56+
.add_systems(OnEnter(GameState::Disconnected), stop_networking)
57+
.add_systems(
58+
Update,
59+
(
60+
show_connecting_text.run_if(resource_added::<ExampleClient>),
61+
show_waiting_client_text.run_if(resource_added::<ExampleServer>),
62+
client_start.run_if(client_just_connected),
6763
(
68-
show_connecting_text.run_if(resource_added::<ExampleClient>),
69-
show_waiting_client_text.run_if(resource_added::<ExampleServer>),
70-
client_start.run_if(client_just_connected),
71-
(
72-
disconnect_by_server.run_if(client_just_disconnected),
73-
update_buttons_background.run_if(local_player_turn),
74-
show_turn_symbol.run_if(resource_changed::<TurnSymbol>),
75-
)
76-
.run_if(in_state(GameState::InGame)),
77-
),
78-
);
79-
}
64+
disconnect_by_server.run_if(client_just_disconnected),
65+
update_buttons_background.run_if(local_player_turn),
66+
show_turn_symbol.run_if(resource_changed::<TurnSymbol>),
67+
)
68+
.run_if(in_state(GameState::InGame)),
69+
),
70+
)
71+
.run();
8072
}
8173

8274
const GRID_SIZE: usize = 3;

0 commit comments

Comments
 (0)