void WorldModel::setEntity(const UUID& id, const EntityConstPtr& e) { std::map<UUID, Idx>::const_iterator it_idx = entity_map_.find(id); if (it_idx == entity_map_.end()) { addNewEntity(e); } else { entities_[it_idx->second] = e; } }
EntityPtr WorldModel::getOrAddEntity(const UUID& id, std::map<UUID, EntityPtr>& new_entities) { // Check if the id is already in the new_entities map. If so, return it std::map<UUID, EntityPtr>::const_iterator it_e = new_entities.find(id); if (it_e != new_entities.end()) return it_e->second; EntityPtr e; Idx idx; if (findEntityIdx(id, idx)) { // Create a copy of the existing entity e = boost::make_shared<Entity>(*entities_[idx]); // Set the copy entities_[idx] = e; } else { // Does not yet exist e = boost::make_shared<Entity>(id); idx = addNewEntity(e); } // Update entity revision e->setRevision(revision_); new_entities[id] = e; for(std::size_t i = entity_revisions_.size(); i < idx + 1; ++i) entity_revisions_.push_back(0); entity_revisions_[idx] = revision_; return e; }
LocatedEntity * spawnNewEntity(const std::string & name, const std::string & type, const Atlas::Objects::Entity::RootEntity & desc) { return addNewEntity(type, desc); }
//----- Setup -----// void MainWindow::createActions() { newAction = new QAction(QIcon(":/images/new.png"), tr("&Novo mapa"),this); newAction->setShortcuts(QKeySequence::New); newAction->setStatusTip(tr("Cria um novo mapa")); connect(newAction, SIGNAL(triggered()), this, SLOT(newFile())); newEntityAction = new QAction(QIcon(":/images/new.png"), tr("&Nova entidade"),this); newEntityAction->setStatusTip(tr("Cria uma nova entidade")); connect(newEntityAction, SIGNAL(triggered()), this, SLOT(addNewEntity())); openAction = new QAction(QIcon(":/images/open.png"), tr("Abrir &mapa"),this); openAction->setShortcuts(QKeySequence::Open); openAction->setStatusTip(tr("Abre o mapa")); connect(openAction, SIGNAL(triggered()), this, SLOT(open())); saveAction = new QAction(QIcon(":/images/save.png"), tr("&Salvar mapa"),this); saveAction->setShortcuts(QKeySequence::Save); saveAction->setStatusTip(tr("Salva o mapa")); connect(saveAction, SIGNAL(triggered()), this, SLOT(save())); saveAsAction = new QAction(tr("&Salvar como..."),this); saveAsAction->setShortcuts(QKeySequence::SaveAs); saveAsAction->setStatusTip(tr("Salva o mapa com um novo nome")); connect(saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs())); exitAction = new QAction(tr("Sai&r mapa"),this); exitAction->setShortcuts(QKeySequence::Quit); exitAction->setStatusTip(tr("Sai da ferramenta")); connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); aboutAction = new QAction(tr("&Sobre"),this); aboutAction->setStatusTip(tr("Sobre a ferramenta")); connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); editModeAction = new QAction(QIcon(":/images/edit.png"),tr("Editar entidades"),this); editModeAction->setStatusTip(tr("Edita propriedades dos blocos, se passáveis ou não")); editModeAction->setShortcut(tr("TAB")); editModeAction->setCheckable(true); connect(editModeAction, SIGNAL(triggered()), mapView, SLOT(toogleEditMode()) ); connect(editModeAction, SIGNAL(triggered(bool)), this, SLOT(toogleEditMode(bool)) ); showPathAction = new QAction(QIcon(":/images/show.png"),tr("Mostrar caminhos"),this); showPathAction->setStatusTip(tr("Mostra propriedades dos blocos, se passáveis ou não")); showPathAction->setShortcut(tr("CTRL+H")); showPathAction->setCheckable(true); connect(showPathAction, SIGNAL(triggered()), mapView, SLOT(toogleShowPath()) ); connect(showPathAction, SIGNAL(triggered()), tilesetEditor, SLOT(forceUpdate())); showGridAction = new QAction(QIcon(":/images/grid.png"),tr("Mostrar quadrados"),this); showGridAction->setStatusTip(tr("Mostra divisão entre os blocos")); showGridAction->setShortcut(tr("CTRL+G")); showGridAction->setCheckable(true); showGridAction->setChecked(true); connect(showGridAction, SIGNAL(triggered()), mapView, SLOT(toogleShowGrid()) ); showEnemyAction = new QAction(QIcon(":/images/enemy.png"),tr("Mostrar inimigos"),this); showEnemyAction->setStatusTip(tr("Mostra inimigos no mapa")); showEnemyAction->setShortcut(tr("CTRL+E")); showEnemyAction->setCheckable(true); showEnemyAction->setChecked(true); connect(showEnemyAction, SIGNAL(triggered()), mapView, SLOT(toogleShowEnemy()) ); showItemAction = new QAction(QIcon(":/images/item.png"),tr("Mostrar itens"),this); showItemAction->setStatusTip(tr("Mostra itens no mapa")); showItemAction->setShortcut(tr("CTRL+I")); showItemAction->setCheckable(true); showItemAction->setChecked(true); connect(showItemAction, SIGNAL(triggered()), mapView, SLOT(toogleShowItem()) ); //Tools paintToolAction = new QAction(QIcon(":/images/paint.png"),tr("Pincel"),this); paintToolAction->setStatusTip(tr("Pinta quadrados")); paintToolAction->setShortcut(tr("F")); paintToolAction->setCheckable(true); paintToolAction->setChecked(true); connect(paintToolAction, SIGNAL(triggered(bool)), this, SLOT(tooglePaintTool(bool)) ); cursorToolAction = new QAction(QIcon(":/images/cursor.png"),tr("Selecionar"),this); cursorToolAction->setStatusTip(tr("Seleciona e edita entidades no modo edição")); cursorToolAction->setShortcut(tr("S")); cursorToolAction->setCheckable(true); cursorToolAction->setChecked(false); cursorToolAction->setEnabled(false); connect(cursorToolAction, SIGNAL(triggered(bool)), this, SLOT(toogleCursorTool(bool)) ); rectangleToolAction = new QAction(QIcon(":/images/rectanglePaint.png"),tr("Retangulo"),this); rectangleToolAction->setStatusTip(tr("Pinta em uma area retangular")); rectangleToolAction->setShortcut(tr("SHIFT+F")); rectangleToolAction->setCheckable(true); rectangleToolAction->setChecked(false); connect(rectangleToolAction, SIGNAL(triggered(bool)), this, SLOT(toogleRectangleTool(bool)) ); startToolAction = new QAction(QIcon(":/images/start.png"),tr("Ponto de Inicio"),this); startToolAction ->setStatusTip(tr("Coloca ponto de entrada do mapa(somente 1)")); startToolAction ->setShortcut(tr("I")); startToolAction ->setCheckable(true); startToolAction ->setChecked(false); connect(startToolAction, SIGNAL(triggered(bool)), this, SLOT(toogleStartTool(bool)) ); endToolAction = new QAction(QIcon(":/images/end.png"),tr("Pontos de Saída"),this); endToolAction ->setStatusTip(tr("Coloca pontos de saída do mapa")); endToolAction ->setShortcut(tr("E")); endToolAction ->setCheckable(true); endToolAction ->setChecked(false); connect(endToolAction, SIGNAL(triggered(bool)), this, SLOT(toogleEndTool(bool)) ); }