2023-04-07 23:21:15 -04:00
|
|
|
#include "Director.h"
|
|
|
|
|
|
|
|
namespace NVL::Director {
|
2023-04-08 02:33:37 -04:00
|
|
|
Director::Director(const Compiler::NVLGraph& g) :
|
|
|
|
g(g), current_position(0), active(true), description(g.nodes[0].description), current_node(g.nodes[0]) {
|
2023-04-07 23:21:15 -04:00
|
|
|
for (const String& s : g.static_refs)
|
2023-04-08 02:33:37 -04:00
|
|
|
resolve.push_back(Environment::ENVIRONMENT.get(s));
|
2023-04-07 23:21:15 -04:00
|
|
|
}
|
2023-04-08 02:33:37 -04:00
|
|
|
Environment::Variable Director::CollectVariable(const Environment::Variable& v) {
|
|
|
|
if (v.type == Environment::Type::StaticReference)
|
|
|
|
return this->resolve[static_cast<u16>(std::get<Number>(v.value))];
|
|
|
|
else if (v.type == Environment::Type::Array) {
|
|
|
|
Vector<Environment::Variable> a{};
|
|
|
|
for (const auto& x : std::get<Vector<Environment::Variable>>(v.value))
|
|
|
|
a.push_back(CollectVariable(x));
|
|
|
|
return Environment::Variable(a);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return v;
|
2023-04-07 23:21:15 -04:00
|
|
|
}
|
|
|
|
void Director::Advance() {
|
2023-04-08 02:33:37 -04:00
|
|
|
if (current_position >= current_node.sequence.size()) {
|
|
|
|
this->active = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto& cmd = this->current_node.sequence[current_position];
|
|
|
|
Vector<Environment::Variable> args{};
|
|
|
|
for (u32 i = 1; i < cmd.size(); i++) {
|
|
|
|
args.push_back(CollectVariable(cmd[i]));
|
|
|
|
}
|
|
|
|
std::get<std::function<Environment::Variable(Vector<Environment::Variable>)>>(CollectVariable(cmd[0]).value)(args);
|
|
|
|
this->current_position++;
|
2023-04-07 23:21:15 -04:00
|
|
|
}
|
|
|
|
void Director::GetBacklog() {
|
|
|
|
|
|
|
|
}
|
|
|
|
void Director::Save() {
|
|
|
|
|
|
|
|
}
|
|
|
|
void Director::Load() {
|
|
|
|
|
|
|
|
}
|
|
|
|
void Director::Jump() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|