aboutsummaryrefslogtreecommitdiff
path: root/apps/client
diff options
context:
space:
mode:
Diffstat (limited to 'apps/client')
-rw-r--r--apps/client/Cargo.toml15
-rw-r--r--apps/client/arts/Concept.psdbin0 -> 7568065 bytes
-rw-r--r--apps/client/src/bevy_plugins/mod.rs1
-rw-r--r--apps/client/src/bevy_plugins/plugin_client_app.rs80
-rw-r--r--apps/client/src/bin/pad.rs23
-rw-r--r--apps/client/src/data/layout_data.rs106
-rw-r--r--apps/client/src/data/mod.rs1
-rw-r--r--apps/client/src/lib.rs2
8 files changed, 228 insertions, 0 deletions
diff --git a/apps/client/Cargo.toml b/apps/client/Cargo.toml
new file mode 100644
index 0000000..fe90d6b
--- /dev/null
+++ b/apps/client/Cargo.toml
@@ -0,0 +1,15 @@
+[package]
+name = "nogamepads-client"
+edition = "2024"
+version.workspace = true
+
+[dependencies]
+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/apps/client/arts/Concept.psd b/apps/client/arts/Concept.psd
new file mode 100644
index 0000000..5735606
--- /dev/null
+++ b/apps/client/arts/Concept.psd
Binary files differ
diff --git a/apps/client/src/bevy_plugins/mod.rs b/apps/client/src/bevy_plugins/mod.rs
new file mode 100644
index 0000000..0f0aa3e
--- /dev/null
+++ b/apps/client/src/bevy_plugins/mod.rs
@@ -0,0 +1 @@
+pub mod plugin_client_app; \ No newline at end of file
diff --git a/apps/client/src/bevy_plugins/plugin_client_app.rs b/apps/client/src/bevy_plugins/plugin_client_app.rs
new file mode 100644
index 0000000..e7d60d2
--- /dev/null
+++ b/apps/client/src/bevy_plugins/plugin_client_app.rs
@@ -0,0 +1,80 @@
+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/apps/client/src/bin/pad.rs b/apps/client/src/bin/pad.rs
new file mode 100644
index 0000000..796dea3
--- /dev/null
+++ b/apps/client/src/bin/pad.rs
@@ -0,0 +1,23 @@
+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/apps/client/src/data/layout_data.rs b/apps/client/src/data/layout_data.rs
new file mode 100644
index 0000000..f960b41
--- /dev/null
+++ b/apps/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/apps/client/src/data/mod.rs b/apps/client/src/data/mod.rs
new file mode 100644
index 0000000..0e0a42e
--- /dev/null
+++ b/apps/client/src/data/mod.rs
@@ -0,0 +1 @@
+pub mod layout_data; \ No newline at end of file
diff --git a/apps/client/src/lib.rs b/apps/client/src/lib.rs
new file mode 100644
index 0000000..bcfa9d8
--- /dev/null
+++ b/apps/client/src/lib.rs
@@ -0,0 +1,2 @@
+pub mod bevy_plugins;
+pub mod data; \ No newline at end of file