You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
#include "engine/load_clx.hpp" |
|
|
|
#include <cstdint> |
|
|
|
#include <SDL.h> |
|
|
|
#ifdef USE_SDL1 |
|
#include "utils/sdl2_to_1_2_backports.h" |
|
#endif |
|
|
|
#include "appfat.h" |
|
#include "engine/assets.hpp" |
|
#include "engine/load_file.hpp" |
|
|
|
namespace devilution { |
|
|
|
OptionalOwnedClxSpriteListOrSheet LoadOptionalClxListOrSheet(const char *path) |
|
{ |
|
AssetRef ref = FindAsset(path); |
|
if (!ref.ok()) |
|
return std::nullopt; |
|
const size_t size = ref.size(); |
|
std::unique_ptr<uint8_t[]> data { new uint8_t[size] }; |
|
{ |
|
AssetHandle handle = OpenAsset(std::move(ref)); |
|
if (!handle.ok() || !handle.read(data.get(), size)) |
|
return std::nullopt; |
|
} |
|
return OwnedClxSpriteListOrSheet::FromBuffer(std::move(data), size); |
|
} |
|
|
|
tl::expected<OwnedClxSpriteListOrSheet, std::string> LoadClxListOrSheetWithStatus(const char *path) |
|
{ |
|
size_t size; |
|
tl::expected<std::unique_ptr<uint8_t[]>, std::string> data = LoadFileInMemWithStatus<uint8_t>(path, &size); |
|
if (!data.has_value()) return tl::make_unexpected(std::move(data).error()); |
|
return OwnedClxSpriteListOrSheet::FromBuffer(std::move(data).value(), size); |
|
} |
|
|
|
OwnedClxSpriteListOrSheet LoadClxListOrSheet(const char *path) |
|
{ |
|
tl::expected<OwnedClxSpriteListOrSheet, std::string> result = LoadClxListOrSheetWithStatus(path); |
|
if (!result.has_value()) app_fatal(result.error()); |
|
return std::move(result).value(); |
|
} |
|
|
|
} // namespace devilution
|
|
|