void PrefabSystem::updateComponentInPrefab(const QString& path, const QString& component, const QVariantMap& values, bool updateInstances) { EntitySystem* es = entityManager()->system(component); Q_ASSERT(es); auto i = _prefabs.find(path); if(i == _prefabs.end()) { return; } Prefab* prefab = i.value().data(); QVariantMap current = prefab->components()[component].toMap(); for(QString param : values.keys()) { current[param] = values[param]; } for(QString param : prefab->parameters()) { current.remove(param); } prefab->_components[component] = current; if(updateInstances) { for(auto k = this->begin(); k != this->end(); ++k) { if(es->component(k->first)) { es->fromVariantMap(k->first, values); } } } }
int mainML() { sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!"); MotionControlSystem motionControlSystem; EntityManager entityManager(new FamilyManager()); EntityCreator entityCreator; //Starship erstellen entityManager.addEntity(entityCreator.createStarship()); //Darzustellende Objekte registrieren while (window.isOpen()) { sf::Event event1; while(window.pollEvent(event1)) { if(event1.type == sf::Event::KeyPressed) { motionControlSystem.update(); } } } return 0; }
QVector<Buildable*> Colony::buildableItems() const { QVector<Buildable*> items; for (ShipType* shipType : entityManager().shipTypes()) { if (canBuild(shipType)) { items.append(shipType); } } for (BuildingType* buildingType : entityManager().buildingTypes()) { if (canBuild(buildingType)) { items.append(buildingType); } } return items; }
void PrefabSystem::createPrefabComponents(QtEntity::EntityId id, Prefab* prefab) const { const QVariantMap& c = prefab->components(); for(auto i = c.begin(); i != c.end(); ++i) { const QString& classname = i.key(); const QVariant& var = i.value(); EntitySystem* es = entityManager()->system(classname); if(es) { es->createComponent(id, var.value<QVariantMap>()); } } }
void ParticleEmitterSystem::setEmitters(QtEntity::EntityId eid, const QtEntityUtils::ItemList& emitters) { ParticleEmitter* e; if(component(eid, e)) { e->_emitters = emitters; Shape* shape; if(!entityManager()->component(eid, shape)) return; _renderer->clearEmitters(shape); foreach(QtEntityUtils::Item i, emitters) { _renderer->addEmitter(shape, i._value.toMap()); } }
Boolean EntityApp::makeSystemId(int nFiles, AppChar *const *files, StringC &result) { Vector<StringC> filenames(nFiles == 0 ? 1 : nFiles); int i; for (i = 0; i < nFiles; i++) filenames[i] = convertInput(tcscmp(files[i], SP_T("-")) == 0 ? SP_T("<OSFD>0") : files[i]); if (nFiles == 0) filenames[0] = convertInput(SP_T("<OSFD>0")); return entityManager()->mergeSystemIds(filenames, mapCatalogDocument_, systemCharset_, *this, result); }
void PrefabSystem::updatePrefab(const QString& path, const QVariantMap& newcomponents, bool updateInstances) { // fetch prefab by path Prefab* prefab; { auto i = _prefabs.find(path); if(i == _prefabs.end()) { return; } prefab = i.value().data(); } for(auto k: newcomponents.keys()) { qDebug() << "Receeived: " << k; } if(updateInstances) { // update existing components in prefab and delete components no longer in prefab for(auto j = prefab->components().begin(); j != prefab->components().end(); ++j) { EntitySystem* es = entityManager()->system(j.key()); Q_ASSERT(es); if(!es) continue; // component is in prefab but not in components map. Delete it from prefab instances. if(newcomponents.find(j.key()) == newcomponents.end()) { qDebug() << "Removing from prefab instances:" << j.key(); // find all prefab instances and destroy the component for(auto k = this->begin(); k != this->end(); ++k) { PrefabInstance* pi = static_cast<PrefabInstance*>(k->second); if(pi->prefab() == prefab) { es->destroyComponent(k->first); } } } else { // component exists in component map and in prefab. Update prefab. QVariantMap newvals = newcomponents[j.key()].toMap(); // find all prefab instances and update the components for(auto k = this->begin(); k != this->end(); ++k) { PrefabInstance* pi = static_cast<PrefabInstance*>(k->second); if(pi->prefab() == prefab) { QVariantMap data = es->toVariantMap(k->first); for(auto i = newvals.begin(); i != newvals.end(); ++i) { data[i.key()] = i.value(); } auto i = data.begin(); while(i != data.end()) { if(prefab->parameters().contains(i.key()) || i.key() == "objectName") { i = data.erase(i); } else { ++i; } } es->fromVariantMap(k->first, data); } } } } // now handle the components that did not exist in prefab yet for(auto i = newcomponents.begin(); i != newcomponents.end(); ++i) { QString key = i.key(); if(prefab->components().find(key) == prefab->components().end()) { EntitySystem* es = entityManager()->system(key); Q_ASSERT(es); if(!es) continue; for(auto k = this->begin(); k != this->end(); ++k) { PrefabInstance* pi = static_cast<PrefabInstance*>(k->second); if(pi->prefab() == prefab) { es->createComponent(k->first, i.value().toMap()); } } } } } // finally update prefab in prefab store prefab->setComponents(newcomponents); emit prefabUpdated(path); }