diff --git a/include/screens/unistore_v2.hpp b/include/screens/unistore_v2.hpp index 9dc537e..c25ff61 100644 --- a/include/screens/unistore_v2.hpp +++ b/include/screens/unistore_v2.hpp @@ -29,6 +29,7 @@ #include "common.hpp" #include "json.hpp" +#include "store.hpp" #include "structs.hpp" #include @@ -41,12 +42,16 @@ public: UniStoreV2(nlohmann::json &JSON, const std::string sheetPath); ~UniStoreV2(); private: + std::unique_ptr sortedStore; + bool darkMode = true, sheetLoaded = false, canDisplay = false, hasLoaded = false, isDropDown = false; int selectedBox = 0, lastViewMode = 0, dropSelection = 0, iconAmount = 0, selectedBoxList = 0, selection = -1, storePage = 0, downloadPage = 0, storePageList = 0, mode = 0, subSelection = 0; nlohmann::json storeJson; C2D_SpriteSheet sheet; std::vector objects; + void DrawSortingMenu(void) const; + // Base stuff. void DrawBaseTop(void) const; void DrawBaseBottom(void) const; @@ -98,6 +103,15 @@ private: {5, 70, 140, 25} // Style. }; + const std::vector sortingPos = { + {40, 40, 100, 40}, // Descending. + {180, 40, 100, 40}, // Ascending. + // Now the actual options. + {115, 90, 100, 30}, // Title. + {115, 130, 100, 30}, // Author. + {115, 170, 100, 30} // Last Updated. + }; + u32 barColorLight, barColorDark, bgColorLight, bgColorDark, textColorLight, textColorDark, boxColorLight, boxColorDark, outlineColorLight, outlineColorDark; }; diff --git a/include/utils/store.hpp b/include/utils/store.hpp new file mode 100644 index 0000000..68a9e64 --- /dev/null +++ b/include/utils/store.hpp @@ -0,0 +1,81 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#ifndef STORE_HPP +#define STORE_HPP + +#include "json.hpp" +#include <3ds.h> +#include +#include + +struct UniStoreV2Struct { + std::string title; + std::string author; + std::string version; + std::string category; + std::string console; + std::string last_updated; + int icon_index; + int JSONIndex; +}; + +enum class SortType { + TITLE, + AUTHOR, + LAST_UPDATED +}; + +class Store { +public: + Store(nlohmann::json &JS); + + void sorting(bool Ascending, SortType sorttype); + + std::string returnTitle(const int index); + std::string returnAuthor(const int index); + int returnIconIndex(const int index); + int returnJSONIndex(const int index); + int getSize(); + bool getAscending() { return this->ascending; } + + const int getSortType() { + if (this->sorttype == SortType::TITLE) return 0; + else if (this->sorttype == SortType::AUTHOR) return 1; + else if (this->sorttype == SortType::LAST_UPDATED) return 2; + else return -1; // Should not happen. + } + +private: + std::vector sortedStore, unsortedStore; + bool ascending = false; + nlohmann::json storeJson; + SortType sorttype = SortType::TITLE; + + UniStoreV2Struct getData(const int index); +}; + +#endif \ No newline at end of file diff --git a/romfs/lang/en/app.json b/romfs/lang/en/app.json index 11985d6..ac43273 100644 --- a/romfs/lang/en/app.json +++ b/romfs/lang/en/app.json @@ -188,5 +188,10 @@ "CHANGE_STYLE": "Change Style", "NO_DOWNLOADS_AVAILABLE": "No downloads available.", "UNISTORE_VERSION": "UniStore version: ", - "UNISTORE_NOT_SUPPORTED": "This UniStore version is not supported!" + "UNISTORE_NOT_SUPPORTED": "This UniStore version is not supported!", + "DESCENDING": "Descending", + "ASCENDING": "Ascending", + "TITLE_BTN": "Title", + "AUTHOR_BTN": "Author", + "LAST_UPDATED_BTN": "Last updated" } diff --git a/source/screens/unistore_v2.cpp b/source/screens/unistore_v2.cpp index aa3b876..088120d 100644 --- a/source/screens/unistore_v2.cpp +++ b/source/screens/unistore_v2.cpp @@ -40,6 +40,7 @@ extern bool didAutoboot; UniStoreV2::UniStoreV2(nlohmann::json &JSON, const std::string sheetPath) { this->storeJson = JSON; + this->sortedStore = std::make_unique(this->storeJson); if (access(sheetPath.c_str(), F_OK) != 0) { this->iconAmount = 0; @@ -84,7 +85,6 @@ u32 UniStoreV2::returnTextColor() const { return this->darkMode ? this->textColorDark : this->textColorLight; } - // Base draws. void UniStoreV2::DrawBaseTop(void) const { Gui::ScreenDraw(Top); @@ -123,7 +123,7 @@ void UniStoreV2::drawBox(float xPos, float yPos, float width, float height, bool } void UniStoreV2::DrawGrid(void) const { - for (int i = 0, i2 = 0 + (this->storePage * STORE_ENTRIES); i2 < STORE_ENTRIES + (this->storePage * STORE_ENTRIES) && i2 < (int)this->storeJson.at("storeContent").size(); i2++, i++) { + for (int i = 0, i2 = 0 + (this->storePage * STORE_ENTRIES); i2 < STORE_ENTRIES + (this->storePage * STORE_ENTRIES) && i2 < this->sortedStore->getSize(); i2++, i++) { if (i == this->selectedBox) { this->drawBox(this->StoreBoxesGrid[i].x, this->StoreBoxesGrid[i].y, 100, 50, true); } else { @@ -131,9 +131,9 @@ void UniStoreV2::DrawGrid(void) const { } if (this->sheetLoaded) { - if (this->storeJson.at("storeContent").at(i + (this->storePage * STORE_ENTRIES)).at("info").contains("icon_index")) { - if ((int)this->storeJson.at("storeContent").at(i + (this->storePage * STORE_ENTRIES)).at("info").at("icon_index") < this->iconAmount) { - Gui::DrawSprite(this->sheet, this->storeJson.at("storeContent").at(i + (this->storePage * STORE_ENTRIES)).at("info").at("icon_index"), this->StoreBoxesGrid[i].x+26, this->StoreBoxesGrid[i].y+1); + if (this->sortedStore->returnIconIndex(i + (this->storePage * STORE_ENTRIES)) != -1) { + if (this->sortedStore->returnIconIndex(i + (this->storePage * STORE_ENTRIES)) < this->iconAmount) { + Gui::DrawSprite(this->sheet, this->sortedStore->returnIconIndex(i + (this->storePage * STORE_ENTRIES)), this->StoreBoxesGrid[i].x+26, this->StoreBoxesGrid[i].y+1); } else { GFX::DrawSprite(sprites_noIcon_idx, this->StoreBoxesGrid[i].x+26, this->StoreBoxesGrid[i].y+1); } @@ -147,7 +147,7 @@ void UniStoreV2::DrawGrid(void) const { } void UniStoreV2::DrawList(void) const { - for (int i = 0, i2 = 0 + (this->storePageList * STORE_ENTRIES_LIST); i2 < STORE_ENTRIES_LIST + (this->storePageList * STORE_ENTRIES_LIST) && i2 < (int)this->storeJson.at("storeContent").size(); i2++, i++) { + for (int i = 0, i2 = 0 + (this->storePageList * STORE_ENTRIES_LIST); i2 < STORE_ENTRIES_LIST + (this->storePageList * STORE_ENTRIES_LIST) && i2 < this->sortedStore->getSize(); i2++, i++) { if (i == this->selectedBoxList) { this->drawBox(this->StoreBoxesList[i].x, this->StoreBoxesList[i].y, 360, 50, true); } else { @@ -155,9 +155,9 @@ void UniStoreV2::DrawList(void) const { } if (this->sheetLoaded) { - if (this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").contains("icon_index")) { - if ((int)this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").at("icon_index") < this->iconAmount) { - Gui::DrawSprite(this->sheet, this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").at("icon_index"), this->StoreBoxesList[i].x+1, this->StoreBoxesList[i].y+1); + if (this->sortedStore->returnIconIndex(i + (this->storePageList * STORE_ENTRIES_LIST)) != -1) { + if (this->sortedStore->returnIconIndex(i + (this->storePageList * STORE_ENTRIES_LIST)) < this->iconAmount) { + Gui::DrawSprite(this->sheet, this->sortedStore->returnIconIndex(i + (this->storePageList * STORE_ENTRIES_LIST)), this->StoreBoxesList[i].x+1, this->StoreBoxesList[i].y+1); } else { GFX::DrawSprite(sprites_noIcon_idx, this->StoreBoxesList[i].x+1, this->StoreBoxesList[i].y+1); } @@ -169,20 +169,38 @@ void UniStoreV2::DrawList(void) const { } // Display Author & App name. - if (this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").contains("title")) { - Gui::DrawString(this->StoreBoxesList[i].x+55, this->StoreBoxesList[i].y+12, 0.45f, this->returnTextColor(), (std::string)this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").at("title"), 300); - } else { - Gui::DrawString(this->StoreBoxesList[i].x+55, this->StoreBoxesList[i].y+12, 0.45f, this->returnTextColor(), "?", 300); - } - - if (this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").contains("author")) { - Gui::DrawString(this->StoreBoxesList[i].x+55, this->StoreBoxesList[i].y+28, 0.45f, this->returnTextColor(), (std::string)this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").at("author"), 300); - } else { - Gui::DrawString(this->StoreBoxesList[i].x+55, this->StoreBoxesList[i].y+28, 0.45f, this->returnTextColor(), "?", 300); - } + + Gui::DrawString(this->StoreBoxesList[i].x+55, this->StoreBoxesList[i].y+12, 0.45f, this->returnTextColor(), this->sortedStore->returnTitle(i + (this->storePageList * STORE_ENTRIES_LIST)), 300); + Gui::DrawString(this->StoreBoxesList[i].x+55, this->StoreBoxesList[i].y+28, 0.45f, this->returnTextColor(), this->sortedStore->returnAuthor(i + (this->storePageList * STORE_ENTRIES_LIST)), 300); } } +void UniStoreV2::DrawSortingMenu(void) const { + for (int i = 2; i < (int)sortingPos.size(); i++) { + if (i - 2 == this->sortedStore->getSortType()) { + this->drawBox(sortingPos[i].x, sortingPos[i].y, sortingPos[i].w, sortingPos[i].h, true); + } else { + this->drawBox(sortingPos[i].x, sortingPos[i].y, sortingPos[i].w, sortingPos[i].h, false); + } + } + + Gui::DrawString(sortingPos[2].x+4, sortingPos[2].y+9, 0.55f, this->returnTextColor(), Lang::get("TITLE_BTN")); + Gui::DrawString(sortingPos[3].x+4, sortingPos[3].y+9, 0.55f, this->returnTextColor(), Lang::get("AUTHOR_BTN")); + Gui::DrawString(sortingPos[4].x+4, sortingPos[4].y+9, 0.55f, this->returnTextColor(), Lang::get("LAST_UPDATED_BTN")); + + if (this->sortedStore->getAscending()) { + this->drawBox(sortingPos[0].x, sortingPos[0].y, sortingPos[0].w, sortingPos[0].h, false); + this->drawBox(sortingPos[1].x, sortingPos[1].y, sortingPos[1].w, sortingPos[1].h, true); + } else { + this->drawBox(sortingPos[0].x, sortingPos[0].y, sortingPos[0].w, sortingPos[0].h, true); + this->drawBox(sortingPos[1].x, sortingPos[1].y, sortingPos[1].w, sortingPos[1].h, false); + } + + Gui::DrawString(sortingPos[0].x+4, sortingPos[0].y+9, 0.55f, this->returnTextColor(), Lang::get("DESCENDING")); + Gui::DrawString(sortingPos[1].x+4, sortingPos[1].y+9, 0.55f, this->returnTextColor(), Lang::get("ASCENDING")); +} + + // Parse the objects from a script. void UniStoreV2::parseObjects(int selection) { this->objects.clear(); @@ -304,6 +322,7 @@ void UniStoreV2::Draw(void) const { if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); this->DrawBaseBottom(); + this->DrawSortingMenu(); if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); } else if (this->mode == 1) { @@ -320,7 +339,7 @@ void UniStoreV2::Draw(void) const { if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); this->DrawBaseBottom(); - + this->DrawSortingMenu(); if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); } else if (this->mode == 2) { this->displaySelectedEntry(this->selection); @@ -386,12 +405,12 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { if (hDown & KEY_RIGHT) { // Try to go to next page. if (this->selectedBox == 2 || this->selectedBox == 5 || this->selectedBox == 8) { - if (STORE_ENTRIES + (this->storePage * STORE_ENTRIES) < (int)this->storeJson.at("storeContent").size()) { + if (STORE_ENTRIES + (this->storePage * STORE_ENTRIES) < (int)this->sortedStore->getSize()) { this->selectedBox = 0; this->storePage++; } } else { - if ((this->storePage * STORE_ENTRIES) + this->selectedBox + 1 < (int)this->storeJson.at("storeContent").size()) { + if ((this->storePage * STORE_ENTRIES) + this->selectedBox + 1 < (int)this->sortedStore->getSize()) { if (this->selectedBox < 8 + (this->storePage * STORE_ENTRIES)) this->selectedBox++; } } @@ -414,13 +433,13 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } if (hDown & KEY_DOWN) { - if ((this->storePage * STORE_ENTRIES) + this->selectedBox + 3 < (int)this->storeJson.at("storeContent").size()) { + if ((this->storePage * STORE_ENTRIES) + this->selectedBox + 3 < (int)this->sortedStore->getSize()) { if (this->selectedBox < 6) this->selectedBox += 3; } } if (hDown & KEY_R) { - if (STORE_ENTRIES + (this->storePage * STORE_ENTRIES) < (int)this->storeJson.at("storeContent").size()) { + if (STORE_ENTRIES + (this->storePage * STORE_ENTRIES) < (int)this->sortedStore->getSize()) { this->selectedBox = 0; this->storePage++; } @@ -435,8 +454,8 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { if (hDown & KEY_A) { - if (this->selectedBox + (this->storePage * STORE_ENTRIES) < (int)this->storeJson.at("storeContent").size()) { - this->selection = this->selectedBox + (this->storePage * STORE_ENTRIES); + if (this->sortedStore->returnJSONIndex(this->selectedBox + (this->storePage * STORE_ENTRIES)) < (int)this->storeJson.at("storeContent").size()) { + this->selection = this->sortedStore->returnJSONIndex(this->selectedBox + (this->storePage * STORE_ENTRIES)); this->parseObjects(this->selection); this->canDisplay = true; this->lastViewMode = this->mode; @@ -444,6 +463,20 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } } + if (hDown & KEY_TOUCH) { + if (touching(touch, sortingPos[0])) { + this->sortedStore->sorting(false, SortType(this->sortedStore->getSortType())); + } else if (touching(touch, sortingPos[1])) { + this->sortedStore->sorting(true, SortType(this->sortedStore->getSortType())); + } else if (touching(touch, sortingPos[2])) { + this->sortedStore->sorting(this->sortedStore->getAscending(), SortType(0)); + } else if (touching(touch, sortingPos[3])) { + this->sortedStore->sorting(this->sortedStore->getAscending(), SortType(1)); + } else if (touching(touch, sortingPos[4])) { + this->sortedStore->sorting(this->sortedStore->getAscending(), SortType(2)); + } + } + } else if (this->mode == 1) { if (hDown & KEY_B) { if (!didAutoboot) didAutoboot = true; @@ -452,7 +485,7 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } if (hDown & KEY_DOWN) { - if ((this->storePageList * STORE_ENTRIES_LIST) + this->selectedBoxList + 1 < (int)this->storeJson.at("storeContent").size()) { + if ((this->storePageList * STORE_ENTRIES_LIST) + this->selectedBoxList + 1 < (int)this->sortedStore->getSize()) { if (this->selectedBoxList < STORE_ENTRIES_LIST-1) this->selectedBoxList++; } } @@ -462,7 +495,7 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } if (hDown & KEY_RIGHT || hDown & KEY_R) { - if (STORE_ENTRIES_LIST + (this->storePageList * STORE_ENTRIES_LIST) < (int)this->storeJson.at("storeContent").size()) { + if (STORE_ENTRIES_LIST + (this->storePageList * STORE_ENTRIES_LIST) < (int)this->sortedStore->getSize()) { this->selectedBoxList = 0; this->storePageList++; } @@ -476,8 +509,8 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } if (hDown & KEY_A) { - if (this->selectedBoxList + (this->storePageList * STORE_ENTRIES_LIST) < (int)this->storeJson.at("storeContent").size()) { - this->selection = this->selectedBoxList + (this->storePageList * STORE_ENTRIES_LIST); + if (this->sortedStore->returnJSONIndex(this->selectedBoxList + (this->storePageList * STORE_ENTRIES_LIST)) < (int)this->storeJson.at("storeContent").size()) { + this->selection = this->sortedStore->returnJSONIndex(this->selectedBoxList + (this->storePageList * STORE_ENTRIES_LIST)); this->parseObjects(this->selection); this->canDisplay = true; this->lastViewMode = this->mode; @@ -485,6 +518,20 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } } + if (hDown & KEY_TOUCH) { + if (touching(touch, sortingPos[0])) { + this->sortedStore->sorting(false, SortType(this->sortedStore->getSortType())); + } else if (touching(touch, sortingPos[1])) { + this->sortedStore->sorting(true, SortType(this->sortedStore->getSortType())); + } else if (touching(touch, sortingPos[2])) { + this->sortedStore->sorting(this->sortedStore->getAscending(), SortType(0)); + } else if (touching(touch, sortingPos[3])) { + this->sortedStore->sorting(this->sortedStore->getAscending(), SortType(1)); + } else if (touching(touch, sortingPos[4])) { + this->sortedStore->sorting(this->sortedStore->getAscending(), SortType(2)); + } + } + } else if (this->mode == 2) { if (hDown & KEY_TOUCH) { if (this->objects.size() > 0) { diff --git a/source/utils/store.cpp b/source/utils/store.cpp new file mode 100644 index 0000000..8283d57 --- /dev/null +++ b/source/utils/store.cpp @@ -0,0 +1,170 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#include "store.hpp" + +Store::Store(nlohmann::json &JS) { + this->storeJson = JS; + for (int i = 0; i < (int)this->storeJson.at("storeContent").size(); i++) { + this->unsortedStore.push_back(this->getData(i)); + } + + this->sortedStore = this->unsortedStore; // Put that to sorted store as well. +} + +// Here we get the data of the UniStore! +UniStoreV2Struct Store::getData(const int index) { + UniStoreV2Struct temp = {"", "", "", "", "" ,"", -1, 0}; + + if (index > (int)this->storeJson.at("storeContent").size()) return temp; // Empty. + + // Here we check. + // Title. + if (this->storeJson.at("storeContent").at(index).at("info").contains("title")) { + temp.title = this->storeJson.at("storeContent").at(index).at("info").at("title"); + } + + // Author. + if (this->storeJson.at("storeContent").at(index).at("info").contains("author")) { + temp.author = this->storeJson.at("storeContent").at(index).at("info").at("author"); + } + + // Version. + if (this->storeJson.at("storeContent").at(index).at("info").contains("version")) { + temp.version = this->storeJson.at("storeContent").at(index).at("info").at("version"); + } + + if (this->storeJson.at("storeContent").at(index).at("info").contains("category")) { + temp.category = this->storeJson.at("storeContent").at(index).at("info").at("category"); + } + + // Console. + if (this->storeJson.at("storeContent").at(index).at("info").contains("console")) { + temp.console = this->storeJson.at("storeContent").at(index).at("info").at("console"); + } + + // Last updated. + if (this->storeJson.at("storeContent").at(index).at("info").contains("last_updated")) { + temp.last_updated = this->storeJson.at("storeContent").at(index).at("info").at("last_updated"); + } + + // Icon index. + if (this->storeJson.at("storeContent").at(index).at("info").contains("icon_index")) { + temp.icon_index = this->storeJson.at("storeContent").at(index).at("info").at("icon_index"); + } + + // JSON index. + temp.JSONIndex = index; + + return temp; +} + +// Title. +bool compareTitleDescending(const UniStoreV2Struct& a, const UniStoreV2Struct& b) { + int result = a.title.compare(b.title); + if (result > 0) return true; + else return false; +} +bool compareTitleAscending(const UniStoreV2Struct& a, const UniStoreV2Struct& b) { + int result = b.title.compare(a.title); + if (result > 0) return true; + else return false; +} + +// Author. +bool compareAuthorDescending(const UniStoreV2Struct& a, const UniStoreV2Struct& b) { + int result = a.author.compare(b.author); + if (result > 0) return true; + else return false; +} +bool compareAuthorAscending(const UniStoreV2Struct& a, const UniStoreV2Struct& b) { + int result = b.author.compare(a.author); + if (result > 0) return true; + else return false; +} + +// Last updated. +bool compareUpdateDescending(const UniStoreV2Struct& a, const UniStoreV2Struct& b) { + int result = a.last_updated.compare(b.last_updated); + if (result > 0) return true; + else return false; +} +bool compareUpdateAscending(const UniStoreV2Struct& a, const UniStoreV2Struct& b) { + int result = b.last_updated.compare(a.last_updated); + if (result > 0) return true; + else return false; +} + +void Store::sorting(bool Ascending, SortType sorttype) { + this->ascending = Ascending; + this->sorttype = sorttype; + switch(this->sorttype) { + case SortType::TITLE: + if (Ascending) { + std::sort(this->sortedStore.begin(), this->sortedStore.end(), compareTitleAscending); + } else { + std::sort(this->sortedStore.begin(), this->sortedStore.end(), compareTitleDescending); + } + break; + case SortType::AUTHOR: + if (Ascending) { + std::sort(this->sortedStore.begin(), this->sortedStore.end(), compareAuthorAscending); + } else { + std::sort(this->sortedStore.begin(), this->sortedStore.end(), compareAuthorDescending); + } + break; + case SortType::LAST_UPDATED: + if (Ascending) { + std::sort(this->sortedStore.begin(), sortedStore.end(), compareUpdateAscending); + } else { + std::sort(this->sortedStore.begin(), sortedStore.end(), compareUpdateDescending); + } + break; + } +} + +// Some return stuff with checks! +std::string Store::returnTitle(const int index) { + if (index > (int)this->sortedStore.size()) return "?"; // Out of scope. + return this->sortedStore[index].title; +} + +std::string Store::returnAuthor(const int index) { + if (index > (int)this->sortedStore.size()) return "?"; // Out of scope. + return this->sortedStore[index].author; +} + +int Store::returnIconIndex(const int index) { + if (index > (int)this->sortedStore.size()) return -1; // Out of scope. + return this->sortedStore[index].icon_index; +} + +int Store::returnJSONIndex(const int index) { + if (index > (int)this->sortedStore.size()) return -1; // Out of scope. + return this->sortedStore[index].JSONIndex; +} + +int Store::getSize() { return (int)this->sortedStore.size(); } \ No newline at end of file