-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19dfd68
commit 56dc9ae
Showing
5 changed files
with
99 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() }); | ||
// }), | ||
// ); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters