1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:37:45 +00:00

Snake: Use new GML compiler

This commit is contained in:
Brandon Woodford 2023-11-11 06:27:40 -06:00 committed by Tim Schumacher
parent 5f275cd5ce
commit cdbc2a0dcd
5 changed files with 29 additions and 11 deletions

View file

@ -4,7 +4,7 @@ serenity_component(
TARGETS Snake TARGETS Snake
) )
stringify_gml(Snake.gml SnakeGML.h snake_gml) compile_gml(Snake.gml SnakeGML.cpp)
set(SOURCES set(SOURCES
Game.cpp Game.cpp
@ -12,10 +12,7 @@ set(SOURCES
Skins/ClassicSkin.cpp Skins/ClassicSkin.cpp
Skins/ImageSkin.cpp Skins/ImageSkin.cpp
Skins/SnakeSkin.cpp Skins/SnakeSkin.cpp
) SnakeGML.cpp
set(GENERATED_SOURCES
SnakeGML.h
) )
serenity_app(Snake ICON app-snake) serenity_app(Snake ICON app-snake)

View file

@ -16,8 +16,6 @@
#include <LibGfx/Font/Font.h> #include <LibGfx/Font/Font.h>
#include <LibGfx/Font/FontDatabase.h> #include <LibGfx/Font/FontDatabase.h>
REGISTER_WIDGET(Snake, Game);
namespace Snake { namespace Snake {
ErrorOr<NonnullRefPtr<Game>> Game::try_create() ErrorOr<NonnullRefPtr<Game>> Game::try_create()

View file

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

View file

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

View file

@ -6,9 +6,9 @@
*/ */
#include "Game.h" #include "Game.h"
#include "MainWidget.h"
#include "Skins/SnakeSkin.h" #include "Skins/SnakeSkin.h"
#include <AK/URL.h> #include <AK/URL.h>
#include <Games/Snake/SnakeGML.h>
#include <LibConfig/Client.h> #include <LibConfig/Client.h>
#include <LibCore/Directory.h> #include <LibCore/Directory.h>
#include <LibCore/System.h> #include <LibCore/System.h>
@ -52,8 +52,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_title("Snake"); window->set_title("Snake");
window->resize(324, 345); window->resize(324, 345);
auto widget = window->set_main_widget<GUI::Widget>(); auto widget = TRY(Snake::MainWidget::try_create());
TRY(widget->load_from_gml(snake_gml)); window->set_main_widget(widget);
auto& game = *widget->find_descendant_of_type_named<Snake::Game>("game"); auto& game = *widget->find_descendant_of_type_named<Snake::Game>("game");
game.set_focus(true); game.set_focus(true);