Cogs.Core
ScriptSystem.cpp
1#include "ScriptSystem.h"
2
3#include "Scripting/ScriptingManager.h"
4
6{
7 for (auto & component : pool) {
8 auto & data = getData(&component);
9
10 if (!data.scriptContext && !component.source.empty()) {
11 data.scriptContext = context->scriptingManager->createContext(component.getContainer(), component.source, component.flags);
12 } else if (data.scriptContext && component.hasChanged()) {
13 data.scriptContext->addScript(component.source, ScriptFlags::SourcePath);
14 }
15 }
16}
17
18Cogs::Core::ScriptContextHandle Cogs::Core::ScriptSystem::getScriptContext(ScriptComponent * scriptComponent, ScriptFlags flags)
19{
20 auto & data = getData(scriptComponent);
21
22 if (!data.scriptContext) {
23 data.scriptContext = context->scriptingManager->createContext(scriptComponent->getContainer(), "", flags | ScriptFlags::SourceText);
24 }
25
26 return data.scriptContext;
27}
class Entity * getContainer() const
Get the container currently owning this component instance.
Definition: Component.h:151
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
ComponentPool< ComponentType > pool
Pool of components managed by the system.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
std::unique_ptr< class ScriptingManager > scriptingManager
ScriptingManager service instance.
Definition: Context.h:192