Porytiles
Loading...
Searching...
No Matches
verify_primary_tileset.cpp
Go to the documentation of this file.
2
3#include <string>
4
7
8namespace porytiles2 {
9
10[[nodiscard]] ChainableResult<void> VerifyPrimaryTileset::verify(const std::string &tileset_name) const
11{
12 // 1. Check if the primary tileset exists. If not, abort with error.
13 if (!tileset_repo_->exists(tileset_name)) {
15 FormattableError{"tileset '{}' does not exist", FormatParam{tileset_name, Style::bold}}};
16 }
17
18 // 2. Load the tileset into a `Tileset` aggregate.
19 auto maybe_tileset = tileset_repo_->load(tileset_name);
20 if (!maybe_tileset.has_value()) {
22 FormattableError{"failed to load tileset '{}'", FormatParam{tileset_name, Style::bold}}, maybe_tileset};
23 }
24 const auto tileset = std::move(maybe_tileset.value());
25
26 // TODO: should we split this into separate handling of Porymap and Porytiles assets?
27 const auto artifact_keys = tileset_repo_->key_provider().get_all_artifact_keys(tileset_name);
28 const auto mismatched_keys =
29 tileset_repo_->checksum_provider().find_unsynced_tileset_artifacts(tileset_name, artifact_keys);
30 if (!mismatched_keys.empty()) {
31 std::vector<FormatParam> keys;
32 keys.reserve(mismatched_keys.size());
33 for (const auto &key : mismatched_keys) {
34 keys.emplace_back(key.key(), Style::bold);
35 }
36 // TODO: create some kind of MultilineFormattableError that can correctly format a multiline message
37 return ChainableResult<void>{FormattableError{"changes present in tileset assets: {}", keys}};
38 }
39
40 return {};
41}
42
43} // namespace porytiles2
virtual std::vector< ArtifactKey > find_unsynced_tileset_artifacts(const std::string &tileset_name, const std::vector< ArtifactKey > &artifact_keys) const
Finds all artifacts for the given Tileset with unsynced changes compared to cached checksums.
A result type that maintains a chainable sequence of errors for debugging and error reporting.
A text parameter with associated styling for formatted output.
General-purpose error implementation with formatted message support.
Definition error.hpp:117
virtual std::vector< ArtifactKey > get_all_artifact_keys(const std::string &tileset_name) const
Gets the keys for all tileset artifacts (both Porytiles and Porymap) present in the given Tileset.
bool exists(const std::string &name) const
Checks if the given Tileset exists in the backing store.
ChainableResult< std::unique_ptr< Tileset > > load(const std::string &name) const
Loads an existing Tileset from storage.
const ArtifactChecksumProvider & checksum_provider() const
Gets a reference to the ArtifactChecksumProvider for this repo.
const TilesetArtifactKeyProvider & key_provider() const
Gets a reference to the TilesetArtifactKeyProvider for this repo.
ChainableResult< void > verify(const std::string &tileset_name) const
@ bold
Bold text formatting.