适配Qt5.12.9并添加fragment-layer-checker

This commit is contained in:
codeboss 2025-05-17 16:42:07 +08:00
parent 123cc2a05a
commit 0290c8bf55
9 changed files with 98 additions and 38 deletions

View File

@ -36,12 +36,12 @@
<Import Project="$(QtMsBuild)\qt_defaults.props" />
</ImportGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtInstall>5.12.9_msvc2017_64</QtInstall>
<QtModules>core</QtModules>
<QtBuildConfig>debug</QtBuildConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtInstall>5.12.9_msvc2017_64</QtInstall>
<QtModules>core</QtModules>
<QtBuildConfig>release</QtBuildConfig>
</PropertyGroup>

View File

@ -36,12 +36,12 @@
<Import Project="$(QtMsBuild)\qt_defaults.props" />
</ImportGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtInstall>5.12.9_msvc2017_64</QtInstall>
<QtModules>core</QtModules>
<QtBuildConfig>debug</QtBuildConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtInstall>5.12.9_msvc2017_64</QtInstall>
<QtModules>core</QtModules>
<QtBuildConfig>release</QtBuildConfig>
</PropertyGroup>

View File

@ -37,12 +37,12 @@
<Import Project="$(QtMsBuild)\qt_defaults.props" />
</ImportGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtInstall>5.12.9_msvc2017_64</QtInstall>
<QtModules>core;xml;gui;widgets</QtModules>
<QtBuildConfig>debug</QtBuildConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtInstall>5.12.9_msvc2017_64</QtInstall>
<QtModules>core;xml</QtModules>
<QtBuildConfig>release</QtBuildConfig>
</PropertyGroup>

View File

@ -13,6 +13,7 @@ NovelParser::NovelParser() {
checker_list << std::make_shared<FragmentExistsCheck>();
checker_list << std::make_shared<StoryOrderCheck>();
checker_list << std::make_shared<PointGraphCheck>();
checker_list << std::make_shared<FragmentLayerCheck>();
analyzer_ref = std::make_shared<Analyzer>(checker_list);
}

View File

@ -37,12 +37,12 @@
<Import Project="$(QtMsBuild)\qt_defaults.props" />
</ImportGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtInstall>5.12.9_msvc2017_64</QtInstall>
<QtModules>core;xml;gui;widgets</QtModules>
<QtBuildConfig>debug</QtBuildConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtInstall>5.12.9_msvc2017_64</QtInstall>
<QtModules>core</QtModules>
<QtBuildConfig>release</QtBuildConfig>
</PropertyGroup>

View File

