File indexing completed on 2024-04-14 04:00:17

0001 /***************************************************************************
0002                                cmapcmdtogglepathtwoway.cpp
0003                              -------------------
0004     begin                : Thu Mar 7 2002
0005     copyright            : (C) 2002 by Kmud Developer Team
0006     email                : kmud-devel@kmud.de
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "cmapcmdtogglepathtwoway.h"
0019 
0020 #include "cmappath.h"
0021 #include "cmaplevel.h"
0022 #include "cmapmanager.h"
0023 #include "cmaproom.h"
0024 
0025 CMapCmdTogglePathTwoWay::CMapCmdTogglePathTwoWay(CMapManager *mapManager,QString name,CMapPath *path) : CMapCommand(name),CMapElementUtil(mapManager)
0026 {
0027     m_srcRoom    = path->getSrcRoom()->getRoomID();
0028     m_srcLevel   = path->getSrcRoom()->getLevel()->getLevelID();
0029     m_srcDir     = path->getSrcDir();
0030     m_specialCmd = path->getSpecialCmd();
0031     
0032     m_mapManager = mapManager;  
0033 }
0034 
0035 CMapCmdTogglePathTwoWay::~CMapCmdTogglePathTwoWay()
0036 {
0037 }
0038 
0039 void CMapCmdTogglePathTwoWay::redo()
0040 {
0041     CMapLevel *srcLevel = m_mapManager->findLevel(m_srcLevel);
0042     CMapRoom *srcRoom = srcLevel->findRoom(m_srcRoom);
0043     CMapPath *path = srcRoom->getPathDirection(m_srcDir,m_specialCmd);
0044     togglePath (path);
0045 }
0046 
0047 void CMapCmdTogglePathTwoWay::undo()
0048 {
0049     CMapLevel *srcLevel = m_mapManager->findLevel(m_srcLevel);
0050     CMapRoom *srcRoom = srcLevel->findRoom(m_srcRoom);
0051     CMapPath *path = srcRoom->getPathDirection(m_srcDir,m_specialCmd);
0052     togglePath (path);
0053 }
0054 
0055 void CMapCmdTogglePathTwoWay::togglePath(CMapPath *path)
0056 {
0057   if (path->getOpsitePath())
0058   {
0059     path->makeOneWay();
0060   }
0061   else
0062   {
0063     path->makeTwoWay();
0064   }
0065 }