Skip to content

Commit 2b9f656

Browse files
committed
Remove example plugins (#465)
Just define directly in main. Doesn't make much sense to create a plugin for an example.
1 parent 0c2735f commit 2b9f656

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
@@ -25,26 +25,18 @@ fn main() {
2525
DefaultPlugins,
2626
RepliconPlugins,
2727
RepliconExampleBackendPlugins,
28-
SimpleBoxPlugin,
2928
))
29+
.replicate::<BoxPosition>()
30+
.replicate::<PlayerBox>()
31+
.add_client_trigger::<MoveBox>(Channel::Ordered)
32+
.add_observer(spawn_clients)
33+
.add_observer(despawn_clients)
34+
.add_observer(apply_movement)
35+
.add_systems(Startup, (read_cli.map(Result::unwrap), spawn_camera))
36+
.add_systems(Update, (read_input, draw_boxes))
3037
.run();
3138
}
3239

33-
struct SimpleBoxPlugin;
34-
35-
impl Plugin for SimpleBoxPlugin {
36-
fn build(&self, app: &mut App) {
37-
app.replicate::<BoxPosition>()
38-
.replicate::<PlayerBox>()
39-
.add_client_trigger::<MoveBox>(Channel::Ordered)
40-
.add_observer(spawn_clients)
41-
.add_observer(despawn_clients)
42-
.add_observer(apply_movement)
43-
.add_systems(Startup, (read_cli.map(Result::unwrap), spawn_camera))
44-
.add_systems(Update, (read_input, draw_boxes));
45-
}
46-
}
47-
4840
fn read_cli(mut commands: Commands, cli: Res<Cli>) -> Result<()> {
4941
match *cli {
5042
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
@@ -31,53 +31,45 @@ fn main() {
3131
..Default::default()
3232
}),
3333
RepliconExampleBackendPlugins,
34-
TicTacToePlugin,
3534
))
36-
.run();
37-
}
38-
39-
struct TicTacToePlugin;
40-
41-
impl Plugin for TicTacToePlugin {
42-
fn build(&self, app: &mut App) {
43-
app.init_state::<GameState>()
44-
.init_resource::<SymbolFont>()
45-
.init_resource::<TurnSymbol>()
46-
.replicate::<Symbol>()
47-
.add_client_trigger::<CellPick>(Channel::Ordered)
48-
.add_client_trigger::<MapCells>(Channel::Ordered)
49-
.add_server_trigger::<MakeLocal>(Channel::Ordered)
50-
.insert_resource(ClearColor(BACKGROUND_COLOR))
51-
.add_observer(disconnect_by_client)
52-
.add_observer(init_client)
53-
.add_observer(make_local)
54-
.add_observer(apply_pick)
55-
.add_observer(init_symbols)
56-
.add_observer(advance_turn)
57-
.add_systems(Startup, (setup_ui, read_cli.map(Result::unwrap)))
58-
.add_systems(
59-
OnEnter(GameState::InGame),
60-
(show_turn_text, show_turn_symbol),
61-
)
62-
.add_systems(OnEnter(GameState::Disconnected), show_disconnected_text)
63-
.add_systems(OnEnter(GameState::Winner), show_winner_text)
64-
.add_systems(OnEnter(GameState::Tie), show_tie_text)
65-
.add_systems(OnEnter(GameState::Disconnected), stop_networking)
66-
.add_systems(
67-
Update,
35+
.init_state::<GameState>()
36+
.init_resource::<SymbolFont>()
37+
.init_resource::<TurnSymbol>()
38+
.replicate::<Symbol>()
39+
.add_client_trigger::<CellPick>(Channel::Ordered)
40+
.add_client_trigger::<MapCells>(Channel::Ordered)
41+
.add_server_trigger::<MakeLocal>(Channel::Ordered)
42+
.insert_resource(ClearColor(BACKGROUND_COLOR))
43+
.add_observer(disconnect_by_client)
44+
.add_observer(init_client)
45+
.add_observer(make_local)
46+
.add_observer(apply_pick)
47+
.add_observer(init_symbols)
48+
.add_observer(advance_turn)
49+
.add_systems(Startup, (setup_ui, read_cli.map(Result::unwrap)))
50+
.add_systems(
51+
OnEnter(GameState::InGame),
52+
(show_turn_text, show_turn_symbol),
53+
)
54+
.add_systems(OnEnter(GameState::Disconnected), show_disconnected_text)
55+
.add_systems(OnEnter(GameState::Winner), show_winner_text)
56+
.add_systems(OnEnter(GameState::Tie), show_tie_text)
57+
.add_systems(OnEnter(GameState::Disconnected), stop_networking)
58+
.add_systems(
59+
Update,
60+
(
61+
show_connecting_text.run_if(resource_added::<ExampleClient>),
62+
show_waiting_client_text.run_if(resource_added::<ExampleServer>),
63+
client_start.run_if(client_just_connected),
6864
(
69-
show_connecting_text.run_if(resource_added::<ExampleClient>),
70-
show_waiting_client_text.run_if(resource_added::<ExampleServer>),
71-
client_start.run_if(client_just_connected),
72-
(
73-
disconnect_by_server.run_if(client_just_disconnected),
74-
update_buttons_background.run_if(local_player_turn),
75-
show_turn_symbol.run_if(resource_changed::<TurnSymbol>),
76-
)
77-
.run_if(in_state(GameState::InGame)),
78-
),
79-
);
80-
}
65+
disconnect_by_server.run_if(client_just_disconnected),
66+
update_buttons_background.run_if(local_player_turn),
67+
show_turn_symbol.run_if(resource_changed::<TurnSymbol>),
68+
)
69+
.run_if(in_state(GameState::InGame)),
70+
),
71+
)
72+
.run();
8173
}
8274

8375
const GRID_SIZE: usize = 3;

0 commit comments

Comments
 (0)