diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1c86e4e6..81fd937b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,6 +63,7 @@ if(APPLE) app/core/platform/app_delegate.mm app/core/platform/font_loader.mm app/core/platform/clipboard.mm + app/core/platform/file_path.mm ) find_library(COCOA_LIBRARY Cocoa) diff --git a/src/app/core/platform/file_path.h b/src/app/core/platform/file_path.h new file mode 100644 index 00000000..5cffc9de --- /dev/null +++ b/src/app/core/platform/file_path.h @@ -0,0 +1,6 @@ +#ifndef YAZE_APP_CORE_PLATFORM_FILE_PATH_H +#define YAZE_APP_CORE_PLATFORM_FILE_PATH_H + +std::string GetBundleResourcePath(); + +#endif // YAZE_APP_CORE_PLATFORM_FILE_PATH_H diff --git a/src/app/core/platform/file_path.mm b/src/app/core/platform/file_path.mm new file mode 100644 index 00000000..74dccef7 --- /dev/null +++ b/src/app/core/platform/file_path.mm @@ -0,0 +1,26 @@ +#include +#include + +#if defined(__APPLE__) && defined(__MACH__) +#include +#include + +#if TARGET_IPHONE_SIMULATOR == 1 +std::string GetBundleResourcePath() {} +#elif TARGET_OS_IPHONE == 1 +std::string GetBundleResourcePath() { + NSBundle* bundle = [NSBundle mainBundle]; + NSString* resourceDirectoryPath = [bundle bundlePath]; + NSString* path = [resourceDirectoryPath stringByAppendingString:@"/"]; + return [path UTF8String]; +} +#elif TARGET_OS_MAC == 1 +std::string GetBundleResourcePath() { + NSBundle* bundle = [NSBundle mainBundle]; + NSString* resourceDirectoryPath = [bundle bundlePath]; + NSString* path = [resourceDirectoryPath stringByAppendingString:@"/"]; + return [path UTF8String]; +} + +#endif +#endif diff --git a/src/app/gui/zeml.cc b/src/app/gui/zeml.cc index d587b78b..8c43a635 100644 --- a/src/app/gui/zeml.cc +++ b/src/app/gui/zeml.cc @@ -13,6 +13,7 @@ #include "app/gui/canvas.h" #include "app/gui/input.h" +#include "app/core/platform/file_path.h" namespace yaze { namespace app { @@ -590,7 +591,18 @@ void BindSelectable(Node* node, bool* selected, std::string LoadFile(const std::string& filename) { std::string fileContents; const std::string kPath = "assets/layouts/"; - std::ifstream file(kPath + filename); + + #ifdef __APPLE__ + #ifdef TARGET_OS_IOS + + const std::string kBundlePath = GetBundleResourcePath(); + std::ifstream file(kBundlePath + filename); + #else + std::ifstream file(kPath + filename); + #endif + #else + std::ifstream file(kPath + filename); + #endif if (file.is_open()) { std::string line;