(ctx: &ReducerContext, resources: Vec<WorldGenGeneratedResourceDeposit>)
| 365 | |
| 366 | create_building_footprint(ctx, entity_id, building_component.direction_index, building_description, &None); |
| 367 | |
| 368 | if !ignore_claim_creation { |
| 369 | if let Err(error) = create_building_claim(ctx, entity_id, true) { |
| 370 | log::error!("Failed to create building claim: {}", error); |
| 371 | continue; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | if ctx |
| 376 | .db |
| 377 | .interior_network_desc() |
| 378 | .building_id() |
| 379 | .find(&building_description.id) |
| 380 | .is_some() |
| 381 | { |
| 382 | if let Err(error) = create_building_interior(ctx, entity_id) { |
| 383 | log::error!("Failed to create building interior: {}", error); |
| 384 | continue; |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | create_building_spawns(ctx, entity_id); |
| 389 | |
| 390 | building_count += 1; |
| 391 | } |
| 392 | |
| 393 | log::info!("Inserted {} buildings", building_count); |
| 394 | } |
| 395 | |
| 396 | fn insert_resources(ctx: &ReducerContext, resources: Vec<WorldGenGeneratedResourceDeposit>) { |
| 397 | // Keep a counter of total resources inserted, to put in logs. |
| 398 | let mut resource_count = 0; |
| 399 | |
| 400 | // Keep counters of the number of each resource type inserted, |
| 401 | // to store in the `ResourceCount` table. |
| 402 | // Keep the counters in-memory and do one `ResourceCount::insert` at the end, |
| 403 | // rather than eagerly updating the counters in the database by `ResourceState::insert_one`. |
| 404 | let mut resource_counters: std::collections::HashMap<i32, i32> = ctx |
| 405 | .db |
| 406 | .resource_count() |
| 407 | .iter() |
| 408 | .map(|counter| (counter.resource_id, counter.num_in_world)) |
| 409 | .collect(); |
| 410 | |
| 411 | for resource in resources { |
| 412 | let entity_id = create_entity(ctx); |
| 413 | let resource_deposit = resource.deposit.as_ref().unwrap(); |
| 414 | |
| 415 | let offset = OffsetCoordinatesSmall { |
| 416 | x: resource.x, |
| 417 | z: resource.z, |
| 418 | dimension: resource.dimension, |
| 419 | }; |
| 420 | |
| 421 | let deposit_description = ctx.db.resource_desc().id().find(&resource_deposit.resource_id).unwrap(); |
| 422 | let _ = ResourceState::spawn( |
| 423 | ctx, |
| 424 | Some(entity_id), |
no test coverage detected