From 343d6b001fa94d9707d443f00d295fdfcc4f1511 Mon Sep 17 00:00:00 2001 From: Sanil Date: Tue, 9 Jan 2024 21:12:00 +0530 Subject: [PATCH] Hearts: Port to GML compiler --- Userland/Games/Hearts/CMakeLists.txt | 7 ++----- Userland/Games/Hearts/Game.cpp | 4 +--- Userland/Games/Hearts/Hearts.gml | 2 +- Userland/Games/Hearts/MainWidget.h | 23 +++++++++++++++++++++++ Userland/Games/Hearts/main.cpp | 7 +++---- 5 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 Userland/Games/Hearts/MainWidget.h diff --git a/Userland/Games/Hearts/CMakeLists.txt b/Userland/Games/Hearts/CMakeLists.txt index a7e8322988..ef6832b69e 100644 --- a/Userland/Games/Hearts/CMakeLists.txt +++ b/Userland/Games/Hearts/CMakeLists.txt @@ -5,7 +5,7 @@ serenity_component( TARGETS Hearts ) -stringify_gml(Hearts.gml HeartsGML.h hearts_gml) +compile_gml(Hearts.gml HeartsGML.cpp) set(SOURCES Game.cpp @@ -13,10 +13,7 @@ set(SOURCES Player.cpp ScoreCard.cpp SettingsDialog.cpp -) - -set(GENERATED_SOURCES - HeartsGML.h + HeartsGML.cpp ) serenity_app(Hearts ICON app-hearts) diff --git a/Userland/Games/Hearts/Game.cpp b/Userland/Games/Hearts/Game.cpp index 729620455f..76315ff3ed 100644 --- a/Userland/Games/Hearts/Game.cpp +++ b/Userland/Games/Hearts/Game.cpp @@ -19,8 +19,6 @@ #include #include -REGISTER_WIDGET(Hearts, Game); - namespace Hearts { Game::Game() @@ -598,7 +596,7 @@ void Game::play_card(Player& player, size_t card_index) card->set_upside_down(false); m_trick.append(*card); - const Gfx::IntPoint trick_card_positions[] = { + Gfx::IntPoint const trick_card_positions[] = { { width / 2 - Card::width / 2, height / 2 - 30 }, { width / 2 - Card::width + 15, height / 2 - Card::height / 2 - 15 }, { width / 2 - Card::width / 2 + 15, height / 2 - Card::height + 15 }, diff --git a/Userland/Games/Hearts/Hearts.gml b/Userland/Games/Hearts/Hearts.gml index 9bfce41fd9..01f08d5a4b 100644 --- a/Userland/Games/Hearts/Hearts.gml +++ b/Userland/Games/Hearts/Hearts.gml @@ -1,4 +1,4 @@ -@GUI::Widget { +@Hearts::MainWidget { fill_with_background_color: true layout: @GUI::VerticalBoxLayout {} diff --git a/Userland/Games/Hearts/MainWidget.h b/Userland/Games/Hearts/MainWidget.h new file mode 100644 index 0000000000..2a63d64992 --- /dev/null +++ b/Userland/Games/Hearts/MainWidget.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024, Sanil Gupta . + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Hearts { + +class MainWidget : public GUI::Widget { + C_OBJECT_ABSTRACT(MainWidget) +public: + static ErrorOr> try_create(); + virtual ~MainWidget() override = default; + +private: + MainWidget() = default; +}; + +} diff --git a/Userland/Games/Hearts/main.cpp b/Userland/Games/Hearts/main.cpp index 94964170ba..7c889a7b24 100644 --- a/Userland/Games/Hearts/main.cpp +++ b/Userland/Games/Hearts/main.cpp @@ -8,9 +8,9 @@ */ #include "Game.h" +#include "MainWidget.h" #include "SettingsDialog.h" #include -#include #include #include #include @@ -25,7 +25,6 @@ #include #include #include -#include ErrorOr serenity_main(Main::Arguments arguments) { @@ -50,8 +49,8 @@ ErrorOr serenity_main(Main::Arguments arguments) auto window = GUI::Window::construct(); window->set_title("Hearts"); - auto widget = window->set_main_widget(); - TRY(widget->load_from_gml(hearts_gml)); + auto widget = TRY(Hearts::MainWidget::try_create()); + window->set_main_widget(widget); auto& game = *widget->find_descendant_of_type_named("game"); game.set_focus(true);