addded clang-tidy to cmake
c41059b parent: cc750ae modified
CMakeLists.txt +4 -0 | @@ -18,6 +18,8 @@ endif() | ||
| 18 | 18 | |
| 19 | 19 | |
| 20 | 20 | |
| 21 | +find_program(CLANG_TIDY NAMES "clang-tidy" REQUIRED) | |
| 22 | +set(CLANG_TIDY_COMMAND "${CLANG_TIDY}" "-checks=-*,modernize-*") | |
| 21 | 23 | |
| 22 | 24 | |
| 23 | 25 | find_package(SQLite3 REQUIRED) |
| @@ -26,12 +28,14 @@ include_directories(${CMAKE_SOURCE_DIR}/include) | ||
| 26 | 28 | |
| 27 | 29 | add_executable(fluffy src/main.cpp) |
| 28 | 30 | |
| 31 | + | |
| 29 | 32 | target_link_libraries(fluffy |
| 30 | 33 | PRIVATE ftxui::screen |
| 31 | 34 | PRIVATE ftxui::dom |
| 32 | 35 | PRIVATE ftxui::component |
| 33 | 36 | PRIVATE SQLite::SQLite3 |
| 34 | 37 | ) |
| 38 | +set_target_properties(fluffy PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") | |
| 35 | 39 | |
| 36 | 40 | if (EMSCRIPTEN) |
| 37 | 41 | string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS") |
| @@ -18,6 +18,8 @@ endif() | |||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | +find_program(CLANG_TIDY NAMES "clang-tidy" REQUIRED) | ||
| 22 | +set(CLANG_TIDY_COMMAND "${CLANG_TIDY}" "-checks=-*,modernize-*") | ||
| 21 | 23 | ||
| 22 | 24 | ||
| 23 | find_package(SQLite3 REQUIRED) | 25 | find_package(SQLite3 REQUIRED) |
| @@ -26,12 +28,14 @@ include_directories(${CMAKE_SOURCE_DIR}/include) | |||
| 26 | 28 | ||
| 27 | add_executable(fluffy src/main.cpp) | 29 | add_executable(fluffy src/main.cpp) |
| 28 | 30 | ||
| 31 | + | ||
| 29 | target_link_libraries(fluffy | 32 | target_link_libraries(fluffy |
| 30 | PRIVATE ftxui::screen | 33 | PRIVATE ftxui::screen |
| 31 | PRIVATE ftxui::dom | 34 | PRIVATE ftxui::dom |
| 32 | PRIVATE ftxui::component | 35 | PRIVATE ftxui::component |
| 33 | PRIVATE SQLite::SQLite3 | 36 | PRIVATE SQLite::SQLite3 |
| 34 | ) | 37 | ) |
| 38 | +set_target_properties(fluffy PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") | ||
| 35 | 39 | ||
| 36 | if (EMSCRIPTEN) | 40 | if (EMSCRIPTEN) |
| 37 | string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS") | 41 | string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS") |
modified
include/game.hpp +11 -10 | @@ -2,17 +2,18 @@ | ||
| 2 | 2 | |
| 3 | 3 | #include <string> |
| 4 | 4 | |
| 5 | -class Game | |
| 6 | -{ | |
| 5 | +class Game { | |
| 7 | 6 | private: |
| 8 | - int id; | |
| 9 | - std::string name; | |
| 10 | - std::string path; | |
| 7 | + int id; | |
| 8 | + std::string name; | |
| 9 | + std::string path; | |
| 10 | + | |
| 11 | 11 | public: |
| 12 | - Game(int id, std::string name, std::string path) : id{id}, name{name}, path{path} { } | |
| 13 | - ~Game() { } | |
| 12 | + Game(int id, std::string name, std::string path) | |
| 13 | + : id{id}, name{name}, path{path} {} | |
| 14 | + ~Game() {} | |
| 14 | 15 | |
| 15 | - int getId() { return id; } | |
| 16 | - std::string getName() { return name; } | |
| 17 | - std::string getPath() { return path; } | |
| 16 | + int getId() { return id; } | |
| 17 | + std::string getName() { return name; } | |
| 18 | + std::string getPath() { return path; } | |
| 18 | 19 | }; |
| @@ -2,17 +2,18 @@ | |||
| 2 | 2 | ||
| 3 | #include <string> | 3 | #include <string> |
| 4 | 4 | ||
| 5 | -class Game | 5 | +class Game { |
| 6 | -{ | ||
| 7 | private: | 6 | private: |
| 8 | - int id; | 7 | + int id; |
| 9 | - std::string name; | 8 | + std::string name; |
| 10 | - std::string path; | 9 | + std::string path; |
| 10 | + | ||
| 11 | public: | 11 | public: |
| 12 | - Game(int id, std::string name, std::string path) : id{id}, name{name}, path{path} { } | 12 | + Game(int id, std::string name, std::string path) |
| 13 | - ~Game() { } | 13 | + : id{id}, name{name}, path{path} {} |
| 14 | + ~Game() {} | ||
| 14 | 15 | ||
| 15 | - int getId() { return id; } | 16 | + int getId() { return id; } |
| 16 | - std::string getName() { return name; } | 17 | + std::string getName() { return name; } |
| 17 | - std::string getPath() { return path; } | 18 | + std::string getPath() { return path; } |
| 18 | }; | 19 | }; |
modified
src/main.cpp +215 -216 | @@ -1,16 +1,17 @@ | ||
| 1 | -#include "ftxui/dom/elements.hpp" | |
| 2 | -#include "ftxui/screen/screen.hpp" | |
| 3 | -#include "ftxui/screen/string.hpp" | |
| 4 | 1 | #include "ftxui/component/component.hpp" |
| 2 | +#include "ftxui/component/component_base.hpp" | |
| 5 | 3 | #include "ftxui/component/component_options.hpp" |
| 6 | 4 | #include "ftxui/component/screen_interactive.hpp" |
| 5 | +#include "ftxui/dom/elements.hpp" | |
| 6 | +#include "ftxui/screen/screen.hpp" | |
| 7 | +#include "ftxui/screen/string.hpp" | |
| 7 | 8 | |
| 8 | -#include <iostream> | |
| 9 | -#include <string> | |
| 10 | 9 | #include <cstdlib> |
| 11 | 10 | #include <filesystem> |
| 12 | -#include <sqlite3.h> | |
| 11 | +#include <iostream> | |
| 13 | 12 | #include <map> |
| 13 | +#include <sqlite3.h> | |
| 14 | +#include <string> | |
| 14 | 15 | #include <vector> |
| 15 | 16 | |
| 16 | 17 | #include <game.hpp> |
| @@ -19,249 +20,247 @@ using namespace ftxui; | ||
| 19 | 20 | |
| 20 | 21 | std::vector<Game> games; |
| 21 | 22 | |
| 22 | -std::string database_initialization_command = "CREATE TABLE GAME(" | |
| 23 | - "GAME_ID INT PRIMARY KEY NOT NULL, " | |
| 24 | - "GAME_NAME TEXT NOT NULL, " | |
| 25 | - "GAME_PATH TEXT NOT NULL);"; | |
| 23 | +std::string database_initialization_command = | |
| 24 | + "CREATE TABLE GAME(" | |
| 25 | + "GAME_ID INT PRIMARY KEY NOT NULL, " | |
| 26 | + "GAME_NAME TEXT NOT NULL, " | |
| 27 | + "GAME_PATH TEXT NOT NULL);"; | |
| 26 | 28 | |
| 27 | -const char* select_all_games_command = "SELECT * FROM GAME;"; | |
| 29 | +std::string select_all_games_command = "SELECT * FROM GAME;"; | |
| 28 | 30 | |
| 29 | 31 | bool debugRun = true; |
| 30 | 32 | |
| 31 | 33 | void printMessage(std::string message) { |
| 32 | - if (debugRun) { | |
| 33 | - std::cout << message << std::endl; | |
| 34 | - } | |
| 34 | + if (debugRun) { | |
| 35 | + std::cout << message << std::endl; | |
| 36 | + } | |
| 35 | 37 | } |
| 36 | 38 | |
| 37 | -void execute_sql_command(sqlite3* database, std::string command) { | |
| 38 | - int exit = 0; | |
| 39 | - char* messageError; | |
| 40 | - exit = sqlite3_exec(database, command.c_str(), NULL, 0, &messageError); | |
| 41 | - | |
| 42 | - if (exit != SQLITE_OK) { | |
| 43 | - printMessage("Error with command: " + command + " " + messageError); | |
| 44 | - sqlite3_free(messageError); | |
| 45 | - } | |
| 39 | +void execute_sql_command(sqlite3 *database, std::string command) { | |
| 40 | + int exit = 0; | |
| 41 | + char *messageError; | |
| 42 | + exit = sqlite3_exec(database, command.c_str(), NULL, 0, &messageError); | |
| 43 | + | |
| 44 | + if (exit != SQLITE_OK) { | |
| 45 | + printMessage("Error with command: " + command + " " + messageError); | |
| 46 | + sqlite3_free(messageError); | |
| 47 | + } | |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | -int calculateFirstGameIdAvailable() { | |
| 49 | - int availableId{}; | |
| 50 | +auto calculateFirstGameIdAvailable() -> int { | |
| 51 | + int availableId{}; | |
| 50 | 52 | |
| 51 | - std::vector<int> usedIds{}; | |
| 52 | - for (auto& game : games) { | |
| 53 | - usedIds.push_back(game.getId()); | |
| 54 | - } | |
| 53 | + std::vector<int> usedIds{}; | |
| 54 | + for (auto &game : games) { | |
| 55 | + usedIds.emplace_back(game.getId()); | |
| 56 | + } | |
| 55 | 57 | |
| 56 | - bool found{ true }; | |
| 57 | - while(found) { | |
| 58 | - found = std::find(usedIds.begin(), usedIds.end(), availableId) != std::end(usedIds); | |
| 59 | - availableId++; | |
| 60 | - } | |
| 58 | + bool found{true}; | |
| 59 | + while (found) { | |
| 60 | + found = std::find(usedIds.begin(), usedIds.end(), availableId) != | |
| 61 | + std::end(usedIds); | |
| 62 | + availableId++; | |
| 63 | + } | |
| 61 | 64 | |
| 62 | - return availableId; | |
| 65 | + return availableId; | |
| 63 | 66 | } |
| 64 | 67 | |
| 65 | -void addGameToDatabase(sqlite3* database, int id, std::string name, std::string path) { | |
| 66 | - std::string command = "INSERT INTO GAME (GAME_ID, GAME_NAME, GAME_PATH) VALUES ("; | |
| 67 | - command += std::to_string(id) + ", '" + name + "', \"" + path + "\");"; | |
| 68 | - execute_sql_command(database, command); | |
| 68 | +void addGameToDatabase(sqlite3 *database, int id, std::string name, | |
| 69 | + std::string path) { | |
| 70 | + std::string command = | |
| 71 | + "INSERT INTO GAME (GAME_ID, GAME_NAME, GAME_PATH) VALUES ("; | |
| 72 | + command += std::to_string(id) + ", '" + name + "', \"" + path + "\");"; | |
| 73 | + execute_sql_command(database, command); | |
| 69 | 74 | } |
| 70 | 75 | |
| 71 | -void addGame(sqlite3* database, std::string name, std::string path) { | |
| 72 | - int id = calculateFirstGameIdAvailable(); | |
| 73 | - addGameToDatabase(database, id, name, path); | |
| 76 | +void addGame(sqlite3 *database, std::string name, std::string path) { | |
| 77 | + int id = calculateFirstGameIdAvailable(); | |
| 78 | + addGameToDatabase(database, id, name, path); | |
| 74 | 79 | } |
| 75 | 80 | |
| 76 | -void removeGame(sqlite3* database, std::string name) { | |
| 77 | - std::string command = "DELETE FROM GAME WHERE GAME_NAME="; | |
| 78 | - command += "'" + name + "';"; | |
| 79 | - execute_sql_command(database, command); | |
| 81 | +void removeGame(sqlite3 *database, std::string name) { | |
| 82 | + std::string command = "DELETE FROM GAME WHERE GAME_NAME="; | |
| 83 | + command += "'" + name + "';"; | |
| 84 | + execute_sql_command(database, command); | |
| 80 | 85 | } |
| 81 | 86 | |
| 82 | -void initialize_database(sqlite3* database) { | |
| 83 | - execute_sql_command(database, database_initialization_command); | |
| 84 | - printMessage("Database Initialized"); | |
| 87 | +void initialize_database(sqlite3 *database) { | |
| 88 | + execute_sql_command(database, database_initialization_command); | |
| 89 | + printMessage("Database Initialized"); | |
| 85 | 90 | } |
| 86 | 91 | |
| 87 | -void runGame(sqlite3* database, std::string gameName) { | |
| 88 | - std::string pathToRun = ""; | |
| 89 | - for (auto& game : games) { | |
| 90 | - if (gameName == game.getName()) { | |
| 91 | - pathToRun = game.getPath(); | |
| 92 | - } | |
| 92 | +void runGame(sqlite3 *database, std::string gameName) { | |
| 93 | + std::string pathToRun = ""; | |
| 94 | + for (auto &game : games) { | |
| 95 | + if (gameName == game.getName()) { | |
| 96 | + pathToRun = game.getPath(); | |
| 93 | 97 | } |
| 94 | - system(pathToRun.c_str()); | |
| 98 | + } | |
| 99 | + system(pathToRun.c_str()); | |
| 95 | 100 | } |
| 96 | 101 | |
| 97 | -void handleCommand(int argc, char const *argv[], sqlite3* database) { | |
| 98 | - std::string command{}; | |
| 99 | - switch (argc) { | |
| 100 | - case 2: | |
| 101 | - command = argv[1]; | |
| 102 | - if (command == "show") { | |
| 103 | - for (auto& game : games) { | |
| 104 | - std::cout << game.getName() << ": " << game.getPath() << std::endl; | |
| 105 | - } | |
| 106 | - } | |
| 107 | - break; | |
| 108 | - case 3: | |
| 109 | - command = argv[1]; | |
| 110 | - if (command == "rm") { | |
| 111 | - std::string gameName{ argv[2] }; | |
| 112 | - removeGame(database, gameName); | |
| 113 | - } | |
| 114 | - else if(command == "play") { | |
| 115 | - std::string gameName{ argv[2] }; | |
| 116 | - runGame(database, gameName); | |
| 117 | - } | |
| 118 | - case 4: | |
| 119 | - command = argv[1]; | |
| 120 | - if (command == "add") { | |
| 121 | - std::string gameName{ argv[2] }; | |
| 122 | - auto localPath = std::filesystem::path(argv[3]); | |
| 123 | - std::string globalPath = std::filesystem::absolute(localPath).lexically_normal().string(); | |
| 124 | - | |
| 125 | - std::string temp{}; | |
| 126 | - for (const auto a : globalPath) { | |
| 127 | - if (a != ' ') { | |
| 128 | - temp += a; | |
| 129 | - } | |
| 130 | - else { | |
| 131 | - temp += "\' \'"; | |
| 132 | - } | |
| 133 | - } | |
| 134 | - | |
| 135 | - addGame(database, gameName, temp); | |
| 136 | - } | |
| 137 | - break; | |
| 102 | +void handleCommand(int argc, char const *argv[], sqlite3 *database) { | |
| 103 | + std::string command{}; | |
| 104 | + switch (argc) { | |
| 105 | + case 2: | |
| 106 | + command = argv[1]; | |
| 107 | + if (command == "show") { | |
| 108 | + for (auto &game : games) { | |
| 109 | + std::cout << game.getName() << ": " << game.getPath() << std::endl; | |
| 110 | + } | |
| 138 | 111 | } |
| 139 | -} | |
| 140 | - | |
| 141 | -int main(int argc, char const *argv[]) { | |
| 142 | - bool newCreation = not std::filesystem::exists("data.db"); | |
| 143 | - | |
| 144 | - char* messageError; | |
| 145 | - sqlite3* database; | |
| 146 | - sqlite3_stmt* stmt; | |
| 147 | - int exit = 0; | |
| 148 | - exit = sqlite3_open("data.db", &database); | |
| 112 | + break; | |
| 113 | + case 3: | |
| 114 | + command = argv[1]; | |
| 115 | + if (command == "rm") { | |
| 116 | + std::string gameName{argv[2]}; | |
| 117 | + removeGame(database, gameName); | |
| 118 | + } else if (command == "play") { | |
| 119 | + std::string gameName{argv[2]}; | |
| 120 | + runGame(database, gameName); | |
| 121 | + } | |
| 122 | + case 4: | |
| 123 | + command = argv[1]; | |
| 124 | + if (command == "add") { | |
| 125 | + std::string gameName{argv[2]}; | |
| 126 | + auto localPath = std::filesystem::path(argv[3]); | |
| 127 | + std::string globalPath = | |
| 128 | + std::filesystem::absolute(localPath).lexically_normal().string(); | |
| 129 | + | |
| 130 | + std::string temp{}; | |
| 131 | + for (const auto a : globalPath) { | |
| 132 | + if (a != ' ') { | |
| 133 | + temp += a; | |
| 134 | + } else { | |
| 135 | + temp += "\' \'"; | |
| 136 | + } | |
| 137 | + } | |
| 149 | 138 | |
| 150 | - if (exit) { | |
| 151 | - std::cerr << "Error opening database" << sqlite3_errmsg(database) << std::endl; | |
| 152 | - return -1; | |
| 153 | - } | |
| 154 | - | |
| 155 | - printMessage("Opened database successfully!"); | |
| 139 | + addGame(database, gameName, temp); | |
| 140 | + } | |
| 141 | + break; | |
| 142 | + } | |
| 143 | +} | |
| 156 | 144 | |
| 157 | - if (newCreation) { | |
| 158 | - initialize_database(database); | |
| 145 | +auto Style() -> ButtonOption { | |
| 146 | + auto option = ButtonOption::Border(); | |
| 147 | + option.transform = [](const EntryState &s) { | |
| 148 | + auto element = text(s.label); | |
| 149 | + if (s.focused) { | |
| 150 | + element |= bold; | |
| 159 | 151 | } |
| 152 | + return element | size(HEIGHT, LESS_THAN, 10); | |
| 153 | + }; | |
| 154 | + return option; | |
| 155 | +} | |
| 160 | 156 | |
| 161 | - exit = sqlite3_prepare_v2(database, select_all_games_command, -1, &stmt, 0); | |
| 157 | +auto main(int argc, char const *argv[]) -> int { | |
| 158 | + bool newCreation = not std::filesystem::exists("data.db"); | |
| 159 | + char *messageError; | |
| 160 | + sqlite3 *database; | |
| 161 | + sqlite3_stmt *stmt; | |
| 162 | + int exit = 0; | |
| 163 | + exit = sqlite3_open("data.db", &database); | |
| 162 | 164 | |
| 163 | - if (exit) { | |
| 164 | - std::cerr << "Error retrieving data" << sqlite3_errmsg(database) << std::endl; | |
| 165 | - sqlite3_close(database); | |
| 166 | - return -1; | |
| 167 | - } | |
| 165 | + if (exit) { | |
| 166 | + std::cerr << "Error opening database" << sqlite3_errmsg(database) | |
| 167 | + << std::endl; | |
| 168 | + return -1; | |
| 169 | + } | |
| 168 | 170 | |
| 169 | - while (sqlite3_step(stmt) == SQLITE_ROW) { | |
| 170 | - int id = sqlite3_column_int(stmt, 0); | |
| 171 | - const unsigned char* gameName = sqlite3_column_text(stmt, 1); | |
| 172 | - const unsigned char* gamePath = sqlite3_column_text(stmt, 2); | |
| 173 | - | |
| 174 | - games.push_back( | |
| 175 | - Game { | |
| 176 | - id, | |
| 177 | - reinterpret_cast<const char*>(gameName), | |
| 178 | - reinterpret_cast<const char*>(gamePath) | |
| 179 | - } | |
| 180 | - ); | |
| 181 | - } | |
| 182 | - sqlite3_finalize(stmt); | |
| 171 | + printMessage("Opened database successfully!"); | |
| 183 | 172 | |
| 184 | - if (argc > 1) { | |
| 185 | - handleCommand(argc, argv, database); | |
| 186 | - return 0; | |
| 187 | - } | |
| 173 | + if (newCreation) { | |
| 174 | + initialize_database(database); | |
| 175 | + } | |
| 188 | 176 | |
| 189 | - int exit_id = games.size(); | |
| 190 | - int choice = 0; | |
| 191 | - do { | |
| 192 | - system("clear"); | |
| 193 | - | |
| 194 | - auto header = vbox({ | |
| 195 | - center(text(L" Fluffy v0.1 ")), | |
| 196 | - }); | |
| 197 | - | |
| 198 | - header = header | size(WIDTH, LESS_THAN, 120); | |
| 199 | - | |
| 200 | - auto headerScreen = Screen::Create(Dimension::Full(), Dimension::Fit(header)); | |
| 201 | - Render(headerScreen, header); | |
| 202 | - | |
| 203 | - std::cout << headerScreen.ToString() << '\0' << std::endl; | |
| 204 | - | |
| 205 | - std::vector<std::string> menuOptions{ | |
| 206 | - "Games", | |
| 207 | - "Info", | |
| 208 | - }; | |
| 209 | - int menuOptionSelected{ 0 }; | |
| 210 | - auto menuOptionToggle = Toggle(&menuOptions, &menuOptionSelected); | |
| 211 | - | |
| 212 | - | |
| 213 | - auto menu_screen = ScreenInteractive::TerminalOutput(); | |
| 214 | - | |
| 215 | - std::vector<std::string> localGames = {}; | |
| 216 | - for (auto& game : games) { | |
| 217 | - localGames.push_back(game.getName()); | |
| 218 | - } | |
| 219 | - localGames.push_back("Exit"); | |
| 220 | - | |
| 221 | - | |
| 222 | - std::vector<std::string> info{ | |
| 223 | - "test", | |
| 224 | - }; | |
| 225 | - int info_selected = 0; | |
| 226 | - | |
| 227 | - MenuOption option; | |
| 228 | - option.on_enter = menu_screen.ExitLoopClosure(); | |
| 229 | - auto menu = Menu(&localGames, &choice, option); | |
| 230 | - | |
| 231 | - auto appContainer = Container::Tab({ | |
| 232 | - Menu(&localGames, &choice, option), | |
| 233 | - Radiobox(&info, &info_selected), | |
| 234 | - }, &menuOptionSelected); | |
| 235 | - | |
| 236 | - auto container = Container::Horizontal({ | |
| 237 | - menuOptionToggle, | |
| 238 | - appContainer, | |
| 239 | - }); | |
| 240 | - | |
| 241 | - auto renderer = Renderer(container, [&] { | |
| 242 | - return vbox({ | |
| 243 | - menuOptionToggle->Render(), | |
| 244 | - separator(), | |
| 245 | - appContainer->Render(), | |
| 246 | - }) | border; | |
| 247 | - }); | |
| 248 | - | |
| 249 | - | |
| 250 | - menu_screen.Loop(renderer); | |
| 251 | - | |
| 252 | - if (choice != exit_id) { | |
| 253 | - int i{ 0 }; | |
| 254 | - std::string gameToRun = ""; | |
| 255 | - for (auto& game : games) { | |
| 256 | - | |
| 257 | - if (i == choice) { | |
| 258 | - gameToRun = game.getName(); | |
| 259 | - } | |
| 260 | - i++; | |
| 261 | - } | |
| 262 | - runGame(database, gameToRun); | |
| 263 | - } | |
| 264 | - } while (choice != exit_id); | |
| 177 | + exit = sqlite3_prepare_v2(database, select_all_games_command.c_str(), -1, &stmt, 0); | |
| 178 | + | |
| 179 | + if (exit) { | |
| 180 | + std::cerr << "Error retrieving data" << sqlite3_errmsg(database) | |
| 181 | + << std::endl; | |
| 265 | 182 | sqlite3_close(database); |
| 266 | - return EXIT_SUCCESS; | |
| 183 | + return -1; | |
| 184 | + } | |
| 185 | + | |
| 186 | + while (sqlite3_step(stmt) == SQLITE_ROW) { | |
| 187 | + int id = sqlite3_column_int(stmt, 0); | |
| 188 | + const unsigned char *gameName = sqlite3_column_text(stmt, 1); | |
| 189 | + const unsigned char *gamePath = sqlite3_column_text(stmt, 2); | |
| 190 | + | |
| 191 | + games.emplace_back(Game{id, reinterpret_cast<const char *>(gameName), | |
| 192 | + reinterpret_cast<const char *>(gamePath)}); | |
| 193 | + } | |
| 194 | + sqlite3_finalize(stmt); | |
| 195 | + | |
| 196 | + if (argc > 1) { | |
| 197 | + handleCommand(argc, argv, database); | |
| 198 | + return 0; | |
| 199 | + } | |
| 200 | + | |
| 201 | + int exit_id = games.size(); | |
| 202 | + int choice = 0; | |
| 203 | + // do { | |
| 204 | + system("clear"); | |
| 205 | + | |
| 206 | + std::vector<std::string> menuOptions{ | |
| 207 | + "Games (old)", | |
| 208 | + "Games", | |
| 209 | + }; | |
| 210 | + int menuOptionSelected{0}; | |
| 211 | + auto menuOptionToggle = Toggle(&menuOptions, &menuOptionSelected); | |
| 212 | + | |
| 213 | + std::vector<std::string> localGames = {}; | |
| 214 | + for (auto &game : games) { | |
| 215 | + localGames.emplace_back(game.getName()); | |
| 216 | + } | |
| 217 | + localGames.emplace_back("Exit"); | |
| 218 | + | |
| 219 | + auto gamesContainer{Container::Vertical({})}; | |
| 220 | + for (auto &game : games) { | |
| 221 | + gamesContainer->Add(Button( | |
| 222 | + game.getName(), [&] { runGame(database, game.getName()); }, Style())); | |
| 223 | + } | |
| 224 | + | |
| 225 | + auto menu_screen = ScreenInteractive::TerminalOutput(); | |
| 226 | + gamesContainer->Add(Button( | |
| 227 | + "Exit", [&] { menu_screen.ExitLoopClosure(); }, Style())); | |
| 228 | + MenuOption option; | |
| 229 | + // option.on_enter = menu_screen.ExitLoopClosure(); | |
| 230 | + auto menu = Menu(&localGames, &choice, option); | |
| 231 | + | |
| 232 | + auto appContainer = | |
| 233 | + Container::Tab({menu, gamesContainer}, &menuOptionSelected); | |
| 234 | + | |
| 235 | + auto container = Container::Horizontal({ | |
| 236 | + menuOptionToggle, | |
| 237 | + appContainer, | |
| 238 | + }); | |
| 239 | + | |
| 240 | + auto renderer = Renderer(container, [&] { | |
| 241 | + return vbox({ | |
| 242 | + center(text(L" Fluffy v0.1 ")), | |
| 243 | + menuOptionToggle->Render(), | |
| 244 | + appContainer->Render(), | |
| 245 | + }) | | |
| 246 | + border | size(WIDTH, LESS_THAN, 120); | |
| 247 | + }); | |
| 248 | + | |
| 249 | + menu_screen.Loop(renderer); | |
| 250 | + | |
| 251 | + // if (choice != exit_id) { | |
| 252 | + // int i{0}; | |
| 253 | + // std::string gameToRun = ""; | |
| 254 | + // for (auto &game : games) { | |
| 255 | + | |
| 256 | + // if (i == choice) { | |
| 257 | + // gameToRun = game.getName(); | |
| 258 | + // } | |
| 259 | + // i++; | |
| 260 | + // } | |
| 261 | + // runGame(database, gameToRun); | |
| 262 | + // } | |
| 263 | + // } while (choice != exit_id); | |
| 264 | + sqlite3_close(database); | |
| 265 | + return EXIT_SUCCESS; | |
| 267 | 266 | } |
| \ No newline at end of file | ||
| @@ -1,16 +1,17 @@ | |||
| 1 | -#include "ftxui/dom/elements.hpp" | ||
| 2 | -#include "ftxui/screen/screen.hpp" | ||
| 3 | -#include "ftxui/screen/string.hpp" | ||
| 4 | #include "ftxui/component/component.hpp" | 1 | #include "ftxui/component/component.hpp" |
| 2 | +#include "ftxui/component/component_base.hpp" | ||
| 5 | #include "ftxui/component/component_options.hpp" | 3 | #include "ftxui/component/component_options.hpp" |
| 6 | #include "ftxui/component/screen_interactive.hpp" | 4 | #include "ftxui/component/screen_interactive.hpp" |
| 5 | +#include "ftxui/dom/elements.hpp" | ||
| 6 | +#include "ftxui/screen/screen.hpp" | ||
| 7 | +#include "ftxui/screen/string.hpp" | ||
| 7 | 8 | ||
| 8 | -#include <iostream> | ||
| 9 | -#include <string> | ||
| 10 | #include <cstdlib> | 9 | #include <cstdlib> |
| 11 | #include <filesystem> | 10 | #include <filesystem> |
| 12 | -#include <sqlite3.h> | 11 | +#include <iostream> |
| 13 | #include <map> | 12 | #include <map> |
| 13 | +#include <sqlite3.h> | ||
| 14 | +#include <string> | ||
| 14 | #include <vector> | 15 | #include <vector> |
| 15 | 16 | ||
| 16 | #include <game.hpp> | 17 | #include <game.hpp> |
| @@ -19,249 +20,247 @@ using namespace ftxui; | |||
| 19 | 20 | ||
| 20 | std::vector<Game> games; | 21 | std::vector<Game> games; |
| 21 | 22 | ||
| 22 | -std::string database_initialization_command = "CREATE TABLE GAME(" | 23 | +std::string database_initialization_command = |
| 23 | - "GAME_ID INT PRIMARY KEY NOT NULL, " | 24 | + "CREATE TABLE GAME(" |
| 24 | - "GAME_NAME TEXT NOT NULL, " | 25 | + "GAME_ID INT PRIMARY KEY NOT NULL, " |
| 25 | - "GAME_PATH TEXT NOT NULL);"; | 26 | + "GAME_NAME TEXT NOT NULL, " |
| 27 | + "GAME_PATH TEXT NOT NULL);"; | ||
| 26 | 28 | ||
| 27 | -const char* select_all_games_command = "SELECT * FROM GAME;"; | 29 | +std::string select_all_games_command = "SELECT * FROM GAME;"; |
| 28 | 30 | ||
| 29 | bool debugRun = true; | 31 | bool debugRun = true; |
| 30 | 32 | ||
| 31 | void printMessage(std::string message) { | 33 | void printMessage(std::string message) { |
| 32 | - if (debugRun) { | 34 | + if (debugRun) { |
| 33 | - std::cout << message << std::endl; | 35 | + std::cout << message << std::endl; |
| 34 | - } | 36 | + } |
| 35 | } | 37 | } |
| 36 | 38 | ||
| 37 | -void execute_sql_command(sqlite3* database, std::string command) { | 39 | +void execute_sql_command(sqlite3 *database, std::string command) { |
| 38 | - int exit = 0; | 40 | + int exit = 0; |
| 39 | - char* messageError; | 41 | + char *messageError; |
| 40 | - exit = sqlite3_exec(database, command.c_str(), NULL, 0, &messageError); | 42 | + exit = sqlite3_exec(database, command.c_str(), NULL, 0, &messageError); |
| 41 | - | 43 | + |
| 42 | - if (exit != SQLITE_OK) { | 44 | + if (exit != SQLITE_OK) { |
| 43 | - printMessage("Error with command: " + command + " " + messageError); | 45 | + printMessage("Error with command: " + command + " " + messageError); |
| 44 | - sqlite3_free(messageError); | 46 | + sqlite3_free(messageError); |
| 45 | - } | 47 | + } |
| 46 | } | 48 | } |
| 47 | 49 | ||
| 48 | -int calculateFirstGameIdAvailable() { | 50 | +auto calculateFirstGameIdAvailable() -> int { |
| 49 | - int availableId{}; | 51 | + int availableId{}; |
| 50 | 52 | ||
| 51 | - std::vector<int> usedIds{}; | 53 | + std::vector<int> usedIds{}; |
| 52 | - for (auto& game : games) { | 54 | + for (auto &game : games) { |
| 53 | - usedIds.push_back(game.getId()); | 55 | + usedIds.emplace_back(game.getId()); |
| 54 | - } | 56 | + } |
| 55 | 57 | ||
| 56 | - bool found{ true }; | 58 | + bool found{true}; |
| 57 | - while(found) { | 59 | + while (found) { |
| 58 | - found = std::find(usedIds.begin(), usedIds.end(), availableId) != std::end(usedIds); | 60 | + found = std::find(usedIds.begin(), usedIds.end(), availableId) != |
| 59 | - availableId++; | 61 | + std::end(usedIds); |
| 60 | - } | 62 | + availableId++; |
| 63 | + } | ||
| 61 | 64 | ||
| 62 | - return availableId; | 65 | + return availableId; |
| 63 | } | 66 | } |
| 64 | 67 | ||
| 65 | -void addGameToDatabase(sqlite3* database, int id, std::string name, std::string path) { | 68 | +void addGameToDatabase(sqlite3 *database, int id, std::string name, |
| 66 | - std::string command = "INSERT INTO GAME (GAME_ID, GAME_NAME, GAME_PATH) VALUES ("; | 69 | + std::string path) { |
| 67 | - command += std::to_string(id) + ", '" + name + "', \"" + path + "\");"; | 70 | + std::string command = |
| 68 | - execute_sql_command(database, command); | 71 | + "INSERT INTO GAME (GAME_ID, GAME_NAME, GAME_PATH) VALUES ("; |
| 72 | + command += std::to_string(id) + ", '" + name + "', \"" + path + "\");"; | ||
| 73 | + execute_sql_command(database, command); | ||
| 69 | } | 74 | } |
| 70 | 75 | ||
| 71 | -void addGame(sqlite3* database, std::string name, std::string path) { | 76 | +void addGame(sqlite3 *database, std::string name, std::string path) { |
| 72 | - int id = calculateFirstGameIdAvailable(); | 77 | + int id = calculateFirstGameIdAvailable(); |
| 73 | - addGameToDatabase(database, id, name, path); | 78 | + addGameToDatabase(database, id, name, path); |
| 74 | } | 79 | } |
| 75 | 80 | ||
| 76 | -void removeGame(sqlite3* database, std::string name) { | 81 | +void removeGame(sqlite3 *database, std::string name) { |
| 77 | - std::string command = "DELETE FROM GAME WHERE GAME_NAME="; | 82 | + std::string command = "DELETE FROM GAME WHERE GAME_NAME="; |
| 78 | - command += "'" + name + "';"; | 83 | + command += "'" + name + "';"; |
| 79 | - execute_sql_command(database, command); | 84 | + execute_sql_command(database, command); |
| 80 | } | 85 | } |
| 81 | 86 | ||
| 82 | -void initialize_database(sqlite3* database) { | 87 | +void initialize_database(sqlite3 *database) { |
| 83 | - execute_sql_command(database, database_initialization_command); | 88 | + execute_sql_command(database, database_initialization_command); |
| 84 | - printMessage("Database Initialized"); | 89 | + printMessage("Database Initialized"); |
| 85 | } | 90 | } |
| 86 | 91 | ||
| 87 | -void runGame(sqlite3* database, std::string gameName) { | 92 | +void runGame(sqlite3 *database, std::string gameName) { |
| 88 | - std::string pathToRun = ""; | 93 | + std::string pathToRun = ""; |
| 89 | - for (auto& game : games) { | 94 | + for (auto &game : games) { |
| 90 | - if (gameName == game.getName()) { | 95 | + if (gameName == game.getName()) { |
| 91 | - pathToRun = game.getPath(); | 96 | + pathToRun = game.getPath(); |
| 92 | - } | ||
| 93 | } | 97 | } |
| 94 | - system(pathToRun.c_str()); | 98 | + } |
| 99 | + system(pathToRun.c_str()); | ||
| 95 | } | 100 | } |
| 96 | 101 | ||
| 97 | -void handleCommand(int argc, char const *argv[], sqlite3* database) { | 102 | +void handleCommand(int argc, char const *argv[], sqlite3 *database) { |
| 98 | - std::string command{}; | 103 | + std::string command{}; |
| 99 | - switch (argc) { | 104 | + switch (argc) { |
| 100 | - case 2: | 105 | + case 2: |
| 101 | - command = argv[1]; | 106 | + command = argv[1]; |
| 102 | - if (command == "show") { | 107 | + if (command == "show") { |
| 103 | - for (auto& game : games) { | 108 | + for (auto &game : games) { |
| 104 | - std::cout << game.getName() << ": " << game.getPath() << std::endl; | 109 | + std::cout << game.getName() << ": " << game.getPath() << std::endl; |
| 105 | - } | 110 | + } |
| 106 | - } | ||
| 107 | - break; | ||
| 108 | - case 3: | ||
| 109 | - command = argv[1]; | ||
| 110 | - if (command == "rm") { | ||
| 111 | - std::string gameName{ argv[2] }; | ||
| 112 | - removeGame(database, gameName); | ||
| 113 | - } | ||
| 114 | - else if(command == "play") { | ||
| 115 | - std::string gameName{ argv[2] }; | ||
| 116 | - runGame(database, gameName); | ||
| 117 | - } | ||
| 118 | - case 4: | ||
| 119 | - command = argv[1]; | ||
| 120 | - if (command == "add") { | ||
| 121 | - std::string gameName{ argv[2] }; | ||
| 122 | - auto localPath = std::filesystem::path(argv[3]); | ||
| 123 | - std::string globalPath = std::filesystem::absolute(localPath).lexically_normal().string(); | ||
| 124 | - | ||
| 125 | - std::string temp{}; | ||
| 126 | - for (const auto a : globalPath) { | ||
| 127 | - if (a != ' ') { | ||
| 128 | - temp += a; | ||
| 129 | - } | ||
| 130 | - else { | ||
| 131 | - temp += "\' \'"; | ||
| 132 | - } | ||
| 133 | - } | ||
| 134 | - | ||
| 135 | - addGame(database, gameName, temp); | ||
| 136 | - } | ||
| 137 | - break; | ||
| 138 | } | 111 | } |
| 139 | -} | 112 | + break; |
| 140 | - | 113 | + case 3: |
| 141 | -int main(int argc, char const *argv[]) { | 114 | + command = argv[1]; |
| 142 | - bool newCreation = not std::filesystem::exists("data.db"); | 115 | + if (command == "rm") { |
| 143 | - | 116 | + std::string gameName{argv[2]}; |
| 144 | - char* messageError; | 117 | + removeGame(database, gameName); |
| 145 | - sqlite3* database; | 118 | + } else if (command == "play") { |
| 146 | - sqlite3_stmt* stmt; | 119 | + std::string gameName{argv[2]}; |
| 147 | - int exit = 0; | 120 | + runGame(database, gameName); |
| 148 | - exit = sqlite3_open("data.db", &database); | 121 | + } |
| 122 | + case 4: | ||
| 123 | + command = argv[1]; | ||
| 124 | + if (command == "add") { | ||
| 125 | + std::string gameName{argv[2]}; | ||
| 126 | + auto localPath = std::filesystem::path(argv[3]); | ||
| 127 | + std::string globalPath = | ||
| 128 | + std::filesystem::absolute(localPath).lexically_normal().string(); | ||
| 129 | + | ||
| 130 | + std::string temp{}; | ||
| 131 | + for (const auto a : globalPath) { | ||
| 132 | + if (a != ' ') { | ||
| 133 | + temp += a; | ||
| 134 | + } else { | ||
| 135 | + temp += "\' \'"; | ||
| 136 | + } | ||
| 137 | + } | ||
| 149 | 138 | ||
| 150 | - if (exit) { | 139 | + addGame(database, gameName, temp); |
| 151 | - std::cerr << "Error opening database" << sqlite3_errmsg(database) << std::endl; | 140 | + } |
| 152 | - return -1; | 141 | + break; |
| 153 | - } | 142 | + } |
| 154 | - | 143 | +} |
| 155 | - printMessage("Opened database successfully!"); | ||
| 156 | 144 | ||
| 157 | - if (newCreation) { | 145 | +auto Style() -> ButtonOption { |
| 158 | - initialize_database(database); | 146 | + auto option = ButtonOption::Border(); |
| 147 | + option.transform = [](const EntryState &s) { | ||
| 148 | + auto element = text(s.label); | ||
| 149 | + if (s.focused) { | ||
| 150 | + element |= bold; | ||
| 159 | } | 151 | } |
| 152 | + return element | size(HEIGHT, LESS_THAN, 10); | ||
| 153 | + }; | ||
| 154 | + return option; | ||
| 155 | +} | ||
| 160 | 156 | ||
| 161 | - exit = sqlite3_prepare_v2(database, select_all_games_command, -1, &stmt, 0); | 157 | +auto main(int argc, char const *argv[]) -> int { |
| 158 | + bool newCreation = not std::filesystem::exists("data.db"); | ||
| 159 | + char *messageError; | ||
| 160 | + sqlite3 *database; | ||
| 161 | + sqlite3_stmt *stmt; | ||
| 162 | + int exit = 0; | ||
| 163 | + exit = sqlite3_open("data.db", &database); | ||
| 162 | 164 | ||
| 163 | - if (exit) { | 165 | + if (exit) { |
| 164 | - std::cerr << "Error retrieving data" << sqlite3_errmsg(database) << std::endl; | 166 | + std::cerr << "Error opening database" << sqlite3_errmsg(database) |
| 165 | - sqlite3_close(database); | 167 | + << std::endl; |
| 166 | - return -1; | 168 | + return -1; |
| 167 | - } | 169 | + } |
| 168 | 170 | ||
| 169 | - while (sqlite3_step(stmt) == SQLITE_ROW) { | 171 | + printMessage("Opened database successfully!"); |
| 170 | - int id = sqlite3_column_int(stmt, 0); | ||
| 171 | - const unsigned char* gameName = sqlite3_column_text(stmt, 1); | ||
| 172 | - const unsigned char* gamePath = sqlite3_column_text(stmt, 2); | ||
| 173 | - | ||
| 174 | - games.push_back( | ||
| 175 | - Game { | ||
| 176 | - id, | ||
| 177 | - reinterpret_cast<const char*>(gameName), | ||
| 178 | - reinterpret_cast<const char*>(gamePath) | ||
| 179 | - } | ||
| 180 | - ); | ||
| 181 | - } | ||
| 182 | - sqlite3_finalize(stmt); | ||
| 183 | 172 | ||
| 184 | - if (argc > 1) { | 173 | + if (newCreation) { |
| 185 | - handleCommand(argc, argv, database); | 174 | + initialize_database(database); |
| 186 | - return 0; | 175 | + } |
| 187 | - } | ||
| 188 | 176 | ||
| 189 | - int exit_id = games.size(); | 177 | + exit = sqlite3_prepare_v2(database, select_all_games_command.c_str(), -1, &stmt, 0); |
| 190 | - int choice = 0; | 178 | + |
| 191 | - do { | 179 | + if (exit) { |
| 192 | - system("clear"); | 180 | + std::cerr << "Error retrieving data" << sqlite3_errmsg(database) |
| 193 | - | 181 | + << std::endl; |
| 194 | - auto header = vbox({ | ||
| 195 | - center(text(L" Fluffy v0.1 ")), | ||
| 196 | - }); | ||
| 197 | - | ||
| 198 | - header = header | size(WIDTH, LESS_THAN, 120); | ||
| 199 | - | ||
| 200 | - auto headerScreen = Screen::Create(Dimension::Full(), Dimension::Fit(header)); | ||
| 201 | - Render(headerScreen, header); | ||
| 202 | - | ||
| 203 | - std::cout << headerScreen.ToString() << '\0' << std::endl; | ||
| 204 | - | ||
| 205 | - std::vector<std::string> menuOptions{ | ||
| 206 | - "Games", | ||
| 207 | - "Info", | ||
| 208 | - }; | ||
| 209 | - int menuOptionSelected{ 0 }; | ||
| 210 | - auto menuOptionToggle = Toggle(&menuOptions, &menuOptionSelected); | ||
| 211 | - | ||
| 212 | - | ||
| 213 | - auto menu_screen = ScreenInteractive::TerminalOutput(); | ||
| 214 | - | ||
| 215 | - std::vector<std::string> localGames = {}; | ||
| 216 | - for (auto& game : games) { | ||
| 217 | - localGames.push_back(game.getName()); | ||
| 218 | - } | ||
| 219 | - localGames.push_back("Exit"); | ||
| 220 | - | ||
| 221 | - | ||
| 222 | - std::vector<std::string> info{ | ||
| 223 | - "test", | ||
| 224 | - }; | ||
| 225 | - int info_selected = 0; | ||
| 226 | - | ||
| 227 | - MenuOption option; | ||
| 228 | - option.on_enter = menu_screen.ExitLoopClosure(); | ||
| 229 | - auto menu = Menu(&localGames, &choice, option); | ||
| 230 | - | ||
| 231 | - auto appContainer = Container::Tab({ | ||
| 232 | - Menu(&localGames, &choice, option), | ||
| 233 | - Radiobox(&info, &info_selected), | ||
| 234 | - }, &menuOptionSelected); | ||
| 235 | - | ||
| 236 | - auto container = Container::Horizontal({ | ||
| 237 | - menuOptionToggle, | ||
| 238 | - appContainer, | ||
| 239 | - }); | ||
| 240 | - | ||
| 241 | - auto renderer = Renderer(container, [&] { | ||
| 242 | - return vbox({ | ||
| 243 | - menuOptionToggle->Render(), | ||
| 244 | - separator(), | ||
| 245 | - appContainer->Render(), | ||
| 246 | - }) | border; | ||
| 247 | - }); | ||
| 248 | - | ||
| 249 | - | ||
| 250 | - menu_screen.Loop(renderer); | ||
| 251 | - | ||
| 252 | - if (choice != exit_id) { | ||
| 253 | - int i{ 0 }; | ||
| 254 | - std::string gameToRun = ""; | ||
| 255 | - for (auto& game : games) { | ||
| 256 | - | ||
| 257 | - if (i == choice) { | ||
| 258 | - gameToRun = game.getName(); | ||
| 259 | - } | ||
| 260 | - i++; | ||
| 261 | - } | ||
| 262 | - runGame(database, gameToRun); | ||
| 263 | - } | ||
| 264 | - } while (choice != exit_id); | ||
| 265 | sqlite3_close(database); | 182 | sqlite3_close(database); |
| 266 | - return EXIT_SUCCESS; | 183 | + return -1; |
| 184 | + } | ||
| 185 | + | ||
| 186 | + while (sqlite3_step(stmt) == SQLITE_ROW) { | ||
| 187 | + int id = sqlite3_column_int(stmt, 0); | ||
| 188 | + const unsigned char *gameName = sqlite3_column_text(stmt, 1); | ||
| 189 | + const unsigned char *gamePath = sqlite3_column_text(stmt, 2); | ||
| 190 | + | ||
| 191 | + games.emplace_back(Game{id, reinterpret_cast<const char *>(gameName), | ||
| 192 | + reinterpret_cast<const char *>(gamePath)}); | ||
| 193 | + } | ||
| 194 | + sqlite3_finalize(stmt); | ||
| 195 | + | ||
| 196 | + if (argc > 1) { | ||
| 197 | + handleCommand(argc, argv, database); | ||
| 198 | + return 0; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + int exit_id = games.size(); | ||
| 202 | + int choice = 0; | ||
| 203 | + // do { | ||
| 204 | + system("clear"); | ||
| 205 | + | ||
| 206 | + std::vector<std::string> menuOptions{ | ||
| 207 | + "Games (old)", | ||
| 208 | + "Games", | ||
| 209 | + }; | ||
| 210 | + int menuOptionSelected{0}; | ||
| 211 | + auto menuOptionToggle = Toggle(&menuOptions, &menuOptionSelected); | ||
| 212 | + | ||
| 213 | + std::vector<std::string> localGames = {}; | ||
| 214 | + for (auto &game : games) { | ||
| 215 | + localGames.emplace_back(game.getName()); | ||
| 216 | + } | ||
| 217 | + localGames.emplace_back("Exit"); | ||
| 218 | + | ||
| 219 | + auto gamesContainer{Container::Vertical({})}; | ||
| 220 | + for (auto &game : games) { | ||
| 221 | + gamesContainer->Add(Button( | ||
| 222 | + game.getName(), [&] { runGame(database, game.getName()); }, Style())); | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + auto menu_screen = ScreenInteractive::TerminalOutput(); | ||
| 226 | + gamesContainer->Add(Button( | ||
| 227 | + "Exit", [&] { menu_screen.ExitLoopClosure(); }, Style())); | ||
| 228 | + MenuOption option; | ||
| 229 | + // option.on_enter = menu_screen.ExitLoopClosure(); | ||
| 230 | + auto menu = Menu(&localGames, &choice, option); | ||
| 231 | + | ||
| 232 | + auto appContainer = | ||
| 233 | + Container::Tab({menu, gamesContainer}, &menuOptionSelected); | ||
| 234 | + | ||
| 235 | + auto container = Container::Horizontal({ | ||
| 236 | + menuOptionToggle, | ||
| 237 | + appContainer, | ||
| 238 | + }); | ||
| 239 | + | ||
| 240 | + auto renderer = Renderer(container, [&] { | ||
| 241 | + return vbox({ | ||
| 242 | + center(text(L" Fluffy v0.1 ")), | ||
| 243 | + menuOptionToggle->Render(), | ||
| 244 | + appContainer->Render(), | ||
| 245 | + }) | | ||
| 246 | + border | size(WIDTH, LESS_THAN, 120); | ||
| 247 | + }); | ||
| 248 | + | ||
| 249 | + menu_screen.Loop(renderer); | ||
| 250 | + | ||
| 251 | + // if (choice != exit_id) { | ||
| 252 | + // int i{0}; | ||
| 253 | + // std::string gameToRun = ""; | ||
| 254 | + // for (auto &game : games) { | ||
| 255 | + | ||
| 256 | + // if (i == choice) { | ||
| 257 | + // gameToRun = game.getName(); | ||
| 258 | + // } | ||
| 259 | + // i++; | ||
| 260 | + // } | ||
| 261 | + // runGame(database, gameToRun); | ||
| 262 | + // } | ||
| 263 | + // } while (choice != exit_id); | ||
| 264 | + sqlite3_close(database); | ||
| 265 | + return EXIT_SUCCESS; | ||
| 267 | } | 266 | } |
| \ No newline at end of file | \ No newline at end of file | ||