diff options
Diffstat (limited to 'client')
| -rw-r--r-- | client/src/main.rs | 43 | ||||
| -rw-r--r-- | client/src/plugin_client.rs | 66 |
2 files changed, 75 insertions, 34 deletions
diff --git a/client/src/main.rs b/client/src/main.rs index 178122f..39d3dba 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -1,12 +1,9 @@ -use bevy::prelude::App; -use bevy::prelude::ResMut; -use bevy::prelude::Startup; -use bevy::tasks::block_on; +mod plugin_client; + +use crate::plugin_client::PadClientPlugin; +use bevy::prelude::{App}; use bevy::DefaultPlugins; -use bevy_tokio_tasks::{TokioTasksPlugin, TokioTasksRuntime}; -use nogamepads_lib_rs::pad_data::pad_player_info::nogamepads_player_info::PlayerInfo; -use nogamepads_lib_rs::pad_service::client::nogamepads_client::PadClient; -use std::net::{IpAddr, Ipv4Addr}; +use bevy_tokio_tasks::TokioTasksPlugin; use tokio::runtime::Builder; fn main() { @@ -16,36 +13,14 @@ fn main() { app.add_plugins(DefaultPlugins); app.add_plugins(TokioTasksPlugin { make_runtime: Box::new(|| { - Builder::new_multi_thread() - .enable_all() - .build().unwrap() + Builder::new_multi_thread().enable_all().build().unwrap() }), ..TokioTasksPlugin::default() }); - // 系统 - app.add_systems(Startup, client_init); + // 自定义插件 + app.add_plugins(PadClientPlugin); + // 启动 app.run(); } - -fn client_init( - runtime: ResMut<TokioTasksRuntime> -) { - let mut client = - PadClient::bind_addr(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))); - - let mut player_info = PlayerInfo::new(); - player_info.setup_account_info( - env!("TEST_PLAYER_ACCOUNT"), - env!("TEST_PLAYER_PASSWORD")); - player_info.set_nickname(env!("TEST_PLAYER_NICKNAME")); - player_info.set_customize_color_hsv(320, 0.5, 1.0); // PINK - - client.bind_player(player_info); // 绑定玩家 - - runtime.spawn_background_task(|context| async move { - let entry = client.get_connect_entry(); - block_on(entry); - }); -} diff --git a/client/src/plugin_client.rs b/client/src/plugin_client.rs new file mode 100644 index 0000000..2449f3a --- /dev/null +++ b/client/src/plugin_client.rs @@ -0,0 +1,66 @@ + + +// #[derive(Component)] +// struct ClientComponent { +// pad_client: Arc<PadClient>, +// } + +use bevy::prelude::{App, Plugin}; + +pub struct PadClientPlugin; +impl Plugin for PadClientPlugin { + fn build(&self, app: &mut App) { + // app.add_systems(PreStartup, client_init); + // app.add_systems(Startup, client_start); + // app.add_systems(Update, client_exit.run_if(input_just_pressed(KeyCode::Escape))); + } +} +// +// fn client_init( +// mut commands: Commands +// ) { +// // 构建玩家信息 +// let mut player_info = PlayerInfo::new(); +// player_info.setup_account_info( +// env!("TEST_PLAYER_ACCOUNT"), +// env!("TEST_PLAYER_PASSWORD")); +// player_info.set_nickname(env!("TEST_PLAYER_NICKNAME")); +// player_info.set_customize_color_hsv(320, 0.5, 1.0); // PINK +// +// // 构建客户端 +// let mut pad_client = PadClient::default(); +// pad_client.bind_player(player_info); +// pad_client.quiet(); +// +// // 将客户端放入实体 +// commands.spawn( +// ClientComponent { +// pad_client: pad_client.build(), +// } +// ); +// } +// +// fn client_start( +// client_components: Query<&mut ClientComponent>, +// runtime: ResMut<TokioTasksRuntime> +// ) { +// for client_component in client_components.iter() { +// let pad_client = Arc::clone(&client_component.pad_client); +// +// // 启动服务器 +// runtime.spawn_background_task(|_ctx|async move { +// let entry = pad_client.get_connect_entry(); +// block_on(entry); +// info!("Finished"); +// }); +// } +// } +// +// fn client_exit( +// client_components: Query<&mut ClientComponent> +// ){ +// for client_component in client_components.iter() { +// let pad_client = Arc::clone(&client_component.pad_client); +// pad_client.request_disconnect(); +// } +// }
\ No newline at end of file |
