Skip to content

Commit

Permalink
feat: public parse fn
Browse files Browse the repository at this point in the history
  • Loading branch information
mosure committed Jan 26, 2024
1 parent eb392c1 commit 816ab03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_args"
description = "bevy plugin to parse command line arguments and URL query parameters"
version = "1.1.0"
version = "1.2.0"
edition = "2021"
authors = ["mosure <[email protected]>"]
license = "MIT"
Expand Down
19 changes: 11 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ impl<R: Default + Parser + Resource + Serialize + for<'a> Deserialize<'a>> Plugi
fn build(&self, app: &mut App) {
app.insert_resource(R::default());

app.add_systems(PreStartup, parse_args::<R>);
app.add_systems(PreStartup, parse_args_system::<R>);
}
}


fn parse_args<R: Resource + Parser + Serialize + for<'a> Deserialize<'a>>(
mut args: ResMut<R>,
) {
pub fn parse_args<R: Resource + Parser + Serialize + for<'a> Deserialize<'a>>() -> R {
#[cfg(target_arch = "wasm32")]
{
let window = web_sys::window().unwrap();
Expand All @@ -47,11 +45,16 @@ fn parse_args<R: Resource + Parser + Serialize + for<'a> Deserialize<'a>>(

let query_string = search.trim_start_matches('?');

*args = from_str(query_string).unwrap();
return from_str(query_string).unwrap();
}

#[cfg(not(target_arch = "wasm32"))]
{
*args = R::parse();
}
R::parse()
}


fn parse_args_system<R: Resource + Parser + Serialize + for<'a> Deserialize<'a>>(
mut args: ResMut<R>,
) {
*args = parse_args::<R>();
}

0 comments on commit 816ab03

Please sign in to comment.