Add ResourceLoader
This commit is contained in:
19
openVulkanoCpp/Host/iOS/BundledResoureLoaderIos.h
Normal file
19
openVulkanoCpp/Host/iOS/BundledResoureLoaderIos.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#include "Host/ResourceLoader.hpp"
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
class BundledResourceLoaderIOS : public ResourceLoader
|
||||
{
|
||||
public:
|
||||
Array<char> GetResource(const std::string& resourceName) override;
|
||||
};
|
||||
}
|
||||
30
openVulkanoCpp/Host/iOS/BundledResoureLoaderIos.mm
Normal file
30
openVulkanoCpp/Host/iOS/BundledResoureLoaderIos.mm
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "BundledResoureLoaderIos.h"
|
||||
#include "Base/Logger.hpp"
|
||||
#include "Base/Utils.hpp"
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void* LOADER_HANDLE = ResourceLoader::RegisterResourceLoader(std::move(std::unique_ptr<ResourceLoader>(new BundledResourceLoaderIOS())));
|
||||
}
|
||||
|
||||
|
||||
Array<char> BundledResourceLoaderIOS::GetResource(const std::string& resourceName)
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
auto [fileName, fileType] = Utils::SplitAtLastOccurrence(resourceName, '.');
|
||||
NSString* filePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:fileName.c_str()] ofType:[NSString stringWithUTF8String:fileType.c_str()]];
|
||||
return Utils::ReadFile(std::string([filePath UTF8String]));
|
||||
}
|
||||
Logger::FILESYS->warn("Failed to find resource: '{}' in bundle", resourceName);
|
||||
return {0};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user