Skip to content

Commit

Permalink
Format and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Leinnan committed Mar 11, 2024
1 parent 22981f0 commit 77dfae7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 34 deletions.
72 changes: 39 additions & 33 deletions bevy_forge/src/beam/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ pub struct BeamContext {

impl BeamContext {
pub fn id(&self) -> Option<i64> {
match &self.user {
Some(user_view) => Some(user_view.id),
None => None,
}
self.user.as_ref().map(|view| view.id)
}
}

Expand Down Expand Up @@ -197,7 +194,7 @@ pub fn save_user_info(

pub fn update_user_info(
mut ev: EventReader<PostTokenEvent>,
mut beam: Option<ResMut<BeamContext>>,
beam: Option<ResMut<BeamContext>>,
mut pkv: ResMut<PkvStore>,
) {
let Some(mut beam) = beam else {
Expand Down Expand Up @@ -251,15 +248,49 @@ pub fn handle_inventory_get(
}
}

pub fn handle_accounts_callbacks(
pub fn handle_token_callbacks(
mut get_token_events: EventReader<GetTokenEvent>,
mut post_token_events: EventReader<PostTokenEvent>,
beam: Option<ResMut<BeamContext>>,
mut commands: Commands,
) {
let Some(mut beam) = beam else {
return;
};
for event in get_token_events.read() {
debug!("GetTokenEvent: {:#?}", event);
match &**event {
Ok(data) => {
beam.token.as_mut().unwrap().access_token = Some(data.token.clone());
commands.beam_get_inventory(Some("currency.coins,items.AiItemContent".to_owned()));
commands.beam_get_user_info();
}
Err(_) => {
let token = beam.token.as_ref().unwrap();
commands.beam_post_token(token.refresh_token.clone().unwrap());
}
}
}
for event in post_token_events.read() {
debug!("PostTokenEvent: {:#?}", event);
match &**event {
Ok(data) => {
beam.token = Some(TokenStorage::from_token_response(data));
commands.beam_get_inventory(Some("currency.coins,items.AiItemContent".to_owned()));
commands.beam_get_user_info();
}
Err(_) => {}
}
}
}

pub fn handle_accounts_callbacks(
mut get_user_event: EventReader<GetAccountMeCompletedEvent>,
mut attach_third_party_event: EventReader<AttachFederatedIdentityCompletedEvent>,
beam: Option<ResMut<BeamContext>>,
external_identity: Option<Res<BeamExternalIdentityConfig>>,
mut commands: Commands,
mut next_state: ResMut<NextState<super::state::BeamableInitStatus>>,
beam: Option<ResMut<BeamContext>>,
mut commands: Commands,
) {
let Some(mut beam) = beam else {
return;
Expand Down Expand Up @@ -292,29 +323,4 @@ pub fn handle_accounts_callbacks(
next_state.set(super::state::BeamableInitStatus::FullyInitialized);
}
}
for event in get_token_events.read() {
debug!("GetTokenEvent: {:#?}", event);
match &**event {
Ok(data) => {
beam.token.as_mut().unwrap().access_token = Some(data.token.clone());
commands.beam_get_inventory(Some("currency.coins,items.AiItemContent".to_owned()));
commands.beam_get_user_info();
}
Err(_) => {
let token = beam.token.as_ref().clone().unwrap();
commands.beam_post_token(token.refresh_token.clone().unwrap());
}
}
}
for event in post_token_events.read() {
debug!("PostTokenEvent: {:#?}", event);
match &**event {
Ok(data) => {
beam.token = Some(TokenStorage::from_token_response(data));
commands.beam_get_inventory(Some("currency.coins,items.AiItemContent".to_owned()));
commands.beam_get_user_info();
}
Err(_) => {}
}
}
}
1 change: 1 addition & 0 deletions bevy_forge/src/beam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl Plugin for BeamPlugin {
Update,
(
context::handle_accounts_callbacks,
context::handle_token_callbacks,
context::handle_inventory_get,
context::update_user_info,
),
Expand Down
2 changes: 1 addition & 1 deletion bevy_forge/src/game/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Plugin for GamePlugin {
}
}

fn hide_items(mut q: Query<&mut Style, Added<components::HiddenUiElement>>) {
fn hide_items(mut q: Query<&mut Style, With<components::HiddenUiElement>>) {
for mut s in q.iter_mut() {
s.display = Display::None;
}
Expand Down

0 comments on commit 77dfae7

Please sign in to comment.