Porytiles
Loading...
Searching...
No Matches
yaml_file_provider.cpp
Go to the documentation of this file.
2
3#include <cstdint>
4#include <filesystem>
5#include <fstream>
6#include <map>
7#include <sstream>
8
9#include "yaml-cpp/yaml.h"
10
13
15
16namespace porytiles {
17
18// NOTE: DO NOT EDIT THIS FILE DIRECTLY. It is AUTO-GENERATED from config_schema.yaml.
19// To add new config values or make other changes, edit config_schema.yaml and regenerate via:
20//
21// uv run scripts/generate_config.py
22
24 gsl::not_null<const TextFormatter *> format,
25 const UserDiagnostics *diagnostics,
26 const std::filesystem::path &project_root)
27 : format_{format}, diagnostics_{diagnostics}, project_root_{project_root}
28{
29 // Config files are loaded lazily when first accessed via the anonymous namespace functions
30}
31
32YamlFileProvider::YamlFileProvider(const UserDiagnostics *diagnostics, const std::filesystem::path &project_root)
33 : owned_format_{std::make_unique<PlainTextFormatter>()}, format_{owned_format_.get()}, diagnostics_{diagnostics},
34 project_root_{project_root}
35{
36 // Config files are loaded lazily when first accessed via the anonymous namespace functions
37}
38
39std::string YamlFileProvider::name() const
40{
41 return "YamlFileProvider";
42}
43
44bool YamlFileProvider::preload_and_validate(ConfigScopeType type, const std::string &scope) const
45{
46 return preload_and_validate_yaml_files(format_, diagnostics_, project_root_, type, scope);
47}
48
50{
51 auto paths_result = get_config_path_chain(project_root_, type, scope);
52 if (!paths_result.has_value()) {
54 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
55 }
56 return search_config_files<std::size_t>(
57 format_,
58 paths_result.value(),
59 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
60 [](const YAML::Node &doc) { return doc["fieldmap"]["num_tiles_in_primary"]; },
61 parse_size_t,
62 "fieldmap.num_tiles_in_primary",
63 "fieldmap.num_tiles_in_primary");
64}
65
67{
68 auto paths_result = get_config_path_chain(project_root_, type, scope);
69 if (!paths_result.has_value()) {
71 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
72 }
73 return search_config_files<std::size_t>(
74 format_,
75 paths_result.value(),
76 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
77 [](const YAML::Node &doc) { return doc["fieldmap"]["num_tiles_total"]; },
78 parse_size_t,
79 "fieldmap.num_tiles_total",
80 "fieldmap.num_tiles_total");
81}
82
84{
85 auto paths_result = get_config_path_chain(project_root_, type, scope);
86 if (!paths_result.has_value()) {
88 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
89 }
90 return search_config_files<std::size_t>(
91 format_,
92 paths_result.value(),
93 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
94 [](const YAML::Node &doc) { return doc["fieldmap"]["num_metatiles_in_primary"]; },
95 parse_size_t,
96 "fieldmap.num_metatiles_in_primary",
97 "fieldmap.num_metatiles_in_primary");
98}
99
101{
102 auto paths_result = get_config_path_chain(project_root_, type, scope);
103 if (!paths_result.has_value()) {
105 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
106 }
107 return search_config_files<std::size_t>(
108 format_,
109 paths_result.value(),
110 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
111 [](const YAML::Node &doc) { return doc["fieldmap"]["num_metatiles_total"]; },
112 parse_size_t,
113 "fieldmap.num_metatiles_total",
114 "fieldmap.num_metatiles_total");
115}
116
118{
119 auto paths_result = get_config_path_chain(project_root_, type, scope);
120 if (!paths_result.has_value()) {
122 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
123 }
124 return search_config_files<std::size_t>(
125 format_,
126 paths_result.value(),
127 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
128 [](const YAML::Node &doc) { return doc["fieldmap"]["num_palettes_in_primary"]; },
129 parse_size_t,
130 "fieldmap.num_palettes_in_primary",
131 "fieldmap.num_palettes_in_primary");
132}
133
135{
136 auto paths_result = get_config_path_chain(project_root_, type, scope);
137 if (!paths_result.has_value()) {
139 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
140 }
141 return search_config_files<std::size_t>(
142 format_,
143 paths_result.value(),
144 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
145 [](const YAML::Node &doc) { return doc["fieldmap"]["num_palettes_total"]; },
146 parse_size_t,
147 "fieldmap.num_palettes_total",
148 "fieldmap.num_palettes_total");
149}
150
152{
153 auto paths_result = get_config_path_chain(project_root_, type, scope);
154 if (!paths_result.has_value()) {
156 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
157 }
158 return search_config_files<std::size_t>(
159 format_,
160 paths_result.value(),
161 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
162 [](const YAML::Node &doc) { return doc["fieldmap"]["max_map_data_size"]; },
163 parse_size_t,
164 "fieldmap.max_map_data_size",
165 "fieldmap.max_map_data_size");
166}
167
169{
170 auto paths_result = get_config_path_chain(project_root_, type, scope);
171 if (!paths_result.has_value()) {
173 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
174 }
175 return search_config_files<std::size_t>(
176 format_,
177 paths_result.value(),
178 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
179 [](const YAML::Node &doc) { return doc["fieldmap"]["num_tiles_per_metatile"]; },
180 parse_size_t,
181 "fieldmap.num_tiles_per_metatile",
182 "fieldmap.num_tiles_per_metatile");
183}
184
186{
187 auto paths_result = get_config_path_chain(project_root_, type, scope);
188 if (!paths_result.has_value()) {
189 return LayerValue<Rgba32>::invalid(paths_result.error().join(PlainTextFormatter{}), "config path resolution");
190 }
191 return search_config_files<Rgba32>(
192 format_,
193 paths_result.value(),
194 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
195 [](const YAML::Node &doc) { return doc["tileset"]["extrinsic_transparency"]; },
196 parse_rgba32,
197 "tileset.extrinsic_transparency",
198 "tileset.extrinsic_transparency");
199}
200
202{
203 auto paths_result = get_config_path_chain(project_root_, type, scope);
204 if (!paths_result.has_value()) {
205 return LayerValue<bool>::invalid(paths_result.error().join(PlainTextFormatter{}), "config path resolution");
206 }
207 return search_config_files<bool>(
208 format_,
209 paths_result.value(),
210 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
211 [](const YAML::Node &doc) { return doc["tileset"]["ignore_triple_layer_content"]; },
212 parse_bool,
213 "tileset.ignore_triple_layer_content",
214 "tileset.ignore_triple_layer_content");
215}
216
218{
219 auto paths_result = get_config_path_chain(project_root_, type, scope);
220 if (!paths_result.has_value()) {
222 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
223 }
224 return search_config_files<ArtifactEditMode>(
225 format_,
226 paths_result.value(),
227 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
228 [](const YAML::Node &doc) { return doc["tileset"]["tiles"]["edit_mode"]; },
229 parse_artifact_edit_mode,
230 "tileset.tiles.edit_mode",
231 "tileset.tiles.edit_mode");
232}
233
235{
236 auto paths_result = get_config_path_chain(project_root_, type, scope);
237 if (!paths_result.has_value()) {
239 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
240 }
241 return search_config_files<ArtifactEditMode>(
242 format_,
243 paths_result.value(),
244 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
245 [](const YAML::Node &doc) { return doc["tileset"]["palettes"]["edit_mode"]; },
246 parse_artifact_edit_mode,
247 "tileset.palettes.edit_mode",
248 "tileset.palettes.edit_mode");
249}
250
252{
253 auto paths_result = get_config_path_chain(project_root_, type, scope);
254 if (!paths_result.has_value()) {
255 return LayerValue<bool>::invalid(paths_result.error().join(PlainTextFormatter{}), "config path resolution");
256 }
257 return search_config_files<bool>(
258 format_,
259 paths_result.value(),
260 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
261 [](const YAML::Node &doc) { return doc["tileset"]["palettes"]["packing"]["hints_enabled"]; },
262 parse_bool,
263 "tileset.palettes.packing.hints_enabled",
264 "tileset.palettes.packing.hints_enabled");
265}
266
268YamlFileProvider::palette_hints(ConfigScopeType type, const std::string &scope) const
269{
270 auto paths_result = get_config_path_chain(project_root_, type, scope);
271 if (!paths_result.has_value()) {
273 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
274 }
275 return search_config_files<std::vector<PaletteHint>>(
276 format_,
277 paths_result.value(),
278 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
279 [](const YAML::Node &doc) { return doc["tileset"]["palettes"]["packing"]["hints"]; },
280 parse_palette_hints,
281 "tileset.palettes.packing.hints",
282 "tileset.palettes.packing.hints");
283}
284
286{
287 auto paths_result = get_config_path_chain(project_root_, type, scope);
288 if (!paths_result.has_value()) {
290 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
291 }
292 return search_config_files<PackingStrategyType>(
293 format_,
294 paths_result.value(),
295 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
296 [](const YAML::Node &doc) { return doc["tileset"]["palettes"]["packing"]["strategy"]; },
297 parse_packing_strategy_type,
298 "tileset.palettes.packing.strategy",
299 "tileset.palettes.packing.strategy");
300}
301
304{
305 auto paths_result = get_config_path_chain(project_root_, type, scope);
306 if (!paths_result.has_value()) {
308 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
309 }
310 return search_config_files<PackingStrategyParams>(
311 format_,
312 paths_result.value(),
313 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
314 [](const YAML::Node &doc) { return doc["tileset"]["palettes"]["packing"]["strategy_params"]; },
315 parse_packing_strategy_params,
316 "tileset.palettes.packing.strategy_params",
317 "tileset.palettes.packing.strategy_params");
318}
319
321YamlFileProvider::tile_sharing_packing(ConfigScopeType type, const std::string &scope) const
322{
323 auto paths_result = get_config_path_chain(project_root_, type, scope);
324 if (!paths_result.has_value()) {
326 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
327 }
328 return search_config_files<TileSharingPacking>(
329 format_,
330 paths_result.value(),
331 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
332 [](const YAML::Node &doc) { return doc["tileset"]["tiles"]["sharing"]["packing"]; },
333 parse_tile_sharing_packing,
334 "tileset.tiles.sharing.packing",
335 "tileset.tiles.sharing.packing");
336}
337
340{
341 auto paths_result = get_config_path_chain(project_root_, type, scope);
342 if (!paths_result.has_value()) {
344 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
345 }
346 return search_config_files<TileSharingAlignment>(
347 format_,
348 paths_result.value(),
349 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
350 [](const YAML::Node &doc) { return doc["tileset"]["tiles"]["sharing"]["alignment"]; },
351 parse_tile_sharing_alignment,
352 "tileset.tiles.sharing.alignment",
353 "tileset.tiles.sharing.alignment");
354}
355
357{
358 auto paths_result = get_config_path_chain(project_root_, type, scope);
359 if (!paths_result.has_value()) {
361 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
362 }
363 return search_config_files<TilesPaletteMode>(
364 format_,
365 paths_result.value(),
366 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
367 [](const YAML::Node &doc) { return doc["tileset"]["tiles"]["palette_mode"]; },
368 parse_tiles_palette_mode,
369 "tileset.tiles.palette_mode",
370 "tileset.tiles.palette_mode");
371}
372
375{
376 auto paths_result = get_config_path_chain(project_root_, type, scope);
377 if (!paths_result.has_value()) {
379 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
380 }
381 return search_config_files<AnimPaletteResolutionStrategy>(
382 format_,
383 paths_result.value(),
384 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
385 [](const YAML::Node &doc) { return doc["tileset"]["animations"]["palette_resolution_strategy"]; },
386 parse_anim_palette_resolution_strategy,
387 "tileset.animations.palette_resolution_strategy",
388 "tileset.animations.palette_resolution_strategy");
389}
390
393{
394 auto paths_result = get_config_path_chain(project_root_, type, scope);
395 if (!paths_result.has_value()) {
397 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
398 }
399 return search_config_files<AnimKeyFrameResolutionStrategy>(
400 format_,
401 paths_result.value(),
402 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
403 [](const YAML::Node &doc) { return doc["tileset"]["animations"]["key_frame_resolution_strategy"]; },
404 parse_anim_key_frame_resolution_strategy,
405 "tileset.animations.key_frame_resolution_strategy",
406 "tileset.animations.key_frame_resolution_strategy");
407}
408
411 ConfigScopeType type, const std::string &scope) const
412{
413 auto paths_result = get_config_path_chain(project_root_, type, scope);
414 if (!paths_result.has_value()) {
416 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
417 }
418 return search_config_files<AnimMultiPaletteSubtileResolutionStrategy>(
419 format_,
420 paths_result.value(),
421 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
422 [](const YAML::Node &doc) { return doc["tileset"]["animations"]["multi_palette_subtile_resolution_strategy"]; },
423 parse_anim_multi_palette_subtile_resolution_strategy,
424 "tileset.animations.multi_palette_subtile_resolution_strategy",
425 "tileset.animations.multi_palette_subtile_resolution_strategy");
426}
427
429{
430 auto paths_result = get_config_path_chain(project_root_, type, scope);
431 if (!paths_result.has_value()) {
433 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
434 }
435 return search_config_files<FrameLinking>(
436 format_,
437 paths_result.value(),
438 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
439 [](const YAML::Node &doc) { return doc["tileset"]["animations"]["frame_linking"]; },
440 parse_frame_linking,
441 "tileset.animations.frame_linking",
442 "tileset.animations.frame_linking");
443}
444
446{
447 auto paths_result = get_config_path_chain(project_root_, type, scope);
448 if (!paths_result.has_value()) {
450 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
451 }
452 return search_config_files<PerAnimOverrides>(
453 format_,
454 paths_result.value(),
455 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
456 [](const YAML::Node &doc) { return doc["tileset"]["animations"]["per_animation_overrides"]; },
457 parse_per_anim_overrides,
458 "tileset.animations.per_animation_overrides",
459 "tileset.animations.per_animation_overrides");
460}
461
463{
464 auto paths_result = get_config_path_chain(project_root_, type, scope);
465 if (!paths_result.has_value()) {
466 return LayerValue<bool>::invalid(paths_result.error().join(PlainTextFormatter{}), "config path resolution");
467 }
468 return search_config_files<bool>(
469 format_,
470 paths_result.value(),
471 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
472 [](const YAML::Node &doc) { return doc["tileset"]["animations"]["cross_tileset_linking"]; },
473 parse_bool,
474 "tileset.animations.cross_tileset_linking",
475 "tileset.animations.cross_tileset_linking");
476}
477
479{
480 auto paths_result = get_config_path_chain(project_root_, type, scope);
481 if (!paths_result.has_value()) {
482 return LayerValue<bool>::invalid(paths_result.error().join(PlainTextFormatter{}), "config path resolution");
483 }
484 return search_config_files<bool>(
485 format_,
486 paths_result.value(),
487 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
488 [](const YAML::Node &doc) { return doc["verify_checksums"]; },
489 parse_bool,
490 "verify_checksums",
491 "verify_checksums");
492}
493
495YamlFileProvider::primary_pairing_mode(ConfigScopeType type, const std::string &scope) const
496{
497 auto paths_result = get_config_path_chain(project_root_, type, scope);
498 if (!paths_result.has_value()) {
500 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
501 }
502 return search_config_files<PrimaryPairingMode>(
503 format_,
504 paths_result.value(),
505 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
506 [](const YAML::Node &doc) { return doc["tileset"]["primary_pairing"]["mode"]; },
507 parse_primary_pairing_mode,
508 "tileset.primary_pairing.mode",
509 "tileset.primary_pairing.mode");
510}
511
514{
515 auto paths_result = get_config_path_chain(project_root_, type, scope);
516 if (!paths_result.has_value()) {
518 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
519 }
520 return search_config_files<std::vector<std::string>>(
521 format_,
522 paths_result.value(),
523 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
524 [](const YAML::Node &doc) { return doc["tileset"]["primary_pairing"]["partners"]; },
525 parse_string_vector,
526 "tileset.primary_pairing.partners",
527 "tileset.primary_pairing.partners");
528}
529
532{
533 auto paths_result = get_config_path_chain(project_root_, type, scope);
534 if (!paths_result.has_value()) {
536 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
537 }
538 return search_config_files<std::vector<std::string>>(
539 format_,
540 paths_result.value(),
541 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
542 [](const YAML::Node &doc) { return doc["diagnostics"]["warnings"]["exclude"]; },
543 parse_string_vector,
544 "diagnostics.warnings.exclude",
545 "diagnostics.warnings.exclude");
546}
547
550{
551 auto paths_result = get_config_path_chain(project_root_, type, scope);
552 if (!paths_result.has_value()) {
554 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
555 }
556 return search_config_files<std::vector<std::string>>(
557 format_,
558 paths_result.value(),
559 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
560 [](const YAML::Node &doc) { return doc["diagnostics"]["warnings"]["include"]; },
561 parse_string_vector,
562 "diagnostics.warnings.include",
563 "diagnostics.warnings.include");
564}
565
568{
569 auto paths_result = get_config_path_chain(project_root_, type, scope);
570 if (!paths_result.has_value()) {
572 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
573 }
574 return search_config_files<std::vector<std::string>>(
575 format_,
576 paths_result.value(),
577 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
578 [](const YAML::Node &doc) { return doc["diagnostics"]["remarks"]["exclude"]; },
579 parse_string_vector,
580 "diagnostics.remarks.exclude",
581 "diagnostics.remarks.exclude");
582}
583
586{
587 auto paths_result = get_config_path_chain(project_root_, type, scope);
588 if (!paths_result.has_value()) {
590 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
591 }
592 return search_config_files<std::vector<std::string>>(
593 format_,
594 paths_result.value(),
595 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
596 [](const YAML::Node &doc) { return doc["diagnostics"]["remarks"]["include"]; },
597 parse_string_vector,
598 "diagnostics.remarks.include",
599 "diagnostics.remarks.include");
600}
601
604{
605 auto paths_result = get_config_path_chain(project_root_, type, scope);
606 if (!paths_result.has_value()) {
608 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
609 }
610 return search_config_files<std::string>(
611 format_,
612 paths_result.value(),
613 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
614 [](const YAML::Node &doc) { return doc["tileset"]["paths"]["primary"]["src"]; },
615 parse_string,
616 "tileset.paths.primary.src",
617 "tileset.paths.primary.src");
618}
619
622{
623 auto paths_result = get_config_path_chain(project_root_, type, scope);
624 if (!paths_result.has_value()) {
626 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
627 }
628 return search_config_files<std::string>(
629 format_,
630 paths_result.value(),
631 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
632 [](const YAML::Node &doc) { return doc["tileset"]["paths"]["primary"]["bin"]; },
633 parse_string,
634 "tileset.paths.primary.bin",
635 "tileset.paths.primary.bin");
636}
637
640{
641 auto paths_result = get_config_path_chain(project_root_, type, scope);
642 if (!paths_result.has_value()) {
644 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
645 }
646 return search_config_files<std::string>(
647 format_,
648 paths_result.value(),
649 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
650 [](const YAML::Node &doc) { return doc["tileset"]["paths"]["secondary"]["src"]; },
651 parse_string,
652 "tileset.paths.secondary.src",
653 "tileset.paths.secondary.src");
654}
655
658{
659 auto paths_result = get_config_path_chain(project_root_, type, scope);
660 if (!paths_result.has_value()) {
662 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
663 }
664 return search_config_files<std::string>(
665 format_,
666 paths_result.value(),
667 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
668 [](const YAML::Node &doc) { return doc["tileset"]["paths"]["secondary"]["bin"]; },
669 parse_string,
670 "tileset.paths.secondary.bin",
671 "tileset.paths.secondary.bin");
672}
673
676{
677 auto paths_result = get_config_path_chain(project_root_, type, scope);
678 if (!paths_result.has_value()) {
680 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
681 }
682 return search_config_files<std::optional<std::size_t>>(
683 format_,
684 paths_result.value(),
685 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
686 [](const YAML::Node &doc) { return doc["fieldmap"]["metatile_attribute_size"]; },
687 parse_optional_size_t,
688 "fieldmap.metatile_attribute_size",
689 "fieldmap.metatile_attribute_size");
690}
691
694{
695 auto paths_result = get_config_path_chain(project_root_, type, scope);
696 if (!paths_result.has_value()) {
698 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
699 }
700 return search_config_files<std::optional<std::size_t>>(
701 format_,
702 paths_result.value(),
703 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
704 [](const YAML::Node &doc) { return doc["fieldmap"]["metatile_attribute_declaration_size"]; },
705 parse_optional_size_t,
706 "fieldmap.metatile_attribute_declaration_size",
707 "fieldmap.metatile_attribute_declaration_size");
708}
709
712{
713 auto paths_result = get_config_path_chain(project_root_, type, scope);
714 if (!paths_result.has_value()) {
716 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
717 }
718 return search_config_files<MetatileAttributeFieldDefinitions>(
719 format_,
720 paths_result.value(),
721 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
722 [](const YAML::Node &doc) { return doc["fieldmap"]["metatile_attribute_fields"]; },
723 parse_metatile_attribute_fields,
724 "fieldmap.metatile_attribute_fields",
725 "fieldmap.metatile_attribute_fields");
726}
727
730{
731 auto paths_result = get_config_path_chain(project_root_, type, scope);
732 if (!paths_result.has_value()) {
734 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
735 }
736 return search_config_files<MetatileAttributeFieldOverrides>(
737 format_,
738 paths_result.value(),
739 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
740 [](const YAML::Node &doc) { return doc["fieldmap"]["metatile_attribute_field_overrides"]; },
741 parse_metatile_attribute_field_overrides,
742 "fieldmap.metatile_attribute_field_overrides",
743 "fieldmap.metatile_attribute_field_overrides");
744}
745
747{
748 auto paths_result = get_config_path_chain(project_root_, type, scope);
749 if (!paths_result.has_value()) {
751 paths_result.error().join(PlainTextFormatter{}), "config path resolution");
752 }
753 return search_config_files<RolePinDefinitions>(
754 format_,
755 paths_result.value(),
756 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
757 [](const YAML::Node &doc) { return doc["fieldmap"]["role_pins"]; },
758 parse_role_pins,
759 "fieldmap.role_pins",
760 "fieldmap.role_pins");
761}
762
765{
766 auto paths_result = get_config_path_chain(project_root_, type, scope);
767 if (!paths_result.has_value()) {
768 return LayerValue<bool>::invalid(paths_result.error().join(PlainTextFormatter{}), "config path resolution");
769 }
770 return search_config_files<bool>(
771 format_,
772 paths_result.value(),
773 [this](const std::filesystem::path &p) { return load_yaml_file(p, format_, diagnostics_); },
774 [](const YAML::Node &doc) { return doc["tileset"]["animations"]["wire_anim_code"]; },
775 parse_bool,
776 "tileset.animations.wire_anim_code",
777 "tileset.animations.wire_anim_code");
778}
779
780} // namespace porytiles
TextFormatter implementation that strips all styling from text.
Abstract class for structured error reporting and diagnostic output.
LayerValue< TilesPaletteMode > tiles_palette_mode(ConfigScopeType type, const std::string &scope) const override
LayerValue< ArtifactEditMode > palettes_edit_mode(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::size_t > num_tiles_in_primary(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::vector< std::string > > diagnostic_remarks_exclude(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::string > tileset_paths_secondary_bin(ConfigScopeType type, const std::string &scope) const override
LayerValue< Rgba32 > extrinsic_transparency(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::vector< PaletteHint > > palette_hints(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::vector< std::string > > primary_pairing_partners(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::optional< std::size_t > > metatile_attribute_declaration_size(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::size_t > num_metatiles_in_primary(ConfigScopeType type, const std::string &scope) const override
LayerValue< AnimKeyFrameResolutionStrategy > global_anim_key_frame_resolution_strategy(ConfigScopeType type, const std::string &scope) const override
LayerValue< RolePinDefinitions > role_pins(ConfigScopeType type, const std::string &scope) const override
LayerValue< bool > tileset_animations_wire_anim_code(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::size_t > max_map_data_size(ConfigScopeType type, const std::string &scope) const override
YamlFileProvider(gsl::not_null< const TextFormatter * > format, const UserDiagnostics *diagnostics, const std::filesystem::path &project_root)
Constructs a YamlFileProvider that searches for configuration across multiple YAML files.
LayerValue< std::string > tileset_paths_primary_src(ConfigScopeType type, const std::string &scope) const override
LayerValue< bool > palette_hints_enabled(ConfigScopeType type, const std::string &scope) const override
LayerValue< PerAnimOverrides > per_anim_overrides(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::string > tileset_paths_primary_bin(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::string > tileset_paths_secondary_src(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::vector< std::string > > diagnostic_remarks_include(ConfigScopeType type, const std::string &scope) const override
LayerValue< PrimaryPairingMode > primary_pairing_mode(ConfigScopeType type, const std::string &scope) const override
LayerValue< MetatileAttributeFieldDefinitions > metatile_attribute_fields(ConfigScopeType type, const std::string &scope) const override
LayerValue< ArtifactEditMode > tiles_edit_mode(ConfigScopeType type, const std::string &scope) const override
LayerValue< MetatileAttributeFieldOverrides > metatile_attribute_field_overrides(ConfigScopeType type, const std::string &scope) const override
LayerValue< bool > cross_tileset_anim_linking(ConfigScopeType type, const std::string &scope) const override
LayerValue< bool > verify_checksums(ConfigScopeType type, const std::string &scope) const override
LayerValue< PackingStrategyType > packing_strategy(ConfigScopeType type, const std::string &scope) const override
LayerValue< FrameLinking > global_frame_linking(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::vector< std::string > > diagnostic_warnings_include(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::size_t > num_palettes_total(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::size_t > num_tiles_total(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::size_t > num_metatiles_total(ConfigScopeType type, const std::string &scope) const override
LayerValue< bool > ignore_triple_layer_content(ConfigScopeType type, const std::string &scope) const override
bool preload_and_validate(ConfigScopeType type, const std::string &scope) const
Eagerly loads all YAML config files and validates them for unknown keys.
std::string name() const override
Gets the name of this config layer.
LayerValue< TileSharingPacking > tile_sharing_packing(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::size_t > num_palettes_in_primary(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::optional< std::size_t > > metatile_attribute_size(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::size_t > num_tiles_per_metatile(ConfigScopeType type, const std::string &scope) const override
LayerValue< AnimMultiPaletteSubtileResolutionStrategy > global_anim_multi_palette_subtile_resolution_strategy(ConfigScopeType type, const std::string &scope) const override
LayerValue< AnimPaletteResolutionStrategy > global_anim_palette_resolution_strategy(ConfigScopeType type, const std::string &scope) const override
LayerValue< std::vector< std::string > > diagnostic_warnings_exclude(ConfigScopeType type, const std::string &scope) const override
LayerValue< PackingStrategyParams > packing_strategy_params(ConfigScopeType type, const std::string &scope) const override
LayerValue< TileSharingAlignment > tile_sharing_alignment(ConfigScopeType type, const std::string &scope) const override
@ invalid
no layout could be determined from what the project declares (fatal at resolution time)
ConfigScopeType
Specifies the scope type for configuration value lookups.
Utility functions for string manipulation and formatting.
A small container that holds an optional-wrapped value, validation state, and metadata about the valu...
static LayerValue invalid(std::string error, std::string source_info)
Creates a LayerValue representing an invalid configuration value.