@ -54,7 +54,8 @@ void FragmentExistsCheck::exists_check(std::shared_ptr<ElementsCache> root, std:
}
FragmentExistsCheck::FragmentExistsCheck()
:_nodes_cache(std::make_shared<ElementsCache>()) { }
:_nodes_cache(std::make_shared<ElementsCache>()) {
}
void FragmentExistsCheck::validCheck(std::shared_ptr<const ElementAccess> root) const {
const_cast<FragmentExistsCheck*>(this)->nodes_regist(this->_nodes_cache, root);
@ -277,7 +278,8 @@ QString PointGraphCheck::name() const {
return "情节网络引用检查器";
}
PointGraphHelper::PointGraphHelper(std::shared_ptr<const FragmentSlice> node) : node_peer(node) { }
PointGraphHelper::PointGraphHelper(std::shared_ptr<const FragmentSlice> node) : node_peer(node) {
}
std::shared_ptr<const FragmentSlice> PointGraphHelper::nodePeer() const {
return this->node_peer;
@ -409,9 +411,9 @@ std::shared_ptr<FragmentNode> FragmentLayerCheck::_sets_fill(std::shared_ptr<con
}
void FragmentLayerCheck::_refers_rebuild(std::shared_ptr<const FragmentNode> node) {
auto fragm = std::static_pointer_cast<FragmentSlice>(node->bind()->element());
auto fragm = std::static_pointer_cast<const FragmentSlice>(node->bind()->element());
for (auto node_t : fragm->children()) {
auto refn = std::static_pointer_cast<FragmentRefers>(node_t);
auto refn = std::static_pointer_cast<const FragmentRefers>(node_t);
auto target_node = _node_set[refn->referSignature()];
std::const_pointer_cast<FragmentNode>(node)->appendNext(target_node);
}
@ -427,6 +429,62 @@ void FragmentLayerCheck::node_relayer(std::shared_ptr<FragmentNode> node, int cu
}
}
/// <summary>
/// 层级确认
/// </summary>
/// <param name="node">故事线</param>
void FragmentLayerCheck::layer_check(std::shared_ptr<const ElementAccess> node) {
switch ((NovelNode) node->element()->typeMark()) {
case NovelNode::StoryDefine:
story_layer_check(node);
break;
default:
layer_check(node);
break;
}
}
void FragmentLayerCheck::story_layer_check(std::shared_ptr<const ast_gen::ElementAccess> story) {
auto fragms_list = story->children();
for (auto curr = ++fragms_list.begin(); curr != fragms_list.end(); ++curr) {
auto prev = curr - 1;
auto curr_sign = (*curr)->element()->signature();
auto prev_sign = (*prev)->element()->signature();
sibling_element_compair(_node_set[prev_sign], _node_set[curr_sign]);
}
}
void FragmentLayerCheck::sibling_element_compair(std::shared_ptr<const FragmentNode> prev, std::shared_ptr<const FragmentNode> curr) {
auto prev_childs = prev->referNodes();
auto curr_childs = curr->referNodes();
QList<int> prev_layers;
std::transform(prev_childs.begin(), prev_childs.end(), std::back_inserter(prev_layers),
[](std::shared_ptr<const FragmentNode> ins) { return ins->layerNumber(); });
QList<int> next_layers;
std::transform(curr_childs.begin(), curr_childs.end(), std::back_inserter(next_layers),
[](std::shared_ptr<const FragmentNode> ins) { return ins->layerNumber(); });
auto min0 = *std::min_element(prev_layers.begin(), prev_layers.end());
auto max1 = *std::max_element(next_layers.begin(), next_layers.end());
if (min0 < max1) {
decltype(prev_childs) tempx;
std::copy_if(curr_childs.begin(), curr_childs.end(), std::back_inserter(tempx),
[=](std::shared_ptr<const FragmentNode> ins) { return ins->layerNumber() >= min0; });
QStringList names;
std::transform(tempx.begin(), tempx.end(), std::back_inserter(names),
[=](std::shared_ptr<const FragmentNode> ins) { return ins->bind()->element()->signature(); });
throw new CheckException(QString("CheckError[0x0009]情节时间序错误!%1->%2\n\t\t%3->{%4}")
.arg(prev->bind()->element()->signature()).arg(curr->bind()->element()->signature())
.arg(curr->bind()->element()->signature(), names.join(",")));
}
}
QString FragmentLayerCheck::name() const {
return "情节时间层级校验器";
}
@ -437,14 +495,15 @@ void FragmentLayerCheck::validCheck(std::shared_ptr<const ast_gen::ElementAccess
for (auto node : chk->_node_set)
chk->_refers_rebuild(node);
for (auto node : chk->_story_start)
chk->node_relayer(node);
chk->layer_check(root);
}
FragmentNode::FragmentNode(std::shared_ptr<ElementAccess> bind) :_src_fragm(bind) { }
FragmentNode::FragmentNode(std::shared_ptr<const ElementAccess> bind) :_src_fragm(bind) {
}
std::shared_ptr<ElementAccess> FragmentNode::bind() const {
std::shared_ptr<const ElementAccess> FragmentNode::bind() const {
return this->_src_fragm;
}
@ -452,14 +511,6 @@ void FragmentNode::setLayer(int number) {
this->_layer_number = number;
}
void FragmentNode::setLayer(int number) {
this->_layer_number = number;
}
int FragmentNode::layerNumber() const {
return this->_layer_number;
}
int FragmentNode::layerNumber() const {
return this->_layer_number;
}

View File

@ -111,13 +111,13 @@ namespace example_novel {
class FragmentNode : public std::enable_shared_from_this<FragmentNode> {
private:
std::shared_ptr<ast_gen::ElementAccess> _src_fragm = nullptr;
std::shared_ptr<const ast_gen::ElementAccess> _src_fragm = nullptr;
QList<std::shared_ptr<FragmentNode>> _next_fragms;
int _layer_number = -1;
public:
FragmentNode(std::shared_ptr<ast_gen::ElementAccess> bind);
std::shared_ptr<ast_gen::ElementAccess> bind() const;
FragmentNode(std::shared_ptr<const ast_gen::ElementAccess> bind);
std::shared_ptr<const ast_gen::ElementAccess> bind() const;
void setLayer(int number);
int layerNumber() const;
@ -138,17 +138,25 @@ namespace example_novel {
* @brief 线
*/
std::shared_ptr<FragmentNode> _sets_fill(std::shared_ptr<const ast_gen::ElementAccess> node);
/**
* @brief
*/
/// <summary>
/// 引用网络重构
/// </summary>
/// <param name="node">传入情节定义结点</param>
void _refers_rebuild(std::shared_ptr<const FragmentNode> node);
/**
* @brief
*/
/// <summary>
/// 节点层级重排
/// </summary>
/// <param name="node">目标结点</param>
/// <param name="curr">目标层级</param>
void node_relayer(std::shared_ptr<FragmentNode> node, int curr = 0);
void layer_check(std::shared_ptr<const ast_gen::ElementAccess> node){ }
/// <summary>
/// 层级确认
/// </summary>
/// <param name="node">故事线</param>
void layer_check(std::shared_ptr<const ast_gen::ElementAccess> node);
void story_layer_check(std::shared_ptr<const ast_gen::ElementAccess> story);
void sibling_element_compair(std::shared_ptr<const FragmentNode> prev, std::shared_ptr<const FragmentNode> curr);
public:
// 通过 CheckProvider 继承

View File

@ -38,12 +38,12 @@
<Import Project="$(QtMsBuild)\qt_defaults.props" />
</ImportGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtInstall>5.12.9_msvc2017_64</QtInstall>
<QtModules>core;xml;gui;widgets</QtModules>
<QtBuildConfig>debug</QtBuildConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtInstall>5.12.9_msvc2017_64</QtInstall>
<QtModules>core</QtModules>
<QtBuildConfig>release</QtBuildConfig>
</PropertyGroup>

View File

@ -36,12 +36,12 @@
<Import Project="$(QtMsBuild)\qt_defaults.props" />
</ImportGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtInstall>5.12.9_msvc2017_64</QtInstall>
<QtModules>core</QtModules>
<QtBuildConfig>release</QtBuildConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtInstall>5.12.9_msvc2017_64</QtInstall>
<QtModules>core</QtModules>
<QtBuildConfig>debug</QtBuildConfig>
</PropertyGroup>