aboutsummaryrefslogtreecommitdiff
path: root/core/src/data/game
diff options
context:
space:
mode:
author1992414357@qq.com <1992414357@qq.com>2025-06-11 19:14:04 +0800
committer1992414357@qq.com <1992414357@qq.com>2025-06-11 19:14:04 +0800
commit9e48af01ae56fe813869ada24de291ab98b361e2 (patch)
tree82b56adecbeb260ebbf2c512d78fe2d63805eb36 /core/src/data/game
parentaa326e69b18a4390ffbc97268eaec4793761f083 (diff)
组合模块中 structs.rs 和 implements.rs 文件
Diffstat (limited to 'core/src/data/game')
-rw-r--r--core/src/data/game/cli/mod.rs1
-rw-r--r--core/src/data/game/game_cli.rs (renamed from core/src/data/game/cli/cli_command.rs)4
-rw-r--r--core/src/data/game/game_data.rs (renamed from core/src/data/game/implements.rs)32
-rw-r--r--core/src/data/game/game_runtime.rs (renamed from core/src/data/game/runtime/implements.rs)51
-rw-r--r--core/src/data/game/mod.rs7
-rw-r--r--core/src/data/game/runtime/mod.rs2
-rw-r--r--core/src/data/game/runtime/structs.rs42
-rw-r--r--core/src/data/game/structs.rs29
-rw-r--r--core/src/data/game/types.rs2
9 files changed, 78 insertions, 92 deletions
diff --git a/core/src/data/game/cli/mod.rs b/core/src/data/game/cli/mod.rs
deleted file mode 100644
index 043f7b8..0000000
--- a/core/src/data/game/cli/mod.rs
+++ /dev/null
@@ -1 +0,0 @@
-pub mod cli_command; \ No newline at end of file
diff --git a/core/src/data/game/cli/cli_command.rs b/core/src/data/game/game_cli.rs
index 5f296f8..521de3f 100644
--- a/core/src/data/game/cli/cli_command.rs
+++ b/core/src/data/game/game_cli.rs
@@ -3,8 +3,8 @@ use clap::{Args, Parser, Subcommand};
use clearscreen::clear;
use log::{info, warn};
use nogamepads::entry_mutex;
-use crate::data::game::runtime::structs::GameRuntime;
-use crate::data::player::structs::Player;
+use crate::data::game::game_runtime::GameRuntime;
+use crate::data::player::player_data::Player;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
diff --git a/core/src/data/game/implements.rs b/core/src/data/game/game_data.rs
index ad86572..3bdf28b 100644
--- a/core/src/data/game/implements.rs
+++ b/core/src/data/game/game_data.rs
@@ -1,9 +1,35 @@
+use std::collections::HashMap;
use std::sync::{Arc, Mutex};
+use serde::{Deserialize, Serialize};
use nogamepads::entry_mutex;
-use crate::data::game::runtime::structs::{GameControlRuntime, GameRuntime, GameRuntimeData};
-use crate::data::game::structs::{GameControlData, GameData, GameRuntimeDataArchive};
+use crate::data::game::game_runtime::{GameControlRuntime, GameRuntime, GameRuntimeData};
use crate::data::game::types::{GameInfo, Players};
-use crate::data::player::structs::Player;
+use crate::data::player::player_data::{Account, Player};
+
+/// Game pad_client data
+/// Describes the basic information of the game pad_client
+#[derive(Clone, Serialize, Deserialize, PartialEq, Debug)]
+pub struct GameData {
+ pub info: GameInfo,
+ pub control: GameControlData,
+ pub archive: GameRuntimeDataArchive
+}
+
+/// Game control information
+/// Describes the buttons, axes, and directions that can be controlled.
+#[derive(Default, Clone, Serialize, Deserialize, PartialEq, Debug)]
+pub struct GameControlData {
+ pub direction_keys : HashMap<u8, String>,
+ pub axis_keys : HashMap<u8, String>,
+ pub button_keys : HashMap<u8, String>,
+}
+
+/// Archive of game runtime data
+/// The game pad_client can convert data into this structure for persistence.
+#[derive(Default, Clone, Serialize, Deserialize, PartialEq, Debug)]
+pub struct GameRuntimeDataArchive {
+ pub banned: Vec<Account>
+}
impl Default for GameData {
fn default() -> Self {
diff --git a/core/src/data/game/runtime/implements.rs b/core/src/data/game/game_runtime.rs
index 22b6a5d..1c5a548 100644
--- a/core/src/data/game/runtime/implements.rs
+++ b/core/src/data/game/game_runtime.rs
@@ -1,20 +1,55 @@
use std::collections::{HashMap, VecDeque};
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::SeqCst;
+use std::sync::Mutex;
use log::{info, trace, warn};
use nogamepads::entry_mutex;
-use crate::data::game::runtime::structs::{GameControlRuntime, GameRuntime, GameRuntimeData};
-use crate::data::game::types::Players;
-use crate::data::message::enums::{JoinFailedMessage, ControlMessage, ExitReason, GameMessage};
-use crate::data::message::enums::JoinFailedMessage::{ContainIdenticalPlayer, GameLocked, PlayerBanned};
-use crate::data::message::enums::ControlMessage::{Axis, Dir, Msg, Pressed, Released};
-use crate::data::message::enums::ExitReason::{YouAreBanned, YouAreKicked};
-use crate::data::message::enums::GameMessage::{EventTrigger, LetExit};
+use crate::data::game::game_data::GameControlData;
+use crate::data::game::types::{GameInfo, Players};
+use crate::data::message::message_enums::{JoinFailedMessage, ControlMessage, ExitReason, GameMessage};
+use crate::data::message::message_enums::JoinFailedMessage::{ContainIdenticalPlayer, GameLocked, PlayerBanned};
+use crate::data::message::message_enums::ControlMessage::{Axis, Dir, Msg, Pressed, Released};
+use crate::data::message::message_enums::ExitReason::{YouAreBanned, YouAreKicked};
+use crate::data::message::message_enums::GameMessage::{EventTrigger, LetExit};
use crate::data::message::traits::MessageManager;
-use crate::data::player::structs::{Account, Player};
+use crate::data::player::player_data::{Account, Player};
use crate::service::service_types::ServiceType;
use crate::service::service_types::ServiceType::TCPConnection;
+/// Game pad_client runtime
+/// Stores the game state, player information, and all data involved in controller-side interactions during runtime
+pub struct GameRuntime {
+
+ pub info: GameInfo,
+ pub data: GameRuntimeData,
+ pub control: GameControlRuntime,
+
+ pub writer_count: i32,
+ pub reader_count: i32,
+}
+
+pub struct GameRuntimeData {
+
+ pub(crate) received: HashMap<(ServiceType, Account), VecDeque<(Account, ControlMessage)>>,
+ pub(crate) send: HashMap<(ServiceType, Account), VecDeque<(Account, GameMessage)>>,
+
+ pub(crate) players_online: Players,
+ pub(crate) players_banned: Players,
+ pub(crate) account_service_type: Mutex<HashMap<Account, ServiceType>>,
+
+ pub locked: AtomicBool,
+ pub close: AtomicBool,
+}
+
+#[derive(Default)]
+pub struct GameControlRuntime {
+ pub(crate) keys: GameControlData,
+ pub(crate) directions : HashMap<u8, HashMap<Account, (f64, f64)>>,
+ pub(crate) axes : HashMap<u8, HashMap<Account, f64>>,
+ pub(crate) button : HashMap<u8, HashMap<Account, bool>>,
+ pub(crate) events : VecDeque<(Account, ControlMessage)>
+}
+
impl GameRuntime {
/// Attempt to have the specified player join the game
diff --git a/core/src/data/game/mod.rs b/core/src/data/game/mod.rs
index 4a0a3d4..1a31cf1 100644
--- a/core/src/data/game/mod.rs
+++ b/core/src/data/game/mod.rs
@@ -1,6 +1,5 @@
-pub mod cli;
-pub mod runtime;
+pub mod game_cli;
-pub mod implements;
-pub mod structs;
+pub mod game_data;
+pub mod game_runtime;
pub mod types; \ No newline at end of file
diff --git a/core/src/data/game/runtime/mod.rs b/core/src/data/game/runtime/mod.rs
deleted file mode 100644
index 0ff870f..0000000
--- a/core/src/data/game/runtime/mod.rs
+++ /dev/null
@@ -1,2 +0,0 @@
-pub mod implements;
-pub mod structs; \ No newline at end of file
diff --git a/core/src/data/game/runtime/structs.rs b/core/src/data/game/runtime/structs.rs
deleted file mode 100644
index c6e005f..0000000
--- a/core/src/data/game/runtime/structs.rs
+++ /dev/null
@@ -1,42 +0,0 @@
-use std::collections::{HashMap, VecDeque};
-use std::sync::atomic::AtomicBool;
-use std::sync::Mutex;
-use crate::data::game::structs::GameControlData;
-use crate::data::game::types::{GameInfo, Players};
-use crate::data::message::enums::{ControlMessage, GameMessage};
-use crate::data::player::structs::Account;
-use crate::service::service_types::ServiceType;
-
-/// Game pad_client runtime
-/// Stores the game state, player information, and all data involved in controller-side interactions during runtime
-pub struct GameRuntime {
-
- pub info: GameInfo,
- pub data: GameRuntimeData,
- pub control: GameControlRuntime,
-
- pub writer_count: i32,
- pub reader_count: i32,
-}
-
-pub struct GameRuntimeData {
-
- pub(crate) received: HashMap<(ServiceType, Account), VecDeque<(Account, ControlMessage)>>,
- pub(crate) send: HashMap<(ServiceType, Account), VecDeque<(Account, GameMessage)>>,
-
- pub(crate) players_online: Players,
- pub(crate) players_banned: Players,
- pub(crate) account_service_type: Mutex<HashMap<Account, ServiceType>>,
-
- pub locked: AtomicBool,
- pub close: AtomicBool,
-}
-
-#[derive(Default)]
-pub struct GameControlRuntime {
- pub(crate) keys: GameControlData,
- pub(crate) directions : HashMap<u8, HashMap<Account, (f64, f64)>>,
- pub(crate) axes : HashMap<u8, HashMap<Account, f64>>,
- pub(crate) button : HashMap<u8, HashMap<Account, bool>>,
- pub(crate) events : VecDeque<(Account, ControlMessage)>
-} \ No newline at end of file
diff --git a/core/src/data/game/structs.rs b/core/src/data/game/structs.rs
deleted file mode 100644
index 52fc0f1..0000000
--- a/core/src/data/game/structs.rs
+++ /dev/null
@@ -1,29 +0,0 @@
-use std::collections::HashMap;
-use serde::{Deserialize, Serialize};
-use crate::data::game::types::GameInfo;
-use crate::data::player::structs::Account;
-
-/// Game pad_client data
-/// Describes the basic information of the game pad_client
-#[derive(Clone, Serialize, Deserialize, PartialEq, Debug)]
-pub struct GameData {
- pub info: GameInfo,
- pub control: GameControlData,
- pub archive: GameRuntimeDataArchive
-}
-
-/// Game control information
-/// Describes the buttons, axes, and directions that can be controlled.
-#[derive(Default, Clone, Serialize, Deserialize, PartialEq, Debug)]
-pub struct GameControlData {
- pub direction_keys : HashMap<u8, String>,
- pub axis_keys : HashMap<u8, String>,
- pub button_keys : HashMap<u8, String>,
-}
-
-/// Archive of game runtime data
-/// The game pad_client can convert data into this structure for persistence.
-#[derive(Default, Clone, Serialize, Deserialize, PartialEq, Debug)]
-pub struct GameRuntimeDataArchive {
- pub banned: Vec<Account>
-} \ No newline at end of file
diff --git a/core/src/data/game/types.rs b/core/src/data/game/types.rs
index 8af17d3..778201f 100644
--- a/core/src/data/game/types.rs
+++ b/core/src/data/game/types.rs
@@ -1,6 +1,6 @@
use std::collections::HashMap;
use std::sync::Mutex;
-use crate::data::player::structs::{Account, Player};
+use crate::data::player::player_data::{Account, Player};
pub(crate) type GameInfo = HashMap<String, String>;