diff options
| author | 1992414357@qq.com <1992414357@qq.com> | 2025-06-13 16:25:22 +0800 |
|---|---|---|
| committer | 1992414357@qq.com <1992414357@qq.com> | 2025-06-13 16:25:22 +0800 |
| commit | 98dad6afa316b9a44ff76b305520339ddc44c789 (patch) | |
| tree | 9a6d0b566b23f0bab270b68e4766a60349abf18b | |
| parent | 9e48af01ae56fe813869ada24de291ab98b361e2 (diff) | |
.
| -rw-r--r-- | .idea/runConfigurations/Run_Bevy_Client.xml | 2 | ||||
| -rw-r--r-- | Cargo.lock | 12 | ||||
| -rw-r--r-- | Config_Export.toml | 18 | ||||
| -rw-r--r-- | LICENSE-THIRD-PARTY | 2 | ||||
| -rw-r--r-- | client/Cargo.toml | 2 | ||||
| -rw-r--r-- | client/src/bevy_plugins/mod.rs | 1 | ||||
| -rw-r--r-- | client/src/bevy_plugins/plugin_client_app.rs (renamed from client/src/plugin_client.rs) | 25 | ||||
| -rw-r--r-- | client/src/bin/pad.rs (renamed from client/src/main.rs) | 14 | ||||
| -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 | ||||
| -rw-r--r-- | export/.gitignore | 3 | ||||
| -rw-r--r-- | export/dev/LICENSE-THIRD-PARTY | 2 | ||||
| -rw-r--r-- | export/dev/bin/padc.exe | bin | 6470144 -> 6470144 bytes |
14 files changed, 171 insertions, 19 deletions
diff --git a/.idea/runConfigurations/Run_Bevy_Client.xml b/.idea/runConfigurations/Run_Bevy_Client.xml index 3374e23..24269f8 100644 --- a/.idea/runConfigurations/Run_Bevy_Client.xml +++ b/.idea/runConfigurations/Run_Bevy_Client.xml @@ -1,7 +1,7 @@ <component name="ProjectRunConfigurationManager"> <configuration default="false" name="Run Bevy Client" type="CargoCommandRunConfiguration" factoryName="Cargo Command" folderName="Run" focusToolWindowBeforeRun="true"> <option name="buildProfileId" value="dev" /> - <option name="command" value="run --package nogamepads-client --bin nogamepads-client" /> + <option name="command" value="run --package nogamepads-client --bin client_app" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" /> <envs /> <option name="emulateTerminal" value="true" /> @@ -3211,6 +3211,8 @@ dependencies = [ "bevy-tokio-tasks", "nogamepads", "nogamepads-core", + "quick-xml", + "serde", "tokio", ] @@ -3875,6 +3877,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afbdc74edc00b6f6a218ca6a5364d6226a259d4b8ea1af4a0ea063f27e179f4d" [[package]] +name = "quick-xml" +version = "0.37.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb" +dependencies = [ + "memchr", + "serde", +] + +[[package]] name = "quote" version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Config_Export.toml b/Config_Export.toml index d1d0491..ba1e03a 100644 --- a/Config_Export.toml +++ b/Config_Export.toml @@ -1,9 +1,21 @@ -#./ +# No Gamepads Export Configure +# This document details release file information for executing cargo export or cargo dev. + +# Items defined in [release.root] +# It will search starting from the project directory and copy to the specified location in the target directory. [release.root] + +# License files, third-party licenses license = { raw = "./", target = "./", files = ["LICENSE-LGPL-2", "LICENSE-THIRD-PARTY"] } + +# Powershell auto-completion scripts powershell_complete = { raw = "./.cargo/resources/scripts/", target = "./bin/completeion", files = ["install_completion_powershell.ps1"] } -#./.cargo/shared/target/export/deps +# Items defined in [release.deps] +# It will search starting from the build directory and copy to the specified location in the target directory. [release.deps] -padc = { raw = "./", target = "./bin", files = ["padc.exe"] } +# Windows executables +win_exes = { raw = "./", target = "./bin", files = [ + "padc.exe", "pad.exe" +] }
\ No newline at end of file diff --git a/LICENSE-THIRD-PARTY b/LICENSE-THIRD-PARTY index 47b501f..6d81b7e 100644 --- a/LICENSE-THIRD-PARTY +++ b/LICENSE-THIRD-PARTY @@ -7,6 +7,7 @@ This project uses third-party components with the following licenses: ----------------------------------------------------------------------- * bincode * crossterm +* quick-xml * tokio * bevy (original license: Apache-2.0 OR MIT) * chrono (original license: Apache-2.0 OR MIT) @@ -38,6 +39,7 @@ Copyright (c) 2013-2014 The Rust Project Developers. * env_logger - Copyright (c) The env_logger Project Developer(s). * hex - Copyright (c) 2015-2020 The rust-hex Developers. * log - Copyright (c) The log Project Developer(s). +* quick-xml - Copyright (c) 2016 Johann Tuffe. * rand - Copyright 2018 Developers of the Rand project. * serde - Copyright (c) The serde Project Developer(s). * serde_yaml - Copyright (c) The serde_yaml Project Developer(s). diff --git a/client/Cargo.toml b/client/Cargo.toml index ba6cb01..665e335 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -7,6 +7,8 @@ version.workspace = true nogamepads = { path = "../../NoGamepads" } nogamepads-core = { path = "../core" } +serde = { version = "1.0.219", features = ["derive"] } +quick-xml = { version = "0.37.5", features = ["serde", "serialize"] } bevy-tokio-tasks = "0.16.0" tokio = { version = "1.45.0", features = ["full"] } bevy = "0.16.0" diff --git a/client/src/bevy_plugins/mod.rs b/client/src/bevy_plugins/mod.rs new file mode 100644 index 0000000..0f0aa3e --- /dev/null +++ b/client/src/bevy_plugins/mod.rs @@ -0,0 +1 @@ +pub mod plugin_client_app;
\ No newline at end of file diff --git a/client/src/plugin_client.rs b/client/src/bevy_plugins/plugin_client_app.rs index d998f75..e7d60d2 100644 --- a/client/src/plugin_client.rs +++ b/client/src/bevy_plugins/plugin_client_app.rs @@ -1,25 +1,36 @@ use std::sync::{Arc, Mutex}; +use bevy::app::FixedLast; use bevy::input::common_conditions::input_just_pressed; use bevy::log::info; -use bevy::prelude::{App, Commands, Component, IntoScheduleConfigs, KeyCode, Plugin, PreStartup, Query, ResMut, Startup, Update}; +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 PadClientPlugin; -impl Plugin for PadClientPlugin { +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(Update, client_exit.run_if(input_just_pressed(KeyCode::Escape))); + app.add_systems(OnEnter(Exiting), client_exit); } } @@ -60,10 +71,10 @@ fn client_start( fn client_exit( client_components: Query<&mut ClientComponent> -){ +) { for client_component in client_components.iter() { entry_mutex!(client_component.pad_client, |guard| { guard.close(); }) - } -}
\ No newline at end of file + }; +} diff --git a/client/src/main.rs b/client/src/bin/pad.rs index 31fb406..796dea3 100644 --- a/client/src/main.rs +++ b/client/src/bin/pad.rs @@ -1,23 +1,23 @@ -mod plugin_client; - -use crate::plugin_client::PadClientPlugin; 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() - }), + make_runtime: Box::new(|| Builder::new_multi_thread().enable_all().build().unwrap()), ..TokioTasksPlugin::default() }); - app.add_plugins(PadClientPlugin); + // 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 new file mode 100644 index 0000000..f960b41 --- /dev/null +++ b/client/src/data/layout_data.rs @@ -0,0 +1,106 @@ +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 new file mode 100644 index 0000000..0e0a42e --- /dev/null +++ b/client/src/data/mod.rs @@ -0,0 +1 @@ +pub mod layout_data;
\ No newline at end of file diff --git a/client/src/lib.rs b/client/src/lib.rs new file mode 100644 index 0000000..bcfa9d8 --- /dev/null +++ b/client/src/lib.rs @@ -0,0 +1,2 @@ +pub mod bevy_plugins; +pub mod data;
\ No newline at end of file diff --git a/export/.gitignore b/export/.gitignore index 8d2f96c..fe049dc 100644 --- a/export/.gitignore +++ b/export/.gitignore @@ -4,4 +4,5 @@ !src/ !src/** !dev/ -!dev/**
\ No newline at end of file +!dev/** +/dev/bin/pad.exe diff --git a/export/dev/LICENSE-THIRD-PARTY b/export/dev/LICENSE-THIRD-PARTY index 47b501f..6d81b7e 100644 --- a/export/dev/LICENSE-THIRD-PARTY +++ b/export/dev/LICENSE-THIRD-PARTY @@ -7,6 +7,7 @@ This project uses third-party components with the following licenses: ----------------------------------------------------------------------- * bincode * crossterm +* quick-xml * tokio * bevy (original license: Apache-2.0 OR MIT) * chrono (original license: Apache-2.0 OR MIT) @@ -38,6 +39,7 @@ Copyright (c) 2013-2014 The Rust Project Developers. * env_logger - Copyright (c) The env_logger Project Developer(s). * hex - Copyright (c) 2015-2020 The rust-hex Developers. * log - Copyright (c) The log Project Developer(s). +* quick-xml - Copyright (c) 2016 Johann Tuffe. * rand - Copyright 2018 Developers of the Rand project. * serde - Copyright (c) The serde Project Developer(s). * serde_yaml - Copyright (c) The serde_yaml Project Developer(s). diff --git a/export/dev/bin/padc.exe b/export/dev/bin/padc.exe Binary files differindex 5c6b7a0..5256895 100644 --- a/export/dev/bin/padc.exe +++ b/export/dev/bin/padc.exe |
