mirror of
https://github.com/diasurgical/DevilutionX.git
synced 2026-10-12 02:13:06 +00:00
Now that the project targets C++23, use the standard library's std::expected instead of the vendored tl::expected polyfill: - tl::expected -> std::expected, tl::unexpected/tl::make_unexpected -> std::unexpected - .map()/.map_error() -> .transform()/.transform_error() - #include <expected.hpp> -> #include <expected>, grouped with std headers - Remove 3rdParty/tl/expected.hpp (the tl target remains for function_ref.hpp) Co-Authored-By: Claude Fable 5 <[email protected]>
44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
#include "engine/load_clx.hpp"
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <expected>
|
|
|
|
#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);
|
|
}
|
|
|
|
std::expected<OwnedClxSpriteListOrSheet, std::string> LoadClxListOrSheetWithStatus(const char *path)
|
|
{
|
|
size_t size;
|
|
std::expected<std::unique_ptr<uint8_t[]>, std::string> data = LoadFileInMemWithStatus<uint8_t>(path, &size);
|
|
if (!data.has_value()) return std::unexpected(std::move(data).error());
|
|
return OwnedClxSpriteListOrSheet::FromBuffer(std::move(data).value(), size);
|
|
}
|
|
|
|
OwnedClxSpriteListOrSheet LoadClxListOrSheet(const char *path)
|
|
{
|
|
std::expected<OwnedClxSpriteListOrSheet, std::string> result = LoadClxListOrSheetWithStatus(path);
|
|
if (!result.has_value()) app_fatal(result.error());
|
|
return std::move(result).value();
|
|
}
|
|
|
|
} // namespace devilution
|