mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Refactor settings system.
This commit is contained in:
parent
6ef4287197
commit
7f0a2da7a6
12 changed files with 78 additions and 39 deletions
3
Justfile
3
Justfile
|
@ -1,6 +1,9 @@
|
||||||
run:
|
run:
|
||||||
cd noita-proxy && NP_APPID=480 NP_SKIP_MOD_CHECK=1 cargo run
|
cd noita-proxy && NP_APPID=480 NP_SKIP_MOD_CHECK=1 cargo run
|
||||||
|
|
||||||
|
build:
|
||||||
|
cd noita-proxy && cargo build --release
|
||||||
|
|
||||||
run-rel:
|
run-rel:
|
||||||
cd noita-proxy && NP_APPID=480 NP_SKIP_MOD_CHECK=1 cargo run --release
|
cd noita-proxy && NP_APPID=480 NP_SKIP_MOD_CHECK=1 cargo run --release
|
||||||
|
|
||||||
|
|
2
noita-proxy/Cargo.lock
generated
2
noita-proxy/Cargo.lock
generated
|
@ -1962,7 +1962,7 @@ checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "noita-proxy"
|
name = "noita-proxy"
|
||||||
version = "0.13.8"
|
version = "0.14.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argh",
|
"argh",
|
||||||
"bincode",
|
"bincode",
|
||||||
|
|
|
@ -4,7 +4,7 @@ members = ["tangled"]
|
||||||
[package]
|
[package]
|
||||||
name = "noita-proxy"
|
name = "noita-proxy"
|
||||||
description = "Noita Entangled Worlds companion app."
|
description = "Noita Entangled Worlds companion app."
|
||||||
version = "0.13.8"
|
version = "0.14.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -16,6 +16,7 @@ connect_settings_wsv = World sync version to use:
|
||||||
connect_settings_player_tether = Player tether enabled
|
connect_settings_player_tether = Player tether enabled
|
||||||
connect_settings_player_tether_desc = Player tether: Teleports clients to host if they get far enough.
|
connect_settings_player_tether_desc = Player tether: Teleports clients to host if they get far enough.
|
||||||
connect_settings_player_tether_length = Tether length
|
connect_settings_player_tether_length = Tether length
|
||||||
|
connect_settings_item_dedup = Deduplicate (sync) items spawned by world generation.
|
||||||
connect_settings_local = Local settings
|
connect_settings_local = Local settings
|
||||||
connect_settings_autostart = Start the game automatically
|
connect_settings_autostart = Start the game automatically
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ pub struct GameSettings {
|
||||||
player_tether: bool,
|
player_tether: bool,
|
||||||
tether_length: u32,
|
tether_length: u32,
|
||||||
use_constant_seed: bool,
|
use_constant_seed: bool,
|
||||||
|
item_dedup: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for GameSettings {
|
impl Default for GameSettings {
|
||||||
|
@ -51,6 +52,7 @@ impl Default for GameSettings {
|
||||||
player_tether: false,
|
player_tether: false,
|
||||||
tether_length: 750,
|
tether_length: 750,
|
||||||
use_constant_seed: false,
|
use_constant_seed: false,
|
||||||
|
item_dedup: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -421,6 +423,7 @@ impl App {
|
||||||
Slider::new(&mut self.saved_state.game_settings.tether_length, 10..=5000)
|
Slider::new(&mut self.saved_state.game_settings.tether_length, 10..=5000)
|
||||||
.text(tr("connect_settings_player_tether_length")),
|
.text(tr("connect_settings_player_tether_length")),
|
||||||
);
|
);
|
||||||
|
ui.checkbox(&mut self.saved_state.game_settings.item_dedup, tr("connect_settings_item_dedup"));
|
||||||
|
|
||||||
heading_with_underline(ui, tr("connect_settings_local"));
|
heading_with_underline(ui, tr("connect_settings_local"));
|
||||||
ui.checkbox(
|
ui.checkbox(
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use messages::NetMsg;
|
use messages::NetMsg;
|
||||||
use omni::OmniPeerId;
|
use omni::OmniPeerId;
|
||||||
|
use proxy_opt::ProxyOpt;
|
||||||
use socket2::{Domain, Socket, Type};
|
use socket2::{Domain, Socket, Type};
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
|
@ -20,6 +21,7 @@ use tungstenite::{accept, WebSocket};
|
||||||
use crate::GameSettings;
|
use crate::GameSettings;
|
||||||
|
|
||||||
pub mod messages;
|
pub mod messages;
|
||||||
|
mod proxy_opt;
|
||||||
pub mod steam_networking;
|
pub mod steam_networking;
|
||||||
pub mod world;
|
pub mod world;
|
||||||
|
|
||||||
|
@ -30,13 +32,6 @@ pub(crate) fn ws_encode_proxy(key: &'static str, value: impl Display) -> tungste
|
||||||
tungstenite::Message::Binary(buf)
|
tungstenite::Message::Binary(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn ws_encode_proxy_opt(key: &'static str, value: impl Display) -> tungstenite::Message {
|
|
||||||
let mut buf = Vec::new();
|
|
||||||
buf.push(2);
|
|
||||||
write!(buf, "proxy_opt {} {}", key, value).unwrap();
|
|
||||||
tungstenite::Message::Binary(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn ws_encode_proxy_bin(key: u8, data: &[u8]) -> tungstenite::Message {
|
pub fn ws_encode_proxy_bin(key: u8, data: &[u8]) -> tungstenite::Message {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
buf.push(3);
|
buf.push(3);
|
||||||
|
@ -67,6 +62,13 @@ impl NetInnerState {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub(crate) fn try_ws_write_option(&mut self, key: &str, value: impl ProxyOpt) {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
buf.push(2);
|
||||||
|
value.write_opt(&mut buf, key);
|
||||||
|
let message = tungstenite::Message::Binary(buf);
|
||||||
|
self.try_ws_write(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod omni;
|
pub mod omni;
|
||||||
|
@ -276,20 +278,15 @@ impl NetManager {
|
||||||
));
|
));
|
||||||
if let Some(nickname) = &self.init_settings.my_nickname {
|
if let Some(nickname) = &self.init_settings.my_nickname {
|
||||||
info!("Chosen nickname: {}", nickname);
|
info!("Chosen nickname: {}", nickname);
|
||||||
state.try_ws_write(ws_encode_proxy("name", nickname));
|
state.try_ws_write_option("name", nickname.as_str());
|
||||||
} else {
|
} else {
|
||||||
info!("No nickname chosen");
|
info!("No nickname chosen");
|
||||||
}
|
}
|
||||||
state.try_ws_write(ws_encode_proxy(
|
state.try_ws_write_option("debug", settings.debug_mode);
|
||||||
"debug",
|
state.try_ws_write_option("world_sync_version", settings.world_sync_version);
|
||||||
if settings.debug_mode { "true" } else { "false" },
|
state.try_ws_write_option("player_tether", settings.player_tether);
|
||||||
));
|
state.try_ws_write_option("tether_length", settings.tether_length);
|
||||||
state.try_ws_write(ws_encode_proxy_opt(
|
state.try_ws_write_option("item_dedup", settings.item_dedup);
|
||||||
"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_opt("tether_length", settings.tether_length));
|
|
||||||
|
|
||||||
state.try_ws_write(ws_encode_proxy("ready", ""));
|
state.try_ws_write(ws_encode_proxy("ready", ""));
|
||||||
// TODO? those are currently ignored by mod
|
// TODO? those are currently ignored by mod
|
||||||
|
|
30
noita-proxy/src/net/proxy_opt.rs
Normal file
30
noita-proxy/src/net/proxy_opt.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
|
/// Trait that allows to pass value to mod as proxy options.
|
||||||
|
pub(crate) trait ProxyOpt {
|
||||||
|
fn write_opt(self, buf: &mut Vec<u8>, key: &str);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProxyOpt for bool {
|
||||||
|
fn write_opt(self, buf: &mut Vec<u8>, key: &str) {
|
||||||
|
write!(
|
||||||
|
buf,
|
||||||
|
"proxy_opt_bool {} {}",
|
||||||
|
key,
|
||||||
|
if self { "true" } else { "false" }
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProxyOpt for u32 {
|
||||||
|
fn write_opt(self, buf: &mut Vec<u8>, key: &str) {
|
||||||
|
write!(buf, "proxy_opt_num {} {}", key, self).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProxyOpt for &str {
|
||||||
|
fn write_opt(self, buf: &mut Vec<u8>, key: &str) {
|
||||||
|
write!(buf, "proxy_opt {} {}", key, self).unwrap();
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,10 +40,20 @@ function net_handling.proxy.name(_, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
function net_handling.proxy.proxy_opt(_, key, value)
|
function net_handling.proxy.proxy_opt(_, key, value)
|
||||||
print("Proxy opt: "..key.." = "..value)
|
print("Proxy opt [str]: "..key.." = "..value)
|
||||||
ctx.proxy_opt[key] = value
|
ctx.proxy_opt[key] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function net_handling.proxy.proxy_opt_num(_, key, value)
|
||||||
|
print("Proxy opt [num]: "..key.." = "..value)
|
||||||
|
ctx.proxy_opt[key] = tonumber(value)
|
||||||
|
end
|
||||||
|
|
||||||
|
function net_handling.proxy.proxy_opt_bool(_, key, value)
|
||||||
|
print("Proxy opt [bool]: "..key.." = "..value)
|
||||||
|
ctx.proxy_opt[key] = value == "true"
|
||||||
|
end
|
||||||
|
|
||||||
function net_handling.mod.inventory(peer_id, inventory_state)
|
function net_handling.mod.inventory(peer_id, inventory_state)
|
||||||
if not player_fns.peer_has_player(peer_id) then
|
if not player_fns.peer_has_player(peer_id) then
|
||||||
return
|
return
|
||||||
|
|
|
@ -43,11 +43,9 @@ function module.on_local_player_spawn(my_player)
|
||||||
end
|
end
|
||||||
|
|
||||||
function module.on_world_update_host()
|
function module.on_world_update_host()
|
||||||
if ctx.debug then
|
local hp, max_hp = util.get_ent_health(ctx.my_player.entity)
|
||||||
local hp, max_hp = util.get_ent_health(ctx.my_player.entity)
|
if hp < max_hp / 2 then
|
||||||
if hp < max_hp / 2 then
|
-- util.set_ent_health(ctx.my_player.entity, {max_hp, max_hp})
|
||||||
-- util.set_ent_health(ctx.my_player.entity, {max_hp, max_hp})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ local ctx = dofile_once("mods/quant.ew/files/src/ctx.lua")
|
||||||
local net = dofile_once("mods/quant.ew/files/src/net.lua")
|
local net = dofile_once("mods/quant.ew/files/src/net.lua")
|
||||||
local player_fns = dofile_once("mods/quant.ew/files/src/player_fns.lua")
|
local player_fns = dofile_once("mods/quant.ew/files/src/player_fns.lua")
|
||||||
|
|
||||||
local tether_length = tonumber(ctx.proxy_opt.tether_length)
|
local tether_length = ctx.proxy_opt.tether_length
|
||||||
local tether_length_2 = tether_length + 200
|
local tether_length_2 = tether_length + 200
|
||||||
|
|
||||||
local module = {}
|
local module = {}
|
||||||
|
|
|
@ -9,19 +9,16 @@ local module = {}
|
||||||
ModLuaFileAppend("data/scripts/director_helpers.lua", "mods/quant.ew/files/src/system/spawn_hooks/append/director_helpers.lua")
|
ModLuaFileAppend("data/scripts/director_helpers.lua", "mods/quant.ew/files/src/system/spawn_hooks/append/director_helpers.lua")
|
||||||
ModLuaFileAppend("data/scripts/item_spawnlists.lua", "mods/quant.ew/files/src/system/spawn_hooks/append/item_spawnlist.lua")
|
ModLuaFileAppend("data/scripts/item_spawnlists.lua", "mods/quant.ew/files/src/system/spawn_hooks/append/item_spawnlist.lua")
|
||||||
|
|
||||||
local marked = {}
|
|
||||||
-- This entity needs to be synced by item_sync
|
-- This entity needs to be synced by item_sync
|
||||||
local function is_sync_item(ent_path)
|
local function is_sync_item(ent_path)
|
||||||
|
-- No item needs to be synced when this option is off.
|
||||||
local start = "data/entities/items/"
|
if not ctx.proxy_opt.item_dedup then
|
||||||
if string.sub(ent_path, 1, #start) ~= start then
|
return false
|
||||||
if marked[ent_path] == nil then
|
end
|
||||||
marked[ent_path] = true
|
local start = "data/entities/items/"
|
||||||
print("skip "..ent_path)
|
if string.sub(ent_path, 1, #start) ~= start then
|
||||||
end
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
print(ent_path)
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ local function load_modules()
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/damage/sync.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/damage/sync.lua")
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/nickname.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/nickname.lua")
|
||||||
|
|
||||||
if ctx.debug then
|
if ctx.proxy_opt.debug then
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/debug.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/debug.lua")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ local function load_modules()
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/weather_sync.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/weather_sync.lua")
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/polymorph/sync.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/polymorph/sync.lua")
|
||||||
|
|
||||||
if ctx.proxy_opt.world_sync_version == "1" then
|
if ctx.proxy_opt.world_sync_version == 1 then
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/world_sync_v1.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/world_sync_v1.lua")
|
||||||
else
|
else
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/world_sync_v2.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/world_sync_v2.lua")
|
||||||
|
@ -54,7 +54,7 @@ local function load_modules()
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/proxy_info.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/proxy_info.lua")
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/perk_patches/init.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/perk_patches/init.lua")
|
||||||
|
|
||||||
if ctx.proxy_opt.player_tether == "true" then
|
if ctx.proxy_opt.player_tether then
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/player_tether/player_tether.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/player_tether/player_tether.lua")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue