Load sys fonts if assets dir not found, return err if unsupported

This commit is contained in:
scawful
2024-10-04 01:33:13 -04:00
parent cc735d0094
commit a64700d601
2 changed files with 13 additions and 9 deletions

View File

@@ -55,10 +55,6 @@ class ExperimentFlags {
// Use the new platform specific file dialog wrappers.
bool kNewFileDialogWrapper = true;
// Platform specific loading of fonts from the system. Currently
// only supports macOS.
bool kLoadSystemFonts = true;
// Uses texture streaming from SDL for my dynamic updates.
bool kLoadTexturesAsStreaming = true;
@@ -125,8 +121,6 @@ class ExperimentFlags {
std::to_string(flags_->kDrawDungeonRoomGraphics) + "\n";
result += "kNewFileDialogWrapper: " +
std::to_string(flags_->kNewFileDialogWrapper) + "\n";
result +=
"kLoadSystemFonts: " + std::to_string(flags_->kLoadSystemFonts) + "\n";
result += "kLoadTexturesAsStreaming: " +
std::to_string(flags_->kLoadTexturesAsStreaming) + "\n";
result +=

View File

@@ -2,6 +2,7 @@
#include <SDL.h>
#include <filesystem>
#include <memory>
#include "absl/status/status.h"
@@ -402,10 +403,19 @@ absl::Status Controller::CreateGuiContext() {
Renderer::GetInstance().renderer());
ImGui_ImplSDLRenderer2_Init(Renderer::GetInstance().renderer());
if (flags()->kLoadSystemFonts) {
LoadSystemFonts();
} else {
// 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)) {
RETURN_IF_ERROR(LoadFontFamilies());
} else {
#ifdef __APPLE__
LoadSystemFonts();
#else
return absl::InternalError(
"Could not find assets/fonts directory in the current working "
"directory");
#endif
}
// Set the default style