WsParser_VS/StoryPresent/storypresent.cpp

56 lines
1.5 KiB
C++
Raw Normal View History

2024-09-24 10:43:10 +00:00
#include "storypresent.h"
2024-10-05 02:11:42 +00:00
#include <QFileInfo>
#include <QMessageBox>
2024-09-24 10:43:10 +00:00
2024-10-05 02:11:42 +00:00
using namespace dags;
using namespace xast_parse;
StoryPresent::StoryPresent(QWidget* parent)
: QMainWindow(parent), _story_present(new DAGActiveView(this))
2024-09-24 10:43:10 +00:00
{
2024-10-05 02:11:42 +00:00
setCentralWidget(_story_present);
2024-09-24 10:43:10 +00:00
}
StoryPresent::~StoryPresent()
{}
2024-10-05 02:11:42 +00:00
#include "xast_parse.h"
void StoryPresent::loadXAST(const QString& ast_path)
{
QFileInfo finfo(ast_path);
if (!finfo.exists() || !finfo.isFile()) {
QMessageBox::critical(this, u8"<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", QString(u8"ָ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>%1<><31><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>").arg(ast_path));
return;
}
xast_parse::XAST_Parser t(ast_path);
this->_story_graph = t.storyGraph();
QList<graph_data::Arrow> arrows;
for (auto& key : this->_story_graph.keys()) {
auto story_line = this->_story_graph[key];
auto arrow_start = story_line->name();
auto frag_temp = story_line->firstChild();
while (frag_temp) {
switch (frag_temp->type()) {
case SliceType::FragmentDefines: {
auto arrow_tail = std::dynamic_pointer_cast<FragmentDefine>(frag_temp)->name() + u8"@" + story_line->name();
arrows << graph_data::Arrow(arrow_start, arrow_tail);
arrow_start = arrow_tail;
}break;
case SliceType::FragmentRefers: {
auto conv_refer = std::dynamic_pointer_cast<FragmentRefer>(frag_temp);
auto arrow_tail = conv_refer->fragmentRefer() + u8"@" + conv_refer->storyRefer();
arrows << graph_data::Arrow(arrow_start, arrow_tail);
arrow_start = arrow_tail;
}break;
default: break;
}
frag_temp = frag_temp->nextSlice();
}
}
this->_story_present->updateWithEdges(arrows);
}