Przeglądaj źródła

MasterWord: Use GML compiler

toadkarter 1 rok temu
rodzic
commit
4e2e2027c3

+ 2 - 5
Userland/Games/MasterWord/CMakeLists.txt

@@ -4,15 +4,12 @@ serenity_component(
     TARGETS MasterWord
     TARGETS MasterWord
 )
 )
 
 
-stringify_gml(MasterWord.gml MasterWordGML.h master_word_gml)
+compile_gml(MasterWord.gml MasterWordGML.cpp master_word_gml)
 
 
 set(SOURCES
 set(SOURCES
     main.cpp
     main.cpp
     WordGame.cpp
     WordGame.cpp
-)
-
-set(GENERATED_SOURCES
-    MasterWordGML.h
+    MasterWordGML.cpp
 )
 )
 
 
 serenity_app(MasterWord ICON app-masterword)
 serenity_app(MasterWord ICON app-masterword)

+ 23 - 0
Userland/Games/MasterWord/MainWidget.h

@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2023, the SerenityOS developers
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibGUI/Widget.h>
+
+namespace MasterWord {
+
+class MainWidget : public GUI::Widget {
+    C_OBJECT_ABSTRACT(MainWidget)
+public:
+    static ErrorOr<NonnullRefPtr<MainWidget>> try_create();
+    virtual ~MainWidget() override = default;
+
+private:
+    MainWidget() = default;
+};
+
+}

+ 1 - 1
Userland/Games/MasterWord/MasterWord.gml

@@ -1,4 +1,4 @@
-@GUI::Widget {
+@MasterWord::MainWidget {
     fill_with_background_color: true
     fill_with_background_color: true
     layout: @GUI::VerticalBoxLayout {}
     layout: @GUI::VerticalBoxLayout {}
 
 

+ 0 - 2
Userland/Games/MasterWord/WordGame.cpp

@@ -18,8 +18,6 @@
 #include <LibGfx/Font/FontDatabase.h>
 #include <LibGfx/Font/FontDatabase.h>
 #include <LibGfx/Palette.h>
 #include <LibGfx/Palette.h>
 
 
-REGISTER_WIDGET(MasterWord, WordGame)
-
 // TODO: Add stats
 // TODO: Add stats
 namespace MasterWord {
 namespace MasterWord {
 
 

+ 3 - 3
Userland/Games/MasterWord/main.cpp

@@ -4,9 +4,9 @@
  * SPDX-License-Identifier: BSD-2-Clause
  * SPDX-License-Identifier: BSD-2-Clause
  */
  */
 
 
+#include "MainWidget.h"
 #include "WordGame.h"
 #include "WordGame.h"
 #include <AK/URL.h>
 #include <AK/URL.h>
-#include <Games/MasterWord/MasterWordGML.h>
 #include <LibConfig/Client.h>
 #include <LibConfig/Client.h>
 #include <LibCore/System.h>
 #include <LibCore/System.h>
 #include <LibDesktop/Launcher.h>
 #include <LibDesktop/Launcher.h>
@@ -47,8 +47,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     window->set_resizable(false);
     window->set_resizable(false);
     window->set_auto_shrink(true);
     window->set_auto_shrink(true);
 
 
-    auto main_widget = window->set_main_widget<GUI::Widget>();
-    TRY(main_widget->load_from_gml(master_word_gml));
+    auto main_widget = TRY(MasterWord::MainWidget::try_create());
+    window->set_main_widget(main_widget);
     auto& game = *main_widget->find_descendant_of_type_named<MasterWord::WordGame>("word_game");
     auto& game = *main_widget->find_descendant_of_type_named<MasterWord::WordGame>("word_game");
     auto& statusbar = *main_widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
     auto& statusbar = *main_widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
     GUI::Application::the()->on_action_enter = [&statusbar](GUI::Action& action) {
     GUI::Application::the()->on_action_enter = [&statusbar](GUI::Action& action) {