SimsWorld/SimsBasic/internal_impl.cpp

280 lines
6.4 KiB
C++
Raw Permalink Normal View History

2025-06-10 04:52:59 +00:00
#include "internal_impl.h"
RtWsEntity::RtWsEntity() {}
void RtWsEntity::resetTemplet(const QString& name) {
this->_templet_name = name;
}
QString RtWsEntity::templetName() const {
return this->_templet_name;
}
void RtWsEntity::resetID(uint64_t id) {
this->_entity_id = id;
}
uint64_t RtWsEntity::entityID() const {
return this->_entity_id;
}
void RtWsEntity::resetName(const QString& name) {
this->_runtime_name = name;
}
QString RtWsEntity::name() const {
return this->_runtime_name;
}
2025-07-11 16:30:19 +00:00
void RtWsEntity::append(std::shared_ptr<WsComponent> ins) {
2025-06-10 04:52:59 +00:00
if (this->_comps_list.contains(ins->name()))
return;
ins->bindEntity(this->shared_from_this());
this->_comps_list[ins->name()] = ins;
}
void RtWsEntity::remove(const QString& component_type) {
this->_comps_list.remove(component_type);
}
2025-07-11 16:30:19 +00:00
QList<std::shared_ptr<WsComponent>> RtWsEntity::components() const {
2025-06-10 04:52:59 +00:00
return _comps_list.values();
}
2025-06-28 09:09:10 +00:00
std::shared_ptr<Serializable> RtWsEntity::newDefault() const {
2025-06-10 04:52:59 +00:00
auto newx = std::make_shared<RtWsEntity>();
newx->_entity_id = this->_entity_id;
newx->_templet_name = this->_templet_name;
newx->_runtime_name = this->_runtime_name;
for (auto c : this->_comps_list)
2025-07-11 16:30:19 +00:00
newx->append(std::static_pointer_cast<WsComponent>(c->newDefault()));
2025-06-10 04:52:59 +00:00
return newx;
}
#include <QSet>
QList<QString> RtWsEntity::inputTypes() const
2025-06-10 04:52:59 +00:00
{
QList<QString> types;
for (auto c : this->_comps_list) {
2025-06-26 16:56:06 +00:00
for (auto f : c->respondSignatures())
types.append(f.first);
}
2025-06-10 04:52:59 +00:00
return types.toSet().toList();
}
#include <QVariant>
#include <QJsonArray>
2025-06-26 16:56:06 +00:00
QList<WsRespondEntry> RtWsEntity::getRespondWithSignature(const WsRespondSignatureType& t) const
2025-06-10 04:52:59 +00:00
{
QList<WsRespondEntry> list;
for (auto c : this->_comps_list)
2025-06-26 16:56:06 +00:00
list.append(c->getRespondWithSignature(t));
2025-06-10 04:52:59 +00:00
return list;
}
2025-06-26 16:56:06 +00:00
QList<WsRespondEntry> RtWsEntity::getRespondWithInType(const QString& msg_type) const
2025-06-10 04:52:59 +00:00
{
QList<WsRespondEntry> list;
for (auto c : this->_comps_list)
2025-06-26 16:56:06 +00:00
list.append(c->getRespondWithInType(msg_type));
2025-06-10 04:52:59 +00:00
return list;
}
2025-06-26 16:56:06 +00:00
2025-06-10 04:52:59 +00:00
void RtWsEntity::recoveryFrom(const QJsonObject& obj)
{
this->_entity_id = obj["entity_id"].toVariant().toULongLong();
this->_runtime_name = obj["entity_name"].toString();
this->_templet_name = obj["entity_templet"].toString();
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 + "<EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>");
compins->recoveryFrom(value);
}
}
void RtWsEntity::saveTo(QJsonObject& obj) const
{
obj["entity_id"] = QJsonValue::fromVariant(QVariant::fromValue(this->_entity_id));
obj["entity_name"] = this->_runtime_name;
obj["entity_templet"] = this->_templet_name;
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;
}
QString RtEntityManager::templetName() const
{
return "ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
}
uint64_t RtEntityManager::entityID() const
{
return const_id;
}
QString RtEntityManager::name() const
{
return "ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ψһʵ<EFBFBD><EFBFBD>";
}
2025-07-11 16:30:19 +00:00
void RtEntityManager::append(std::shared_ptr<WsComponent> ins) {
2025-06-10 15:44:38 +00:00
ins->bindEntity(this->shared_from_this());
2025-06-10 04:52:59 +00:00
_comps_list[ins->name()] = ins;
}
2025-06-28 09:09:10 +00:00
std::shared_ptr<Serializable> RtEntityManager::newDefault() const
2025-06-10 04:52:59 +00:00
{
return nullptr;
}
2025-06-26 16:56:06 +00:00
QList<WsRespondEntry> RtEntityManager::getRespondWithSignature(const WsRespondSignatureType& t) const
2025-06-10 04:52:59 +00:00
{
QList<WsRespondEntry> list;
for (auto c : this->_comps_list)
2025-06-26 16:56:06 +00:00
list.append(c->getRespondWithSignature(t));
2025-06-10 04:52:59 +00:00
return list;
}
2025-06-26 16:56:06 +00:00
QList<WsRespondEntry> RtEntityManager::getRespondWithInType(const QString& msg_type) const
2025-06-10 04:52:59 +00:00
{
QList<WsRespondEntry> list;
for (auto c : this->_comps_list)
2025-06-26 16:56:06 +00:00
list.append(c->getRespondWithInType(msg_type));
2025-06-10 04:52:59 +00:00
return list;
}
void RtEntityManager::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 + "<EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>");
compins->recoveryFrom(value);
}
}
void RtEntityManager::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 RtEntityManager::remove(const QString& component_type)
{
this->_comps_list.remove(component_type);
}
2025-07-11 16:30:19 +00:00
QList<std::shared_ptr<WsComponent>> RtEntityManager::components() const
2025-06-10 04:52:59 +00:00
{
return this->_comps_list.values();
}
2025-06-12 00:04:17 +00:00
QString RtResourceManager::templetName() const
{
return "RtResourceManager";
}
uint64_t RtResourceManager::entityID() const
{
return const_id;
}
QString RtResourceManager::name() const
{
return "<EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>";
}
2025-06-28 09:09:10 +00:00
std::shared_ptr<Serializable> RtResourceManager::newDefault() const
2025-06-12 00:04:17 +00:00
{
return nullptr;
}
2025-06-26 16:56:06 +00:00
QList<WsRespondEntry> RtResourceManager::getRespondWithSignature(const WsRespondSignatureType& t) const
2025-06-12 00:04:17 +00:00
{
QList<WsRespondEntry> list;
for (auto c : this->_comps_list)
2025-06-26 16:56:06 +00:00
list.append(c->getRespondWithSignature(t));
2025-06-12 00:04:17 +00:00
return list;
}
2025-06-26 16:56:06 +00:00
QList<WsRespondEntry> RtResourceManager::getRespondWithInType(const QString& msg_type) const
2025-06-12 00:04:17 +00:00
{
QList<WsRespondEntry> list;
for (auto c : this->_comps_list)
2025-06-26 16:56:06 +00:00
list.append(c->getRespondWithInType(msg_type));
2025-06-12 00:04:17 +00:00
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 + "<EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>");
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;
}
2025-07-11 16:30:19 +00:00
void RtResourceManager::append(std::shared_ptr<WsComponent> ins)
2025-06-12 00:04:17 +00:00
{
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);
}
2025-07-11 16:30:19 +00:00
QList<std::shared_ptr<WsComponent>> RtResourceManager::components() const
2025-06-12 00:04:17 +00:00
{
return this->_comps_list.values();
}