MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / loadGameObject

Method loadGameObject

src/Core/Script/GameObject.cpp:146–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144 }
145
146 void GameObject::loadGameObject(
147 Scene::Scene& scene, vili::node& obj, Engine::ResourceManager* resources)
148 {
149 Debug::Log->debug("<GameObject> Loading GameObject '{0}' ({1})", m_id, m_type);
150 // Script
151 if (!obj["permanent"].is_null())
152 {
153 m_permanent = obj.at("permanent");
154 }
155 if (!obj["Script"].is_null())
156 {
157 m_hasScriptEngine = true;
158 m_environment = sol::environment(m_lua, sol::create, m_lua.globals());
159 m_privateKey = Utils::String::getRandomKey(Utils::String::Alphabet, 1)
160 + Utils::String::getRandomKey(
161 Utils::String::Alphabet + Utils::String::Numbers, 11);
162 m_triggers.createNamespace(m_privateKey);
163 t_local = m_triggers.createTriggerGroup(m_privateKey, "Local");
164
165 m_environment["This"] = this;
166
167 t_local->add("Init").add("Delete");
168
169 m_environment["__OBJECT_TYPE"] = m_type;
170 m_environment["__OBJECT_ID"] = m_id;
171 m_environment["__OBJECT_INIT"] = false;
172 m_environment["Private"] = m_privateKey;
173
174 m_lua.safe_script_file("Lib/Internal/ObjectInit.lua"_fs, m_environment);
175
176 auto loadSource = [&](const std::string& path) {
177 const std::string fullPath = System::Path(path).find();
178 if (fullPath.empty())
179 {
180 throw Exceptions::ScriptFileNotFound(m_type, m_id, path, EXC_INFO);
181 }
182 m_lua.safe_script_file(fullPath, m_environment);
183 };
184 if (!obj.at("Script")["source"].is_null())
185 {
186 const vili::node& sourceNode = obj.at("Script").at("source");
187 if (sourceNode.is<vili::string>())
188 {
189 loadSource(sourceNode);
190 }
191 else
192 {
193 throw Exceptions::WrongSourceAttributeType(m_type, "source",
194 vili::string_type, vili::to_string(sourceNode.type()), EXC_INFO);
195 }
196 }
197 else if (!obj.at("Script")["sources"].is_null())
198 {
199 vili::node& sourceNode = obj.at("Script").at("sources");
200 if (sourceNode.is<vili::array>())
201 {
202 for (auto source : sourceNode)
203 {

Callers 2

LoadClassGameObjectFunction · 0.80
Scene.cppFile · 0.80

Calls 15

getRandomKeyFunction · 0.85
PathClass · 0.85
ScriptFileNotFoundClass · 0.85
debugMethod · 0.80
globalsMethod · 0.80
createNamespaceMethod · 0.80
createTriggerGroupMethod · 0.80
safe_script_fileMethod · 0.80
reorganizeLayersMethod · 0.80
setTargetMethod · 0.80
setKeyMethod · 0.80

Tested by

no test coverage detected