From e358126d4f068cfcbe9a261e098338b0f9ea06c9 Mon Sep 17 00:00:00 2001 From: pv Date: Tue, 1 Aug 2023 08:55:09 +0300 Subject: [PATCH] Add yaml templates --- .../Declarative/Yaml/YamlReader.Template.cpp | 19 +++++++++++-------- .../Tweaks/Declarative/Yaml/YamlReader.cpp | 2 +- .../Tweaks/Declarative/Yaml/YamlReader.hpp | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/App/Tweaks/Declarative/Yaml/YamlReader.Template.cpp b/src/App/Tweaks/Declarative/Yaml/YamlReader.Template.cpp index 1275427..22be5aa 100644 --- a/src/App/Tweaks/Declarative/Yaml/YamlReader.Template.cpp +++ b/src/App/Tweaks/Declarative/Yaml/YamlReader.Template.cpp @@ -2,7 +2,7 @@ namespace { -constexpr auto TemplateAttrKey = "$data"; +constexpr auto InstanceAttrKey = "$instances"; constexpr auto AttrMark = '$'; constexpr auto AttrOpen = '{'; @@ -49,7 +49,10 @@ std::string FormatString(const std::string& aInput, const Core::Map> templates; @@ -152,7 +155,7 @@ void App::YamlReader::ExpandTemplates(YAML::Node& aRootNode) const auto& subKey = nodeIt.first.Scalar(); const auto& subNode = nodeIt.second; - if (!subNode.IsMap() || !subNode[TemplateAttrKey].IsDefined()) + if (!subNode.IsMap() || !subNode[InstanceAttrKey].IsDefined()) continue; templates.emplace_back(subKey, subNode); @@ -162,15 +165,15 @@ void App::YamlReader::ExpandTemplates(YAML::Node& aRootNode) { aRootNode.remove(templateName); - const auto& dataNode = templateNode[TemplateAttrKey]; + const auto& dataNode = templateNode[InstanceAttrKey]; if (!dataNode.IsSequence()) { - LogError("{}: Template data must be an array of structs.", templateName); + LogError("{}: Template instances must be an array of structs.", templateName); continue; } - templateNode.remove(TemplateAttrKey); + templateNode.remove(InstanceAttrKey); for (std::size_t i = 0; i < dataNode.size(); ++i) { @@ -191,7 +194,7 @@ void App::YamlReader::ExpandTemplates(YAML::Node& aRootNode) if (aRootNode[instanceName].IsDefined()) { - LogError("{}: Cannot instantiate {}, because it already exists.", + LogError("{}: Cannot create instance {}, because it already exists.", templateName, instanceName); continue; } diff --git a/src/App/Tweaks/Declarative/Yaml/YamlReader.cpp b/src/App/Tweaks/Declarative/Yaml/YamlReader.cpp index 8686eb2..3596efc 100644 --- a/src/App/Tweaks/Declarative/Yaml/YamlReader.cpp +++ b/src/App/Tweaks/Declarative/Yaml/YamlReader.cpp @@ -68,7 +68,7 @@ void App::YamlReader::Read(App::TweakChangeset& aChangeset) } ConvertLegacyNodes(); - ExpandTemplates(m_data); + ProcessTemplates(m_data); auto propMode = ResolvePropertyMode(m_data); diff --git a/src/App/Tweaks/Declarative/Yaml/YamlReader.hpp b/src/App/Tweaks/Declarative/Yaml/YamlReader.hpp index a229e4b..63e42bd 100644 --- a/src/App/Tweaks/Declarative/Yaml/YamlReader.hpp +++ b/src/App/Tweaks/Declarative/Yaml/YamlReader.hpp @@ -60,7 +60,7 @@ class YamlReader Red::InstancePtr<> MakeValue(const Red::CBaseRTTIType* aType, const YAML::Node& aNode); std::pair> TryMakeValue(const YAML::Node& aNode); - void ExpandTemplates(YAML::Node& aRootNode); + void ProcessTemplates(YAML::Node& aRootNode); void ConvertLegacyNodes(); std::filesystem::path m_path;