1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
//
// lager - library for functional interactive c++ programs
// Copyright (C) 2019 Carl Bussey
//
// This file is part of lager.
//
// lager is free software: you can redistribute it and/or modify
// it under the terms of the MIT License, as detailed in the LICENSE
// file located at the root of this source code distribution,
// or here: <https://github.com/arximboldi/lager/blob/master/LICENSE>
//
#include "../model.hpp"
#include "qmodel.hpp"
#include <lager/event_loop/qt.hpp>
#include <lager/store.hpp>
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <random>
#include <utility>
using namespace sn;
int main(int argc, char** argv)
{
QApplication app{argc, argv};
QQmlApplicationEngine engine;
std::random_device rd;
auto initial_state = make_initial(rd());
auto store = lager::make_store<action_t>(std::move(initial_state),
lager::with_qt_event_loop{app});
Game game{store};
watch(store, [&](auto&& state) { game.setModel(state.game); });
game.setModel(store.get().game);
auto* qmlContext = engine.rootContext();
qmlContext->setContextProperty(QStringLiteral("game"), &game);
qRegisterMetaType<SnakeBody*>("SnakeBody*");
engine.load(LAGER_SNAKE_QML_DIR "/main.qml");
return app.exec();
}
|