diff options
| author | 2022-04-29 10:48:09 +0200 | |
|---|---|---|
| committer | 2022-04-29 10:48:09 +0200 | |
| commit | 07c5f6ec23fcf9237a24e71adcfacabce677f818 (patch) | |
| tree | 588e8c5f82b9163181fad3581f610e6f1d88cba4 /src/bin/mobile/maincontroller.cpp | |
| parent | a9153f1615a842cfb9e9bcda4d9071e202618569 (diff) | |
| download | OneRoll-07c5f6ec23fcf9237a24e71adcfacabce677f818.tar.gz OneRoll-07c5f6ec23fcf9237a24e71adcfacabce677f818.zip | |
Change file organization.
Diffstat (limited to 'src/bin/mobile/maincontroller.cpp')
| -rw-r--r-- | src/bin/mobile/maincontroller.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/bin/mobile/maincontroller.cpp b/src/bin/mobile/maincontroller.cpp new file mode 100644 index 0000000..6f301ff --- /dev/null +++ b/src/bin/mobile/maincontroller.cpp @@ -0,0 +1,44 @@ +#include "maincontroler.h" + +#include <QJSValue> +#include <QQmlEngine> + +MainControler::MainControler(QObject* parent) : QObject(parent) +{ + + m_diceParser= new DiceParser(); + qmlRegisterSingletonType("DiceParser", 1, 0, "Model", [](QQmlEngine* engine, QJSEngine* scriptEngine) -> QObject* { + Q_UNUSED(engine) + static CommandModel model; + static bool initialized= false; + if(!initialized) + { + model.insertCmd("L5R", "8D10e10k4"); + initialized= true; + } + return &model; + }); +} +void MainControler::initEngine(QQmlApplicationEngine* engine) +{ + m_engine= engine; + engine->rootContext()->setContextProperty("_model", m_model); + connect(m_engine, SIGNAL(objectCreated(QObject*, QUrl)), this, SLOT(setConnections(QObject*, QUrl))); +} +void MainControler::rollDice(QString cmd) +{ + if(m_diceParser->parseLine(cmd)) + { + m_diceParser->start(); + for(int i= 0; i < m_diceParser->getStartNodeCount(); ++i) + { + // qDebug() << m_diceParser->getSumOfDiceResult(i); + } + } +} +void MainControler::setConnections(QObject* root, QUrl url) +{ + // QObject* root = engine->rootContext()->contextObject(); + connect(root, SIGNAL(roll(QString)), this, SLOT(rollDice(QString))); + connect(root, SIGNAL(addRoll(QString, QString)), m_model, SLOT(insertCmd(QString, QString))); +} |