This commit is contained in:
parent
4a23bc826d
commit
436e88a708
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LocalDebuggerCommandArguments>--test</LocalDebuggerCommandArguments>
|
||||
<LocalDebuggerCommandArguments>--graph dag --path E:/storyline.xast</LocalDebuggerCommandArguments>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
|
|
|
@ -227,6 +227,7 @@ QList<std::shared_ptr<DAGOrderHelper>> DAGGraph::tidy_graph_nodes() {
|
|||
return temp_array;
|
||||
}
|
||||
|
||||
#include <QDebug>
|
||||
void DAGGraph::graph_layer_nodes_sort(int layer_index, QList<std::shared_ptr<DAGOrderHelper>> nodes) {
|
||||
QList<std::shared_ptr<DAGOrderHelper>> nodes_within_current_layer;
|
||||
for (auto n : nodes)
|
||||
|
@ -253,18 +254,27 @@ void DAGGraph::graph_layer_nodes_sort(int layer_index, QList<std::shared_ptr<DAG
|
|||
if (prev_sorts.size()) {
|
||||
auto target_sum = std::accumulate(prev_sorts.begin(), prev_sorts.end(), 0.0);
|
||||
target_node->setSortNumber(target_sum / prev_sorts.size());
|
||||
if (!target_node->isFakeNode() && std::shared_ptr<DAGOrderHelper>(target_node)->layerNode()->bindPoint().name().contains(u8"小师姐叛逃")) {
|
||||
qDebug() << "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 当前层次节点排序值修正
|
||||
std::sort(nodes_within_current_layer.begin(), nodes_within_current_layer.end(),
|
||||
[](std::shared_ptr<DAGOrderHelper> a, std::shared_ptr<DAGOrderHelper> b){ return a->sortNumber() < b->sortNumber(); });
|
||||
// 提取当前层次节点排序值
|
||||
QList<double> sort_values;
|
||||
std::transform(nodes_within_current_layer.begin(), nodes_within_current_layer.end(),
|
||||
std::back_inserter(sort_values), [](std::shared_ptr<DAGOrderHelper> n) { return n->sortNumber(); });
|
||||
sort_values = sort_values.toSet().toList();
|
||||
|
||||
for (auto idx = 1; idx < nodes_within_current_layer.size(); ++idx) {
|
||||
auto prev = nodes_within_current_layer[idx - 1];
|
||||
auto curr = nodes_within_current_layer[idx];
|
||||
if (prev->sortNumber() == curr->sortNumber())
|
||||
curr->setSortNumber(curr->sortNumber() + 0.000000000000001);
|
||||
for (auto& sort_v : sort_values) {
|
||||
decltype(nodes_within_current_layer) pick_items;
|
||||
std::copy_if(nodes_within_current_layer.begin(), nodes_within_current_layer.end(),
|
||||
std::back_inserter(pick_items), [=](std::shared_ptr<DAGOrderHelper> ins) { return ins->sortNumber() == sort_v; });
|
||||
|
||||
for (int idx = 0; idx < pick_items.size(); ++idx) {
|
||||
auto item = pick_items[idx];
|
||||
item->setSortNumber(item->sortNumber() + 0.000000001 * idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "dag_present.h"
|
||||
#include "cmp_present.h"
|
||||
#include <argsparser.h>
|
||||
#include "storypresent.h"
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
#include <QTextEdit>
|
||||
|
@ -24,7 +25,13 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
auto test_mode = std::make_shared<MatchMode>(0x000bu, u8"开发过程内部测试");
|
||||
cmdrec << test_mode;
|
||||
(*test_mode) << std::make_shared<IndexParam>(u8"StoryPresent", u8"程序名") << make_shared<FloatOption>(u8"test", u8"打印帮助文档");
|
||||
(*test_mode) << std::make_shared<IndexParam>(u8"StoryPresent", u8"程序名") << make_shared<FloatOption>(u8"test", u8"内部开发测试选项");
|
||||
|
||||
auto graph_mode = std::make_shared<MatchMode>(0x000cu, u8"图形化展示故事内容");
|
||||
cmdrec << graph_mode;
|
||||
(*graph_mode) << std::make_shared<IndexParam>(u8"StoryPresent", u8"程序名")
|
||||
<< make_shared<FloatKeyValue>(u8"graph", u8"内部开发测试选项,填写dag或udg")
|
||||
<< make_shared<FloatKeyValue>(u8"path", u8"指定xast文件路径");
|
||||
|
||||
auto rst = cmdrec.parse(argc, argv);
|
||||
QTextEdit msg;
|
||||
|
@ -44,26 +51,16 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
case 0x000bu:
|
||||
{
|
||||
auto arrows = QList<graph_data::Arrow>() <<
|
||||
graph_data::Arrow(u8"a中文测试", u8"b中文测试") <<
|
||||
graph_data::Arrow(u8"c中文测试", u8"b中文测试") <<
|
||||
graph_data::Arrow(u8"c中文测试", u8"d中文测试") <<
|
||||
graph_data::Arrow(u8"b中文测试", u8"e中文测试") <<
|
||||
graph_data::Arrow(u8"d中文测试", u8"e中文测试") <<
|
||||
graph_data::Arrow(u8"c中文测试", u8"e中文测试");
|
||||
auto view = new dags::DAGActiveView;
|
||||
view->updateWithEdges(arrows);
|
||||
}break;
|
||||
case 0x000cu:
|
||||
{
|
||||
auto type = rst->getUnitViaKey(u8"graph");
|
||||
auto path = rst->getUnitViaKey(u8"path");
|
||||
if (type->value().toString() == "dag") {
|
||||
auto view = new StoryPresent();
|
||||
view->loadXAST(path->value().toString());
|
||||
view->show();
|
||||
|
||||
//dags::DAGGraph tools;
|
||||
//tools.rebuildFromEdges(arrows);
|
||||
//tools.graphLayout();
|
||||
|
||||
//for (auto n : tools.nodeWithLayout()) {
|
||||
// msg.setWindowTitle("layout-message");
|
||||
// msg.append(QString("node:%3,layer:%1,sort:%2").arg(n->layerNumber()).arg(n->sortNumber()).arg(n->layerNode()->bindPoint().name()));
|
||||
// msg.show();
|
||||
//}
|
||||
}
|
||||
}break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -1,9 +1,55 @@
|
|||
#include "storypresent.h"
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
|
||||
using namespace dags;
|
||||
using namespace xast_parse;
|
||||
|
||||
StoryPresent::StoryPresent(QWidget* parent)
|
||||
: QMainWindow(parent)
|
||||
: QMainWindow(parent), _story_present(new DAGActiveView(this))
|
||||
{
|
||||
setCentralWidget(_story_present);
|
||||
}
|
||||
|
||||
StoryPresent::~StoryPresent()
|
||||
{}
|
||||
|
||||
#include "xast_parse.h"
|
||||
void StoryPresent::loadXAST(const QString& ast_path)
|
||||
{
|
||||
QFileInfo finfo(ast_path);
|
||||
if (!finfo.exists() || !finfo.isFile()) {
|
||||
QMessageBox::critical(this, u8"文件错误", QString(u8"指定文件(%1)非法!").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);
|
||||
}
|
||||
|
|
|
@ -11,4 +11,9 @@ public:
|
|||
StoryPresent(QWidget* parent = nullptr);
|
||||
~StoryPresent();
|
||||
|
||||
void loadXAST(const QString &ast_path);
|
||||
|
||||
private:
|
||||
dags::DAGActiveView *const _story_present;
|
||||
QHash<QString, std::shared_ptr<xast_parse::StoryDefine>> _story_graph;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue