Compare commits

...

4 Commits

Author SHA1 Message Date
f45f15b3bf Fix warnings 2026-07-29 20:20:00 +03:00
eb6ea6caf3 Move commands to game/commands.rs 2026-07-29 20:19:05 +03:00
215c88cb49 Move GameOptions to game/opts.rs 2026-07-29 20:16:48 +03:00
897a1dbef6 Refactor game_manager to game/mod.rs 2026-07-29 20:14:14 +03:00
31 changed files with 210 additions and 184 deletions

View File

@ -4,7 +4,7 @@ use godot::{
tools::get_autoload_by_name,
};
use crate::game_manager::GameManager;
use crate::game::GameManager;
pub const MUSIC_MANAGER_GLOBAL: &str = "MusicManagerGlobal";

View File

@ -2,7 +2,7 @@ use godot::{classes::RichTextLabel, prelude::*};
use crate::{
announcer::Announcement,
game_manager::{Game, Player},
game::{Game, Player},
player::DamageSource,
};

View File

@ -3,7 +3,7 @@ use std::net::SocketAddr;
use godot::{classes::Os, prelude::*};
use crate::{
game_manager::{Game, GameManager},
game::{Game, GameManager},
net::network_manager::NetworkManager,
};

74
rust/src/game/commands.rs Normal file
View File

@ -0,0 +1,74 @@
use godot::classes::class_macros::private::virtuals::Xrvrs::Gd;
use crate::{
game::Game,
ui::cli::{CliColor, Command, CommandLinePanel},
};
pub fn register_commands(cli: &mut Gd<CommandLinePanel>) {
cli.bind_mut()
.register_command("respawn_ball".to_string(), Box::new(RespawnBallCommand));
cli.bind_mut()
.register_command("players".to_string(), Box::new(ListPlayersCommand));
cli.bind_mut()
.register_command("kill".to_string(), Box::new(KillCommand));
}
pub fn unregister_commands(cli: &mut Gd<CommandLinePanel>) {
cli.bind_mut()
.unregister_command("respawn_ball".to_string());
cli.bind_mut().unregister_command("players".to_string());
cli.bind_mut().unregister_command("kill".to_string());
}
pub struct RespawnBallCommand;
impl Command for RespawnBallCommand {
fn execute(&self, _: &mut CommandLinePanel, _: &[&str]) {
if let Some(game) = &mut Game::singleton() {
game.bind_mut().respawn_ball();
}
}
fn help(&self) -> &str {
"respawns the ball"
}
}
pub struct ListPlayersCommand;
impl Command for ListPlayersCommand {
fn execute(&self, cli: &mut CommandLinePanel, _: &[&str]) {
if let Some(game) = &mut Game::singleton() {
for player in &game.bind().players {
cli.publish_message(
format!(" - {} ({})", player.data.name, player.id()),
CliColor::Info,
);
}
}
}
fn help(&self) -> &str {
"lists all players"
}
}
pub struct KillCommand;
impl Command for KillCommand {
fn execute(&self, cli: &mut CommandLinePanel, args: &[&str]) {
if let Some(player_str) = args.first() {
if let Ok(player_id) = player_str.parse() {
if let Some(game) = &mut Game::singleton() {
game.bind_mut().kill_player(player_id);
}
} else {
cli.publish_message("Invalid player id".to_string(), CliColor::Error);
}
} else {
cli.publish_message("Usage: kill [player_id]".to_string(), CliColor::Error);
}
}
fn help(&self) -> &str {
"kills given player"
}
}

View File

