kitchen counter appliances
This commit is contained in:
parent
2498152b21
commit
2874f832db
1 changed files with 76 additions and 6 deletions
|
@ -82,13 +82,20 @@ impl Room {
|
||||||
let mut empty_spots: IndexSet<u8> = (0 .. width).collect();
|
let mut empty_spots: IndexSet<u8> = (0 .. width).collect();
|
||||||
let mut assets_used: HashSet<&'static str> = HashSet::new();
|
let mut assets_used: HashSet<&'static str> = HashSet::new();
|
||||||
|
|
||||||
fn random_empty_spot(empty_spots: &mut IndexSet<u8>) -> Option<u8> {
|
fn random_empty_spot<T>(empty_spots: &mut IndexSet<T>) -> Option<T> {
|
||||||
if empty_spots.is_empty() {
|
if empty_spots.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let random_idx = usize::gen_range(0, empty_spots.len());
|
let random_idx = usize::gen_range(0, empty_spots.len());
|
||||||
empty_spots.swap_remove_index(random_idx)
|
empty_spots.swap_remove_index(random_idx)
|
||||||
}
|
}
|
||||||
|
fn random_appliance<T>(empty_spots: &mut Vec<T>) -> Option<T> {
|
||||||
|
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 SIDEBOARD_HEIGHT: f32 = 0.1;
|
||||||
const STOVE_HEIGHT: f32 = 0.025;
|
const STOVE_HEIGHT: f32 = 0.025;
|
||||||
|
@ -159,12 +166,21 @@ impl Room {
|
||||||
z: 1
|
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 {
|
for _ in 0 .. empty_spots.len() / 2 {
|
||||||
let asset = match u8::gen_range(0, 2) {
|
let Some(asset) = random_empty_spot(&mut remaining_appliances) else {
|
||||||
0 => "drawer",
|
break;
|
||||||
1 => "drawer_cupboard",
|
|
||||||
_ => unreachable!()
|
|
||||||
};
|
};
|
||||||
let Some(spot) = random_empty_spot(&mut empty_spots) else {
|
let Some(spot) = random_empty_spot(&mut empty_spots) else {
|
||||||
error!("WTF I shouldn't've used more than half of the available spots");
|
error!("WTF I shouldn't've used more than half of the available spots");
|
||||||
|
@ -183,6 +199,60 @@ impl Room {
|
||||||
z: 1
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
Loading…
Reference in a new issue