# HG changeset patch # User unc0rr # Date 1514332766 -3600 # Node ID fe16fa088b69cf3a52e32adefd20094c7c85a4a6 # Parent 488782d9aba932d3e1a67288d46147b4a0f035fa Make playing a game possible diff -r 488782d9aba9 -r fe16fa088b69 qmlfrontend/CMakeLists.txt --- a/qmlfrontend/CMakeLists.txt Tue Dec 26 01:36:58 2017 +0100 +++ b/qmlfrontend/CMakeLists.txt Wed Dec 27 00:59:26 2017 +0100 @@ -12,6 +12,7 @@ "hwengine.cpp" "hwengine.h" "gameconfig.cpp" "gameconfig.h" "runqueue.cpp" "runqueue.h" + "team.cpp" "team.h" "previewimageprovider.cpp" "previewimageprovider.h" "flib.h") diff -r 488782d9aba9 -r fe16fa088b69 qmlfrontend/Page1.qml --- a/qmlfrontend/Page1.qml Tue Dec 26 01:36:58 2017 +0100 +++ b/qmlfrontend/Page1.qml Wed Dec 27 00:59:26 2017 +0100 @@ -2,8 +2,10 @@ import Hedgewars.Engine 1.0 Page1Form { + gameButton.onClicked: { + HWEngine.runQuickGame() +} button1.onClicked: { - console.log("Button clicked") HWEngine.getPreview() } diff -r 488782d9aba9 -r fe16fa088b69 qmlfrontend/Page1Form.ui.qml --- a/qmlfrontend/Page1Form.ui.qml Tue Dec 26 01:36:58 2017 +0100 +++ b/qmlfrontend/Page1Form.ui.qml Wed Dec 27 00:59:26 2017 +0100 @@ -5,6 +5,7 @@ Item { property alias button1: button1 property alias previewImage: previewImage + property alias gameButton: gameButton RowLayout { anchors.horizontalCenter: parent.horizontalCenter @@ -12,8 +13,13 @@ anchors.top: parent.top Button { - id: button1 - text: qsTr("Run") + id: button1 + text: qsTr("Preview") + } + + Button { + id: gameButton + text: qsTr("Game") } } diff -r 488782d9aba9 -r fe16fa088b69 qmlfrontend/gameconfig.cpp --- a/qmlfrontend/gameconfig.cpp Tue Dec 26 01:36:58 2017 +0100 +++ b/qmlfrontend/gameconfig.cpp Wed Dec 27 00:59:26 2017 +0100 @@ -1,11 +1,9 @@ #include "gameconfig.h" GameConfig::GameConfig() + : m_isPreview(true) { - m_arguments - << "" - << "--internal" - << "--landpreview"; + setPreview(m_isPreview); } const char** GameConfig::argv() const @@ -41,14 +39,54 @@ cfgAppend("eseed " + seed); } +void GameConfig::cmdTheme(const QByteArray& theme) +{ + cfgAppend("e$theme " + theme); +} + void GameConfig::cmdMapgen(int mapgen) { cfgAppend("e$mapgen " + QByteArray::number(mapgen)); } -bool GameConfig::isPreview() +void GameConfig::cmdTeam(const Team& team) +{ + cfgAppend("eaddteam " + team.color + " " + team.name); + + for (const Hedgehog& h : team.hedgehogs()) { + cfgAppend("eaddhh " + QByteArray::number(h.level) + " " + QByteArray::number(h.hp) + " " + h.name); + cfgAppend("ehat " + h.hat); + } + cfgAppend("eammloadt 9391929422199121032235111001200000000211100101011111000102"); + cfgAppend("eammprob 0405040541600655546554464776576666666155510101115411111114"); + cfgAppend("eammdelay 0000000000000205500000040007004000000000220000000600020000"); + cfgAppend("eammreinf 1311110312111111123114111111111111111211111111111111111111"); + cfgAppend("eammstore"); +} + +bool GameConfig::isPreview() const { - return true; + return m_isPreview; +} + +void GameConfig::setPreview(bool isPreview) +{ + m_isPreview = isPreview; + + m_arguments.clear(); + + if (m_isPreview) { + m_arguments + << "" + << "--internal" + << "--landpreview"; + + } else { + m_arguments + << "" + << "--internal" + << "--nomusic"; + } } void GameConfig::cfgAppend(const QByteArray& cmd) diff -r 488782d9aba9 -r fe16fa088b69 qmlfrontend/gameconfig.h --- a/qmlfrontend/gameconfig.h Tue Dec 26 01:36:58 2017 +0100 +++ b/qmlfrontend/gameconfig.h Wed Dec 27 00:59:26 2017 +0100 @@ -4,6 +4,8 @@ #include #include +#include "team.h" + class GameConfig { public: explicit GameConfig(); @@ -14,14 +16,19 @@ void clear(); void cmdSeed(const QByteArray& seed); + void cmdTheme(const QByteArray& theme); void cmdMapgen(int mapgen); + void cmdTeam(const Team& team); - bool isPreview(); + bool isPreview() const; + void setPreview(bool isPreview); private: mutable QVector m_argv; QList m_arguments; QList m_cfg; + QList m_teams; + bool m_isPreview; void cfgAppend(const QByteArray& cmd); }; diff -r 488782d9aba9 -r fe16fa088b69 qmlfrontend/hwengine.cpp --- a/qmlfrontend/hwengine.cpp Tue Dec 26 01:36:58 2017 +0100 +++ b/qmlfrontend/hwengine.cpp Wed Dec 27 00:59:26 2017 +0100 @@ -110,12 +110,23 @@ void HWEngine::getPreview() { - GameConfig cfg; - cfg.cmdSeed(QUuid::createUuid().toByteArray()); + m_gameConfig.cmdSeed(QUuid::createUuid().toByteArray()); + m_gameConfig.setPreview(true); - m_runQueue->queue(cfg); + m_runQueue->queue(m_gameConfig); } void HWEngine::runQuickGame() { + m_gameConfig.cmdTheme("Bamboo"); + Team team1; + team1.name = "team1"; + Team team2; + team2.name = "team2"; + team2.color = "7654321"; + m_gameConfig.cmdTeam(team1); + m_gameConfig.cmdTeam(team2); + m_gameConfig.setPreview(false); + + m_runQueue->queue(m_gameConfig); } diff -r 488782d9aba9 -r fe16fa088b69 qmlfrontend/hwengine.h --- a/qmlfrontend/hwengine.h Tue Dec 26 01:36:58 2017 +0100 +++ b/qmlfrontend/hwengine.h Wed Dec 27 00:59:26 2017 +0100 @@ -5,6 +5,7 @@ #include #include "flib.h" +#include "gameconfig.h" class QQmlEngine; class PreviewImageProvider; @@ -34,6 +35,7 @@ QQmlEngine* m_engine; PreviewImageProvider* m_previewProvider; RunQueue* m_runQueue; + GameConfig m_gameConfig; static void guiMessagesCallback(void* context, MessageType mt, const char* msg, uint32_t len); diff -r 488782d9aba9 -r fe16fa088b69 qmlfrontend/team.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qmlfrontend/team.cpp Wed Dec 27 00:59:26 2017 +0100 @@ -0,0 +1,27 @@ +#include "team.h" + +Hedgehog::Hedgehog() + : name(QObject::tr("unnamed", "default hedgehog name").toUtf8()) + , hat("NoHat") + , hp(100) + , level(0) +{ +} + +Team::Team() + : name(QObject::tr("unnamed", "default team name").toUtf8()) + , color("12345678") + , m_hedgehogsNumber(4) +{ + m_hedgehogs.resize(8); +} + +void Team::resize(int number) +{ + m_hedgehogsNumber = number; +} + +QVector Team::hedgehogs() const +{ + return m_hedgehogs.mid(0, m_hedgehogsNumber); +} diff -r 488782d9aba9 -r fe16fa088b69 qmlfrontend/team.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qmlfrontend/team.h Wed Dec 27 00:59:26 2017 +0100 @@ -0,0 +1,31 @@ +#ifndef TEAM_H +#define TEAM_H + +#include +#include + +struct Hedgehog { + Hedgehog(); + + QByteArray name; + QByteArray hat; + quint32 hp; + int level; +}; + +class Team { +public: + explicit Team(); + + void resize(int number); + QVector hedgehogs() const; + + QByteArray name; + QByteArray color; + +private: + QVector m_hedgehogs; + int m_hedgehogsNumber; +}; + +#endif // TEAM_H