@ -10,6 +10,10 @@ use crate::{
},
bgm::{Music, MusicManager},
chat::{Chat, ChatMessage},
game::{
commands::{register_commands, unregister_commands},
opts::{GameOption, GameOptionValue, GameOptions},
},
map::Map,
map_resource::MapResource,
net::{
@ -29,9 +33,12 @@ use crate::{
},
replay::{ReplayEvent, ReplayPlayback, ReplayRecorder},
team_resource::TeamResource,
ui::cli::{CliColor, Command, CommandLinePanel},
ui::cli::CommandLinePanel,
};
pub mod commands;
pub mod opts;
pub const GAME_MANAGER_GLOBAL: &str = "GameManagerGlobal";
#[derive(GodotClass)]
@ -152,141 +159,6 @@ impl GameManager {
}
}
#[derive(Debug)]
pub struct GameOptions {
pub values: HashMap<GameOption, GameOptionValue>,
}
impl Default for GameOptions {
fn default() -> Self {
let mut opts = HashMap::new();
opts.insert(GameOption::AllowAnyMap, GameOptionValue::Boolean(false));
opts.insert(GameOption::AllowAnyTeam, GameOptionValue::Boolean(false));
opts.insert(GameOption::FriendlyFire, GameOptionValue::Boolean(true));
opts.insert(GameOption::GoalsNeededToWin, GameOptionValue::Number(5.));
opts.insert(GameOption::RespawnTimer, GameOptionValue::Number(5.));
opts.insert(
GameOption::TelegrenadesAllowed,
GameOptionValue::Boolean(true),
);
Self { values: opts }
}
}
impl GameOptions {
pub fn is_true(&self, opt: GameOption) -> bool {
let opt = self
.values
.get(&opt)
.copied()
.unwrap_or(GameOptionValue::Boolean(false));
match opt {
GameOptionValue::Boolean(value) => value,
_ => false,
}
}
pub fn get_float(&self, opt: GameOption) -> f64 {
let opt = self
.values
.get(&opt)
.copied()
.unwrap_or(GameOptionValue::Number(0.));
match opt {
GameOptionValue::Number(value) => value,
_ => 0.,
}
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Hash, Copy, Clone, Serialize, Deserialize)]
pub enum GameOption {
/// Allow anyone to select a map, not just the host
AllowAnyMap,
/// Allow anyone to select anyone's team, not just themselves and the host
AllowAnyTeam,
/// Allow anyone to shoot anyone, not just other team's members
FriendlyFire,
/// The number of goals needed to win a match
GoalsNeededToWin,
/// Whether telegrenades are allowed or not.
TelegrenadesAllowed,
/// How long in seconds does it take for a player to respawn
RespawnTimer,
}
impl ToString for GameOption {
fn to_string(&self) -> String {
match self {
GameOption::AllowAnyMap => "Allow anyone to select the map",
GameOption::AllowAnyTeam => "Allow anyone to select any teams",
GameOption::FriendlyFire => "Friendly fire",
GameOption::GoalsNeededToWin => "Goals needed to win",
GameOption::TelegrenadesAllowed => "Telegrenades allowed",
GameOption::RespawnTimer => "Respawn Time (seconds)",
}
.to_owned()
}
}
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub enum GameOptionValue {
Boolean(bool),
Number(f64),
}
pub struct RespawnBallCommand;
impl Command for RespawnBallCommand {
fn execute(&self, _: &mut CommandLinePanel, _: &[&str]) {
if let Some(game) = &mut Game::singleton() {
game.bind_mut().respawn_ball();
}
}
fn help(&self) -> &str {
"respawns the ball"
}
}
pub struct ListPlayersCommand;
impl Command for ListPlayersCommand {
fn execute(&self, cli: &mut CommandLinePanel, _: &[&str]) {
if let Some(game) = &mut Game::singleton() {
for player in &game.bind().players {
cli.publish_message(
format!(" - {} ({})", player.data.name, player.id()),
CliColor::Info,
);
}
}
}
fn help(&self) -> &str {
"lists all players"
}
}
pub struct KillCommand;
impl Command for KillCommand {
fn execute(&self, cli: &mut CommandLinePanel, args: &[&str]) {
if let Some(player_str) = args.first() {
if let Ok(player_id) = player_str.parse() {
if let Some(game) = &mut Game::singleton() {
game.bind_mut().kill_player(player_id);
}
} else {
cli.publish_message("Invalid player id".to_string(), CliColor::Error);
}
} else {
cli.publish_message("Usage: kill [player_id]".to_string(), CliColor::Error);
}
}
fn help(&self) -> &str {
"kills given player"
}
}
#[derive(GodotClass)]
#[class(base=Node, init)]
pub struct Game {
@ -520,12 +392,7 @@ impl Game {
peer.set_accepting_connections(false);
let mut cli = CommandLinePanel::singleton();
cli.bind_mut()
.register_command("respawn_ball".to_string(), Box::new(RespawnBallCommand));
cli.bind_mut()
.register_command("players".to_string(), Box::new(ListPlayersCommand));
cli.bind_mut()
.register_command("kill".to_string(), Box::new(KillCommand));
register_commands(&mut cli);
}
}
});
@ -594,10 +461,7 @@ impl Game {
});
let mut cli = CommandLinePanel::singleton();
cli.bind_mut()
.unregister_command("respawn_ball".to_string());
cli.bind_mut().unregister_command("players".to_string());
cli.bind_mut().unregister_command("kill".to_string());
unregister_commands(&mut cli);
}
pub fn change_option(&mut self, opt: GameOption, value: GameOptionValue) {

86
rust/src/game/opts.rs Normal file
View File

@ -0,0 +1,86 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Debug)]
pub struct GameOptions {
pub values: HashMap<GameOption, GameOptionValue>,
}
impl Default for GameOptions {
fn default() -> Self {
let mut opts = HashMap::new();
opts.insert(GameOption::AllowAnyMap, GameOptionValue::Boolean(false));
opts.insert(GameOption::AllowAnyTeam, GameOptionValue::Boolean(false));
opts.insert(GameOption::FriendlyFire, GameOptionValue::Boolean(true));
opts.insert(GameOption::GoalsNeededToWin, GameOptionValue::Number(5.));
opts.insert(GameOption::RespawnTimer, GameOptionValue::Number(5.));
opts.insert(
GameOption::TelegrenadesAllowed,
GameOptionValue::Boolean(true),
);
Self { values: opts }
}
}
impl GameOptions {
pub fn is_true(&self, opt: GameOption) -> bool {
let opt = self
.values
.get(&opt)
.copied()
.unwrap_or(GameOptionValue::Boolean(false));
match opt {
GameOptionValue::Boolean(value) => value,
_ => false,
}
}
pub fn get_float(&self, opt: GameOption) -> f64 {
let opt = self
.values
.get(&opt)
.copied()
.unwrap_or(GameOptionValue::Number(0.));
match opt {
GameOptionValue::Number(value) => value,
_ => 0.,
}
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Hash, Copy, Clone, Serialize, Deserialize)]
pub enum GameOption {
/// Allow anyone to select a map, not just the host
AllowAnyMap,
/// Allow anyone to select anyone's team, not just themselves and the host
AllowAnyTeam,
/// Allow anyone to shoot anyone, not just other team's members
FriendlyFire,
/// The number of goals needed to win a match
GoalsNeededToWin,
/// Whether telegrenades are allowed or not.
TelegrenadesAllowed,
/// How long in seconds does it take for a player to respawn
RespawnTimer,
}
impl ToString for GameOption {
fn to_string(&self) -> String {
match self {
GameOption::AllowAnyMap => "Allow anyone to select the map",
GameOption::AllowAnyTeam => "Allow anyone to select any teams",
GameOption::FriendlyFire => "Friendly fire",
GameOption::GoalsNeededToWin => "Goals needed to win",
GameOption::TelegrenadesAllowed => "Telegrenades allowed",
GameOption::RespawnTimer => "Respawn Time (seconds)",
}
.to_owned()
}
}
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub enum GameOptionValue {
Boolean(bool),
Number(f64),
}

