summaryrefslogtreecommitdiffstats
path: root/api/logic/modplatform/modpacksch/PackManifest.cpp
blob: 5ffd18de915946e22375cb8bd3448a4df5c7df2f (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "PackManifest.h"

#include "Json.h"

static void loadSpecs(ModpacksCH::Specs & s, QJsonObject & obj)
{
    s.id = Json::requireInteger(obj, "id");
    s.minimum = Json::requireInteger(obj, "minimum");
    s.recommended = Json::requireInteger(obj, "recommended");
}

static void loadTag(ModpacksCH::Tag & t, QJsonObject & obj)
{
    t.id = Json::requireInteger(obj, "id");
    t.name = Json::requireString(obj, "name");
}

static void loadArt(ModpacksCH::Art & a, QJsonObject & obj)
{
    a.id = Json::requireInteger(obj, "id");
    a.url = Json::requireString(obj, "url");
    a.type = Json::requireString(obj, "type");
    a.width = Json::requireInteger(obj, "width");
    a.height = Json::requireInteger(obj, "height");
    a.compressed = Json::requireBoolean(obj, "compressed");
    a.sha1 = Json::requireString(obj, "sha1");
    a.size = Json::requireInteger(obj, "size");
    a.updated = Json::requireInteger(obj, "updated");
}

static void loadAuthor(ModpacksCH::Author & a, QJsonObject & obj)
{
    a.id = Json::requireInteger(obj, "id");
    a.name = Json::requireString(obj, "name");
    a.type = Json::requireString(obj, "type");
    a.website = Json::requireString(obj, "website");
    a.updated = Json::requireInteger(obj, "updated");
}

static void loadVersionInfo(ModpacksCH::VersionInfo & v, QJsonObject & obj)
{
    v.id = Json::requireInteger(obj, "id");
    v.name = Json::requireString(obj, "name");
    v.type = Json::requireString(obj, "type");
    v.updated = Json::requireInteger(obj, "updated");
    auto specs = Json::requireObject(obj, "specs");
    loadSpecs(v.specs, specs);
}

void ModpacksCH::loadModpack(ModpacksCH::Modpack & m, QJsonObject & obj)
{
    m.id = Json::requireInteger(obj, "id");
    m.name = Json::requireString(obj, "name");
    m.synopsis = Json::requireString(obj, "synopsis");
    m.description = Json::requireString(obj, "description");
    m.type = Json::requireString(obj, "type");
    m.featured = Json::requireBoolean(obj, "featured");
    m.installs = Json::requireInteger(obj, "installs");
    m.plays = Json::requireInteger(obj, "plays");
    m.updated = Json::requireInteger(obj, "updated");
    m.refreshed = Json::requireInteger(obj, "refreshed");
    auto artArr = Json::requireArray(obj, "art");
    for (const auto & artRaw : artArr)
    {
        auto artObj = Json::requireObject(artRaw);
        ModpacksCH::Art art;
        loadArt(art, artObj);
        m.art.append(art);
    }
    auto authorArr = Json::requireArray(obj, "authors");
    for (const auto & authorRaw : authorArr)
    {
        auto authorObj = Json::requireObject(authorRaw);
        ModpacksCH::Author author;
        loadAuthor(author, authorObj);
        m.authors.append(author);
    }
    auto versionArr = Json::requireArray(obj, "versions");
    for (const auto & versionRaw : versionArr)
    {
        auto versionObj = Json::requireObject(versionRaw);
        ModpacksCH::VersionInfo version;
        loadVersionInfo(version, versionObj);
        m.versions.append(version);
    }
    auto tagArr = Json::requireArray(obj, "tags");
    for (const auto & tagRaw : tagArr)
    {
        auto tagObj = Json::requireObject(tagRaw);
        ModpacksCH::Tag tag;
        loadTag(tag, tagObj);
        m.tags.append(tag);
    }
    m.updated = Json::requireInteger(obj, "updated");
}

static void loadVersionTarget(ModpacksCH::VersionTarget & a, QJsonObject & obj)
{
    a.id = Json::requireInteger(obj, "id");
    a.name = Json::requireString(obj, "name");
    a.type = Json::requireString(obj, "type");
    a.version = Json::requireString(obj, "version");
    a.updated = Json::requireInteger(obj, "updated");
}

static void loadVersionFile(ModpacksCH::VersionFile & a, QJsonObject & obj)
{
    a.id = Json::requireInteger(obj, "id");
    a.type = Json::requireString(obj, "type");
    a.path = Json::requireString(obj, "path");
    a.name = Json::requireString(obj, "name");
    a.version = Json::requireString(obj, "version");
    a.url = Json::requireString(obj, "url");
    a.sha1 = Json::requireString(obj, "sha1");
    a.size = Json::requireInteger(obj, "size");
    a.clientOnly = Json::requireBoolean(obj, "clientonly");
    a.serverOnly = Json::requireBoolean(obj, "serveronly");
    a.optional = Json::requireBoolean(obj, "optional");
    a.updated = Json::requireInteger(obj, "updated");
}

void ModpacksCH::loadVersion(ModpacksCH::Version & m, QJsonObject & obj)
{
    m.id = Json::requireInteger(obj, "id");
    m.parent = Json::requireInteger(obj, "parent");
    m.name = Json::requireString(obj, "name");
    m.type = Json::requireString(obj, "type");
    m.installs = Json::requireInteger(obj, "installs");
    m.plays = Json::requireInteger(obj, "plays");
    m.updated = Json::requireInteger(obj, "updated");
    m.refreshed = Json::requireInteger(obj, "refreshed");
    auto specs = Json::requireObject(obj, "specs");
    loadSpecs(m.specs, specs);
    auto targetArr = Json::requireArray(obj, "targets");
    for (const auto & targetRaw : targetArr)
    {
        auto versionObj = Json::requireObject(targetRaw);
        ModpacksCH::VersionTarget target;
        loadVersionTarget(target, versionObj);
        m.targets.append(target);
    }
    auto fileArr = Json::requireArray(obj, "files");
    for (const auto & fileRaw : fileArr)
    {
        auto fileObj = Json::requireObject(fileRaw);
        ModpacksCH::VersionFile file;
        loadVersionFile(file, fileObj);
        m.files.append(file);
    }
}

//static void loadVersionChangelog(ModpacksCH::VersionChangelog & m, QJsonObject & obj)
//{
//    m.content = Json::requireString(obj, "content");
//    m.updated = Json::requireInteger(obj, "updated");
//}