MCPcopy Create free account
hub / github.com/antopilo/Nuake / RegisterEntityScript

Method RegisterEntityScript

Nuake/Source/Nuake/Scripting/ScriptingEngineNet.cpp:550–731  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

548 }
549
550 void ScriptingEngineNet::RegisterEntityScript(Entity& entity)
551 {
552 if (!isInitialized)
553 {
554 return;
555 }
556
557 if (!entity.IsValid())
558 {
559 Logger::Log("Failed to register entity .net script: Entity not valid.", ".net", CRITICAL);
560 return;
561 }
562
563 if (!entity.HasComponent<NetScriptComponent>())
564 {
565 Logger::Log("Failed to register entity .net script: Entity doesn't have a .net script component.", ".net", CRITICAL);
566 return;
567 }
568
569 auto& component = entity.GetComponent<NetScriptComponent>();
570
571 const auto& filePath = component.ScriptPath;
572
573 std::string className;
574 if (String::EndsWith(filePath, ".cs"))
575 {
576 className = FindClassNameInScript(filePath);
577 }
578 else
579 {
580 className = filePath;
581 }
582
583 if(gameEntityTypes.find(className) == gameEntityTypes.end())
584 {
585 // The class name parsed in the file was not found in the game's DLL.
586 const std::string& msg = "Skipped .net entity script: \n Class: " +
587 className + " not found in " + std::string(gameAssembly.GetName());
588 Logger::Log(msg, ".net", CRITICAL);
589 return;
590 }
591
592 auto classInstance = gameEntityTypes[className].coralType->CreateInstance();
593
594 int handle = entity.GetHandle();
595 int id = entity.GetID();
596 classInstance.SetPropertyValue("ECSHandle", handle);
597 classInstance.SetPropertyValue("ID", id);
598
599 if (entity.HasComponent<BSPBrushComponent>())
600 {
601 BSPBrushComponent& brushComponent = entity.GetComponent<BSPBrushComponent>();
602 }
603
604 std::vector<std::string> detectedExposedVar;
605 detectedExposedVar.reserve(std::size(gameEntityTypes[className].exposedVars));
606 // Update new default values if they have changed in the code.
607 for (auto& exposedVar : gameEntityTypes[className].exposedVars)

Callers 3

InitMethod · 0.80
UpdateMethod · 0.80
InitializeNewScriptsMethod · 0.80

Calls 15

LogFunction · 0.85
has_valueMethod · 0.80
GetEntityByIDMethod · 0.80
EndsWithFunction · 0.50
sizeFunction · 0.50
IsValidMethod · 0.45
findMethod · 0.45
endMethod · 0.45
GetNameMethod · 0.45
GetHandleMethod · 0.45
GetIDMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected