mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Snake: Use new GML compiler
This commit is contained in:
parent
5f275cd5ce
commit
cdbc2a0dcd
Notes:
sideshowbarker
2024-07-16 17:05:37 +09:00
Author: https://github.com/bwoodford 🔰 Commit: https://github.com/SerenityOS/serenity/commit/cdbc2a0dcd Pull-request: https://github.com/SerenityOS/serenity/pull/21889 Reviewed-by: https://github.com/timschumi ✅
5 changed files with 29 additions and 11 deletions
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
23
Userland/Games/Snake/MainWidget.h
Normal file
23
Userland/Games/Snake/MainWidget.h
Normal 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;
|
||||
};
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
@GUI::Widget {
|
||||
@Snake::MainWidget {
|
||||
layout: @GUI::VerticalBoxLayout {}
|
||||
fill_with_background_color: true
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue