update ComponentBasic库

This commit is contained in:
codeboss 2025-07-04 23:07:33 +08:00
parent 0272af06d4
commit d4100de598
2 changed files with 30 additions and 32 deletions

View File

@ -109,9 +109,9 @@ void MapKernal::initial()
registData(messageLoader()->makeDefault(key));
// 注册可用节点类型
registNode(std::make_shared<SequenceNode>());
registNode(std::make_shared<SelectorNode>());
registNode(std::make_shared<ParallelNode>());
registNode(std::make_shared<SequenceNode>(this->shared_from_this()));
registNode(std::make_shared<SelectorNode>(this->shared_from_this()));
registNode(std::make_shared<ParallelNode>(this->shared_from_this()));
registNode(std::make_shared<CompareNode>(this->shared_from_this()));
registNode(std::make_shared<ExecuteNode>(this->shared_from_this()));
registNode(std::make_shared<BehaviorMapNode>(this->shared_from_this()));
@ -199,6 +199,11 @@ std::shared_ptr<BehaviorMapNode> LogicalNode::bindMap() const
return std::dynamic_pointer_cast<BehaviorMapNode>(node_temp);
}
std::shared_ptr<MapKernal> LogicalNode::getKernal() const
{
return _bind_kernal;
}
void LogicalNode::setID(int unique_id)
{
this->_node_id = unique_id;
@ -220,12 +225,7 @@ std::weak_ptr<LogicalNode> LogicalNode::parent() const
}
BehaviorMapNode::BehaviorMapNode(std::shared_ptr<MapKernal> core)
:LogicalNode(NodeKind::MAPNODE, core), _bind_kernal(core) {
}
std::shared_ptr<MapKernal> BehaviorMapNode::getKernal() const
{
return _bind_kernal;
:LogicalNode(NodeKind::MAPNODE, core){
}
void BehaviorMapNode::setVariable(const QString& key, IO_TYPE t, std::shared_ptr<TopicData> ins)
@ -251,7 +251,7 @@ void BehaviorMapNode::resetName(const QString& val)
std::shared_ptr<Serializable> BehaviorMapNode::newDefault() const
{
return std::make_shared<BehaviorMapNode>(this->_bind_kernal);
return std::make_shared<BehaviorMapNode>(this->getKernal());
}
void BehaviorMapNode::recoveryFrom(const QJsonObject& obj)
@ -394,7 +394,7 @@ bool SequenceNode::fallback(std::shared_ptr<LogicalNode> node, LogicalResult ste
std::shared_ptr<Serializable> SequenceNode::newDefault() const
{
return std::make_shared<SequenceNode>(this->bindMap()->getKernal());
return std::make_shared<SequenceNode>(this->getKernal());
}
void SequenceNode::reset()
@ -425,8 +425,8 @@ void LogicalNode::remove(std::shared_ptr<LogicalNode> node)
_child_list.removeAll(node);
}
SelectorNode::SelectorNode(std::shared_ptr<MapKernal> kernal)
: LogicalNode(NodeKind::SEQUENCENODE, kernal) {
SelectorNode::SelectorNode(std::shared_ptr<MapKernal> kernal)
: LogicalNode(NodeKind::SEQUENCENODE, kernal) {
}
QList<std::shared_ptr<LogicalNode>> SelectorNode::getForwards() const
@ -455,7 +455,7 @@ bool SelectorNode::fallback(std::shared_ptr<LogicalNode> node, LogicalResult ste
std::shared_ptr<Serializable> SelectorNode::newDefault() const
{
return std::make_shared<SelectorNode>();
return std::make_shared<SelectorNode>(this->getKernal());
}
void SelectorNode::recoveryFrom(const QJsonObject& obj)
@ -541,11 +541,11 @@ LogicalResult ParallelNode::execute()
std::shared_ptr<Serializable> ParallelNode::newDefault() const
{
return std::make_shared<ParallelNode>();
return std::make_shared<ParallelNode>(this->getKernal());
}
ParallelNode::ParallelNode(std::shared_ptr<MapKernal> kernal)
: LogicalNode(NodeKind::PARALLELNODE, kernal) {
ParallelNode::ParallelNode(std::shared_ptr<MapKernal> kernal)
: LogicalNode(NodeKind::PARALLELNODE, kernal) {
}
QHash<QString, std::shared_ptr<TopicData>> ParallelNode::inputList() const
@ -612,11 +612,11 @@ bool CompareNode::fallback(std::shared_ptr<LogicalNode> node, LogicalResult ste)
std::shared_ptr<Serializable> CompareNode::newDefault() const
{
return std::make_shared<CompareNode>(_bind_kernal);
return std::make_shared<CompareNode>(getKernal());
}
CompareNode::CompareNode(std::shared_ptr<MapKernal> ins)
: LogicalNode(NodeKind::COMPARENODE, ins), _bind_kernal(ins) {
: LogicalNode(NodeKind::COMPARENODE, ins) {
_data_map[u8"左值"] = std::make_shared<GeneralData>();
_data_map[u8"右值"] = std::make_shared<GeneralData>();
}
@ -655,7 +655,7 @@ void CompareNode::recoveryFrom(const QJsonObject& obj)
QString delegate_name = "";
STRING_PEAK(delegate_name);
auto deins = _bind_kernal->getCompare(delegate_name);
auto deins = getKernal()->getCompare(delegate_name);
bindDelegate(deins);
}
@ -746,7 +746,7 @@ std::shared_ptr<TopicData> ConvertDelegate::convert(const QList<std::shared_ptr<
}
ExecuteNode::ExecuteNode(std::shared_ptr<MapKernal> ins)
: LogicalNode(NodeKind::ACTIONNODE), _bind_kernal(ins) {
: LogicalNode(NodeKind::ACTIONNODE, ins) {
}
QString ExecuteNode::delegateName() const
@ -809,7 +809,7 @@ bool ExecuteNode::fallback(std::shared_ptr<LogicalNode> node, LogicalResult ste)
std::shared_ptr<Serializable> ExecuteNode::newDefault() const
{
return std::make_shared<ExecuteNode>(this->_bind_kernal);
return std::make_shared<ExecuteNode>(this->getKernal());
}
void ExecuteNode::recoveryFrom(const QJsonObject& obj)
@ -817,7 +817,7 @@ void ExecuteNode::recoveryFrom(const QJsonObject& obj)
QString delegate_name = "";
STRING_PEAK(delegate_name);
auto de_ins = _bind_kernal->getExecute(delegate_name);
auto de_ins = getKernal()->getExecute(delegate_name);
this->bindDelegate(de_ins);
if (obj.contains("data_json")) {
@ -840,3 +840,7 @@ void ExecuteNode::saveTo(QJsonObject& obj) const
obj["data_json"] = data_json;
}
}
ModifiedNode::ModifiedNode(std::shared_ptr<MapKernal> kernal)
: LogicalNode(NodeKind::MODIFYNODE, kernal) {
}

View File

@ -364,6 +364,7 @@ public:
/// </summary>
/// <returns></returns>
std::shared_ptr<BehaviorMapNode> bindMap() const;
std::shared_ptr<MapKernal> getKernal() const;
/// <summary>
/// 回退节点
@ -466,7 +467,6 @@ enum class IO_TYPE {
/// </summary>
class COMPONENTBASIC_EXPORT BehaviorMapNode : public LogicalNode {
private:
std::shared_ptr<MapKernal> _bind_kernal;
QString _map_name = u8"行为树";
/// <summary>
@ -478,8 +478,6 @@ private:
public:
BehaviorMapNode(std::shared_ptr<MapKernal> kernal);
std::shared_ptr<MapKernal> getKernal() const;
/// <summary>
/// 设置变量如果类型错误会抛出UniException异常
/// 节点初始化时会按照配置注册默认值变量
@ -630,8 +628,6 @@ public:
/// </summary>
class COMPONENTBASIC_EXPORT CompareNode : public LogicalNode {
private:
std::shared_ptr<MapKernal> _bind_kernal;
std::shared_ptr<CompareDelegate> _bind_delegate;
QHash<QString, std::shared_ptr<TopicData>> _data_map;
@ -663,7 +659,6 @@ public:
/// </summary>
class COMPONENTBASIC_EXPORT ExecuteNode : public LogicalNode {
private:
std::shared_ptr<MapKernal> _bind_kernal;
std::shared_ptr<ExecuteDelegate> _bind_delegate;
public:
@ -702,10 +697,9 @@ class COMPONENTBASIC_EXPORT ModifiedNode : public LogicalNode {
private:
std::shared_ptr<MapKernal> _bind_kernal;
ModifyType _type_appoint = ModifyType::NONE;
public:
ModifiedNode(std::shared_ptr<MapKernal> kernal)
: _bind_kernal(kernal){}
ModifiedNode(std::shared_ptr<MapKernal> kernal);
ModifyType modifyType() const;
void resetModify(ModifyType t);