Compare commits

...

10 Commits

Author SHA1 Message Date
7a2d7336fb make tomato compile on new setup
Some checks failed
ContinuousIntegration / linux (push) Successful in 4m22s
ContinuousDelivery / linux-ubuntu (push) Failing after 5m12s
ContinuousIntegration / android (push) Successful in 5m44s
ContinuousDelivery / windows (push) Has been cancelled
ContinuousDelivery / windows-asan (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled
2024-06-02 14:11:30 +02:00
fc5023ec1c fix texture blend mode, reenabling transparency
Some checks failed
ContinuousIntegration / linux (push) Successful in 4m15s
ContinuousDelivery / linux-ubuntu (push) Failing after 4m54s
ContinuousIntegration / android (push) Successful in 5m42s
ContinuousDelivery / windows (push) Has been cancelled
ContinuousDelivery / windows-asan (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled
2024-06-01 12:51:50 +02:00
95eb0eb26d skip command in args
Some checks failed
ContinuousDelivery / windows (push) Waiting to run
ContinuousDelivery / windows-asan (push) Waiting to run
ContinuousDelivery / release (push) Blocked by required conditions
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run
ContinuousIntegration / linux (push) Successful in 4m12s
ContinuousDelivery / linux-ubuntu (push) Failing after 4m55s
ContinuousIntegration / android (push) Successful in 5m49s
2024-05-31 15:34:44 +02:00
d7e658eba6 disable caching the ndk so it works
Some checks failed
ContinuousIntegration / linux (push) Successful in 4m10s
ContinuousDelivery / linux-ubuntu (push) Failing after 5m0s
ContinuousIntegration / android (push) Successful in 5m40s
ContinuousDelivery / windows (push) Has been cancelled
ContinuousDelivery / windows-asan (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled
see https://github.com/nttld/setup-ndk/issues/518
2024-05-30 13:08:23 +02:00
04191858de basic cli args parsing, working plugin paths and semi working configs
Some checks failed
ContinuousDelivery / windows (push) Waiting to run
ContinuousDelivery / windows-asan (push) Waiting to run
ContinuousDelivery / release (push) Blocked by required conditions
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run
ContinuousIntegration / linux (push) Successful in 4m6s
ContinuousDelivery / linux-ubuntu (push) Failing after 4m54s
ContinuousIntegration / android (push) Successful in 14m10s
2024-05-30 11:46:58 +02:00
df449a475c add json dep directly (was already indirect) 2024-05-30 11:14:01 +02:00
9a95dba138 first try at android ci
Some checks failed
ContinuousDelivery / windows (push) Waiting to run
ContinuousDelivery / windows-asan (push) Waiting to run
ContinuousDelivery / release (push) Blocked by required conditions
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run
ContinuousIntegration / linux (push) Successful in 4m7s
ContinuousDelivery / linux-ubuntu (push) Failing after 4m45s
ContinuousIntegration / android (push) Successful in 14m55s
2024-05-29 13:14:26 +02:00
ef79aa8b80 support building tomato as a lib/shared object 2024-05-29 10:38:57 +02:00
ba7188cf66 improve windows debug conformity
Some checks failed
ContinuousDelivery / windows (push) Waiting to run
ContinuousDelivery / windows-asan (push) Waiting to run
ContinuousDelivery / release (push) Blocked by required conditions
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run
ContinuousIntegration / linux (push) Successful in 4m3s
ContinuousDelivery / linux-ubuntu (push) Failing after 4m45s
2024-05-29 09:46:35 +02:00
2d4729a877 update sdl and sdl_image 2024-05-28 17:58:24 +02:00
25 changed files with 238 additions and 33 deletions

View File

@ -22,7 +22,7 @@ jobs:
submodules: recursive
- name: Install Dependencies
run: sudo apt update && sudo apt -y install libsodium-dev
run: sudo apt update && sudo apt -y install libsodium-dev cmake
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

View File

@ -21,7 +21,7 @@ jobs:
submodules: recursive
- name: Install Dependencies
run: sudo apt update && sudo apt -y install libsodium-dev
run: sudo apt update && sudo apt -y install libsodium-dev cmake
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
@ -29,6 +29,50 @@ jobs:
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 -t tomato
android:
timeout-minutes: 30
# contains sections copied from sdl repo
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: nttld/setup-ndk@v1
id: setup_ndk
with:
local-cache: false # https://github.com/nttld/setup-ndk/issues/518
ndk-version: r26d
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: update vcpkg
run: |
git clone https://github.com/microsoft/vcpkg.git
- name: Install Dependencies (host)
run: sudo apt update && sudo apt -y install cmake pkg-config nasm
- name: Install Dependencies (target)
env:
ANDROID_NDK_HOME: ${{steps.setup_ndk.outputs.ndk-path}}
run: vcpkg install --triplet arm64-android --overlay-ports=vcpkg/ports libsodium opus libvpx libpng libjpeg-turbo
# vcpkg scripts root /usr/local/share/vcpkg/scripts
- name: Configure CMake
env:
ANDROID_NDK_HOME: ${{steps.setup_ndk.outputs.ndk-path}}
#run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=${{steps.setup_ndk.outputs.ndk-path}}/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=23 -DANDROID_ABI=arm64-v8a
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=arm64-android -DANDROID=1 -DANDROID_PLATFORM=23 -DANDROID_ABI=arm64-v8a -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${{steps.setup_ndk.outputs.ndk-path}}/build/cmake/android.toolchain.cmake -DSDL3IMAGE_JPG_SHARED=OFF -DSDL3IMAGE_PNG_SHARED=OFF -DTOMATO_MAIN_SO=ON
- name: Build (tomato)
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 -t tomato
macos:
timeout-minutes: 10

View File

@ -18,6 +18,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
option(TOMATO_MAIN_SO "Build tomato as a shared object (for eg android apps)" ANDROID)
option(TOMATO_ASAN "Build tomato with asan (gcc/clang/msvc)" OFF)
if (TOMATO_ASAN)

View File

@ -2,6 +2,8 @@ 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 Normal file
View File

@ -0,0 +1,13 @@
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()

View File

@ -11,9 +11,11 @@ if (NOT TARGET SDL3::SDL3)
GIT_REPOSITORY https://github.com/libsdl-org/SDL
#GIT_TAG 0429f5d6a36fc35b551bcc2acd4a40c2db6dab82 # tip when looking
#GIT_TAG 14f584a94bfd49cf1524db75bf3c419fdf9436cd # tip 26-04-2024
GIT_TAG 06d6f2cb2518622593570985589700910cf4399f # 13-05-2024 - before
#GIT_TAG 06d6f2cb2518622593570985589700910cf4399f # 13-05-2024 - before
# made changes that break imgui release 1.90.6
#GIT_TAG 1103294d33f47ab4c697bb22a9cf27c79c658630 # tip 15-05-2024
#GIT_TAG aacafd62336363077470f678b6217214b3b49473 # tip 28-05-2024
GIT_TAG 5fa9432b7d1c1722de93e1ab46e7a9569a47071e # tip 27-05-2024 - before changes made breaking sdl_image
FIND_PACKAGE_ARGS # for the future
)
FetchContent_MakeAvailable(SDL3)

View File

@ -16,7 +16,8 @@ if (NOT TARGET SDL3_image::SDL3_image)
GIT_REPOSITORY https://github.com/libsdl-org/SDL_image
# waiting on the imgui pr to get merged so i can update sdl <.<
#GIT_TAG a45d6e5b84ccc0f3faae6ba7d561709ed600eee7 # tip last check
GIT_TAG a34ccf16f961e6d5a480045eb650fc3dddb4bfaa # tip 14-05-2024
#GIT_TAG a34ccf16f961e6d5a480045eb650fc3dddb4bfaa # tip 14-05-2024
GIT_TAG 2fc5310a9a2700fc856663200f94edebeb5e554a # tip 28-05-2024
FIND_PACKAGE_ARGS # for the future
)
FetchContent_MakeAvailable(SDL3_image)

16
flake.lock generated
View File

@ -63,34 +63,34 @@
"sdl3": {
"flake": false,
"locked": {
"lastModified": 1715616572,
"narHash": "sha256-SCl7RbRThjci0xXUz9vmwDfqp0kenxEuuvoNlx6yiyU=",
"lastModified": 1716778470,
"narHash": "sha256-/esw8XkLIR7/2HLXaCfsOsEy+Idf6XGsnWGC5yXJipk=",
"owner": "libsdl-org",
"repo": "SDL",
"rev": "06d6f2cb2518622593570985589700910cf4399f",
"rev": "5fa9432b7d1c1722de93e1ab46e7a9569a47071e",
"type": "github"
},
"original": {
"owner": "libsdl-org",
"repo": "SDL",
"rev": "06d6f2cb2518622593570985589700910cf4399f",
"rev": "5fa9432b7d1c1722de93e1ab46e7a9569a47071e",
"type": "github"
}
},
"sdl3_image": {
"flake": false,
"locked": {
"lastModified": 1715708273,
"narHash": "sha256-scNPhzGk+d8VqkOKsSxmH/OVLgkWrOkEeWn/b2f3XaU=",
"lastModified": 1716394356,
"narHash": "sha256-dQ4x7ZbQodOs4PQU90evoa870abC/u0uaVLEqU1nB8k=",
"owner": "libsdl-org",
"repo": "SDL_image",
"rev": "a34ccf16f961e6d5a480045eb650fc3dddb4bfaa",
"rev": "2fc5310a9a2700fc856663200f94edebeb5e554a",
"type": "github"
},
"original": {
"owner": "libsdl-org",
"repo": "SDL_image",
"rev": "a34ccf16f961e6d5a480045eb650fc3dddb4bfaa",
"rev": "2fc5310a9a2700fc856663200f94edebeb5e554a",
"type": "github"
}
},

View File

@ -11,11 +11,11 @@
flake = false;
};
sdl3 = {
url = "github:libsdl-org/SDL/06d6f2cb2518622593570985589700910cf4399f"; # keep in sync this cmake
url = "github:libsdl-org/SDL/5fa9432b7d1c1722de93e1ab46e7a9569a47071e"; # keep in sync this cmake
flake = false;
};
sdl3_image = {
url = "github:libsdl-org/SDL_image/a34ccf16f961e6d5a480045eb650fc3dddb4bfaa";
url = "github:libsdl-org/SDL_image/2fc5310a9a2700fc856663200f94edebeb5e554a";
flake = false;
};
};

