Skip to content

Commit

Permalink
display possible combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Spaink committed Aug 22, 2023
1 parent 3f84a73 commit 56be6c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ impl eframe::App for App {
}
});

ui.horizontal(|ui| {
ui.label(format!("There are {} possible combinations!", assets.total_combinations));
});

ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
Expand Down
12 changes: 12 additions & 0 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct Image {
}

pub struct Assets {
pub total_combinations: u64,
pub colors: HashMap<String, Image>,
pub eyes: HashMap<String, Image>,
pub hats: HashMap<String, Image>,
Expand Down Expand Up @@ -36,13 +37,15 @@ macro_rules! load_image {
impl Assets {
pub fn new() -> Assets {
let mut colors: HashMap<String, Image> = HashMap::new();
let mut category_count = Vec::new();

let images = [
load_image!("colors", "purple"),
load_image!("colors", "orange"),
load_image!("colors", "green"),
load_image!("colors", "blue"),
];
category_count.push(images.len());

for i in images {
colors.insert(i.0, i.1);
Expand All @@ -51,6 +54,7 @@ impl Assets {
let mut eyes: HashMap<String, Image> = HashMap::new();

let images = [load_image!("eyes", "happy"), load_image!("eyes", "girl")];
category_count.push(images.len());

for i in images {
eyes.insert(i.0, i.1);
Expand All @@ -59,6 +63,7 @@ impl Assets {
let mut hats: HashMap<String, Image> = HashMap::new();

let images = [load_image!("hats", "top")];
category_count.push(images.len() + 1);

for i in images {
hats.insert(i.0, i.1);
Expand All @@ -68,7 +73,14 @@ impl Assets {
RetainedImage::from_image_bytes("remove", include_bytes!("../assets/remove_thumb.png"))
.unwrap();

let mut total_combinations: u64 = 1;

for c in category_count {
total_combinations *= c as u64;
}

Assets {
total_combinations,
colors,
eyes,
hats,
Expand Down

0 comments on commit 56be6c4

Please sign in to comment.