View File

@ -1,12 +1,9 @@
use std::{
net::SocketAddr,
time::{Duration, SystemTime, UNIX_EPOCH},
};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use godot::{
classes::{
AudioServer, DisplayServer, FileAccess, InputEvent, InputEventKey, InputEventMouseButton,
InputMap, display_server::WindowMode, file_access::ModeFlags, window::Mode,
InputMap, display_server::WindowMode, file_access::ModeFlags,
},
global::{Key, MouseButton},
prelude::*,

View File

@ -3,7 +3,7 @@ use godot::{
prelude::*,
};
use crate::{game_manager::Game, net::network_manager::NetworkManager, player::ball::Ball};
use crate::{game::Game, net::network_manager::NetworkManager, player::ball::Ball};
#[derive(GodotClass)]
#[class(base=Area3D, init)]

View File

@ -5,7 +5,7 @@ use godot::{
use serde::{Deserialize, Serialize};
use crate::{
game_manager::Game,
game::Game,
net::network_manager::NetworkManager,
player::{DamageSource, IPlayer, ball::Ball},
};

View File

@ -5,7 +5,7 @@ pub mod bgm;
pub mod chat;
pub mod cli_parser;
pub mod credits;
pub mod game_manager;
pub mod game;
pub mod game_settings;
pub mod goal;
pub mod killbox;

View File

@ -2,7 +2,7 @@ use std::{collections::HashMap, f32::consts::PI};
use godot::{classes::RandomNumberGenerator, prelude::*};
use crate::{game_manager::Game, ui::menu_player::MenuPlayer};
use crate::{game::Game, ui::menu_player::MenuPlayer};
#[derive(GodotClass)]
#[class(base=Node3D, init)]

View File

@ -3,7 +3,7 @@ use std::collections::HashMap;
use godot::{classes::CharacterBody3D, prelude::*};
use crate::{
game_manager::{Game, GameManager},
game::{Game, GameManager},
net::util::NetVector3,
pickup::Pickup,
player::{

View File

@ -10,7 +10,10 @@ use teanet::{Peer, PeerConfig, PeerMessage};
use crate::{
announcer::Announcement,
game_manager::{Game, GameManager, GameOption, GameOptionValue, NetPlayer},
game::{
Game, GameManager, NetPlayer,
opts::{GameOption, GameOptionValue},
},
game_settings::GameSettingsManager,
net::{net_stats::Stats, util::NetVector3},
player::{DamageSource, NetTransform, weapon::WeaponType},

View File

@ -4,7 +4,7 @@ use godot::obj::Singleton;
use teanet::PeerMessage;
use crate::{
game_manager::{Game, GameManager, GameOption},
game::{Game, GameManager, opts::GameOption},
game_settings::GameSettingsManager,
net::network_manager::{NetworkManager, Package, PeerKind},
popup_queue::{Popup, PopupQueue},
@ -17,7 +17,7 @@ impl NetworkManager {
if let Some(peer) = &mut self.peer {
match peer {
PeerKind::Client(peer, addr) => match message {
PeerKind::Client(peer, _) => match message {
teanet::PeerMessage::NewConnection(connection) => {
cli.bind_mut().publish_message(
format!("Connected to: {}", connection.address),

View File

@ -2,7 +2,7 @@ use godot::{classes::Area3D, prelude::*};
use serde::{Deserialize, Serialize};
use crate::{
game_manager::Game, map::Map, net::network_manager::NetworkManager, player::IPlayer,
game::Game, map::Map, net::network_manager::NetworkManager, player::IPlayer,
replay::StandaloneReplayManager,
};

View File

@ -10,7 +10,7 @@ use godot::{
};
use crate::{
game_manager::{Game, GameManager, GameOption},
game::{Game, GameManager, opts::GameOption},
game_settings::{GameSettings, GameSettingsManager},
killbox::KillboxKind,
net::{

View File

@ -8,7 +8,7 @@ use godot::{
use serde::{Deserialize, Serialize};
use crate::{
game_manager::{Game, GameOption},
game::{Game, opts::GameOption},
killbox::KillboxKind,
net::{
network_manager::NetworkManager,

View File

@ -8,7 +8,7 @@ use godot::{
};
use crate::{
game_manager::{Game, GameOption},
game::{Game, opts::GameOption},
killbox::KillboxKind,
pickup::PickupKind,
player::{

View File

@ -7,7 +7,7 @@ use godot::{
use serde::{Deserialize, Serialize};
use crate::{
game_manager::Game,
game::Game,
net::util::{cast_ray, shotgun_ray},
player::{DamageSource, shootable::Shootable},
replay::StandaloneReplayManager,

View File

@ -9,7 +9,7 @@ use godot::{
use serde::{Deserialize, Serialize};
use crate::{
game_manager::{Game, GameManager, Player},
game::{Game, GameManager, Player},
game_settings::GameSettingsManager,
map::Map,
net::{network_manager::BallSync, util::NetVector3},
@ -362,9 +362,7 @@ impl INode for ReplayPlayback {
}
self.telegrenades.remove(player_id);
if let Some(map) = &mut self.current_map
&& let Some(player) = self.replay.players.get(player_id)
{
if let Some(map) = &mut self.current_map {
if let Some(telegrenade) = map.bind_mut().spawn_replay_telegrenade(
(*location).into(),
(*velocity).into(),

View File

@ -10,7 +10,7 @@ use godot::{
use crate::{
chat::Chat,
game_manager::Game,
game::Game,
net::network_manager::{NetworkManager, Package, PeerKind},
ui::cli::CommandLinePanel,
};

View File

@ -4,7 +4,7 @@ use godot::{
};
use crate::{
game_manager::{Game, GameManager},
game::{Game, GameManager},
ui::player_listings::PlayerListings,
};

View File

@ -7,7 +7,7 @@ use godot::{
};
use crate::{
game_manager::Game,
game::Game,
net::network_manager::NetworkManager,
ui::{chatbox::ChatBox, cli::CommandLinePanel, settings::SettingsPanel},
};

View File

@ -10,7 +10,10 @@ use godot::{
use crate::{
bgm::{Music, MusicManager},
game_manager::{Game, GameManager, GameOption, GameOptionValue, GameOptions},
game::{
Game, GameManager,
opts::{GameOption, GameOptionValue, GameOptions},
},
net::network_manager::{NetworkManager, Package, PeerKind},
ui::lobby_player_listing::LobbyPlayerListing,
};

View File

@ -4,7 +4,10 @@ use godot::{
};
use crate::{
game_manager::{Game, GameOption, GameOptions},
game::{
Game,
opts::{GameOption, GameOptions},
},
net::network_manager::NetworkManager,
team_resource::TeamResource,
};

View File

@ -3,7 +3,7 @@ use godot::{
prelude::*,
};
use crate::{game_manager::Game, player::soldier_mesh::SoldierMesh};
use crate::{game::Game, player::soldier_mesh::SoldierMesh};
#[derive(GodotClass)]
#[class(base=CharacterBody3D, init)]

View File

@ -3,7 +3,7 @@ use godot::{
prelude::*,
};
use crate::{game_manager::Game, replay::StandaloneReplayManager};
use crate::{game::Game, replay::StandaloneReplayManager};
#[derive(GodotClass)]
#[class(base=HBoxContainer, init)]

View File

@ -4,9 +4,7 @@ use godot::{
prelude::*,
};
use crate::{
game_manager::Game, replay::StandaloneReplayManager, ui::player_listing::PlayerListing,
};
use crate::{game::Game, replay::StandaloneReplayManager, ui::player_listing::PlayerListing};
#[derive(GodotClass)]
#[class(base=HBoxContainer, init)]

View File

@ -4,7 +4,7 @@ use godot::{
};
use crate::{
game_manager::{Game, GameManager},
game::{Game, GameManager},
replay::StandaloneReplayManager,
ui::player_listings::PlayerListings,
};

View File

@ -1,5 +1,5 @@
use godot::{
classes::{Control, IControl, InputEvent, Label, Slider},
classes::{Control, IControl, Label, Slider},
prelude::*,
};

View File

@ -5,7 +5,7 @@ use godot::{
prelude::*,
};
use crate::{game_manager::Game, replay::StandaloneReplayManager};
use crate::{game::Game, replay::StandaloneReplayManager};
#[derive(GodotClass)]
#[class(base=HBoxContainer, init)]