aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
author1992414357@qq.com <1992414357@qq.com>2025-06-13 16:25:22 +0800
committer1992414357@qq.com <1992414357@qq.com>2025-06-13 16:25:22 +0800
commit98dad6afa316b9a44ff76b305520339ddc44c789 (patch)
tree9a6d0b566b23f0bab270b68e4766a60349abf18b /client
parent9e48af01ae56fe813869ada24de291ab98b361e2 (diff)
.
Diffstat (limited to 'client')
-rw-r--r--client/Cargo.toml2
-rw-r--r--client/src/bevy_plugins/mod.rs1
-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.rs106
-rw-r--r--client/src/data/mod.rs1
-rw-r--r--client/src/lib.rs2
7 files changed, 137 insertions, 14 deletions
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