Skip to content

Commit

Permalink
Remove inspector for now
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalKrill committed Feb 20, 2024
1 parent 19dfd68 commit 56dc9ae
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ serde_json = {version = "1.0.95", optional = true }
crossbeam-channel = "0.5.7"

[dev-dependencies]
bevy-inspector-egui = {version = "0.23", git = "https://github.com/Aztro-dev/bevy-inspector-egui.git" }
# bevy-inspector-egui = {version = "0.23", git = "https://github.com/Aztro-dev/bevy-inspector-egui.git" }
bevy = {version = "0.13.0", features = ["multi-threaded"]}

[target.'cfg(target_arch = "x86_64")'.dependencies]
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ use bevy::{log::LogPlugin, prelude::*, time::common_conditions::on_timer};
use bevy_mod_reqwest::*;

fn send_requests(mut client: BevyReqwest) {
let url = "https://jsonplaceholder.typicode.com/posts";
let req = client.get(url).body("some data to send").build().unwrap();
// sends the request, and ignores any response, see the other examples for other uses
client.fire_and_forget(req);
let url = "https://www.boredapi.com/api/activity";
let req = client.get(url).build().unwrap();
// will run the callback, and remove the created entity after callback
client.send(
req,
On::run(|req: Listener<ReqResponse>| {
let res = req.as_str();
bevy::log::info!("return data: {res:?}");
}),
);
}

