Creating the tiles
This step places the game tiles randomly.
Change the main
function and includes in src/main.cpp
to the following:
The code takes the list of tiles, duplicates it, and shuffles it, accessing the memory_tiles
property through the C++ code.
For each top-level property, Slint generates a getter and a setter function. In this case get_memory_tiles
and set_memory_tiles
.
Since memory_tiles
is a Slint array, it’s represented as a std::shared_ptr<slint::Model>
↗.
You can’t change the model generated by Slint, but you can extract the tiles from it and put them
in a slint::VectorModel
↗ which inherits from Model
.
VectorModel
lets you make changes and you can use it to replace the static generated model.
Change main.js
to the following:
The code takes the list of tiles, duplicates it, and shuffles it, accessing the memory_tiles
property through the JavaScript code.
As memory_tiles
is an array, it’s represented as a JavaScript Array
↗.
You can’t change the model generated by Slint, but you can extract the tiles from it and put them
in a slint.ArrayModel
↗ which implements the Model
↗ interface.
ArrayModel
allows you to make changes and you can use it to replace the static generated model.
The code uses the rand
dependency for the randomization. Add it to the Cargo.toml
file using the cargo
command.
Change the main function to the following:
© 2024 SixtyFPS GmbH