3#include <BufferStream.h>
13 BufferStreamReadOnly stream{shtData.data(), shtData.size()};
17 this->
sequences.resize(stream.read<uint32_t>());
19 stream >> sequence.id;
20 sequence.loop = stream.read<uint32_t>();
21 sequence.frames.resize(stream.read<uint32_t>());
22 stream >> sequence.durationTotal;
24 for (
auto& frame : sequence.frames) {
25 frame.duration = stream.read<
float>();
27 auto& bounds = frame.bounds[i];
28 stream >> bounds.x1 >> bounds.y1 >> bounds.x2 >> bounds.y2;
37 :
SHT(fs::readFileBuffer(shtPath)) {}
39SHT::operator bool()
const {
48 if (v != 0 && v != 1) {
63 if (
auto pos = std::find_if(this->
sequences.begin(), this->sequences.end(), [
id](
const Sequence& sequence) {
64 return sequence.id == id;
65 }); pos != this->sequences.end()) {
72 if (
auto pos = std::find_if(this->
sequences.begin(), this->sequences.end(), [
id](
const Sequence& sequence) {
73 return sequence.id == id;
74 }); pos != this->sequences.end()) {
81 return (this->
version > 0) ? 4 : 1;
89 std::vector<std::byte> sheetData;
90 BufferStream stream{sheetData};
96 for (
const auto& sequence : this->
sequences) {
98 .write<uint32_t>(sequence.id)
99 .write<uint32_t>(sequence.loop)
100 .write<uint32_t>(sequence.frames.size())
101 .write<float>(sequence.durationTotal);
103 for (
const auto& frame : sequence.frames) {
104 stream.write<
float>(frame.duration);
107 auto& bounds = frame.bounds[i];
108 stream << bounds.x1 << bounds.y1 << bounds.x2 << bounds.y2;
113 sheetData.resize(stream.tell());
const Sequence * getSequenceFromID(uint32_t id) const
std::vector< Sequence > sequences
void setVersion(uint32_t v)
uint32_t getVersion() const
uint8_t getFrameBoundsCount() const
std::vector< std::byte > bake() const
const std::vector< Sequence > & getSequences() const
bool writeFileBuffer(const std::string &filepath, std::span< const std::byte > buffer)