MCPcopy Create free account
hub / github.com/OpenArkStudio/ARK / LoadConfig

Method LoadConfig

src/plugin/kernel/src/AFCConfigModule.cpp:79–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79bool AFCConfigModule::LoadConfig(std::shared_ptr<AFClassMeta> pClassMeta)
80{
81 ARK_ASSERT_RET_VAL(pClassMeta != nullptr, true);
82
83 const std::string& res_path = pClassMeta->GetResPath();
84 if (res_path.empty())
85 {
86 return true;
87 }
88
89 std::string file_path = GetPluginManager()->GetResPath() + res_path;
90
91 ARK_LOG_INFO("Load data config files: {}", file_path);
92
93 AFXml xml_doc(file_path);
94 auto root_node = xml_doc.GetRootNode();
95 ARK_ASSERT_RET_VAL(root_node.IsValid(), false);
96
97 auto& data_meta_list = pClassMeta->GetDataMetaList();
98 for (auto data_node = root_node.FindNode("data"); data_node.IsValid(); data_node.NextNode())
99 {
100 // must have id
101 auto idx = pClassMeta->GetIndex("id");
102 auto pIDMeta = data_meta_list.find_value(idx);
103 ARK_ASSERT_RET_VAL(pIDMeta != nullptr, false);
104
105 AFINode* pIDData = CreateDataByMeta(pIDMeta);
106 ARK_ASSERT_RET_VAL(pIDData != nullptr, false);
107
108 pIDData->FromString(data_node.GetString(pIDData->GetName().c_str()));
109
110 // create a new object
111 auto pNodeManager = std::make_shared<AFNodeManager>(pClassMeta);
112 ARK_ASSERT_RET_VAL(pNodeManager != nullptr, false);
113
114 auto pObj = m_pStaticEntityManager->CreateStaticEntity(pClassMeta, pNodeManager, pIDData->GetValue());
115 ARK_ASSERT_RET_VAL(pObj != nullptr, false);
116
117 // delete id data do not need it
118 ARK_DELETE(pIDData);
119
120 // read by class meta
121 for (auto iter : data_meta_list)
122 {
123 auto& data_name = iter.first;
124 auto pDataMeta = iter.second;
125 ARK_ASSERT_RET_VAL(pDataMeta != nullptr, false);
126
127 AFINode* pData = pNodeManager->CreateData(pDataMeta);
128 ARK_ASSERT_RET_VAL(pData != nullptr, false);
129
130 pData->FromString(data_node.GetString(pDataMeta->GetName().c_str()));
131 }
132 }
133
134 return true;
135}
136

Callers

nothing calls this directly

Calls 14

CreateDataByMetaFunction · 0.85
GetRootNodeMethod · 0.80
IsValidMethod · 0.80
NextNodeMethod · 0.80
CreateStaticEntityMethod · 0.80
CreateDataMethod · 0.80
emptyMethod · 0.45
FindNodeMethod · 0.45
GetIndexMethod · 0.45
find_valueMethod · 0.45
FromStringMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected