Add player tether option to proxy.

This commit is contained in:
IQuant 2024-07-02 00:45:30 +03:00
parent 56c9e376ef
commit 87f20f6ce0
4 changed files with 36 additions and 16 deletions

View file

@ -13,6 +13,7 @@ connect_settings_debug_en = Debug/cheat mode
connect_settings_debug_fixed_seed = Use fixed seed
connect_settings_seed = Seed:
connect_settings_wsv = World sync version to use:
connect_settings_player_tether = Player tether
lang_picker = Choose a language

View file

@ -11,6 +11,7 @@ connect_settings_debug_en = Подрубить читы
connect_settings_debug_fixed_seed = Фиксированный сид мира
connect_settings_seed = Сид:
connect_settings_wsv = Версия синхронизатора мира:
connect_settings_player_tether = Предел расстояния до хоста
lang_picker = Выберите язык

View file

@ -29,11 +29,23 @@ pub mod releases;
mod self_update;
pub mod steam_helper;
#[derive(Debug, Decode, Encode, Clone)]
#[derive(Debug, Decode, Encode, Clone, Serialize, Deserialize)]
pub struct GameSettings {
seed: u64,
debug_mode: bool,
world_sync_version: u32,
player_tether: bool,
}
impl Default for GameSettings {
fn default() -> Self {
GameSettings {
seed: 0,
debug_mode: false,
world_sync_version: 2,
player_tether: false,
}
}
}
enum AppState {
@ -48,26 +60,24 @@ enum AppState {
#[derive(Debug, Serialize, Deserialize)]
struct AppSavedState {
addr: String,
debug_mode: bool,
use_constant_seed: bool,
nickname: Option<String>,
times_started: u32,
world_sync_version: u32,
lang_id: Option<LanguageIdentifier>,
constant_seed: u64,
game_settings: GameSettings,
}
impl Default for AppSavedState {
fn default() -> Self {
Self {
addr: "127.0.0.1:5123".to_string(),
debug_mode: false,
use_constant_seed: false,
nickname: None,
times_started: 0,
world_sync_version: 2,
lang_id: None,
constant_seed: 0,
game_settings: GameSettings::default(),
}
}
}
@ -163,8 +173,7 @@ impl App {
fn set_netman_settings(&mut self, netman: &Arc<net::NetManager>) {
let mut settings = netman.settings.lock().unwrap();
settings.debug_mode = self.saved_state.debug_mode;
settings.world_sync_version = self.saved_state.world_sync_version;
*settings = self.saved_state.game_settings.clone();
if !self.saved_state.use_constant_seed {
settings.seed = rand::random();
} else {
@ -273,7 +282,7 @@ impl App {
ui.label(tr("connect_settings_debug"));
ui.checkbox(
&mut self.saved_state.debug_mode,
&mut self.saved_state.game_settings.debug_mode,
tr("connect_settings_debug_en"),
);
ui.checkbox(
@ -290,9 +299,22 @@ impl App {
ui.label(tr("connect_settings_wsv"));
ui.horizontal(|ui| {
ui.radio_value(&mut self.saved_state.world_sync_version, 1, "v1");
ui.radio_value(&mut self.saved_state.world_sync_version, 2, "v2");
ui.radio_value(
&mut self.saved_state.game_settings.world_sync_version,
1,
"v1",
);
ui.radio_value(
&mut self.saved_state.game_settings.world_sync_version,
2,
"v2",
);
});
ui.checkbox(
&mut self.saved_state.game_settings.player_tether,
tr("connect_settings_player_tether"),
)
});
});
ui.allocate_ui_at_rect(steam_connect_rect.shrink(group_shrink), |ui| {

View file

@ -91,12 +91,7 @@ impl NetManager {
pub fn new(peer: omni::PeerVariant, init: NetManagerInit) -> Arc<Self> {
Self {
peer,
settings: Mutex::new(GameSettings {
// seed: 1663107061,
seed: 1663107066,
debug_mode: false,
world_sync_version: 1,
}),
settings: Mutex::new(GameSettings::default()),
continue_running: AtomicBool::new(true),
accept_local: AtomicBool::new(false),
local_connected: AtomicBool::new(false),
@ -291,6 +286,7 @@ impl NetManager {
"world_sync_version",
settings.world_sync_version,
));
state.try_ws_write(ws_encode_proxy_opt("player_tether", settings.player_tether));
state.try_ws_write(ws_encode_proxy("ready", ""));
// TODO? those are currently ignored by mod