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
Notes: sideshowbarker 2024-07-16 17:05:37 +09:00
5 changed files with 29 additions and 11 deletions

View file

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

View file

@ -16,8 +16,6 @@
#include <LibGfx/Font/Font.h>
#include <LibGfx/Font/FontDatabase.h>
REGISTER_WIDGET(Snake, Game);
namespace Snake {
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 {}
fill_with_background_color: true

View file

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