// 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 . #include #include 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 &&childNodes) : m_document(IA_MOVE(document)), m_type(type), m_name(name), m_propertiesNode(propertiesNode), m_childNodes(IA_MOVE(childNodes)) { } RefPtr ConfigData::LoadFromFile(IN CONST String &path) { return LoadFromMemory(File::ReadToString(path)); } RefPtr 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 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(IA_MOVE(doc), rootNode.name(), nameAttr ? nameAttr.as_string() : "", propertiesNode, IA_MOVE(childNodes)); } pugi::xml_node ConfigData::Property(IN CONST String &name) { return m_propertiesNode.child(name.c_str()); } } // namespace ia::iae