From 251fa5a2b758970679a4496da01eebbae0451870 Mon Sep 17 00:00:00 2001 From: tehhowch Date: Sat, 17 Jul 2021 11:26:38 -0500 Subject: [PATCH] feat(mechanics,licenses): support "inline" license specifications The wiki describes `licenses` as "a list of names" and provides no examples of what was intended (an indented list). Rather than issue a warning diagnostic for a license that was specified in the same line, add support for that syntax. --- source/Outfit.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/source/Outfit.cpp b/source/Outfit.cpp index 6a67d32f90ad..eb9ffc8f1ab3 100644 --- a/source/Outfit.cpp +++ b/source/Outfit.cpp @@ -178,10 +178,22 @@ void Outfit::Load(const DataNode &node) cost = child.Value(1); else if(child.Token(0) == "mass" && child.Size() >= 2) mass = child.Value(1); - else if(child.Token(0) == "licenses") + else if(child.Token(0) == "licenses" && (child.HasChildren() || child.Size() >= 2)) { + auto isNewLicense = [](const vector &c, const string &val) noexcept -> bool { + return find(c.begin(), c.end(), val) == c.end(); + }; + // Add any new licenses that were specified "inline". + if(child.Size() >= 2) + { + for(auto it = ++begin(child.Tokens()); it != end(child.Tokens()); ++it) + if(isNewLicense(licenses, *it)) + licenses.push_back(*it); + } + // Add any new licenses that were specifed as an indented list. for(const DataNode &grand : child) - licenses.push_back(grand.Token(0)); + if(isNewLicense(licenses, grand.Token(0))) + licenses.push_back(grand.Token(0)); } else if(child.Token(0) == "jump range" && child.Size() >= 2) {