Add LoadConfigFile to Controller, include file_util src in build
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "app/editor/editor_manager.h"
|
||||
#include "app/gui/icons.h"
|
||||
#include "app/gui/style.h"
|
||||
#include "core/utils/file_util.h"
|
||||
#include "imgui/backends/imgui_impl_sdl2.h"
|
||||
#include "imgui/backends/imgui_impl_sdlrenderer2.h"
|
||||
#include "imgui/imgui.h"
|
||||
@@ -405,18 +406,18 @@ absl::Status Controller::CreateGuiContext() {
|
||||
|
||||
// Check if the assets/fonts directory exists in our CWD
|
||||
// Otherwise, load the system fonts.
|
||||
const auto assets_path = std::filesystem::path("assets");
|
||||
if (std::filesystem::is_directory(assets_path)) {
|
||||
// const auto assets_path = std::filesystem::path("assets");
|
||||
// if (std::filesystem::is_directory(assets_path)) {
|
||||
RETURN_IF_ERROR(LoadFontFamilies());
|
||||
} else {
|
||||
#ifdef __APPLE__
|
||||
LoadSystemFonts();
|
||||
#else
|
||||
return absl::InternalError(
|
||||
"Could not find assets/fonts directory in the current working "
|
||||
"directory");
|
||||
#endif
|
||||
}
|
||||
// } else {
|
||||
// #ifdef __APPLE__
|
||||
// LoadSystemFonts();
|
||||
// #else
|
||||
// return absl::InternalError(
|
||||
// "Could not find assets/fonts directory in the current working "
|
||||
// "directory");
|
||||
// #endif
|
||||
//}
|
||||
|
||||
// Set the default style
|
||||
gui::ColorsYaze();
|
||||
@@ -428,6 +429,30 @@ absl::Status Controller::CreateGuiContext() {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status Controller::LoadConfigFiles() {
|
||||
// Create and load a dotfile for the application
|
||||
// This will store the user's preferences and settings
|
||||
std::string config_directory = GetConfigDirectory(platform_);
|
||||
|
||||
// Create the directory if it doesn't exist
|
||||
if (!std::filesystem::exists(config_directory)) {
|
||||
std::filesystem::create_directory(config_directory);
|
||||
}
|
||||
|
||||
// Check if the config file exists
|
||||
std::string config_file = config_directory + "yaze.cfg";
|
||||
if (!std::filesystem::exists(config_file)) {
|
||||
// Create the file if it doesn't exist
|
||||
std::ofstream file(config_file);
|
||||
if (!file.is_open()) {
|
||||
return absl::InternalError(
|
||||
absl::StrFormat("Failed to create config file %s", config_file));
|
||||
}
|
||||
}
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status Controller::LoadFontFamilies() const {
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
|
||||
@@ -437,8 +462,8 @@ absl::Status Controller::LoadFontFamilies() const {
|
||||
static const char *DROID_SANS = "DroidSans.ttf";
|
||||
static const char *NOTO_SANS_JP = "NotoSansJP.ttf";
|
||||
static const char *IBM_PLEX_JP = "IBMPlexSansJP-Bold.ttf";
|
||||
static const float FONT_SIZE_DEFAULT = 14.0f;
|
||||
static const float FONT_SIZE_DROID_SANS = 16.0f;
|
||||
static const float FONT_SIZE_DEFAULT = 16.0f;
|
||||
static const float FONT_SIZE_DROID_SANS = 18.0f;
|
||||
static const float ICON_FONT_SIZE = 18.0f;
|
||||
|
||||
// Icon configuration
|
||||
@@ -457,8 +482,8 @@ absl::Status Controller::LoadFontFamilies() const {
|
||||
icons_config.PixelSnapH = true;
|
||||
|
||||
// List of fonts to be loaded
|
||||
std::vector<const char *> font_paths = {KARLA_REGULAR, ROBOTO_MEDIUM,
|
||||
COUSINE_REGULAR, IBM_PLEX_JP};
|
||||
std::vector<const char *> font_paths = {
|
||||
KARLA_REGULAR, ROBOTO_MEDIUM, COUSINE_REGULAR, IBM_PLEX_JP, DROID_SANS};
|
||||
|
||||
// Load fonts with associated icon and Japanese merges
|
||||
for (const auto &font_path : font_paths) {
|
||||
|
||||
@@ -12,10 +12,9 @@
|
||||
#include "imgui/imgui_internal.h"
|
||||
#include "absl/status/status.h"
|
||||
#include "app/core/platform/renderer.h"
|
||||
#include "app/core/utils/file_util.h"
|
||||
#include "app/editor/editor_manager.h"
|
||||
#include "app/editor/utils/editor.h"
|
||||
#include "app/gui/icons.h"
|
||||
#include "app/gui/style.h"
|
||||
|
||||
int main(int argc, char **argv);
|
||||
|
||||
@@ -23,8 +22,6 @@ namespace yaze {
|
||||
namespace app {
|
||||
namespace core {
|
||||
|
||||
enum class Platform { kUnknown, kMacOS, kiOS, kWindows, kLinux };
|
||||
|
||||
/**
|
||||
* @brief Main controller for the application.
|
||||
*
|
||||
@@ -44,6 +41,7 @@ class Controller : public ExperimentFlags {
|
||||
absl::Status CreateSDL_Window();
|
||||
absl::Status CreateRenderer();
|
||||
absl::Status CreateGuiContext();
|
||||
absl::Status LoadConfigFiles();
|
||||
absl::Status LoadFontFamilies() const;
|
||||
absl::Status LoadAudioDevice();
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ set(
|
||||
app/core/labeling.cc
|
||||
app/emu/emulator.cc
|
||||
app/core/message.cc
|
||||
app/core/utils/file_util.cc
|
||||
)
|
||||
|
||||
if (WIN32 OR MINGW OR UNIX AND NOT APPLE)
|
||||
|
||||
Reference in New Issue
Block a user