From 308ac5746c089d7f2e561a19d4b8704105e19ede Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 3 May 2023 14:10:32 -0400 Subject: [PATCH] Duplicate and shuffle tiles --- src/main.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1a152ff..4f1d4a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,24 @@ -slint::include_modules!(); +use ::rand::seq::SliceRandom; +use ::slint::include_modules; +use ::slint::{Model, VecModel}; +use std::rc::Rc; + +include_modules!(); fn main() { - MainWindow::new().unwrap().run().unwrap(); + let main_window = MainWindow::new().unwrap(); + + // Fetch the tiles from the model + let mut tiles: Vec = main_window.get_memory_tiles().iter().collect(); + // Duplicate the list of tiles so we have pairs + tiles.extend(tiles.clone()); + + let mut rng = rand::thread_rng(); + tiles.shuffle(&mut rng); + + // Update the model + let tiles_model = Rc::new(VecModel::from(tiles)); + main_window.set_memory_tiles(tiles_model.into()); + + main_window.run().unwrap(); }