use bevy::prelude::*;
use tokio::sync::mpsc::{UnboundedReceiver, unbounded_channel};
use super::{DevtoolsConfig, DevtoolsPlugin};
use crate::bridge::OutboundResource;
use crate::protocol::outbound::Outbound;
use crate::reconcile::OpApplyStats;
pub(super) fn test_app(config: DevtoolsConfig) -> (App, UnboundedReceiver<Outbound>) {
let mut app = App::new();
app.insert_non_send(crate::diag::test_lock());
app.add_plugins(MinimalPlugins);
app.init_resource::<ButtonInput<KeyCode>>();
app.init_resource::<ButtonInput<MouseButton>>();
app.init_resource::<OpApplyStats>();
let (tx, rx) = unbounded_channel::<Outbound>();
app.insert_resource(OutboundResource(tx));
app.add_plugins(DevtoolsPlugin::new(config));
(app, rx)
}
pub(super) fn drain_events(
rx: &mut UnboundedReceiver<Outbound>,
) -> Vec<(String, serde_json::Value)> {
let mut out = Vec::new();
while let Ok(msg) = rx.try_recv() {
if let Outbound::Event { name, value } = msg {
out.push((name, value));
}
}
out
}