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