mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Persistent flags sync
This commit is contained in:
parent
ba7a2abb56
commit
e1145706e0
9 changed files with 77 additions and 2 deletions
|
@ -123,6 +123,22 @@ impl ModmanagerSettings {
|
|||
path.push("quant.ew");
|
||||
path
|
||||
}
|
||||
|
||||
pub fn get_progress(&self) -> Option<Vec<String>> {
|
||||
let flags_path = self
|
||||
.game_save_path
|
||||
.as_ref()?
|
||||
.join("save00/persistent/flags/");
|
||||
Some(
|
||||
fs::read_dir(&flags_path)
|
||||
.inspect_err(|e| warn!("Could not read progress: read_dir failed: {e}"))
|
||||
.ok()?
|
||||
.filter_map(|entry| entry.ok())
|
||||
.filter_map(|entry| entry.file_name().into_string().ok())
|
||||
.collect(),
|
||||
)
|
||||
.inspect(|progress: &Vec<String>| info!("Found {} progress entries", progress.len()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Modmanager {
|
||||
|
|
|
@ -68,6 +68,7 @@ pub struct GameSettings {
|
|||
game_mode: GameMode,
|
||||
friendly_fire: bool,
|
||||
enemy_sync_interval: u32,
|
||||
progress: Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for GameSettings {
|
||||
|
@ -85,6 +86,7 @@ impl Default for GameSettings {
|
|||
game_mode: GameMode::SharedHealth,
|
||||
friendly_fire: false,
|
||||
enemy_sync_interval: 2,
|
||||
progress: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -392,6 +394,7 @@ impl App {
|
|||
} else {
|
||||
info!("Using constant seed: {}", settings.seed);
|
||||
}
|
||||
settings.progress = self.modmanager_settings.get_progress().unwrap_or_default();
|
||||
*netman.pending_settings.lock().unwrap() = settings.clone();
|
||||
netman.accept_local.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
|
|
@ -431,6 +431,8 @@ impl NetManager {
|
|||
state.try_ws_write_option("game_mode", settings.game_mode);
|
||||
state.try_ws_write_option("friendly_fire", settings.friendly_fire);
|
||||
state.try_ws_write_option("enemy_sync_interval", settings.enemy_sync_interval);
|
||||
let progress = settings.progress.join(",");
|
||||
state.try_ws_write_option("progress", progress.as_str());
|
||||
|
||||
state.try_ws_write(ws_encode_proxy("ready", ""));
|
||||
// TODO? those are currently ignored by mod
|
||||
|
|
36
quant.ew/files/core/early_init.lua
Normal file
36
quant.ew/files/core/early_init.lua
Normal file
|
@ -0,0 +1,36 @@
|
|||
-- Early init stuff, called before main "mod" is loaded. Meaning we can append to data/scripts/init.lua
|
||||
ModLuaFileAppend("data/scripts/init.lua", "mods/quant.ew/files/resource/append/no_default_death_handling.lua")
|
||||
|
||||
-- All files that use HasFlagPersistent.
|
||||
local uses_persistent_flags = {
|
||||
"data/scripts/debug/persistent_flags_check.lua",
|
||||
"data/scripts/init.lua",
|
||||
"data/scripts/animals/boss_dragon_death.lua",
|
||||
"data/scripts/items/utility_box.lua",
|
||||
"data/scripts/items/generate_shop_item.lua",
|
||||
"data/scripts/items/make_random_card.lua",
|
||||
"data/scripts/gun/gun_actions.lua",
|
||||
"data/scripts/items/chest_random.lua",
|
||||
"data/scripts/buildings/huussi.lua",
|
||||
"data/scripts/perks/perk.lua",
|
||||
"data/scripts/buildings/teleroom.lua",
|
||||
"data/scripts/buildings/chest_light.lua",
|
||||
"data/scripts/buildings/chest_dark.lua",
|
||||
"data/scripts/item_spawnlists.lua",
|
||||
"data/scripts/magic/moon_altar_init.lua",
|
||||
"data/scripts/magic/dark_moon_altar.lua",
|
||||
"data/scripts/magic/dark_moon_altar_init.lua",
|
||||
"data/scripts/magic/amulet.lua",
|
||||
"data/scripts/magic/moon_altar.lua",
|
||||
"data/scripts/biome_modifiers.lua",
|
||||
"data/scripts/biomes/scale.lua",
|
||||
"data/scripts/biomes/mountain_tree.lua",
|
||||
"data/entities/animals/boss_alchemist/death.lua",
|
||||
"data/entities/animals/boss_pit/boss_pit_death.lua",
|
||||
"data/entities/animals/boss_limbs/boss_limbs_death.lua",
|
||||
}
|
||||
|
||||
-- Override HasFlagPersistent in each.
|
||||
for _, file in ipairs(uses_persistent_flags) do
|
||||
ModLuaFileAppend(file, "mods/quant.ew/files/system/flag_sync/append/has_flag_hook.lua")
|
||||
end
|
|
@ -96,6 +96,7 @@ function module.on_world_update_post()
|
|||
tp_button("Null altar", 14000, 7500)
|
||||
tp_button("Orb 0", 765.510, -1075.003)
|
||||
tp_button("Orb 7", 4262.749, 887.997)
|
||||
tp_button("Tree", -1901.962, -1405.003)
|
||||
end
|
||||
if imgui.CollapsingHeader("Game effects") then
|
||||
show_game_effects()
|
||||
|
|
3
quant.ew/files/system/flag_sync/append/has_flag_hook.lua
Normal file
3
quant.ew/files/system/flag_sync/append/has_flag_hook.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
function HasFlagPersistent(flag)
|
||||
return CrossCall("ew_has_flag", flag)
|
||||
end
|
13
quant.ew/files/system/flag_sync/flag_sync.lua
Normal file
13
quant.ew/files/system/flag_sync/flag_sync.lua
Normal file
|
@ -0,0 +1,13 @@
|
|||
local flag_present = {}
|
||||
|
||||
for _, flag in ipairs(util.string_split(ctx.proxy_opt.progress, ",")) do
|
||||
flag_present[flag] = true
|
||||
end
|
||||
|
||||
local function has_flag(flag)
|
||||
return flag_present[flag]
|
||||
end
|
||||
|
||||
np.CrossCallAdd("ew_has_flag", has_flag)
|
||||
|
||||
return {}
|
|
@ -93,6 +93,7 @@ local function load_modules()
|
|||
ctx.load_system("amulet_sync")
|
||||
ctx.load_system("game_effect_sync")
|
||||
ctx.load_system("orb_sync")
|
||||
ctx.load_system("flag_sync")
|
||||
-- ctx.load_system("effect_data_sync")
|
||||
end
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ local function early_init()
|
|||
ModLuaFileAppend("mods/quant.ew/files/core/early_init.lua", "data/scripts/empty.lua")
|
||||
|
||||
-- Early init stuff, called before main "mod" is loaded. Meaning we can append to data/scripts/init.lua
|
||||
dofile("mods/quant.ew/files/core/early_init.lua")
|
||||
end
|
||||
ModLuaFileAppend("data/scripts/init.lua", "mods/quant.ew/files/resource/append/no_default_death_handling.lua")
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue