Skip to content

Commit

Permalink
feat(bsppp): add getter/setter for lump versions
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Jul 18, 2024
1 parent 6575c73 commit ba3b4c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/bsppp/bsppp.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ class BSP {

[[nodiscard]] bool hasLump(BSPLump lumpIndex) const;

[[nodiscard]] int32_t getLumpVersion(BSPLump lumpIndex) const;

void setLumpVersion(BSPLump lumpIndex, int32_t version);

[[nodiscard]] std::optional<std::vector<std::byte>> readLump(BSPLump lumpIndex) const;

void writeLump(BSPLump lumpIndex, const std::vector<std::byte>& data);
Expand Down
12 changes: 12 additions & 0 deletions src/bsppp/bsppp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ bool BSP::hasLump(BSPLump lumpIndex) const {
return this->header.lumps[lump].length != 0 && this->header.lumps[lump].offset != 0;
}

int32_t BSP::getLumpVersion(BSPLump lumpIndex) const {
if (this->path.empty()) {
return 0;
}
return this->header.lumps[static_cast<int32_t>(lumpIndex)].version;
}

void BSP::setLumpVersion(BSPLump lumpIndex, int32_t version) {
this->header.lumps[static_cast<int32_t>(lumpIndex)].version = version;
this->writeHeader();
}

std::optional<std::vector<std::byte>> BSP::readLump(BSPLump lump) const {
if (this->path.empty() || !this->hasLump(lump)) {
return std::nullopt;
Expand Down

0 comments on commit ba3b4c3

Please sign in to comment.