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