Porytiles
Loading...
Searching...
No Matches
metatile_attribute_schema_resolver.cpp
Go to the documentation of this file.
2
3#include <utility>
4
10
11namespace porytiles {
12
14 std::filesystem::path project_root,
15 gsl::not_null<const InfraConfig *> config,
16 gsl::not_null<const TextFormatter *> format,
17 gsl::not_null<const UserDiagnostics *> diag)
18 : project_root_{std::move(project_root)}, config_{config}, format_{format}, diag_{diag}
19{
20}
21
23MetatileAttributeSchemaResolver::resolve(const std::string &tileset_name) const
24{
26 fields_cv,
30 overrides_cv,
34 size_cv,
38 declaration_cv,
41
42 // Gather the project's raw fieldmap facts and run the inference process. Inference runs on whatever the scan
43 // gathered, including nothing at all: a missing fieldmap header is not an error, and it simply reports that
44 // nothing was found so the reconciler can fall back to the user's inputs. Running it even when the scan came up
45 // empty is what lets a file that exists but could not be read be reported as such, rather than as a project that
46 // declares no masks.
47 MetatileAttributeScanner scanner{project_root_, format_, diag_};
48 const auto scan = scanner.scan_project();
49
50 const auto inference = infer_metatile_attribute_candidates(scan, format_);
51
52 // Warn about the attribute defines inference had no rule for, before reconciliation can fail for its own reasons:
53 // an ignored define may be exactly why the resulting layout is missing a field, and that is worth knowing whether
54 // or not resolution goes on to succeed.
55 if (!inference.unrecognized_defines.empty()) {
56 diag_->warning(
58 "Ignoring {} in '{}'. Porytiles reads attribute masks from the METATILE_ATTR_*_MASK and "
59 "METATILE_ATTR_*_MASK_FRLG spellings, and their bit offsets from METATILE_ATTR_*_SHIFT and "
60 "METATILE_ATTR_*_SHIFT_FRLG. Declare the layout with metatile_attribute_fields in your Porytiles config "
61 "if these defines describe one.",
62 FormatParam{join_quoted(inference.unrecognized_defines), Style::bold},
63 FormatParam{scan.header_source, Style::bold});
64 }
65
67 inputs.fields = fields_cv.value();
68 inputs.fields_source = fields_cv.source();
69 inputs.overrides = overrides_cv.value();
70 inputs.attribute_size = size_cv.value();
71 inputs.attribute_size_source = size_cv.source();
72 inputs.declaration_size = declaration_cv.value();
73 inputs.fieldmap_header_source = scan.header_source;
74
75 return reconcile_metatile_attribute_schema(inference, inputs, format_, diag_);
76}
77
78} // namespace porytiles
#define PT_TRY_ASSIGN_PASS_ERR(var, expr, return_type)
Unwraps a ChainableResult, passing through the error chain with an empty FormattableError when types ...
A result type that maintains a chainable sequence of errors for debugging and error reporting.
A text parameter with associated styling for formatted output.
ChainableResult< ConfigValue< MetatileAttributeFieldOverrides > > metatile_attribute_field_overrides(ConfigScopeType type, const std::string &scope) const
ChainableResult< ConfigValue< std::optional< std::size_t > > > metatile_attribute_size(ConfigScopeType type, const std::string &scope) const
ChainableResult< ConfigValue< std::optional< std::size_t > > > metatile_attribute_declaration_size(ConfigScopeType type, const std::string &scope) const
ChainableResult< ConfigValue< MetatileAttributeFieldDefinitions > > metatile_attribute_fields(ConfigScopeType type, const std::string &scope) const
Scans a decomp project's fieldmap sources for the raw metatile attribute facts.
ChainableResult< LoadedMetatileAttributeSchema > resolve(const std::string &tileset_name) const
Resolves the metatile attribute schema for the invocation.
MetatileAttributeSchemaResolver(std::filesystem::path project_root, gsl::not_null< const InfraConfig * > config, gsl::not_null< const TextFormatter * > format, gsl::not_null< const UserDiagnostics * > diag)
static const Style bold
Bold text formatting.
virtual void warning(const std::string &tag, const std::vector< std::string > &lines) const =0
Display a tagged warning message.
MetatileAttributeInferenceResult infer_metatile_attribute_candidates(const MetatileAttributeScan &scan, gsl::not_null< const TextFormatter * > format)
Infers the metatile attribute mask candidate sets from a project's raw fieldmap facts.
constexpr auto metatile_attr_inference_tag
The diagnostic tag the infra-layer scanner emits its warnings under.
ChainableResult< LoadedMetatileAttributeSchema > reconcile_metatile_attribute_schema(const MetatileAttributeInferenceResult &inference, const MetatileAttributeConfigInputs &inputs, gsl::not_null< const TextFormatter * > format, gsl::not_null< const UserDiagnostics * > diag)
Reconciles the inferred metatile attribute facts with the user's config, returning a LoadedMetatileAt...
@ tileset
Configuration scoped to a specific tileset.
std::string join_quoted(const std::vector< std::string > &values, const std::string &delimiter=", ")
Joins strings into a delimited list, wrapping each element in single quotes.
Utility functions for string manipulation and formatting.
The product of reconciling the project's metatile attribute schema.
The user-stated config inputs to metatile attribute schema reconciliation.