This commit is contained in:
Isuru Samarathunga
2025-11-10 09:49:22 +05:30
parent 73d26b2f35
commit 67cb23d589
69 changed files with 9716 additions and 194 deletions

View File

@ -0,0 +1,10 @@
set(SRC_FILES
"imp/cpp/ConfigData.cpp"
)
add_library(ConfigData STATIC ${SRC_FILES})
target_include_directories(ConfigData PUBLIC inc)
target_include_directories(ConfigData PRIVATE imp/hpp)
target_link_libraries(ConfigData PUBLIC Common)

View File

@ -0,0 +1,95 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <ConfigData/ConfigData.hpp>
#include <IACore/File.hpp>
#include <filesystem>
namespace ia::iae
{
ConfigData::ConfigData(IN pugi::xml_document &&document, IN CONST String &type, IN CONST String &name,
IN pugi::xml_node propertiesNode, IN Vector<pugi::xml_node> &&childNodes)
: m_document(IA_MOVE(document)), m_type(type), m_name(name), m_propertiesNode(propertiesNode),
m_childNodes(IA_MOVE(childNodes))
{
}
RefPtr<ConfigData> ConfigData::LoadFromFile(IN CONST String &path)
{
const auto result = LoadFromMemory(File::ReadToString(path));
result->m_filePath = std::filesystem::canonical(path.c_str()).string().c_str();
return result;
}
RefPtr<ConfigData> ConfigData::LoadFromMemory(IN CONST String &data)
{
pugi::xml_document doc;
if (!doc.load_string(data.c_str()))
return nullptr;
if (std::distance(doc.children().begin(), doc.children().end()) != 1)
return nullptr;
const auto rootNode = *doc.children().begin();
// Verify Engine Version
{
const auto engineInfoNode = rootNode.child("IAEngine");
if (!engineInfoNode)
return nullptr;
const auto engineVersionNode = engineInfoNode.child("EngineVersion");
if (!engineVersionNode)
return nullptr;
const auto engineVersion = IA_PARSE_VERSION_STRING(engineVersionNode.text().as_string());
if (engineVersion > ENGINE_VERSION)
{
CFG_LOG_WARN("XML data file was created with a newer version of IAEngine, skipping..");
return nullptr;
}
}
const auto propertiesNode = rootNode.child("Properties");
if (!propertiesNode)
return nullptr;
Vector<pugi::xml_node> childNodes;
for (auto &c : rootNode.children())
{
if ((!strcmp(c.name(), "Properties")) || (!strcmp(c.name(), "IAEngine")))
continue;
childNodes.pushBack(c);
}
const auto nameAttr = rootNode.attribute("name");
return MakeRefPtr<ConfigData>(IA_MOVE(doc), rootNode.name(), nameAttr ? nameAttr.as_string() : "",
propertiesNode, IA_MOVE(childNodes));
}
VOID ConfigData::WriteChangesToDisk()
{
if (m_filePath.empty())
return;
m_document.save_file(m_filePath.c_str());
}
pugi::xml_node ConfigData::Property(IN CONST String &name)
{
return m_propertiesNode.child(name.c_str());
}
} // namespace ia::iae

View File

@ -0,0 +1,33 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <Common/Base.hpp>
#include <pugixml.hpp>
#define CFG_LOG_TAG "CFG"
#define CFG_LOG_INFO(...) ia::Logger::Info(CFG_LOG_TAG, __VA_ARGS__)
#define CFG_LOG_WARN(...) ia::Logger::Warn(CFG_LOG_TAG, __VA_ARGS__)
#define CFG_LOG_ERROR(...) ia::Logger::Error(CFG_LOG_TAG, __VA_ARGS__)
#define CFG_LOG_SUCCESS(...) ia::Logger::Success(CFG_LOG_TAG, __VA_ARGS__)
namespace ia::iae
{
} // namespace ia::iae

View File

@ -0,0 +1,63 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <ConfigData/Base.hpp>
namespace ia::iae
{
class ConfigData
{
public:
STATIC RefPtr<ConfigData> LoadFromFile(IN CONST String &path);
STATIC RefPtr<ConfigData> LoadFromMemory(IN CONST String &data);
VOID WriteChangesToDisk();
public:
pugi::xml_node Property(IN CONST String &name);
public:
CONST String &Type() CONST
{
return m_type;
}
CONST String &Name() CONST
{
return m_name;
}
CONST Vector<pugi::xml_node> &Children() CONST
{
return m_childNodes;
}
private:
String m_filePath{};
CONST String m_type;
CONST String m_name;
CONST pugi::xml_document m_document;
CONST pugi::xml_node m_propertiesNode;
CONST Vector<pugi::xml_node> m_childNodes;
public:
ConfigData(IN pugi::xml_document &&document, IN CONST String &type, IN CONST String &name,
IN pugi::xml_node propertiesNode, IN Vector<pugi::xml_node> &&childNodes);
};
} // namespace ia::iae