qmlfrontend/gameconfig.cpp
author unc0rr
Wed, 27 Dec 2017 00:59:26 +0100
branchqmlfrontend
changeset 12863 fe16fa088b69
parent 12861 488782d9aba9
permissions -rw-r--r--
Make playing a game possible
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12858
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents:
diff changeset
     1
#include "gameconfig.h"
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents:
diff changeset
     2
12859
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
     3
GameConfig::GameConfig()
12863
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
     4
    : m_isPreview(true)
12859
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
     5
{
12863
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
     6
    setPreview(m_isPreview);
12859
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
     7
}
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
     8
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
     9
const char** GameConfig::argv() const
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    10
{
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    11
    m_argv.resize(m_arguments.size());
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    12
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    13
    for (int i = 0; i < m_arguments.size(); ++i)
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    14
        m_argv[i] = m_arguments[i].data();
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    15
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    16
    return m_argv.data();
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    17
}
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    18
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    19
int GameConfig::argc() const
12858
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents:
diff changeset
    20
{
12859
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    21
    return m_arguments.size();
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    22
}
12858
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents:
diff changeset
    23
12860
e33bcb9d5e9c Preview rendering seems to work now
unc0rr
parents: 12859
diff changeset
    24
const QList<QByteArray> GameConfig::config() const
e33bcb9d5e9c Preview rendering seems to work now
unc0rr
parents: 12859
diff changeset
    25
{
e33bcb9d5e9c Preview rendering seems to work now
unc0rr
parents: 12859
diff changeset
    26
    QList<QByteArray> cfg = m_cfg;
e33bcb9d5e9c Preview rendering seems to work now
unc0rr
parents: 12859
diff changeset
    27
    cfg.append("\x01!");
e33bcb9d5e9c Preview rendering seems to work now
unc0rr
parents: 12859
diff changeset
    28
    return cfg;
e33bcb9d5e9c Preview rendering seems to work now
unc0rr
parents: 12859
diff changeset
    29
}
e33bcb9d5e9c Preview rendering seems to work now
unc0rr
parents: 12859
diff changeset
    30
12859
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    31
void GameConfig::clear()
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    32
{
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    33
    m_arguments.clear();
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    34
    m_cfg.clear();
12858
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents:
diff changeset
    35
}
12859
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    36
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    37
void GameConfig::cmdSeed(const QByteArray& seed)
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    38
{
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    39
    cfgAppend("eseed " + seed);
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    40
}
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    41
12863
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    42
void GameConfig::cmdTheme(const QByteArray& theme)
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    43
{
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    44
    cfgAppend("e$theme " + theme);
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    45
}
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    46
12859
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    47
void GameConfig::cmdMapgen(int mapgen)
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    48
{
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    49
    cfgAppend("e$mapgen " + QByteArray::number(mapgen));
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    50
}
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    51
12863
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    52
void GameConfig::cmdTeam(const Team& team)
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    53
{
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    54
    cfgAppend("eaddteam <hash> " + team.color + " " + team.name);
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    55
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    56
    for (const Hedgehog& h : team.hedgehogs()) {
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    57
        cfgAppend("eaddhh " + QByteArray::number(h.level) + " " + QByteArray::number(h.hp) + " " + h.name);
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    58
        cfgAppend("ehat " + h.hat);
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    59
    }
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    60
    cfgAppend("eammloadt 9391929422199121032235111001200000000211100101011111000102");
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    61
    cfgAppend("eammprob 0405040541600655546554464776576666666155510101115411111114");
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    62
    cfgAppend("eammdelay 0000000000000205500000040007004000000000220000000600020000");
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    63
    cfgAppend("eammreinf 1311110312111111123114111111111111111211111111111111111111");
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    64
    cfgAppend("eammstore");
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    65
}
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    66
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    67
bool GameConfig::isPreview() const
12861
488782d9aba9 Recreate uFLRunQueue in Qt, render previews
unc0rr
parents: 12860
diff changeset
    68
{
12863
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    69
    return m_isPreview;
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    70
}
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    71
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    72
void GameConfig::setPreview(bool isPreview)
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    73
{
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    74
    m_isPreview = isPreview;
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    75
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    76
    m_arguments.clear();
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    77
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    78
    if (m_isPreview) {
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    79
        m_arguments
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    80
            << ""
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    81
            << "--internal"
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    82
            << "--landpreview";
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    83
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    84
    } else {
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    85
        m_arguments
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    86
            << ""
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    87
            << "--internal"
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    88
            << "--nomusic";
fe16fa088b69 Make playing a game possible
unc0rr
parents: 12861
diff changeset
    89
    }
12861
488782d9aba9 Recreate uFLRunQueue in Qt, render previews
unc0rr
parents: 12860
diff changeset
    90
}
488782d9aba9 Recreate uFLRunQueue in Qt, render previews
unc0rr
parents: 12860
diff changeset
    91
12859
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    92
void GameConfig::cfgAppend(const QByteArray& cmd)
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    93
{
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    94
    quint8 len = cmd.size();
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    95
    m_cfg.append(QByteArray::fromRawData(reinterpret_cast<const char*>(&len), 1) + cmd);
a03f245243b0 And more refactoring...
unc0rr
parents: 12858
diff changeset
    96
}