2024-03-15 11:47:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "StarAssetSource.hpp"
|
|
|
|
#include "StarIODevice.hpp"
|
|
|
|
|
|
|
|
namespace Star {
|
|
|
|
|
|
|
|
STAR_CLASS(MemoryAssetSource);
|
2024-03-24 16:46:21 +00:00
|
|
|
STAR_CLASS(Image);
|
2024-03-15 11:47:02 +00:00
|
|
|
|
|
|
|
class MemoryAssetSource : public AssetSource {
|
|
|
|
public:
|
2024-03-15 13:02:51 +00:00
|
|
|
MemoryAssetSource(String const& name, JsonObject metadata = JsonObject());
|
2024-03-15 11:47:02 +00:00
|
|
|
|
2024-03-15 13:02:51 +00:00
|
|
|
String name() const;
|
2024-03-15 11:47:02 +00:00
|
|
|
JsonObject metadata() const override;
|
|
|
|
StringList assetPaths() const override;
|
|
|
|
|
2024-03-24 16:46:21 +00:00
|
|
|
// do not use the returned IODevice after the file is gone or bad things will happen
|
2024-03-15 11:47:02 +00:00
|
|
|
IODevicePtr open(String const& path) override;
|
|
|
|
|
|
|
|
bool empty() const;
|
|
|
|
bool contains(String const& path) const;
|
|
|
|
bool erase(String const& path);
|
2024-03-15 13:02:51 +00:00
|
|
|
void set(String const& path, ByteArray data);
|
2024-03-24 16:46:21 +00:00
|
|
|
void set(String const& path, Image const& image);
|
|
|
|
void set(String const& path, Image&& image);
|
2024-03-15 11:47:02 +00:00
|
|
|
ByteArray read(String const& path) override;
|
2024-03-24 16:46:21 +00:00
|
|
|
ImageConstPtr image(String const& path);
|
2024-03-15 11:47:02 +00:00
|
|
|
private:
|
2024-03-24 16:46:21 +00:00
|
|
|
typedef Variant<ByteArray, ImagePtr> FileEntry;
|
|
|
|
|
2024-03-15 13:02:51 +00:00
|
|
|
String m_name;
|
2024-03-15 11:47:02 +00:00
|
|
|
JsonObject m_metadata;
|
2024-03-24 16:46:21 +00:00
|
|
|
StringMap<FileEntry> m_files;
|
2024-03-15 11:47:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|