diff options
| author | 1992414357@qq.com <1992414357@qq.com> | 2025-06-13 19:20:06 +0800 |
|---|---|---|
| committer | 1992414357@qq.com <1992414357@qq.com> | 2025-06-13 19:20:06 +0800 |
| commit | a210ab86ee43dea3b4d9d0f2af5750c5a4adf096 (patch) | |
| tree | 7111a1c93d1f261d097ff0288c8b879db0830085 /client/src | |
| parent | 98dad6afa316b9a44ff76b305520339ddc44c789 (diff) | |
.
Diffstat (limited to 'client/src')
| -rw-r--r-- | client/src/bevy_plugins/mod.rs | 1 | ||||
| -rw-r--r-- | client/src/bevy_plugins/plugin_client_app.rs | 80 | ||||
| -rw-r--r-- | client/src/bin/pad.rs | 23 | ||||
| -rw-r--r-- | client/src/data/layout_data.rs | 106 | ||||
| -rw-r--r-- | client/src/data/mod.rs | 1 | ||||
| -rw-r--r-- | client/src/lib.rs | 2 |
6 files changed, 0 insertions, 213 deletions
diff --git a/client/src/bevy_plugins/mod.rs b/client/src/bevy_plugins/mod.rs deleted file mode 100644 index 0f0aa3e..0000000 --- a/client/src/bevy_plugins/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod plugin_client_app;
\ No newline at end of file diff --git a/client/src/bevy_plugins/plugin_client_app.rs b/client/src/bevy_plugins/plugin_client_app.rs deleted file mode 100644 index e7d60d2..0000000 --- a/client/src/bevy_plugins/plugin_client_app.rs +++ /dev/null @@ -1,80 +0,0 @@ -use std::sync::{Arc, Mutex}; -use bevy::app::FixedLast; -use bevy::input::common_conditions::input_just_pressed; -use bevy::log::info; -use bevy::log::tracing::Instrument; -use bevy::prelude::{App, AppExit, Commands, Component, EventReader, IntoScheduleConfigs, KeyCode, NextState, OnEnter, OnExit, Plugin, PreStartup, Query, ResMut, Startup, State, States, Update}; -use bevy_tokio_tasks::TokioTasksRuntime; -use nogamepads::entry_mutex; -use nogamepads_core::data::controller::controller_data::ControllerData; -use nogamepads_core::data::controller::controller_runtime::ControllerRuntime; -use nogamepads_core::data::player::player_data::Player; -use nogamepads_core::service::tcp_network::pad_client::pad_client_service::PadClientNetwork; -use crate::bevy_plugins::plugin_client_app::GameState::Exiting; - -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default, States)] -enum GameState { - #[default] - Waiting, - Playing, - Exiting -} - -#[derive(Component)] -struct ClientComponent { - pad_client: Arc<Mutex<ControllerRuntime>>, -} - -pub struct ClientAppPlugins; -impl Plugin for ClientAppPlugins { - fn build(&self, app: &mut App) { - app.add_systems(PreStartup, client_init); - app.add_systems(Startup, client_start); - app.add_systems(OnEnter(Exiting), client_exit); - } -} - -fn client_init( - mut commands: Commands -) { - let mut controller_data = ControllerData::default(); - controller_data.bind_player( - Player::register( - env!("TEST_PLAYER_ACCOUNT").to_string(), - env!("TEST_PLAYER_PASSWORD").to_string()) - ); - - let runtime = controller_data.runtime(); - - commands.spawn( - ClientComponent { - pad_client: Arc::clone(&runtime), - } - ); -} - -fn client_start( - client_components: Query<&mut ClientComponent>, - runtime: ResMut<TokioTasksRuntime> -) { - for client_component in client_components.iter() { - let client_runtime = Arc::clone(&client_component.pad_client); - let network = PadClientNetwork::build(client_runtime); - let entry = network.build_entry(); - - runtime.spawn_background_task(|_ctx| async move { - entry.await; - info!("Client finished.") - }); - } -} - -fn client_exit( - client_components: Query<&mut ClientComponent> -) { - for client_component in client_components.iter() { - entry_mutex!(client_component.pad_client, |guard| { - guard.close(); - }) - }; -} diff --git a/client/src/bin/pad.rs b/client/src/bin/pad.rs deleted file mode 100644 index 796dea3..0000000 --- a/client/src/bin/pad.rs +++ /dev/null @@ -1,23 +0,0 @@ -use bevy::prelude::{App}; -use bevy::DefaultPlugins; -use bevy_tokio_tasks::TokioTasksPlugin; -use tokio::runtime::Builder; -use nogamepads_client::bevy_plugins::plugin_client_app::ClientAppPlugins; - -fn main() { - let mut app = App::new(); - - // Default - app.add_plugins(DefaultPlugins); - - // Bevy Tokio Tasks - app.add_plugins(TokioTasksPlugin { - make_runtime: Box::new(|| Builder::new_multi_thread().enable_all().build().unwrap()), - ..TokioTasksPlugin::default() - }); - - // Client App Plugins - app.add_plugins(ClientAppPlugins); - - app.run(); -} diff --git a/client/src/data/layout_data.rs b/client/src/data/layout_data.rs deleted file mode 100644 index f960b41..0000000 --- a/client/src/data/layout_data.rs +++ /dev/null @@ -1,106 +0,0 @@ -use quick_xml::de::from_str; -use serde::Deserialize; - -#[derive(Debug, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct LayoutXml { - - pub preload: Preload, - - pub events: Events, - - pub layout: Layout, -} - -#[derive(Debug, Deserialize)] -struct Preload { - - #[serde(rename = "sound", default)] - pub sounds: Vec<Asset>, - - #[serde(rename = "image", default)] - pub images: Vec<Asset>, - - #[serde(rename = "text", default)] - pub texts: Vec<Asset>, -} - -#[derive(Debug, Deserialize)] -pub struct Asset { - - #[serde(rename = "@src")] - pub src: String, - - #[serde(rename = "$text")] - pub name: String, -} - -#[derive(Debug, Deserialize)] -pub struct Events { - - #[serde(rename = "lua_setup", default)] - pub lua_setup: Option<String>, - - #[serde(rename = "lua_exit", default)] - pub lua_exit: Option<String>, - - #[serde(rename = "lua", default)] - pub lua_scripts: Vec<Lua>, -} - -#[derive(Debug, Deserialize)] -pub struct Lua { - - #[serde(rename = "@id")] - pub id: String, - - #[serde(rename = "@src", default)] - pub src: Option<String>, - - #[serde(rename = "$text", default)] - pub content: Option<String>, -} - -#[derive(Debug, Deserialize)] -pub struct Layout { - - #[serde(rename = "box_layout")] - pub boxes: Vec<BoxLayout>, -} - -#[derive(Debug, Deserialize)] -pub struct BoxLayout { - - pub button_bind: ButtonBind, - - pub position: String, - - pub pivot: String, - - pub size: String, - - pub name: String, -} - -#[derive(Debug, Deserialize)] -pub struct ButtonBind { - - #[serde(rename = "on_click")] - pub on_click: OnClick, -} - -#[derive(Debug, Deserialize)] -pub struct OnClick { - - #[serde(rename = "@event")] - pub event: String, -} - -impl LayoutXml { - pub fn parse_xml(xml: String) -> Result<LayoutXml, quick_xml::DeError> { - let wrapped = format!("<root>{}</root>", xml); - - let layout_xml: LayoutXml = from_str(&wrapped)?; - Ok(layout_xml) - } -}
\ No newline at end of file diff --git a/client/src/data/mod.rs b/client/src/data/mod.rs deleted file mode 100644 index 0e0a42e..0000000 --- a/client/src/data/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod layout_data;
\ No newline at end of file diff --git a/client/src/lib.rs b/client/src/lib.rs deleted file mode 100644 index bcfa9d8..0000000 --- a/client/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod bevy_plugins; -pub mod data;
\ No newline at end of file |
