SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Toggle main menu visibility
Loading...
Searching...
No Matches
HOT.cpp
Go to the documentation of this file.
1
#include <
vtfpp/HOT.h
>
2
3
#include <BufferStream.h>
4
5
using namespace
sourcepp
;
6
using namespace
vtfpp
;
7
8
HOT::HOT
()
9
:
opened
(true) {}
10
11
HOT::HOT
(std::span<const std::byte> hotData) {
12
BufferStreamReadOnly stream{hotData};
13
14
stream >> this->
version
>> this->
flags
;
15
if
(this->
version
!= 1) {
16
return
;
17
}
18
19
this->
rects
.resize(stream.read<uint16_t>());
20
for
(
auto
& [flags_, x1, y1, x2, y2] : this->
rects
) {
21
stream >> flags_ >> x1 >> y1 >> x2 >> y2;
22
}
23
24
this->
opened
=
true
;
25
}
26
27
HOT::HOT
(
const
std::filesystem::path& hotPath)
28
:
HOT
(
fs
::readFileBuffer(hotPath)) {}
29
30
HOT::operator bool()
const
{
31
return
this->
opened
;
32
}
33
34
uint8_t
HOT::getVersion
()
const
{
35
return
this->
version
;
36
}
37
38
void
HOT::setVersion
(uint8_t v) {
39
if
(v != 1) {
40
return
;
41
}
42
this->
version
= v;
43
}
44
45
uint8_t
HOT::getFlags
()
const
{
46
return
this->
flags
;
47
}
48
49
void
HOT::setFlags
(uint8_t f) {
50
this->
flags
= f;
51
}
52
53
const
std::vector<HOT::Rect>&
HOT::getRects
()
const
{
54
return
this->
rects
;
55
}
56
57
std::vector<HOT::Rect>&
HOT::getRects
() {
58
return
this->
rects
;
59
}
60
61
std::vector<std::byte>
HOT::bake
()
const
{
62
if
(!this->
opened
) {
63
return
{};
64
}
65
66
std::vector<std::byte> hotspotData;
67
BufferStream stream{hotspotData};
68
69
stream << this->
version
<< this->
flags
;
70
stream.write<uint16_t>(this->
rects
.size());
71
72
for
(
const
auto
& [flags_, x1, y1, x2, y2] : this->
rects
) {
73
stream << flags_ << x1 << y1 << x2 << y2;
74
}
75
76
hotspotData.resize(stream.tell());
77
return
hotspotData;
78
}
79
80
bool
HOT::bake
(
const
std::filesystem::path& hotPath)
const
{
81
return
fs::writeFileBuffer
(hotPath, this->
bake
());
82
}
HOT.h
vtfpp::HOT::bake
std::vector< std::byte > bake() const
Definition
HOT.cpp:61
vtfpp::HOT::setVersion
void setVersion(uint8_t v)
Definition
HOT.cpp:38
vtfpp::HOT::HOT
HOT()
Definition
HOT.cpp:8
vtfpp::HOT::rects
std::vector< Rect > rects
Definition
HOT.h:57
vtfpp::HOT::getRects
const std::vector< Rect > & getRects() const
Definition
HOT.cpp:53
vtfpp::HOT::getFlags
uint8_t getFlags() const
Definition
HOT.cpp:45
vtfpp::HOT::setFlags
void setFlags(uint8_t f)
Definition
HOT.cpp:49
vtfpp::HOT::opened
bool opened
Definition
HOT.h:53
vtfpp::HOT::flags
uint8_t flags
Definition
HOT.h:56
vtfpp::HOT::version
uint8_t version
Definition
HOT.h:55
vtfpp::HOT::getVersion
uint8_t getVersion() const
Definition
HOT.cpp:34
sourcepp::fs
Definition
FS.h:9
sourcepp::fs::writeFileBuffer
bool writeFileBuffer(const std::filesystem::path &filepath, std::span< const std::byte > buffer)
Definition
FS.cpp:37
sourcepp
Definition
LZMA.h:11
vtfpp
Definition
DistanceMapping.h:8
src
vtfpp
HOT.cpp
Generated on
for SourcePP by
1.17.0