Porytiles
Loading...
Searching...
No Matches
project_tileset_metadata_provider.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <filesystem>
5#include <map>
6#include <set>
7#include <string>
8#include <utility>
9#include <vector>
10
11#include "gsl/pointers"
12
19
20namespace porytiles {
21
22namespace detail {
23
24enum class IncbinResolutionFailure : std::uint8_t {
25 not_found, // The variable name was not declared in any scanned source file.
26 empty_paths // The variable was found but its INCBIN declaration captured no paths.
27};
28
30 std::string field_label; // The struct field, e.g. ".tiles" or ".metatileAttributes".
31 std::string variable_name; // The INCBIN variable the field referenced.
33};
34
35} // namespace detail
36
46 public:
48 std::filesystem::path project_root,
49 gsl::not_null<const TextFormatter *> format,
50 gsl::not_null<const UserDiagnostics *> diag)
51 : project_root_{std::move(project_root)}, format_{format}, diag_{diag}
52 {
53 }
54
55 [[nodiscard]] bool exists(const std::string &tileset_name) const override;
56
57 [[nodiscard]] ChainableResult<bool> is_secondary(const std::string &tileset_name) const override;
58
59 [[nodiscard]] ChainableResult<bool> has_animations(const std::string &tileset_name) const override;
60
61 [[nodiscard]] ChainableResult<std::set<std::string>> tilesets() const override;
62
72 [[nodiscard]] ChainableResult<ProjectTilesetMetadata> metadata_for(const std::string &tileset_name) const;
73
84 artifact_paths_for(const std::string &tileset_name) const;
85
92 void invalidate_metadata_cache() const;
93
94 private:
95 std::filesystem::path project_root_;
96 const TextFormatter *format_;
97 const UserDiagnostics *diag_;
98
99 // Lazy-loaded cache for parsed tileset metadata (mutable for const methods)
100 mutable bool metadata_parsed_{false};
101 mutable std::map<std::string, ProjectTilesetMetadata> tileset_metadata_;
102
103 // Lazy-loaded cache for resolved tileset artifact paths (mutable for const methods)
104 mutable bool artifact_paths_parsed_{false};
105 mutable std::map<std::string, ProjectTilesetArtifactPaths> tileset_artifact_paths_;
106
107 // Per-tileset record of artifact fields that failed INCBIN resolution, for diagnostics
108 mutable std::map<std::string, std::vector<detail::UnresolvedIncbinVar>> tileset_unresolved_vars_;
109};
110
111} // namespace porytiles
A result type that maintains a chainable sequence of errors for debugging and error reporting.
Provides a pokeemerald project filesystem-based implementation for TilesetMetadataProvider.
void invalidate_metadata_cache() const
Invalidates the lazy-loaded metadata and artifact paths caches, forcing a re-parse on next access.
ChainableResult< ProjectTilesetArtifactPaths > artifact_paths_for(const std::string &tileset_name) const
Resolves artifact paths for a tileset by parsing INCBIN declarations.
ChainableResult< std::set< std::string > > tilesets() const override
Returns all tileset names known to this provider.
bool exists(const std::string &tileset_name) const override
Checks whether a tileset exists in the backing store for the given tileset name.
ChainableResult< ProjectTilesetMetadata > metadata_for(const std::string &tileset_name) const
Retrieves metadata for a specific tileset from the struct cache.
ProjectTilesetMetadataProvider(std::filesystem::path project_root, gsl::not_null< const TextFormatter * > format, gsl::not_null< const UserDiagnostics * > diag)
ChainableResult< bool > has_animations(const std::string &tileset_name) const override
Determines whether a tileset has animation support.
ChainableResult< bool > is_secondary(const std::string &tileset_name) const override
Determines whether a tileset is a secondary tileset.
Abstract base class for applying text styling with context-aware formatting.
Abstract interface for querying tileset metadata by name.
Abstract class for structured error reporting and diagnostic output.