View File

@ -1,11 +1,21 @@
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR)
########################################
add_executable(tomato
if (TOMATO_MAIN_SO)
add_library(tomato MODULE)
target_compile_definitions(tomato PUBLIC TOMATO_MAIN_SO)
else()
add_executable(tomato)
endif()
target_sources(tomato PUBLIC
./main.cpp
./icon.rc
./json_to_config.hpp
./json_to_config.cpp
./screen.hpp
./start_screen.hpp
./start_screen.cpp

View File

@ -151,8 +151,7 @@ void SendImagePopup::sendMemory(
}
// copy paste data to memory
original_data.clear();
original_data.insert(original_data.begin(), data, data+data_size);
original_data = {data, data+data_size};
if (!load()) {
std::cerr << "SIP: failed to load image from memory\n";

View File

@ -41,7 +41,7 @@ ImageLoaderQOI::ImageResult ImageLoaderQOI::loadFromMemoryRGBA(const uint8_t* da
auto& new_frame = res.frames.emplace_back();
new_frame.ms = 0;
new_frame.data.insert(new_frame.data.cbegin(), img_data, img_data+(desc.width*desc.height*4));
new_frame.data = {img_data, img_data+(desc.width*desc.height*4)};
free(img_data);
return res;

View File

@ -47,7 +47,7 @@ ImageLoaderSDLBMP::ImageResult ImageLoaderSDLBMP::loadFromMemoryRGBA(const uint8
auto& new_frame = res.frames.emplace_back();
new_frame.ms = 0;
new_frame.data.insert(new_frame.data.cbegin(), (const uint8_t*)conv_surf->pixels, ((const uint8_t*)conv_surf->pixels) + (surf->w*surf->h*4));
new_frame.data = {(const uint8_t*)conv_surf->pixels, ((const uint8_t*)conv_surf->pixels) + (surf->w*surf->h*4)};
SDL_UnlockSurface(conv_surf);
SDL_DestroySurface(conv_surf);

View File

@ -99,7 +99,7 @@ ImageLoaderSDLImage::ImageResult ImageLoaderSDLImage::loadFromMemoryRGBA(const u
auto& new_frame = res.frames.emplace_back();
new_frame.ms = anim->delays[i];
new_frame.data.insert(new_frame.data.cbegin(), (const uint8_t*)conv_surf->pixels, ((const uint8_t*)conv_surf->pixels) + (anim->w*anim->h*4));
new_frame.data = {(const uint8_t*)conv_surf->pixels, ((const uint8_t*)conv_surf->pixels) + (anim->w*anim->h*4)};
SDL_UnlockSurface(conv_surf);
SDL_DestroySurface(conv_surf);

View File

@ -41,7 +41,7 @@ ImageLoaderSTB::ImageResult ImageLoaderSTB::loadFromMemoryRGBA(const uint8_t* da
for (int i = 0; i < z; i++) {
auto& new_frame = res.frames.emplace_back();
new_frame.ms = delays[i];
new_frame.data.insert(new_frame.data.cbegin(), img_data + (i*stride), img_data + ((i+1)*stride));
new_frame.data = {img_data + (i*stride), img_data + ((i+1)*stride)};
}
stbi_image_free(delays); // hope this is right
@ -62,7 +62,7 @@ ImageLoaderSTB::ImageResult ImageLoaderSTB::loadFromMemoryRGBA(const uint8_t* da
auto& new_frame = res.frames.emplace_back();
new_frame.ms = 0;
new_frame.data.insert(new_frame.data.cbegin(), img_data, img_data+(x*y*4));
new_frame.data = {img_data, img_data+(x*y*4)};
stbi_image_free(img_data);
return res;

View File

@ -78,7 +78,7 @@ ImageLoaderWebP::ImageResult ImageLoaderWebP::loadFromMemoryRGBA(const uint8_t*
auto& new_frame = res.frames.emplace_back();
new_frame.ms = timestamp-prev_timestamp;
prev_timestamp = timestamp;
new_frame.data.insert(new_frame.data.end(), buf, buf+(res.width*res.height*4));
new_frame.data = {buf, buf+(res.width*res.height*4)};
}
assert(anim_info.frame_count == res.frames.size());

67
src/json_to_config.cpp Normal file
View File

@ -0,0 +1,67 @@
#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;
}

9
src/json_to_config.hpp Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include <nlohmann/json_fwd.hpp>
// fwd
struct SimpleConfigModel;
bool load_json_into_config(const nlohmann::ordered_json& config_json, SimpleConfigModel& conf);

View File

@ -12,10 +12,17 @@
#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";
@ -42,17 +49,19 @@ int main(int argc, char** argv) {
}
std::unique_ptr<SDL_Renderer, decltype(&SDL_DestroyRenderer)> renderer {
SDL_CreateRenderer(window.get(), nullptr, SDL_RENDERER_PRESENTVSYNC),
SDL_CreateRenderer(window.get(), nullptr),
&SDL_DestroyRenderer
};
if (!renderer) {
std::cerr << "SDL_CreateRenderer failed (" << SDL_GetError() << ")\n";
return 1;
}
SDL_SetRenderVSync(renderer.get(), SDL_RENDERER_VSYNC_ADAPTIVE);
{
SDL_RendererInfo ri;
if (SDL_GetRendererInfo(renderer.get(), &ri) == 0) {
std::cout << "SDL Renderer: " << ri.name << "(f:" << ri.flags << ")\n";
std::cout << "SDL Renderer: " << ri.name << "\n";
}
}
@ -89,7 +98,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>(renderer.get(), theme);
std::unique_ptr<Screen> screen = std::make_unique<StartScreen>(args, renderer.get(), theme);
bool quit = false;

View File

@ -12,8 +12,9 @@
#include <memory>
#include <cmath>
MainScreen::MainScreen(SDL_Renderer* renderer_, Theme& theme_, std::string save_path, std::string save_password, std::string new_username, std::vector<std::string> plugins) :
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) :
renderer(renderer_),
conf(std::move(conf_)),
rmm(cr),
msnj{cr, {}, {}},
mts(rmm),

View File

@ -91,7 +91,7 @@ struct MainScreen final : public Screen {
uint64_t _window_hidden_ts {0};
float _time_since_event {0.f};
MainScreen(SDL_Renderer* renderer_, Theme& theme_, std::string save_path, std::string save_password, std::string new_username, std::vector<std::string> plugins);
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(void);
bool handleEvent(SDL_Event& e) override;

View File

@ -31,6 +31,11 @@ uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t wi
// TODO: error reporting
SDL_UpdateTexture(tex, nullptr, surf->pixels, surf->pitch);
SDL_BlendMode surf_blend_mode = SDL_BLENDMODE_NONE;
if (SDL_GetSurfaceBlendMode(surf, &surf_blend_mode) == 0) {
SDL_SetTextureBlendMode(tex, surf_blend_mode);
}
if (filter == NEAREST) {
SDL_SetTextureScaleMode(tex, SDL_SCALEMODE_NEAREST);
} else if (filter == LINEAR) {

View File

@ -2,14 +2,53 @@
#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(SDL_Renderer* renderer, Theme& theme) : _renderer(renderer), _theme(theme) {
StartScreen::StartScreen(const std::vector<std::string_view>& args, SDL_Renderer* renderer, Theme& theme) : _renderer(renderer), _theme(theme) {
for (size_t ai = 1; 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";
}
}
}
Screen* StartScreen::render(float, bool&) {
@ -143,7 +182,7 @@ Screen* StartScreen::render(float, bool&) {
}
} else {
if (ImGui::Button("load", {60, 25})) {
auto new_screen = std::make_unique<MainScreen>(_renderer, _theme, _tox_profile_path, _password, _user_name, queued_plugin_paths);
auto new_screen = std::make_unique<MainScreen>(std::move(_conf), _renderer, _theme, _tox_profile_path, _password, _user_name, queued_plugin_paths);
return new_screen.release();
}
}

View File

@ -5,6 +5,8 @@
#include "./chat_gui/theme.hpp"
#include "./chat_gui/file_selector.hpp"
#include <solanaceae/util/simple_config_model.hpp>
#include <vector>
#include <string>
@ -16,6 +18,7 @@ extern "C" {
struct StartScreen final : public Screen {
SDL_Renderer* _renderer;
Theme& _theme;
SimpleConfigModel _conf;
FileSelector _fss;
bool _new_save {false};
@ -28,7 +31,7 @@ struct StartScreen final : public Screen {
std::vector<std::string> queued_plugin_paths;
StartScreen(void) = delete;
StartScreen(SDL_Renderer* renderer, Theme& theme);
StartScreen(const std::vector<std::string_view>& args, SDL_Renderer* renderer, Theme& theme);
~StartScreen(void) = default;
// return nullptr if not next