SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
SHT.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstddef>
5#include <span>
6#include <string>
7#include <vector>
8
9#include <sourcepp/Math.h>
10
11namespace vtfpp {
12
13class SHT {
14public:
15 struct Sequence {
16 struct Frame {
17 struct Bounds {
18 float x1;
19 float y1;
20 float x2;
21 float y2;
22 };
23
24 float duration;
25 // A sprite frame can reference 1 or 4 images, depending on the version
26 std::array<Bounds, 4> bounds;
27
28 void setAllBounds(Bounds newBounds) {
29 this->bounds[0] = newBounds;
30 this->bounds[1] = newBounds;
31 this->bounds[2] = newBounds;
32 this->bounds[3] = newBounds;
33 }
34 };
35
36 uint32_t id;
37 bool loop;
38 std::vector<Frame> frames;
40 };
41
42 SHT();
43
44 explicit SHT(std::span<const std::byte> shtData);
45
46 explicit SHT(const std::string& shtPath);
47
48 [[nodiscard]] explicit operator bool() const;
49
50 [[nodiscard]] uint32_t getVersion() const;
51
52 void setVersion(uint32_t v);
53
54 [[nodiscard]] const std::vector<Sequence>& getSequences() const;
55
56 [[nodiscard]] std::vector<Sequence>& getSequences();
57
58 [[nodiscard]] const Sequence* getSequenceFromID(uint32_t id) const;
59
60 [[nodiscard]] Sequence* getSequenceFromID(uint32_t id);
61
62 [[nodiscard]] uint8_t getFrameBoundsCount() const;
63
64 [[nodiscard]] std::vector<std::byte> bake() const;
65
66 bool bake(const std::string& shtPath) const; // NOLINT(*-use-nodiscard)
67
68protected:
69 bool opened;
70
71 uint32_t version;
72 std::vector<Sequence> sequences;
73};
74
75} // namespace vtfpp
Definition: SHT.h:13
const Sequence * getSequenceFromID(uint32_t id) const
Definition: SHT.cpp:62
uint32_t version
Definition: SHT.h:71
bool opened
Definition: SHT.h:69
std::vector< Sequence > sequences
Definition: SHT.h:72
void setVersion(uint32_t v)
Definition: SHT.cpp:47
uint32_t getVersion() const
Definition: SHT.cpp:43
uint8_t getFrameBoundsCount() const
Definition: SHT.cpp:80
std::vector< std::byte > bake() const
Definition: SHT.cpp:84
const std::vector< Sequence > & getSequences() const
Definition: SHT.cpp:54
SHT()
Definition: SHT.cpp:8
void setAllBounds(Bounds newBounds)
Definition: SHT.h:28
std::array< Bounds, 4 > bounds
Definition: SHT.h:26
uint32_t id
Definition: SHT.h:36
float durationTotal
Definition: SHT.h:39
std::vector< Frame > frames
Definition: SHT.h:38