Compare commits
No commits in common. "04191858defe43ec907f4e175defefb3e5961d48" and "9a95dba1387802b79a4bdb3c4be8f94a43801108" have entirely different histories.
04191858de
...
9a95dba138
2
external/CMakeLists.txt
vendored
2
external/CMakeLists.txt
vendored
@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.14...3.24 FATAL_ERROR)
|
||||
|
||||
add_subdirectory(./entt)
|
||||
|
||||
add_subdirectory(./json)
|
||||
|
||||
add_subdirectory(./solanaceae_util)
|
||||
add_subdirectory(./solanaceae_contact)
|
||||
add_subdirectory(./solanaceae_message3)
|
||||
|
13
external/json/CMakeLists.txt
vendored
13
external/json/CMakeLists.txt
vendored
@ -1,13 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.16...3.24 FATAL_ERROR)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
if (NOT TARGET nlohmann_json::nlohmann_json)
|
||||
FetchContent_Declare(json
|
||||
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
|
||||
URL_HASH SHA256=d6c65aca6b1ed68e7a182f4757257b107ae403032760ed6ef121c9d55e81757d
|
||||
EXCLUDE_FROM_ALL
|
||||
)
|
||||
FetchContent_MakeAvailable(json)
|
||||
endif()
|
||||
|
@ -13,9 +13,6 @@ target_sources(tomato PUBLIC
|
||||
./main.cpp
|
||||
./icon.rc
|
||||
|
||||
./json_to_config.hpp
|
||||
./json_to_config.cpp
|
||||
|
||||
./screen.hpp
|
||||
./start_screen.hpp
|
||||
./start_screen.cpp
|
||||
|
@ -1,67 +0,0 @@
|
||||
#include "./json_to_config.hpp"
|
||||
|
||||
#include <solanaceae/util/simple_config_model.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
bool load_json_into_config(const nlohmann::ordered_json& config_json, SimpleConfigModel& conf) {
|
||||
if (!config_json.is_object()) {
|
||||
std::cerr << "TOMATO error: config file is not an json object!!!\n";
|
||||
return false;
|
||||
}
|
||||
for (const auto& [mod, cats] : config_json.items()) {
|
||||
for (const auto& [cat, cat_v] : cats.items()) {
|
||||
if (cat_v.is_object()) {
|
||||
if (cat_v.contains("default")) {
|
||||
const auto& value = cat_v["default"];
|
||||
if (value.is_string()) {
|
||||
conf.set(mod, cat, value.get_ref<const std::string&>());
|
||||
} else if (value.is_boolean()) {
|
||||
conf.set(mod, cat, value.get_ref<const bool&>());
|
||||
} else if (value.is_number_float()) {
|
||||
conf.set(mod, cat, value.get_ref<const double&>());
|
||||
} else if (value.is_number_integer()) {
|
||||
conf.set(mod, cat, value.get_ref<const int64_t&>());
|
||||
} else {
|
||||
std::cerr << "JSON error: wrong value type in " << mod << "::" << cat << " = " << value << "\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (cat_v.contains("entries")) {
|
||||
for (const auto& [ent, ent_v] : cat_v["entries"].items()) {
|
||||
if (ent_v.is_string()) {
|
||||
conf.set(mod, cat, ent, ent_v.get_ref<const std::string&>());
|
||||
} else if (ent_v.is_boolean()) {
|
||||
conf.set(mod, cat, ent, ent_v.get_ref<const bool&>());
|
||||
} else if (ent_v.is_number_float()) {
|
||||
conf.set(mod, cat, ent, ent_v.get_ref<const double&>());
|
||||
} else if (ent_v.is_number_integer()) {
|
||||
conf.set(mod, cat, ent, ent_v.get_ref<const int64_t&>());
|
||||
} else {
|
||||
std::cerr << "JSON error: wrong value type in " << mod << "::" << cat << "::" << ent << " = " << ent_v << "\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (cat_v.is_string()) {
|
||||
conf.set(mod, cat, cat_v.get_ref<const std::string&>());
|
||||
} else if (cat_v.is_boolean()) {
|
||||
conf.set(mod, cat, cat_v.get_ref<const bool&>());
|
||||
} else if (cat_v.is_number_float()) {
|
||||
conf.set(mod, cat, cat_v.get_ref<const double&>());
|
||||
} else if (cat_v.is_number_integer()) {
|
||||
conf.set(mod, cat, cat_v.get_ref<const int64_t&>());
|
||||
} else {
|
||||
std::cerr << "JSON error: wrong value type in " << mod << "::" << cat << " = " << cat_v << "\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
// fwd
|
||||
struct SimpleConfigModel;
|
||||
|
||||
bool load_json_into_config(const nlohmann::ordered_json& config_json, SimpleConfigModel& conf);
|
||||
|
@ -12,17 +12,10 @@
|
||||
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// better args
|
||||
std::vector<std::string_view> args;
|
||||
for (int i = 0; i < argc; i++) {
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
|
||||
// setup hints
|
||||
if (SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1") != SDL_TRUE) {
|
||||
std::cerr << "Failed to set '" << SDL_HINT_VIDEO_ALLOW_SCREENSAVER << "' to 1\n";
|
||||
@ -98,7 +91,7 @@ int main(int argc, char** argv) {
|
||||
ImGui_ImplSDL3_InitForSDLRenderer(window.get(), renderer.get());
|
||||
ImGui_ImplSDLRenderer3_Init(renderer.get());
|
||||
|
||||
std::unique_ptr<Screen> screen = std::make_unique<StartScreen>(args, renderer.get(), theme);
|
||||
std::unique_ptr<Screen> screen = std::make_unique<StartScreen>(renderer.get(), theme);
|
||||
|
||||
|
||||
bool quit = false;
|
||||
|
@ -12,9 +12,8 @@
|
||||
#include <memory>
|
||||
#include <cmath>
|
||||
|
||||
MainScreen::MainScreen(SimpleConfigModel&& conf_, SDL_Renderer* renderer_, Theme& theme_, std::string save_path, std::string save_password, std::string new_username, std::vector<std::string> plugins) :
|
||||
MainScreen::MainScreen(SDL_Renderer* renderer_, Theme& theme_, std::string save_path, std::string save_password, std::string new_username, std::vector<std::string> plugins) :
|
||||
renderer(renderer_),
|
||||
conf(std::move(conf_)),
|
||||
rmm(cr),
|
||||
msnj{cr, {}, {}},
|
||||
mts(rmm),
|
||||
|
@ -91,7 +91,7 @@ struct MainScreen final : public Screen {
|
||||
uint64_t _window_hidden_ts {0};
|
||||
float _time_since_event {0.f};
|
||||
|
||||
MainScreen(SimpleConfigModel&& conf_, SDL_Renderer* renderer_, Theme& theme_, std::string save_path, std::string save_password, std::string new_username, std::vector<std::string> plugins);
|
||||
MainScreen(SDL_Renderer* renderer_, Theme& theme_, std::string save_path, std::string save_password, std::string new_username, std::vector<std::string> plugins);
|
||||
~MainScreen(void);
|
||||
|
||||
bool handleEvent(SDL_Event& e) override;
|
||||
|
@ -2,53 +2,14 @@
|
||||
|
||||
#include "./main_screen.hpp"
|
||||
|
||||
#include "./json_to_config.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/misc/cpp/imgui_stdlib.h>
|
||||
|
||||
#include <cctype>
|
||||
#include <memory>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
StartScreen::StartScreen(const std::vector<std::string_view>& args, SDL_Renderer* renderer, Theme& theme) : _renderer(renderer), _theme(theme) {
|
||||
for (size_t ai = 0; ai < args.size(); ai++) {
|
||||
if (args.at(ai) == "--config" || args.at(ai) == "-c") {
|
||||
if (args.size() == ai+1) {
|
||||
std::cerr << "TOMATO error: argument '" << args.at(ai) << "' missing parameter!\n";
|
||||
break;
|
||||
}
|
||||
ai++;
|
||||
|
||||
const auto& config_path = args.at(ai);
|
||||
auto config_file = std::ifstream(static_cast<std::string>(config_path));
|
||||
if (!config_file.is_open()) {
|
||||
std::cerr << "TOMATO error: failed to open config file '" << config_path << "'\n";
|
||||
break;
|
||||
}
|
||||
|
||||
auto config_json = nlohmann::ordered_json::parse(config_file);
|
||||
if (!load_json_into_config(config_json, _conf)) {
|
||||
std::cerr << "TOMATO error in config json, exiting...\n";
|
||||
break;
|
||||
}
|
||||
} else if (args.at(ai) == "--plugin" || args.at(ai) == "-p") {
|
||||
if (args.size() == ai+1) {
|
||||
std::cerr << "TOMATO error: argument '" << args.at(ai) << "' missing parameter!\n";
|
||||
break;
|
||||
}
|
||||
ai++;
|
||||
|
||||
const auto& plugin_path = args.at(ai);
|
||||
// TODO: check for dups
|
||||
queued_plugin_paths.push_back(static_cast<std::string>(plugin_path));
|
||||
} else {
|
||||
std::cerr << "TOMATO error: unknown cli arg: '" << args.at(ai) << "'\n";
|
||||
}
|
||||
}
|
||||
StartScreen::StartScreen(SDL_Renderer* renderer, Theme& theme) : _renderer(renderer), _theme(theme) {
|
||||
}
|
||||
|
||||
Screen* StartScreen::render(float, bool&) {
|
||||
@ -182,7 +143,7 @@ Screen* StartScreen::render(float, bool&) {
|
||||
}
|
||||
} else {
|
||||
if (ImGui::Button("load", {60, 25})) {
|
||||
auto new_screen = std::make_unique<MainScreen>(std::move(_conf), _renderer, _theme, _tox_profile_path, _password, _user_name, queued_plugin_paths);
|
||||
auto new_screen = std::make_unique<MainScreen>(_renderer, _theme, _tox_profile_path, _password, _user_name, queued_plugin_paths);
|
||||
return new_screen.release();
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,6 @@
|
||||
#include "./chat_gui/theme.hpp"
|
||||
#include "./chat_gui/file_selector.hpp"
|
||||
|
||||
#include <solanaceae/util/simple_config_model.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
@ -18,7 +16,6 @@ extern "C" {
|
||||
struct StartScreen final : public Screen {
|
||||
SDL_Renderer* _renderer;
|
||||
Theme& _theme;
|
||||
SimpleConfigModel _conf;
|
||||
FileSelector _fss;
|
||||
|
||||
bool _new_save {false};
|
||||
@ -31,7 +28,7 @@ struct StartScreen final : public Screen {
|
||||
std::vector<std::string> queued_plugin_paths;
|
||||
|
||||
StartScreen(void) = delete;
|
||||
StartScreen(const std::vector<std::string_view>& args, SDL_Renderer* renderer, Theme& theme);
|
||||
StartScreen(SDL_Renderer* renderer, Theme& theme);
|
||||
~StartScreen(void) = default;
|
||||
|
||||
// return nullptr if not next
|
||||
|
Loading…
x
Reference in New Issue
Block a user