The session UI panel was not updating when networking started via control socket because poll_engine_events used commands.insert_resource which queued updates until end of schedule. The UI could run before the command was applied. Fixed by: - Initialize CurrentSession at startup in offline state (session.rs) - Use direct ResMut mutation in poll_engine_events (engine_bridge.rs) - Check session.state instead of resource existence (session_ui.rs) This ensures Bevy's change detection triggers immediately when engine events update the session state. Refs #131, #132 Signed-off-by: Sienna Meridian Satterwhite <sienna@r3t.io>
43 lines
1.6 KiB
Rust
43 lines
1.6 KiB
Rust
//! App-level offline resource management
|
|
//!
|
|
//! Sets up vector clock and networking resources. Sessions are created later
|
|
//! when the user starts networking.
|
|
|
|
use bevy::prelude::*;
|
|
use libmarathon::{
|
|
networking::{
|
|
CurrentSession, EntityLockRegistry, NetworkEntityMap, NodeVectorClock, Session, VectorClock,
|
|
},
|
|
};
|
|
use uuid::Uuid;
|
|
|
|
/// Initialize offline resources on app startup
|
|
///
|
|
/// This sets up the vector clock and networking-related resources.
|
|
/// Creates an offline CurrentSession that will be updated when networking starts.
|
|
pub fn initialize_offline_resources(world: &mut World) {
|
|
info!("Initializing offline resources...");
|
|
|
|
// Create node ID (persists for this app instance)
|
|
let node_id = Uuid::new_v4();
|
|
info!("Node ID: {}", node_id);
|
|
|
|
// Insert vector clock resource (always available, offline or online)
|
|
world.insert_resource(NodeVectorClock {
|
|
node_id,
|
|
clock: VectorClock::new(),
|
|
});
|
|
|
|
// Insert networking resources (available from startup, even before networking starts)
|
|
world.insert_resource(NetworkEntityMap::default());
|
|
world.insert_resource(EntityLockRegistry::default());
|
|
|
|
// Create offline session (will be updated when networking starts)
|
|
// This ensures CurrentSession resource always exists for UI binding
|
|
let offline_session_id = libmarathon::networking::SessionId::new();
|
|
let offline_session = Session::new(offline_session_id);
|
|
world.insert_resource(CurrentSession::new(offline_session, VectorClock::new()));
|
|
|
|
info!("Offline resources initialized (vector clock ready, session created in offline state)");
|
|
}
|