1
0

Duplicate and shuffle tiles

This commit is contained in:
Timothy Warren 2023-05-03 14:10:32 -04:00
parent 1cfa3f0b53
commit 308ac5746c

View File

@ -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<TileData> = 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();
}