Glimmer Tetris gets menu bar items, including Start, Pause, Restart, and Exit.
Additionally, the Glimmer Tetris code got refactored quite a bit:
- Model::Game class is no longer a singleton, thus can serve multiple Tetris Custom Shell instances independently.
- The multi-threaded Tetromino down movement loop is now synchronized with a Mutex to allow the game to just stop, ending the thread, and restart when the user wants instead of keeping the thread running perpetually. The Mutex ensures the newly started thread doesn't clash with the older one yet waits for it to end before starting the Tetromino down movement loop again.
- Tetris Custom Shell now cleans resources (deregisters observers) when closed in case it was started as part of another app (like the Glimmer Meta-Sample)
- Game Over Dialog has been turned into its own Custom Shell, thus reusable with the game_over_dialog keyword
- The new Tetris Menu Bar has been made its own Custom Widget as shown in the code below. One thing important to note here is that every shell (and dialog by extension) gets its own menu bar in SWT, so to make the Game Over dialog keep the same Tetris menu actions of Start/Pause/Stop/Exit, you simply reuse the Tetris Menu Bar Custom Widget with one keyword: `tetris_menu_bar`
- Some Model logic that was leaked into the Tetris Custom Shell View got extracted and moved into Model::Game
- Improved code according to the Law of Demeter by not calling Model::Tetromino logic directly from the Tetris Custom Shell View, yet creating higher level intermediate methods on Model::Game and calling them instead
- Adding Ruby-idiomatic bang to the end of mutation methods on the Model::Game and Model::Tetromino Models
Tetris Menu Bar Custom Widget
Tetris App Custom Shell
Game Over Dialog Custom Shell
These changes shipped with Glimmer DSL for SWT v22.214.171.124 as part of the following:
- Provide an auto_sync_exec all data-binding config option to automatically sync_exec GUI calls from other threads instead of requiring users to use sync_exec on model attribute-change logic. Default value to false.
- Have CustomShell::launch method take options to pass to custom shell keyword invocation
- Update Glimmer Meta-Sample to load entire gem into user directory (since some new samples rely on images)
- Update Glimmer Meta-Sample to display errors in a `dialog` instead of a `message_box` to allow scrolling
- Removed newly added CustomShell::shutdown as unnecessary (could just do CustomShell::launchd_custom_shell.close)
- Supporting deregistering Display listeners just like standard listeners via deregister
- Enhance performance of excluded keyword check
- Remove CustomWidget support for multiple before_body/after_body blocks instead of one each since it is not needed.
- Add new :fill_screen style for `shell` to start app filling the screen size (not full screen mode though)
- Tetris Menu Bar with Game Menu -> Start, Pause, Restart, and Exit
- Tetris refactor mutation methods to end with bangs
- Tetris Stop game if user does not play again in the end (instead of closing it)
- End Tetris Thread loop gracefully if game over is encountered
- Tetris use more observers instead of callbacks to Game
- Turn Tetris::Model::Game class from a singleton class to a standard class supporting instances
- Fix issue of `tetris` keyword not found when run from meta-sample app
Otherwise, Glimmer DSL for SWT v126.96.36.199 included a major feature: Canvas Transform DSL:
- Canvas Transform DSL (DSL declared Transform objects are auto-disposed after getting used by their parent shape)
- Canvas support a top-level Transform DSL fluent interface for methods that use Transform arguments manually (e.g. tr1 = transform.rotate(90).translate(0, -100))
- Hello, Canvas Transform! Sample
This article is part of the Tetris Saga