From 2399ca47a7cfae8fe6eac6229ba933c3d95d4e26 Mon Sep 17 00:00:00 2001 From: bgkillas Date: Fri, 17 Jan 2025 14:53:22 -0500 Subject: [PATCH] fix an edge case with laser logic, expose some more information --- ewext/noita_api/src/serialize.rs | 2 +- ewext/src/lib.rs | 10 +++++++- ewext/src/modules/entity_sync/diff_model.rs | 28 +++++++++++++-------- quant.ew/files/core/player_fns.lua | 3 +-- quant.ew/init.lua | 3 +-- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/ewext/noita_api/src/serialize.rs b/ewext/noita_api/src/serialize.rs index 5137bb67..a151c608 100644 --- a/ewext/noita_api/src/serialize.rs +++ b/ewext/noita_api/src/serialize.rs @@ -40,4 +40,4 @@ pub fn deserialize_entity(entity_data: &[u8], x: f32, y: f32) -> eyre::Result c_int { let (peer_id, entity): (Cow<'_, str>, Option) = LuaGetValue::get(lua, -1)?; let peer_id = PeerId::from_hex(&peer_id)?; let entity = entity.ok_or_eyre("Expected a valid entity")?; + if entity + .iter_all_components_of_type_including_disabled::(None)? + .all(|var| var.name().unwrap_or("".into()) != "ew_peer_id") + { + let var = entity.add_component::()?; + var.set_name("ew_peer_id".into())?; + var.set_value_string(peer_id.0.to_string().into())?; + } ExtState::with_global(|state| { state.player_entity_map.insert(peer_id, entity); Ok(()) diff --git a/ewext/src/modules/entity_sync/diff_model.rs b/ewext/src/modules/entity_sync/diff_model.rs index 0c260264..52ef88f4 100644 --- a/ewext/src/modules/entity_sync/diff_model.rs +++ b/ewext/src/modules/entity_sync/diff_model.rs @@ -283,16 +283,7 @@ impl LocalDiffModelTracker { { let ai = entity.get_first_component::(None)?; if let Some(target) = ai.m_greatest_prey()? { - game_print(target.0.to_string()); - if let Some(var) = target - .iter_all_components_of_type_including_disabled::( - None, - )? - .find(|var| var.name().unwrap_or("".into()) == "ew_peer_id") - { - game_print(var.value_string()?); - info.laser = Some(PeerId::from_hex(&var.value_string()?)?) - } + info.laser = ctx.player_map.get_by_right(&target).copied() } } @@ -418,10 +409,18 @@ impl LocalDiffModel { "mods/quant.ew/files/system/entity_sync_helper/death_notify.lua".into(), ) })?; + entity + .iter_all_components_of_type_including_disabled::(None)? + .for_each(|var| { + if var.name().unwrap_or("".into()) == "ew_gid_lid" { + let _ = entity.remove_component(*var); + } + }); let var = entity.add_component::()?; var.set_name("ew_gid_lid".into())?; var.set_value_string(gid.0.to_string().into())?; var.set_value_int(i32::from_ne_bytes(lid.0.to_ne_bytes()))?; + var.set_value_bool(true)?; if entity .try_get_first_component::(None)? @@ -1089,7 +1088,6 @@ impl RemoteDiffModel { laser }; if let Some(ent) = ctx.player_map.get_by_left(&peer) { - game_print(ent.0.to_string()); let (x, y) = entity.position()?; let (tx, ty) = ent.position()?; if !raytrace_platforms(x as f64, y as f64, tx as f64, ty as f64)?.0 { @@ -1223,12 +1221,20 @@ impl RemoteDiffModel { } } + entity + .iter_all_components_of_type_including_disabled::(None)? + .for_each(|var| { + if var.name().unwrap_or("".into()) == "ew_gid_lid" { + let _ = entity.remove_component(*var); + } + }); let var = entity.add_component::()?; var.set_name("ew_gid_lid".into())?; if let Some(gid) = self.lid_to_gid.get(&lid) { var.set_value_string(gid.0.to_string().into())?; } var.set_value_int(i32::from_ne_bytes(lid.0.to_ne_bytes()))?; + var.set_value_bool(false)?; Ok(()) } diff --git a/quant.ew/files/core/player_fns.lua b/quant.ew/files/core/player_fns.lua index 06dfdbcf..7cfbbfa4 100644 --- a/quant.ew/files/core/player_fns.lua +++ b/quant.ew/files/core/player_fns.lua @@ -496,7 +496,6 @@ function player_fns.spawn_player_for(peer_id, x, y, existing_playerdata) print("Spawning player for " .. peer_id) local new = EntityLoad("mods/quant.ew/files/system/player/tmp/" .. peer_id .. "_base.xml", x, y) util.make_ephemerial(new) - EntityAddComponent2(new, "VariableStorageComponent", { name = "ew_peer_id", value_string = peer_id }) LoadGameEffectEntityTo(new, "mods/quant.ew/files/system/spectate/no_tinker.xml") for _, child in ipairs(EntityGetAllChildren(new) or {}) do @@ -677,4 +676,4 @@ function player_fns.make_fire_data(special_seed, player_data, mana) end end -return player_fns +return player_fns \ No newline at end of file diff --git a/quant.ew/init.lua b/quant.ew/init.lua index ff485059..85530e25 100755 --- a/quant.ew/init.lua +++ b/quant.ew/init.lua @@ -369,7 +369,6 @@ function OnPlayerSpawned(player_entity) -- This runs when player entity has been ctx.player_data_by_local_entity[player_entity] = my_player ctx.ready = true ctx.my_player = my_player - EntityAddComponent2(player_entity, "VariableStorageComponent", { name = "ew_peer_id", value_string = ctx.my_id }) EntityAddTag(player_entity, "ew_peer") @@ -648,4 +647,4 @@ end function OnPlayerDied(player_entity) ctx.hook.on_player_died(player_entity) print("player died") -end +end \ No newline at end of file