From 80fe64b1575f6153dc9605a222f291bc29f986c9 Mon Sep 17 00:00:00 2001 From: David Ehnert <17857925+DavidLokison@users.noreply.github.com> Date: Tue, 24 Dec 2024 01:03:50 +0100 Subject: [PATCH] adjust projectinfo reader to addon structure --- code/foundation/io/jsonreader.cc | 13 +++++++++++++ code/foundation/io/jsonreader.h | 2 ++ toolkit/toolkit-common/projectinfo.cc | 13 +++++++------ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/code/foundation/io/jsonreader.cc b/code/foundation/io/jsonreader.cc index 23ee98116..0feb62144 100644 --- a/code/foundation/io/jsonreader.cc +++ b/code/foundation/io/jsonreader.cc @@ -323,6 +323,19 @@ JsonReader::GetChildNodeName(SizeT childIndex) return ""; } +//------------------------------------------------------------------------------ +/** + +*/ +bool +JsonReader::IsString() const +{ + n_assert(this->IsOpen()); + n_assert(0 != this->curNode); + return this->curNode->is_string(); +} + + //------------------------------------------------------------------------------ /** diff --git a/code/foundation/io/jsonreader.h b/code/foundation/io/jsonreader.h index bd77ddcf6..da511f4bc 100644 --- a/code/foundation/io/jsonreader.h +++ b/code/foundation/io/jsonreader.h @@ -60,6 +60,8 @@ class JsonReader : public StreamReader /// gets the childname of the child at index, or empty string if no child exists or has no name. Util::String GetChildNodeName(SizeT childIndex); + /// check if current node is a string + bool IsString() const; /// check if current node is an array bool IsArray() const; /// check if current node is an object (can have keys) diff --git a/toolkit/toolkit-common/projectinfo.cc b/toolkit/toolkit-common/projectinfo.cc index b038ea8ef..e2fd116ec 100644 --- a/toolkit/toolkit-common/projectinfo.cc +++ b/toolkit/toolkit-common/projectinfo.cc @@ -200,11 +200,8 @@ ProjectInfo::ParseProjectInfoFile(const IO::URI & path) if (jsonReader->SetToFirstChild()) do { - if (!jsonReader->HasChildren()) - { - this->attrs.Add(jsonReader->GetCurrentNodeName(), jsonReader->GetString()); - } - else + String thing = jsonReader->GetCurrentNodeName(); + if (jsonReader->HasChildren()) { String currentKey = jsonReader->GetCurrentNodeName(); Dictionary values; @@ -212,10 +209,14 @@ ProjectInfo::ParseProjectInfoFile(const IO::URI & path) do { values.Add(jsonReader->GetString("Name"), jsonReader->GetString("Value")); - } + } while (jsonReader->SetToNextChild()); this->listAttrs.Add(currentKey, values); } + else if (jsonReader->IsString()) + { + this->attrs.Add(jsonReader->GetCurrentNodeName(), jsonReader->GetString()); + } } while (jsonReader->SetToNextChild()); return Success;