Move GameOptions to game/opts.rs
This commit is contained in:
parent
897a1dbef6
commit
215c88cb49
@ -10,6 +10,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
bgm::{Music, MusicManager},
|
bgm::{Music, MusicManager},
|
||||||
chat::{Chat, ChatMessage},
|
chat::{Chat, ChatMessage},
|
||||||
|
game::opts::{GameOption, GameOptionValue, GameOptions},
|
||||||
map::Map,
|
map::Map,
|
||||||
map_resource::MapResource,
|
map_resource::MapResource,
|
||||||
net::{
|
net::{
|
||||||
@ -32,6 +33,8 @@ use crate::{
|
|||||||
ui::cli::{CliColor, Command, CommandLinePanel},
|
ui::cli::{CliColor, Command, CommandLinePanel},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub mod opts;
|
||||||
|
|
||||||
pub const GAME_MANAGER_GLOBAL: &str = "GameManagerGlobal";
|
pub const GAME_MANAGER_GLOBAL: &str = "GameManagerGlobal";
|
||||||
|
|
||||||
#[derive(GodotClass)]
|
#[derive(GodotClass)]
|
||||||
@ -152,89 +155,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;
|
pub struct RespawnBallCommand;
|
||||||
impl Command for RespawnBallCommand {
|
impl Command for RespawnBallCommand {
|
||||||
fn execute(&self, _: &mut CommandLinePanel, _: &[&str]) {
|
fn execute(&self, _: &mut CommandLinePanel, _: &[&str]) {
|
||||||
|
|||||||
86
rust/src/game/opts.rs
Normal file
86
rust/src/game/opts.rs
Normal 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),
|
||||||
|
}
|
||||||
@ -10,7 +10,10 @@ use teanet::{Peer, PeerConfig, PeerMessage};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
announcer::Announcement,
|
announcer::Announcement,
|
||||||
game::{Game, GameManager, GameOption, GameOptionValue, NetPlayer},
|
game::{
|
||||||
|
Game, GameManager, NetPlayer,
|
||||||
|
opts::{GameOption, GameOptionValue},
|
||||||
|
},
|
||||||
game_settings::GameSettingsManager,
|
game_settings::GameSettingsManager,
|
||||||
net::{net_stats::Stats, util::NetVector3},
|
net::{net_stats::Stats, util::NetVector3},
|
||||||
player::{DamageSource, NetTransform, weapon::WeaponType},
|
player::{DamageSource, NetTransform, weapon::WeaponType},
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use godot::obj::Singleton;
|
|||||||
use teanet::PeerMessage;
|
use teanet::PeerMessage;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
game::{Game, GameManager, GameOption},
|
game::{Game, GameManager, opts::GameOption},
|
||||||
game_settings::GameSettingsManager,
|
game_settings::GameSettingsManager,
|
||||||
net::network_manager::{NetworkManager, Package, PeerKind},
|
net::network_manager::{NetworkManager, Package, PeerKind},
|
||||||
popup_queue::{Popup, PopupQueue},
|
popup_queue::{Popup, PopupQueue},
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use godot::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
game::{Game, GameManager, GameOption},
|
game::{Game, GameManager, opts::GameOption},
|
||||||
game_settings::{GameSettings, GameSettingsManager},
|
game_settings::{GameSettings, GameSettingsManager},
|
||||||
killbox::KillboxKind,
|
killbox::KillboxKind,
|
||||||
net::{
|
net::{
|
||||||
|
|||||||
@ -8,7 +8,7 @@ use godot::{
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
game::{Game, GameOption},
|
game::{Game, opts::GameOption},
|
||||||
killbox::KillboxKind,
|
killbox::KillboxKind,
|
||||||
net::{
|
net::{
|
||||||
network_manager::NetworkManager,
|
network_manager::NetworkManager,
|
||||||
|
|||||||
@ -8,7 +8,7 @@ use godot::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
game::{Game, GameOption},
|
game::{Game, opts::GameOption},
|
||||||
killbox::KillboxKind,
|
killbox::KillboxKind,
|
||||||
pickup::PickupKind,
|
pickup::PickupKind,
|
||||||
player::{
|
player::{
|
||||||
|
|||||||
@ -10,7 +10,10 @@ use godot::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bgm::{Music, MusicManager},
|
bgm::{Music, MusicManager},
|
||||||
game::{Game, GameManager, GameOption, GameOptionValue, GameOptions},
|
game::{
|
||||||
|
Game, GameManager,
|
||||||
|
opts::{GameOption, GameOptionValue, GameOptions},
|
||||||
|
},
|
||||||
net::network_manager::{NetworkManager, Package, PeerKind},
|
net::network_manager::{NetworkManager, Package, PeerKind},
|
||||||
ui::lobby_player_listing::LobbyPlayerListing,
|
ui::lobby_player_listing::LobbyPlayerListing,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -4,7 +4,10 @@ use godot::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
game::{Game, GameOption, GameOptions},
|
game::{
|
||||||
|
Game,
|
||||||
|
opts::{GameOption, GameOptions},
|
||||||
|
},
|
||||||
net::network_manager::NetworkManager,
|
net::network_manager::NetworkManager,
|
||||||
team_resource::TeamResource,
|
team_resource::TeamResource,
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user