bool ReparentBrushesCommand::performUndo() {
     Model::EntityList entities;
     if (!m_newParent.worldspawn())
         entities.push_back(&m_newParent);
     
     Model::BrushList::const_iterator it, end;
     for (it = m_brushes.begin(), end = m_brushes.end(); it != end; ++it) {
         Model::Brush* brush = *it;
         Model::Entity* oldParent = m_oldParents[brush];
         if (oldParent != NULL &&
             !oldParent->worldspawn() &&
             std::find(entities.begin(), entities.end(), oldParent) == entities.end())
             entities.push_back(oldParent);
     }
     
     document().entitiesWillChange(entities);
     for (it = m_brushes.begin(), end = m_brushes.end(); it != end; ++it) {
         Model::Brush& brush = **it;
         Model::Entity* oldParent = m_oldParents[&brush];
         m_newParent.removeBrush(brush);
         if (oldParent != NULL)
             oldParent->addBrush(brush);
     }
     document().entitiesDidChange(entities);
     
     return true;
 }
예제 #2
0
 Model::Entity* MapParser::parseEntity(const BBox& worldBounds, Utility::ProgressIndicator* indicator) {
     Token token = m_tokenizer.nextToken();
     if (token.type() == TokenType::Eof)
         return NULL;
     
     expect(TokenType::OBrace | TokenType::CBrace, token);
     if (token.type() == TokenType::CBrace)
         return NULL;
     
     Model::Entity* entity = new Model::Entity(worldBounds);
     size_t firstLine = token.line();
     
     while ((token = m_tokenizer.nextToken()).type() != TokenType::Eof) {
         switch (token.type()) {
             case TokenType::String: {
                 String key = token.data();
                 expect(TokenType::String, token = m_tokenizer.nextToken());
                 String value = token.data();
                 entity->setProperty(key, value);
                 break;
             }
             case TokenType::OBrace: {
                 m_tokenizer.pushToken(token);
                 bool moreBrushes = true;
                 while (moreBrushes) {
                     Model::Brush* brush = parseBrush(worldBounds, indicator);
                     if (brush != NULL)
                         entity->addBrush(*brush);
                     expect(TokenType::OBrace | TokenType::CBrace, token = m_tokenizer.nextToken());
                     moreBrushes = (token.type() == TokenType::OBrace);
                     m_tokenizer.pushToken(token);
                 }
                 break;
             }
             case TokenType::CBrace: {
                 if (indicator != NULL)
                     indicator->update(static_cast<int>(token.position()));
                 entity->setFilePosition(firstLine, token.line() - firstLine);
                 return entity;
             }
             default:
                 delete entity;
                 throw MapParserException(token, TokenType::String | TokenType::OBrace | TokenType::CBrace);
         }
     }
     
     return entity;
 }