fn main() {
Expand Down
22 changes: 10 additions & 12 deletions examples/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,27 @@ pub struct Bored {
/// [example](https://github.com/aevyrie/bevy_eventlistener/blob/main/examples/event_listeners.rs)
impl From<ListenerInput<ReqResponse>> for Bored {
fn from(value: ListenerInput<ReqResponse>) -> Self {
log::info!("headers: {:#?}", value.headers());
let s = value.deserialize_json().unwrap();
s
}
}
/// builds the http requests
fn send_requests(mut bevyreq: BevyReqwest) {
for _ in 0..100 {
let url: Url = "https://www.boredapi.com/api/activity".try_into().unwrap();
let reqwest = bevyreq.client().get(url).build().unwrap();
bevyreq.send(
// the http request
reqwest,
// what to do when the api call is complete
On::send_event::<Bored>(),
);
}
log::info!("Sending activity request");
let url: Url = "https://www.boredapi.com/api/activity".try_into().unwrap();
let reqwest = bevyreq.client().get(url).build().unwrap();
bevyreq.send(
// the http request
reqwest,
// what to do when the api call is complete
On::send_event::<Bored>(),
);
}

/// here you can do anything with the data from the events
fn handle_events(mut events: EventReader<Bored>) {
for ev in events.read() {
log::info!("{ev:?}");
log::info!("got respoonse: {ev:?}");
}
}

Expand Down
136 changes: 68 additions & 68 deletions examples/inspector.rs
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
use bevy::prelude::*;
use bevy::time::common_conditions::on_timer;
use bevy_inspector_egui::quick::WorldInspectorPlugin;
use bevy_mod_reqwest::*;
use std::time::Duration;
// use bevy::prelude::*;
// use bevy::time::common_conditions::on_timer;
// use bevy_inspector_egui::quick::WorldInspectorPlugin;
// use bevy_mod_reqwest::*;
// use std::time::Duration;

fn main() {
App::new()
.add_plugins((
DefaultPlugins,
WorldInspectorPlugin::default(),
ReqwestPlugin {
automatically_name_requests: true,
},
))
.add_systems(
Update,
send_ignored_request.run_if(on_timer(Duration::from_secs(1))),
)
.add_systems(
Update,
send_requests_that_remain.run_if(on_timer(Duration::from_secs(1))),
)
.add_systems(
Update,
(spawn_requests_with_generated_name.run_if(on_timer(Duration::from_secs(3))),),
)
.run();
}
// fn main() {
// App::new()
// .add_plugins((
// DefaultPlugins,
// WorldInspectorPlugin::default(),
// ReqwestPlugin {
// automatically_name_requests: true,
// },
// ))
// .add_systems(
// Update,
// send_ignored_request.run_if(on_timer(Duration::from_secs(1))),
// )
// .add_systems(
// Update,
// send_requests_that_remain.run_if(on_timer(Duration::from_secs(1))),
// )
// .add_systems(
// Update,
// (spawn_requests_with_generated_name.run_if(on_timer(Duration::from_secs(3))),),
// )
// .run();
// }

fn send_ignored_request(mut client: BevyReqwest) {
let url = "https://www.boredapi.com/api";
let req = client.get(url).build().unwrap();
// ignores any responses and removes the created entity
client.fire_and_forget(req);
}
// fn send_ignored_request(mut client: BevyReqwest) {
// let url = "https://www.boredapi.com/api";
// let req = client.get(url).build().unwrap();
// // ignores any responses and removes the created entity
// client.fire_and_forget(req);
// }

fn spawn_requests_with_generated_name(mut client: BevyReqwest) {
let url = "https://www.boredapi.com/api";
let req = client.get(url).build().unwrap();
// will run the callback, and remove the created entity after callback
client.send(
req,
On::run(|req: Listener<ReqResponse>| {
let res = req.as_str();
bevy::log::info!("return data: {res:?}");
}),
);
}
// fn spawn_requests_with_generated_name(mut client: BevyReqwest) {
// let url = "https://www.boredapi.com/api";
// let req = client.get(url).build().unwrap();
// // will run the callback, and remove the created entity after callback
// client.send(
// req,
// On::run(|req: Listener<ReqResponse>| {
// let res = req.as_str();
// bevy::log::info!("return data: {res:?}");
// }),
// );
// }

#[derive(Component)]
pub struct Data {
pub s: String,
}
// #[derive(Component)]
// pub struct Data {
// pub s: String,
// }

fn send_requests_that_remain(mut commands: Commands, mut client: BevyReqwest) {
let url = "https://www.boredapi.com/api/activity";
let req = client.get(url).build().unwrap();
let e = commands
.spawn(Name::new("a http request to bored api"))
.id();
// this will not automatically remove the entity after return of data, wich will leave a bunch of entities visible in the inspector
client.send_using_entity(
e,
req,
On::target_commands_mut(|ev, tc| {
let req: &ReqResponse = &ev;
let res: String = req.as_string().unwrap();
bevy::log::info!("return data: {res:?}");
tc.insert(Data { s: res.into() });
}),
);
}
// fn send_requests_that_remain(mut commands: Commands, mut client: BevyReqwest) {
// let url = "https://www.boredapi.com/api/activity";
// let req = client.get(url).build().unwrap();
// let e = commands
// .spawn(Name::new("a http request to bored api"))
// .id();
// // this will not automatically remove the entity after return of data, wich will leave a bunch of entities visible in the inspector
// client.send_using_entity(
// e,
// req,
// On::target_commands_mut(|ev, tc| {
// let req: &ReqResponse = &ev;
// let res: String = req.as_string().unwrap();
// bevy::log::info!("return data: {res:?}");
// tc.insert(Data { s: res.into() });
// }),
// );
// }
14 changes: 10 additions & 4 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ use bevy::{log::LogPlugin, prelude::*, time::common_conditions::on_timer};
use bevy_mod_reqwest::*;

fn send_requests(mut client: BevyReqwest) {
let url = "https://jsonplaceholder.typicode.com/posts";
let req = client.get(url).body("some data to send").build().unwrap();
// sends the request, and ignores any response, see the other examples for other uses
client.fire_and_forget(req);
let url = "https://www.boredapi.com/api/activity";
let req = client.get(url).build().unwrap();
// will run the callback, and remove the created entity after callback
client.send(
req,
On::run(|req: Listener<ReqResponse>| {
let res = req.as_str();
bevy::log::info!("return data: {res:?}");
}),
);
}

fn main() {
Expand Down

0 comments on commit 56dc9ae

Please sign in to comment.