Refactor Controller and File Dialog: streamline platform handling, remove redundant parameters, and enhance initialization logic
This commit is contained in:
@@ -7,10 +7,10 @@
|
|||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "absl/strings/str_format.h"
|
#include "absl/strings/str_format.h"
|
||||||
|
#include "app/core/platform/file_dialog.h"
|
||||||
#include "app/core/platform/font_loader.h"
|
#include "app/core/platform/font_loader.h"
|
||||||
#include "app/editor/editor_manager.h"
|
#include "app/editor/editor_manager.h"
|
||||||
#include "app/gui/style.h"
|
#include "app/gui/style.h"
|
||||||
#include "app/core/platform/file_dialog.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"
|
||||||
@@ -19,26 +19,17 @@ namespace yaze {
|
|||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
absl::Status Controller::OnEntry(std::string filename) {
|
absl::Status Controller::OnEntry(std::string filename) {
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
|
||||||
#if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1
|
|
||||||
platform_ = Platform::kiOS;
|
|
||||||
#elif TARGET_OS_MAC == 1
|
|
||||||
platform_ = Platform::kMacOS;
|
|
||||||
#endif
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
platform_ = Platform::kWindows;
|
|
||||||
#elif defined(__linux__)
|
|
||||||
platform_ = Platform::kLinux;
|
|
||||||
#else
|
|
||||||
platform_ = Platform::kUnknown;
|
|
||||||
#endif
|
|
||||||
RETURN_IF_ERROR(CreateWindow())
|
RETURN_IF_ERROR(CreateWindow())
|
||||||
RETURN_IF_ERROR(CreateRenderer())
|
RETURN_IF_ERROR(CreateRenderer())
|
||||||
RETURN_IF_ERROR(CreateGuiContext())
|
RETURN_IF_ERROR(CreateGuiContext())
|
||||||
RETURN_IF_ERROR(LoadAudioDevice())
|
RETURN_IF_ERROR(LoadAudioDevice())
|
||||||
|
Initialize(filename);
|
||||||
|
return absl::OkStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Controller::Initialize(std::string filename) {
|
||||||
editor_manager_.Initialize(filename);
|
editor_manager_.Initialize(filename);
|
||||||
active_ = true;
|
active_ = true;
|
||||||
return absl::OkStatus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::OnInput() {
|
void Controller::OnInput() {
|
||||||
@@ -225,7 +216,7 @@ absl::Status Controller::LoadAudioDevice() {
|
|||||||
absl::Status Controller::LoadConfigFiles() {
|
absl::Status Controller::LoadConfigFiles() {
|
||||||
// Create and load a dotfile for the application
|
// Create and load a dotfile for the application
|
||||||
// This will store the user's preferences and settings
|
// This will store the user's preferences and settings
|
||||||
std::string config_directory = GetConfigDirectory(platform_);
|
std::string config_directory = GetConfigDirectory();
|
||||||
|
|
||||||
// Create the directory if it doesn't exist
|
// Create the directory if it doesn't exist
|
||||||
if (!std::filesystem::exists(config_directory)) {
|
if (!std::filesystem::exists(config_directory)) {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "app/core/platform/renderer.h"
|
|
||||||
#include "app/core/platform/file_dialog.h"
|
#include "app/core/platform/file_dialog.h"
|
||||||
|
#include "app/core/platform/renderer.h"
|
||||||
#include "app/editor/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/editor/editor_manager.h"
|
#include "app/editor/editor_manager.h"
|
||||||
#include "imgui/backends/imgui_impl_sdl2.h"
|
#include "imgui/backends/imgui_impl_sdl2.h"
|
||||||
@@ -30,6 +30,7 @@ class Controller {
|
|||||||
public:
|
public:
|
||||||
bool IsActive() const { return active_; }
|
bool IsActive() const { return active_; }
|
||||||
absl::Status OnEntry(std::string filename = "");
|
absl::Status OnEntry(std::string filename = "");
|
||||||
|
void Initialize(std::string filename = "");
|
||||||
void OnInput();
|
void OnInput();
|
||||||
absl::Status OnLoad();
|
absl::Status OnLoad();
|
||||||
absl::Status OnTestLoad();
|
absl::Status OnTestLoad();
|
||||||
@@ -43,13 +44,6 @@ class Controller {
|
|||||||
absl::Status LoadAudioDevice();
|
absl::Status LoadAudioDevice();
|
||||||
absl::Status LoadConfigFiles();
|
absl::Status LoadConfigFiles();
|
||||||
|
|
||||||
void SetupScreen(std::string filename = "") {
|
|
||||||
editor_manager_.Initialize(filename);
|
|
||||||
}
|
|
||||||
auto editor_manager() -> editor::EditorManager & { return editor_manager_; }
|
|
||||||
auto renderer() -> SDL_Renderer * {
|
|
||||||
return Renderer::GetInstance().renderer();
|
|
||||||
}
|
|
||||||
auto window() -> SDL_Window * { return window_.get(); }
|
auto window() -> SDL_Window * { return window_.get(); }
|
||||||
void init_test_editor(editor::Editor *editor) { test_editor_ = editor; }
|
void init_test_editor(editor::Editor *editor) { test_editor_ = editor; }
|
||||||
void set_active(bool active) { active_ = active; }
|
void set_active(bool active) { active_ = active; }
|
||||||
@@ -59,7 +53,6 @@ class Controller {
|
|||||||
friend int ::main(int argc, char **argv);
|
friend int ::main(int argc, char **argv);
|
||||||
|
|
||||||
bool active_ = false;
|
bool active_ = false;
|
||||||
Platform platform_ = Platform::kUnknown;
|
|
||||||
editor::Editor *test_editor_ = nullptr;
|
editor::Editor *test_editor_ = nullptr;
|
||||||
editor::EditorManager editor_manager_;
|
editor::EditorManager editor_manager_;
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ std::string LoadConfigFile(const std::string &filename) {
|
|||||||
#else
|
#else
|
||||||
platform = Platform::kLinux;
|
platform = Platform::kLinux;
|
||||||
#endif
|
#endif
|
||||||
std::string filepath = GetConfigDirectory(platform) + "/" + filename;
|
std::string filepath = GetConfigDirectory() + "/" + filename;
|
||||||
std::ifstream file(filepath);
|
std::ifstream file(filepath);
|
||||||
if (file.is_open()) {
|
if (file.is_open()) {
|
||||||
std::stringstream buffer;
|
std::stringstream buffer;
|
||||||
@@ -67,9 +67,8 @@ std::string LoadConfigFile(const std::string &filename) {
|
|||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveFile(const std::string &filename, const std::string &contents,
|
void SaveFile(const std::string &filename, const std::string &contents) {
|
||||||
Platform platform) {
|
std::string filepath = GetConfigDirectory() + "/" + filename;
|
||||||
std::string filepath = GetConfigDirectory(platform) + "/" + filename;
|
|
||||||
std::ofstream file(filepath);
|
std::ofstream file(filepath);
|
||||||
if (file.is_open()) {
|
if (file.is_open()) {
|
||||||
file << contents;
|
file << contents;
|
||||||
@@ -77,8 +76,22 @@ void SaveFile(const std::string &filename, const std::string &contents,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetConfigDirectory(Platform platform) {
|
std::string GetConfigDirectory() {
|
||||||
std::string config_directory = ".yaze";
|
std::string config_directory = ".yaze";
|
||||||
|
Platform platform;
|
||||||
|
#if defined(__APPLE__) && defined(__MACH__)
|
||||||
|
#if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1
|
||||||
|
platform = Platform::kiOS;
|
||||||
|
#elif TARGET_OS_MAC == 1
|
||||||
|
platform = Platform::kMacOS;
|
||||||
|
#endif
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
platform = Platform::kWindows;
|
||||||
|
#elif defined(__linux__)
|
||||||
|
platform = Platform::kLinux;
|
||||||
|
#else
|
||||||
|
platform = Platform::kUnknown;
|
||||||
|
#endif
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case Platform::kWindows:
|
case Platform::kWindows:
|
||||||
config_directory = "~/AppData/Roaming/yaze";
|
config_directory = "~/AppData/Roaming/yaze";
|
||||||
|
|||||||
@@ -38,10 +38,8 @@ std::string GetFileExtension(const std::string &filename);
|
|||||||
std::string GetFileName(const std::string &filename);
|
std::string GetFileName(const std::string &filename);
|
||||||
std::string LoadFile(const std::string &filename);
|
std::string LoadFile(const std::string &filename);
|
||||||
std::string LoadConfigFile(const std::string &filename);
|
std::string LoadConfigFile(const std::string &filename);
|
||||||
std::string GetConfigDirectory(Platform platform);
|
std::string GetConfigDirectory();
|
||||||
|
void SaveFile(const std::string &filename, const std::string &data);
|
||||||
void SaveFile(const std::string &filename, const std::string &data,
|
|
||||||
Platform platform);
|
|
||||||
|
|
||||||
} // namespace core
|
} // namespace core
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#ifndef YAZE_APP_GUI_ZEML_H
|
#ifndef YAZE_APP_GUI_ZEML_H
|
||||||
#define YAZE_APP_GUI_ZEML_H
|
#define YAZE_APP_GUI_ZEML_H
|
||||||
|
|
||||||
#include "imgui/imgui.h"
|
|
||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -10,6 +8,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
|
|
||||||
@@ -163,12 +163,6 @@ void BindSelectable(Node* node, bool* selected, std::function<void()> callback);
|
|||||||
*/
|
*/
|
||||||
WidgetType MapType(const std::string& type);
|
WidgetType MapType(const std::string& type);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Parse a zeml definition
|
|
||||||
*/
|
|
||||||
void ParseDefinitions(const std::vector<Token>& tokens, size_t& index,
|
|
||||||
std::map<std::string, Node>& definitions);
|
|
||||||
|
|
||||||
void ParseFlags(const WidgetType& type, const std::string& flags,
|
void ParseFlags(const WidgetType& type, const std::string& flags,
|
||||||
WidgetAttributes& flags_ptr);
|
WidgetAttributes& flags_ptr);
|
||||||
|
|
||||||
@@ -206,7 +200,6 @@ std::string LoadFile(const std::string& filename);
|
|||||||
|
|
||||||
} // namespace zeml
|
} // namespace zeml
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|
||||||
#endif // YAZE_APP_GUI_YAZON_H_
|
#endif // YAZE_APP_GUI_ZEML_H
|
||||||
|
|||||||
@@ -46,7 +46,17 @@
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
_controller = new yaze::app::core::Controller();
|
_controller = new yaze::core::Controller();
|
||||||
|
|
||||||
|
// Setup Dear ImGui context
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
|
(void)io;
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||||
|
|
||||||
|
yaze::gui::ColorsYaze();
|
||||||
|
|
||||||
SDL_SetMainReady();
|
SDL_SetMainReady();
|
||||||
SDL_iOSSetEventPump(SDL_TRUE);
|
SDL_iOSSetEventPump(SDL_TRUE);
|
||||||
@@ -76,23 +86,14 @@
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup Dear ImGui context
|
ImGui_ImplSDL2_InitForSDLRenderer(_controller->window(),
|
||||||
IMGUI_CHECKVERSION();
|
core::Renderer::GetInstance().renderer());
|
||||||
ImGui::CreateContext();
|
ImGui_ImplSDLRenderer2_Init(core::Renderer::GetInstance().renderer());
|
||||||
ImGuiIO &io = ImGui::GetIO();
|
|
||||||
(void)io;
|
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
|
||||||
|
|
||||||
yaze::app::gui::ColorsYaze();
|
|
||||||
|
|
||||||
ImGui_ImplSDL2_InitForSDLRenderer(_controller->window(), _controller->renderer());
|
|
||||||
ImGui_ImplSDLRenderer2_Init(_controller->renderer());
|
|
||||||
|
|
||||||
if (!_controller->LoadFontFamilies().ok()) {
|
if (!_controller->LoadFontFamilies().ok()) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
_controller->SetupScreen(rom_filename);
|
_controller->Initialize("");
|
||||||
_controller->set_active(true);
|
_controller->set_active(true);
|
||||||
|
|
||||||
_hoverGestureRecognizer =
|
_hoverGestureRecognizer =
|
||||||
|
|||||||
Reference in New Issue
Block a user