mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
WIP
This commit is contained in:
parent
0170acb460
commit
f14a4962d0
@ -84,6 +84,7 @@ pub enum ChatCommand {
|
||||
Waypoint,
|
||||
Whitelist,
|
||||
World,
|
||||
DayCycleSpeed,
|
||||
}
|
||||
|
||||
// Thank you for keeping this sorted alphabetically :-)
|
||||
@ -131,6 +132,7 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[
|
||||
ChatCommand::Sudo,
|
||||
ChatCommand::Tell,
|
||||
ChatCommand::Time,
|
||||
ChatCommand::DayCycleSpeed,
|
||||
ChatCommand::Tp,
|
||||
ChatCommand::Unban,
|
||||
ChatCommand::Version,
|
||||
@ -146,7 +148,7 @@ lazy_static! {
|
||||
('r', ChatCommand::Region),
|
||||
('s', ChatCommand::Say),
|
||||
('t', ChatCommand::Tell),
|
||||
('w', ChatCommand::World),
|
||||
('w', ChatCommand::World),
|
||||
].iter().cloned().collect();
|
||||
|
||||
static ref ALIGNMENTS: Vec<String> = vec!["wild", "enemy", "npc", "pet"]
|
||||
@ -385,6 +387,9 @@ impl ChatCommand {
|
||||
ChatCommand::SetMotd => {
|
||||
cmd(vec![Message(Optional)], "Set the server description", Admin)
|
||||
},
|
||||
ChatCommand::DayCycleSpeed => {
|
||||
cmd(vec![Message(Optional)], "Set the number of days passing per hour", Admin)
|
||||
},
|
||||
ChatCommand::SkillPoint => cmd(
|
||||
vec![
|
||||
Enum("skill tree", SKILL_TREES.clone(), Required),
|
||||
@ -497,6 +502,7 @@ impl ChatCommand {
|
||||
ChatCommand::Waypoint => "waypoint",
|
||||
ChatCommand::Whitelist => "whitelist",
|
||||
ChatCommand::World => "world",
|
||||
ChatCommand::DayCycleSpeed => "days_per_hour",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use editable::EditableSetting;
|
||||
|
||||
/// A resource that stores the time of day.
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, Default)]
|
||||
@ -8,6 +9,10 @@ pub struct TimeOfDay(pub f64);
|
||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
|
||||
pub struct Time(pub f64);
|
||||
|
||||
// A resource that stores the ingame days per real life hour.
|
||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
|
||||
pub struct DayCycleSpeed(pub f64);
|
||||
|
||||
/// A resource that stores the time since the previous tick.
|
||||
#[derive(Default)]
|
||||
pub struct DeltaTime(pub f32);
|
||||
|
@ -6,7 +6,7 @@ use common::{
|
||||
comp,
|
||||
event::{EventBus, LocalEvent, ServerEvent},
|
||||
region::RegionMap,
|
||||
resources::{DeltaTime, GameMode, Time, TimeOfDay},
|
||||
resources::{DeltaTime, GameMode, Time, TimeOfDay, DayCycleSpeed},
|
||||
terrain::{Block, TerrainChunk, TerrainGrid},
|
||||
time::DayPeriod,
|
||||
trade::Trades,
|
||||
@ -414,7 +414,7 @@ impl State {
|
||||
) {
|
||||
span!(_guard, "tick", "State::tick");
|
||||
// Change the time accordingly.
|
||||
self.ecs.write_resource::<TimeOfDay>().0 += dt.as_secs_f64() * DAY_CYCLE_FACTOR;
|
||||
self.ecs.write_resource::<TimeOfDay>().0 += dt.as_secs_f64() * self.ecs.read_resource::<DayCycleSpeed>().0;
|
||||
self.ecs.write_resource::<Time>().0 += dt.as_secs_f64();
|
||||
|
||||
// Update delta time.
|
||||
|
@ -119,6 +119,7 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler {
|
||||
ChatCommand::Sudo => handle_sudo,
|
||||
ChatCommand::Tell => handle_tell,
|
||||
ChatCommand::Time => handle_time,
|
||||
ChatCommand::DayCycleSpeed => handle_day_cycle_speed,
|
||||
ChatCommand::Tp => handle_tp,
|
||||
ChatCommand::Unban => handle_unban,
|
||||
ChatCommand::Version => handle_version,
|
||||
@ -505,6 +506,43 @@ fn handle_kill(
|
||||
.get_mut(target)
|
||||
.map(|mut h| h.set_to(0, reason));
|
||||
}
|
||||
fn handle_day_cycle_speed(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
_target: EcsEntity,
|
||||
args: String,
|
||||
action: &ChatCommand,
|
||||
) {
|
||||
let data_dir = server.data_dir();
|
||||
match scan_fmt!(&args, &action.arg_fmt(), f64) {
|
||||
Ok(factor) => {
|
||||
if factor > 0.0 {
|
||||
server
|
||||
.editable_settings_mut()
|
||||
.day_cycle_speed
|
||||
.edit(data_dir.as_ref(), |d| **d = factor.clone());
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(
|
||||
ChatType::CommandError,
|
||||
format!("Daytime cycle speed set to {}", factor),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(ChatType::CommandError, "The daytime cycle factor can't be 0!"),
|
||||
);
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(ChatType::CommandError, "Specify a valid daytime cycle factor!"),
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_time(
|
||||
server: &mut Server,
|
||||
|
@ -15,6 +15,7 @@ use std::{
|
||||
};
|
||||
use tracing::{error, warn};
|
||||
use world::sim::FileOpts;
|
||||
use common::resources::DayCycleSpeed;
|
||||
|
||||
const DEFAULT_WORLD_SEED: u32 = 59686;
|
||||
const CONFIG_DIR: &str = "server_config";
|
||||
@ -35,6 +36,7 @@ pub struct Settings {
|
||||
//pub pvp_enabled: bool,
|
||||
pub server_name: String,
|
||||
pub start_time: f64,
|
||||
pub day_cycle_speed: f64,
|
||||
/// When set to None, loads the default map file (if available); otherwise,
|
||||
/// uses the value of the file options to decide how to proceed.
|
||||
pub map_file: Option<FileOpts>,
|
||||
@ -54,6 +56,7 @@ impl Default for Settings {
|
||||
server_name: "Veloren Alpha".into(),
|
||||
max_players: 100,
|
||||
start_time: 9.0 * 3600.0,
|
||||
day_cycle_speed: 1.0,
|
||||
map_file: None,
|
||||
max_view_distance: Some(30),
|
||||
banned_words_files: Vec::new(),
|
||||
@ -134,6 +137,7 @@ impl Settings {
|
||||
server_name: "Singleplayer".to_owned(),
|
||||
max_players: 100,
|
||||
start_time: 9.0 * 3600.0,
|
||||
day_cycle_speed: 48.0,
|
||||
max_view_distance: None,
|
||||
client_timeout: Duration::from_secs(180),
|
||||
..load // Fill in remaining fields from server_settings.ron.
|
||||
@ -174,6 +178,10 @@ impl Default for ServerDescription {
|
||||
fn default() -> Self { Self("This is the best Veloren server".into()) }
|
||||
}
|
||||
|
||||
/*#[derive(Deserialize, Serialize, Default)]
|
||||
#[serde(transparent)]
|
||||
pub struct DayCycleSpeed(f64);*/
|
||||
|
||||
#[derive(Deserialize, Serialize, Default)]
|
||||
#[serde(transparent)]
|
||||
pub struct Admins(HashSet<Uuid>);
|
||||
@ -183,6 +191,7 @@ pub struct EditableSettings {
|
||||
pub whitelist: Whitelist,
|
||||
pub banlist: Banlist,
|
||||
pub server_description: ServerDescription,
|
||||
pub day_cycle_speed: DayCycleSpeed,
|
||||
pub admins: Admins,
|
||||
}
|
||||
|
||||
@ -192,6 +201,7 @@ impl EditableSettings {
|
||||
whitelist: Whitelist::load(data_dir),
|
||||
banlist: Banlist::load(data_dir),
|
||||
server_description: ServerDescription::load(data_dir),
|
||||
day_cycle_speed: DayCycleSpeed::load(data_dir),
|
||||
admins: Admins::load(data_dir),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user