From 2874f832dbe476322e4465d0cc0c046b0d54e4c7 Mon Sep 17 00:00:00 2001 From: Dominic Date: Sun, 7 Jul 2024 13:35:48 +0200 Subject: [PATCH] kitchen counter appliances --- src/activities/house/room.rs | 82 +++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 6 deletions(-) diff --git a/src/activities/house/room.rs b/src/activities/house/room.rs index 07db950..f8dd113 100644 --- a/src/activities/house/room.rs +++ b/src/activities/house/room.rs @@ -82,13 +82,20 @@ impl Room { let mut empty_spots: IndexSet = (0 .. width).collect(); let mut assets_used: HashSet<&'static str> = HashSet::new(); - fn random_empty_spot(empty_spots: &mut IndexSet) -> Option { + fn random_empty_spot(empty_spots: &mut IndexSet) -> Option { if empty_spots.is_empty() { return None; } let random_idx = usize::gen_range(0, empty_spots.len()); empty_spots.swap_remove_index(random_idx) } + fn random_appliance(empty_spots: &mut Vec) -> Option { + if empty_spots.is_empty() { + return None; + } + let random_idx = usize::gen_range(0, empty_spots.len()); + Some(empty_spots.swap_remove(random_idx)) + } const SIDEBOARD_HEIGHT: f32 = 0.1; const STOVE_HEIGHT: f32 = 0.025; @@ -159,12 +166,21 @@ impl Room { z: 1 }); - // let's add half of the remaining positions as drawers + // the current list of empty spots is the same list we can use to place + // on-the-counter appliances later + let mut empty_spots_clone = empty_spots.clone(); + + // build a list of the remaining kitchen appliances. we only want them + // included once, most kitchens don't contain two washing machines etc + let mut remaining_appliances: IndexSet<&'static str> = + ["dishwasher", "dryer", "minifridge", "washing_machine"] + .into_iter() + .collect(); + + // let's add at most half of the remaining positions as big appliances for _ in 0 .. empty_spots.len() / 2 { - let asset = match u8::gen_range(0, 2) { - 0 => "drawer", - 1 => "drawer_cupboard", - _ => unreachable!() + let Some(asset) = random_empty_spot(&mut remaining_appliances) else { + break; }; let Some(spot) = random_empty_spot(&mut empty_spots) else { error!("WTF I shouldn't've used more than half of the available spots"); @@ -183,6 +199,60 @@ impl Room { z: 1 }); } + + // and fill the remainder with drawers + while !empty_spots.is_empty() { + let asset = match u8::gen_range(0, 2) { + 0 => "drawer", + 1 => "drawer_cupboard", + _ => unreachable!() + }; + let Some(spot) = random_empty_spot(&mut empty_spots) else { + error!("WTF I should still have spots available"); + return furnitures; + }; + furnitures.push(Tile { + pos: vec2(spot as f32, 0.0), + size: vec2(1.0, 1.0), + f: Furniture::new("kitchen", asset, ctx), + z: 0 + }); + furnitures.push(Tile { + pos: vec2(spot as f32, 1.0), + size: vec2(1.0, SIDEBOARD_HEIGHT), + f: Furniture::new("kitchen", "sideboard_1", ctx), + z: 1 + }); + } + + // build a list of on-the-counter kitchen appliances. we only want them + // included once, most kitchens don't contain two toasters etc + let mut remaining_appliances: Vec<(&'static str, f32, f32)> = [ + ("blender", 0.3, 0.45), + ("kettle", 0.3, 0.4), + ("toaster", 0.5, 0.25) + ] + .into_iter() + .collect(); + + // and then we fill like half the counter with appliances + for _ in 0 .. empty_spots_clone.len() / 2 { + let Some((asset, asset_w, asset_h)) = + random_appliance(&mut remaining_appliances) + else { + break; + }; + let Some(spot) = random_empty_spot(&mut empty_spots_clone) else { + error!("WTF I shouldn't've used more than half of the available spots"); + return furnitures; + }; + furnitures.push(Tile { + pos: vec2(spot as f32 + 0.5, 1.0 + SIDEBOARD_HEIGHT), + size: vec2(asset_w, asset_h), + f: Furniture::new("kitchen", asset, ctx), + z: 0 + }); + } }, _ => {}