Skip to content

Not formatting any part of function #3524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JMS55 opened this issue Apr 23, 2019 · 3 comments
Closed

Not formatting any part of function #3524

JMS55 opened this issue Apr 23, 2019 · 3 comments

Comments

@JMS55
Copy link

JMS55 commented Apr 23, 2019

This function is located in a standalone { } block in main

        fn tree_harvest_ai(self_entity: Entity, lazy_world: &LazyUpdate) {
            lazy_world.exec(move |world| {
                let container_data = world.read_storage::<Container>();
                let world_location_data = world.read_storage::<WorldLocation>();
                let entity_type_data = world.read_storage::<EntityType>();
                let time_tracker_data = world.read_storage::<TimeTracker>();
                let mut action_attack_data = world.write_storage::<ActionAttack>();
                let mut action_move_to_data = world.write_storage::<ActionMoveTo>();
                let mut action_take_from_container_data = world.write_storage::<ActionTakeFromContainer>();
                let self_container = container_data
                    .get(self_entity)
                    .expect("Entity with tree_harvest_ai() did not have a Container component");
                let self_position = &world_location_data
                    .get(self_entity)
                    .expect("Entity with tree_harvest_ai() did not have a Position component")
                    .position;
                if let Some(axe_entity) = self_container.children.iter().find(|child| {
                    entity_type_data
                        .get(**child)
                        .expect("Entity did not have a EntityType component in tree_harvest_ai()")
                        == &EntityType::Axe
                }) {
                    if let Some(tree_entity) = (
                        &entity_type_data,
                        &time_tracker_data,
                        &world_location_data,
                        &world.entities(),
                    )
                        .join()
                        .find(|(entity_type, time_tracker, world_location, _)| {
                            entity_type == &&EntityType::Tree
                                && time_tracker.time_passed
                                    >= (TREE_STAGES - 1) * TIME_PER_TREE_STAGE
                                && world_location.position.is_adjacent_to(self_position)
                        })
                        .map(|(_, _, _, entity)| entity)
                    {
                        action_attack_data
                            .insert(
                                self_entity,
                                ActionAttack {
                                    weapon: axe_entity.clone(),
                                    target_entity: tree_entity,
                                },
                            )
                            .expect("Could not insert ActionAttack component in tree_harvest_ai()");
                    } else {
                        if let Some(tree_position) = (
                            &entity_type_data,
                            &time_tracker_data,
                            &world_location_data,
                        )
                            .join()
                            .find(|(entity_type, time_tracker, _)| {
                                entity_type == &&EntityType::Tree
                                && time_tracker.time_passed  >= (TREE_STAGES - 1) * TIME_PER_TREE_STAGE
                            }).map(|(_, _, world_location)| world_location.position.clone())
                        {
                             action_move_to_data
                            .insert(
                                self_entity,
                              ActionMoveTo::new(tree_position)
                            )
                            .expect("Could not insert ActionMoveTo(tree_position) component in tree_harvest_ai()");
                        }
                    }
                } else {
                    let axe_crate_position = Position {
                        x: I32F32::from(-7),
                        y: I32F32::from(0),
                        z: I32F32::from(1),
                    };
                    if self_position.is_adjacent_to(&axe_crate_position) {
                        if let Some(axe_crate_entity) = (&world_location_data,   &world.entities()).join().find(|(world_location, _)| world_location.position == axe_crate_position).map(|(_, entity)| entity) {
                                                    action_take_from_container_data.insert(self_entity, ActionTakeFromContainer{entity_type: EntityType::Axe, source_container: axe_crate_entity}).expect("Could not insert ActionTakeFromContainer component in tree_harvest_ai()");
                        };
                    } else {
                         action_move_to_data
                            .insert(
                                self_entity,
                              ActionMoveTo::new(axe_crate_position)
                            )
                            .expect("Could not insert ActionMoveTo(axe_crate_position) component in tree_harvest_ai()");
                    }
                }
            });
        }
@topecongiro topecongiro added bug Panic, non-idempotency, invalid code, etc. poor-formatting and removed bug Panic, non-idempotency, invalid code, etc. labels Apr 23, 2019
@topecongiro
Copy link
Contributor

topecongiro commented Apr 24, 2019

Not calling wrap_str when the chain expression is at the statement position (ExprType::Statement) may fix this.

return wrap_str(result, context.config.max_width(), shape);

wrap_str(result, context.config.max_width(), shape)

@ytmimi
Copy link
Contributor

ytmimi commented Jul 20, 2022

@calebcartwright I believe the is a duplicate of #3416. When setting max_width=115 we can get the snippet to format. We could also set format_strings=true to get the snippet to format.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 26, 2022

#3416 was recently closed in favor of #3863, and In the spirit of consolidating duplicates I'm going to close this one as well

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Jul 26, 2022
@calebcartwright calebcartwright removed this from the 3.0.0 milestone Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants