| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The Twos screen held both the game state and the rules that manipulate it alongside its LVGL objects. Move the grid, the score and the functions that act on them into a TwosGrid class, leaving the screen responsible only for drawing. The four swipe branches of OnTouchEvent were the same algorithm written out once per direction. They are replaced by TwosGrid::Slide, which takes the direction as a row/column step, so the sliding and merging rules now exist in one place. Fixes InfiniTimeOrg#1668
|
Build size and comparison to main:
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #1668.
Per the request in the issue, the grid and the functions that manipulate it move out of the Twos screen and into a new TwosGrid class. TwosGrid owns the tiles and the score and knows nothing about LVGL; Twos keeps the styles, the table and the label and just draws whatever the grid currently holds.
While moving the code I also collapsed the four swipe branches. They were the same algorithm written out once per direction, differing only in which axis they walked and in which order. TwosGrid::Slide(rowStep, colStep) takes the direction as a step pair ({0, -1} for left, {1, 0} for down, and so on), so the sliding and merging rules exist in one place instead of four. That is what removes most of the line count here.
Two small things came along with the move:
No behaviour change is intended.
Verification
I do not have the ARM toolchain here, so rather than reason about it I tested the extracted logic directly. Because TwosGrid no longer depends on LVGL, I could compile the old implementation and the new one side by side on the desktop and compare them:
2662144 swipes compared, 0 mismatches. Loop order was the part I most expected to have broken, since the original walks columns-outer for horizontal swipes and rows-outer for vertical ones; rows and columns are independent for their respective directions, and the fuzzing agrees.
Also checked:
What I could not verify is the app running on real hardware or in the simulator, so the LVGL side of Twos is unexercised beyond compiling. Worth a quick look on a watch or in InfiniSim before merging.