diff --git a/ComponentBasic/DeduceFramework.cpp b/ComponentBasic/DeduceFramework.cpp index 87c08b9..2698bdf 100644 --- a/ComponentBasic/DeduceFramework.cpp +++ b/ComponentBasic/DeduceFramework.cpp @@ -65,8 +65,12 @@ void DeduceFramework::init_framework() mgr_e->append(this->shared_from_this()); auto info_pulls = std::make_shared(); mgr_e->append(info_pulls); - this->_entity_map_over_0xffff[mgr_e->entityID()] = mgr_e; + + auto res_e = std::make_shared(); + info_pulls = std::make_shared(); + res_e->append(info_pulls); + this->_entity_map_over_0xffff[res_e->entityID()] = res_e; } std::shared_ptr DeduceFramework::defaultNew() const @@ -174,6 +178,7 @@ void DeduceFramework::execute(std::shared_ptr map, ins->_component_types = this->_factory_ins->allComponentTypes(); ins->_entity_templets[NAME(RtEntityManager)] = RtEntityManager::const_id; + ins->_entity_templets[NAME(RtResourceManager)] = RtResourceManager::const_id; for (auto ekey : this->_templets_within_0x2ff_0xffff.keys()) ins->_entity_templets[ekey] = this->_templets_within_0x2ff_0xffff[ekey]->entityID(); diff --git a/SimsBasic/internal_impl.cpp b/SimsBasic/internal_impl.cpp index 86108ab..da916b1 100644 --- a/SimsBasic/internal_impl.cpp +++ b/SimsBasic/internal_impl.cpp @@ -223,3 +223,88 @@ QList> ImmediateKernel::execute(std::shared_ptr RtResourceManager::defaultNew() const +{ + return nullptr; +} + +QList RtResourceManager::getEntryWithSignature(const WsRespondSignatureType& t) const +{ + QList list; + for (auto c : this->_comps_list) + list.append(c->getEntryWithSignature(t)); + return list; +} + +QList RtResourceManager::getEntryWithInType(const QString& msg_type) const +{ + QList list; + for (auto c : this->_comps_list) + list.append(c->getEntrysWithInType(msg_type)); + return list; +} + +void RtResourceManager::recoveryFrom(const QJsonObject& obj) +{ + auto array = obj["component_array"].toArray(); + for (auto idx = 0; idx < array.size(); ++idx) { + auto value = array.at(idx).toObject(); + auto type = value["component_type"].toString(); + + auto compins = this->_comps_list[type]; + if (!compins) + throw new UniException(type + "类型插件不存在!"); + + compins->recoveryFrom(value); + } +} + +void RtResourceManager::saveTo(QJsonObject& obj) const +{ + QJsonArray array; + for (auto c : this->_comps_list) + { + QJsonObject comp_obj; + comp_obj["component_type"] = c->name(); + c->saveTo(comp_obj); + array.append(comp_obj); + } + obj["component_array"] = array; +} + +void RtResourceManager::append(std::shared_ptr ins) +{ + ins->bindEntity(this->shared_from_this()); + this->_comps_list[ins->name()] = ins; +} + +void RtResourceManager::remove(const QString& component_type) +{ + this->_comps_list.remove(component_type); +} + +QList> RtResourceManager::components() const +{ + return this->_comps_list.values(); +} diff --git a/SimsBasic/internal_impl.h b/SimsBasic/internal_impl.h index 1b2e983..58b7f35 100644 --- a/SimsBasic/internal_impl.h +++ b/SimsBasic/internal_impl.h @@ -118,6 +118,30 @@ public: void saveTo(QJsonObject& obj) const override; }; +class SIMSBASIC_EXPORT RtResourceManager : public WsEntity, public ComponentSet, + public std::enable_shared_from_this +{ +public: + static const uint64_t const_id = 0x01f0; + QHash> _comps_list; + + QString templetName() const override; + uint64_t entityID() const override; + QString name() const override; + + std::shared_ptr defaultNew() const override; + QList getEntryWithSignature(const WsRespondSignatureType& t) const override; + QList getEntryWithInType(const QString& msg_type) const override; + + void recoveryFrom(const QJsonObject& obj) override; + void saveTo(QJsonObject& obj) const override; + + void append(std::shared_ptr ins) override; + void remove(const QString& component_type) override; + QList> components() const override; + +}; + /// /// 实体内迅捷调用核心 /// @@ -133,6 +157,8 @@ public: /// /// virtual uint64_t entityManagerID() const override; + + virtual uint64_t resourceManagerID() const override; /// /// 实体内指定类型的调用立即执行 /// @@ -146,4 +172,5 @@ public: /// virtual QList> execute(std::shared_ptr in) override; + }; \ No newline at end of file diff --git a/SimsBasic/simsbasic.h b/SimsBasic/simsbasic.h index 8b60292..3e973a6 100644 --- a/SimsBasic/simsbasic.h +++ b/SimsBasic/simsbasic.h @@ -77,6 +77,11 @@ public: /// virtual uint64_t entityManagerID() const = 0; /// + /// 获取资源管理器id + /// + /// + virtual uint64_t resourceManagerID() const = 0; + /// /// 实体内指定类型的调用立即执行 /// /// diff --git a/SimsWorld/TempletAssemble.cpp b/SimsWorld/TempletAssemble.cpp index d6e508d..f12ec26 100644 --- a/SimsWorld/TempletAssemble.cpp +++ b/SimsWorld/TempletAssemble.cpp @@ -28,7 +28,8 @@ void TempletAssemble::reply_accept(const QList>& msg_ this->_component_types->addItems(conv->_component_types); for (auto info : conv->_entity_templets.keys()) { auto templat_id = conv->_entity_templets[info]; - if ((QList{RtEntityManager::const_id}).contains(templat_id)) + if ((QList{ RtEntityManager::const_id, RtResourceManager::const_id }) + .contains(templat_id)) continue; auto cell = new QStandardItem(info);