3#include <BufferStream.h>
11 BufferStreamReadOnly stream{shtData.data(), shtData.size()};
15 this->
sequences.resize(stream.read<uint32_t>());
17 stream >> sequence.id;
18 sequence.loop = stream.read<uint32_t>();
19 sequence.frames.resize(stream.read<uint32_t>());
20 stream >> sequence.durationTotal;
22 for (
auto& frame : sequence.frames) {
23 frame.duration = stream.read<
float>();
25 auto& bounds = frame.bounds[i];
26 stream >> bounds.x1 >> bounds.y1 >> bounds.x2 >> bounds.y2;
35 :
SHT(fs::readFileBuffer(shtPath)) {}
37SHT::operator bool()
const {
46 if (v != 0 && v != 1) {
61 if (
auto pos = std::find_if(this->
sequences.begin(), this->sequences.end(), [
id](
const Sequence& sequence) {
62 return sequence.id == id;
63 }); pos != this->sequences.end()) {
70 if (
auto pos = std::find_if(this->
sequences.begin(), this->sequences.end(), [
id](
const Sequence& sequence) {
71 return sequence.id == id;
72 }); pos != this->sequences.end()) {
79 return (this->
version > 0) ? 4 : 1;
87 std::vector<std::byte> sheetData;
88 BufferStream stream{sheetData};
94 for (
const auto& sequence : this->
sequences) {
96 .write<uint32_t>(sequence.id)
97 .write<uint32_t>(sequence.loop)
98 .write<uint32_t>(sequence.frames.size())
99 .write<float>(sequence.durationTotal);
101 for (
const auto& frame : sequence.frames) {
102 stream.write<
float>(frame.duration);
105 auto& bounds = frame.bounds[i];
106 stream << bounds.x1 << bounds.y1 << bounds.x2 << bounds.y2;
111 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)