diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/content/packages.cpp | 15 | ||||
-rw-r--r-- | src/content/packages.h | 16 | ||||
-rw-r--r-- | src/script/lua_api/l_mainmenu.cpp | 32 |
3 files changed, 28 insertions, 35 deletions
diff --git a/src/content/packages.cpp b/src/content/packages.cpp index d50e63a6b..dd7574d48 100644 --- a/src/content/packages.cpp +++ b/src/content/packages.cpp @@ -43,24 +43,19 @@ std::vector<Package> getPackagesFromURL(const std::string &url) for (unsigned int i = 0; i < json.size(); ++i) { Package package; + package.author = json[i]["author"].asString(); package.name = json[i]["name"].asString(); package.title = json[i]["title"].asString(); - package.author = json[i]["author"].asString(); package.type = json[i]["type"].asString(); package.shortDesc = json[i]["shortDesc"].asString(); - package.url = json[i]["url"].asString(); package.release = json[i]["release"].asInt(); + if (json[i].isMember("thumbnail")) + package.thumbnail = json[i]["thumbnail"].asString(); - Json::Value jScreenshots = json[i]["screenshots"]; - for (unsigned int j = 0; j < jScreenshots.size(); ++j) { - package.screenshots.push_back(jScreenshots[j].asString()); - } - - if (package.valid()) { + if (package.valid()) packages.push_back(package); - } else { + else errorstream << "Invalid package at " << i << std::endl; - } } return packages; diff --git a/src/content/packages.h b/src/content/packages.h index 2290bd607..fc60d5703 100644 --- a/src/content/packages.h +++ b/src/content/packages.h @@ -24,20 +24,24 @@ with this program; if not, write to the Free Software Foundation, Inc., struct Package { + std::string author; std::string name; // Technical name std::string title; - std::string author; std::string type; // One of "mod", "game", or "txp" std::string shortDesc; - std::string url; // download URL u32 release; - std::vector<std::string> screenshots; + std::string thumbnail; + + bool valid() const + { + return !(author.empty() || name.empty() || title.empty() || + type.empty() || release <= 0); + } - bool valid() + std::string getDownloadURL(const std::string &baseURL) const { - return !(name.empty() || title.empty() || author.empty() || - type.empty() || url.empty() || release <= 0); + return baseURL + "/packages/" + author + "/" + name + "/download/"; } }; diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 1f49fc211..a5b211bc7 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -1005,7 +1005,7 @@ int ModApiMainMenu::l_get_screen_info(lua_State *L) int ModApiMainMenu::l_get_package_list(lua_State *L) { std::string url = g_settings->get("contentdb_url"); - std::vector<Package> packages = getPackagesFromURL(url + "/packages/"); + std::vector<Package> packages = getPackagesFromURL(url + "/api/packages/"); // Make table lua_newtable(L); @@ -1019,6 +1019,10 @@ int ModApiMainMenu::l_get_package_list(lua_State *L) int top_lvl2 = lua_gettop(L); + lua_pushstring(L, "author"); + lua_pushstring(L, package.author.c_str()); + lua_settable (L, top_lvl2); + lua_pushstring(L, "name"); lua_pushstring(L, package.name.c_str()); lua_settable (L, top_lvl2); @@ -1027,10 +1031,6 @@ int ModApiMainMenu::l_get_package_list(lua_State *L) lua_pushstring(L, package.title.c_str()); lua_settable (L, top_lvl2); - lua_pushstring(L, "author"); - lua_pushstring(L, package.author.c_str()); - lua_settable (L, top_lvl2); - lua_pushstring(L, "type"); lua_pushstring(L, package.type.c_str()); lua_settable (L, top_lvl2); @@ -1039,25 +1039,19 @@ int ModApiMainMenu::l_get_package_list(lua_State *L) lua_pushstring(L, package.shortDesc.c_str()); lua_settable (L, top_lvl2); - lua_pushstring(L, "url"); - lua_pushstring(L, package.url.c_str()); - lua_settable (L, top_lvl2); - lua_pushstring (L, "release"); lua_pushinteger(L, package.release); lua_settable (L, top_lvl2); - lua_pushstring(L, "screenshots"); - lua_newtable(L); - { - int top_screenshots = lua_gettop(L); - for (size_t i = 0; i < package.screenshots.size(); ++i) { - lua_pushnumber(L, i + 1); - lua_pushstring(L, package.screenshots[i].c_str()); - lua_settable(L, top_screenshots); - } + if (package.thumbnail != "") { + lua_pushstring(L, "thumbnail"); + lua_pushstring(L, package.thumbnail.c_str()); + lua_settable (L, top_lvl2); } - lua_settable(L, top_lvl2); + + lua_pushstring(L, "url"); + lua_pushstring(L, package.getDownloadURL(url).c_str()); + lua_settable (L, top_lvl2); lua_settable(L, top); index++; |