xoreos  0.0.5
console.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include <algorithm>
26 
27 #include <boost/bind.hpp>
28 
29 #include "src/common/ustring.h"
30 #include "src/common/util.h"
31 #include "src/common/filepath.h"
32 #include "src/common/filelist.h"
33 #include "src/common/configman.h"
34 
35 #include "src/aurora/resman.h"
36 
38 
45 
46 namespace Engines {
47 
48 namespace KotOR2 {
49 
51  ::Engines::Console(engine, Graphics::Aurora::kSystemFontMono, 13),
52  _engine(&engine), _maxSizeMusic(0) {
53 
54  registerCommand("exitmodule" , boost::bind(&Console::cmdExitModule , this, _1),
55  "Usage: exitmodule\nExit the module, returning to the main menu");
56  registerCommand("listmodules" , boost::bind(&Console::cmdListModules , this, _1),
57  "Usage: listmodules\nList all modules");
58  registerCommand("loadmodule" , boost::bind(&Console::cmdLoadModule , this, _1),
59  "Usage: loadmodule <module>\nLoad and enter the specified module");
60  registerCommand("listmusic" , boost::bind(&Console::cmdListMusic , this, _1),
61  "Usage: listmusic\nList all available music resources");
62  registerCommand("stopmusic" , boost::bind(&Console::cmdStopMusic , this, _1),
63  "Usage: stopmusic\nStop the currently playing music resource");
64  registerCommand("playmusic" , boost::bind(&Console::cmdPlayMusic , this, _1),
65  "Usage: playmusic [<music>]\nPlay the specified music resource. "
66  "If none was specified, play the default area music.");
67  registerCommand("flycam" , boost::bind(&Console::cmdFlyCam , this, _1),
68  "Usage: flycam\nToggle free roam camera mode");
69  registerCommand("showwalkmesh" , boost::bind(&Console::cmdShowWalkmesh , this, _1),
70  "Usage: showwalkmesh\nToggle walkmesh display");
71  registerCommand("showtriggers" , boost::bind(&Console::cmdShowTriggers , this, _1),
72  "Usage: showtriggers\nToggle triggers display");
73  registerCommand("getpcroom" , boost::bind(&Console::cmdGetPCRoom , this, _1),
74  "Usage: getpcroom\nGet a room PC is in");
75  registerCommand("listroomsvisiblefrom", boost::bind(&Console::cmdListRoomsVisibleFrom, this, _1),
76  "Usage: listroomsvisiblefrom <room>\nList rooms that are visible from the specified room");
77  registerCommand("playanim" , boost::bind(&Console::cmdPlayAnim , this, _1),
78  "Usage: playanim <base> [<head>]\nPlay the specified animations on the active object");
79 }
80 
82 }
83 
86 
87  updateModules();
88  updateMusic();
89 }
90 
93 
94  setArguments("loadmodule", _modules);
95 }
96 
98  _music.clear();
99  _maxSizeMusic = 0;
100 
101  const Common::FileList music(Common::FilePath::findSubDirectory(ResMan.getDataBase(), "streammusic", true));
102 
103  for (Common::FileList::const_iterator m = music.begin(); m != music.end(); ++m) {
105  continue;
106 
107  _music.push_back(Common::FilePath::getStem(*m));
108 
109  _maxSizeMusic = MAX(_maxSizeMusic, _music.back().size());
110  }
111 
112  std::sort(_music.begin(), _music.end(), Common::UString::iless());
113  setArguments("playmusic", _music);
114 }
115 
117  hide();
118  _engine->getGame().getModule().exit();
119 }
120 
122  updateModules();
123 
124  for (std::vector<Common::UString>::iterator m = _modules.begin(); m != _modules.end(); ++m)
125  printf("%s (\"%s\")", m->c_str(), Module::getName(*m).c_str());
126 }
127 
129  if (cl.args.empty()) {
130  printCommandHelp(cl.cmd);
131  return;
132  }
133 
134  for (std::vector<Common::UString>::iterator m = _modules.begin(); m != _modules.end(); ++m) {
135  if (m->equalsIgnoreCase(cl.args)) {
136  hide();
137  _engine->getGame().getModule().load(cl.args);
138  return;
139  }
140  }
141 
142  printf("No such module \"%s\"", cl.args.c_str());
143 }
144 
146  updateMusic();
148 }
149 
152 }
153 
155  _engine->getGame().playMusic(cl.args);
156 }
157 
160 }
161 
164 }
165 
168 }
169 
171  const Room *room = _engine->getGame().getModule().getPC()->getRoom();
172  printf("%s", room->getResRef().c_str());
173 }
174 
176  if (cl.args.empty()) {
177  printCommandHelp(cl.cmd);
178  return;
179  }
180 
181  const std::vector<Common::UString> &rooms = _engine->getGame().getModule().getCurrentArea()->getRoomsVisibleFrom(cl.args);
182  for (std::vector<Common::UString>::const_iterator r = rooms.begin();
183  r != rooms.end(); ++r) {
184  printf("%s", r->c_str());
185  }
186 }
187 
189  if (cl.args.empty()) {
190  printCommandHelp(cl.cmd);
191  return;
192  }
193  std::vector<Common::UString> anims;
194  Common::UString::split(cl.args, ' ', anims);
195  size_t animCount = anims.size();
197  animCount >= 2 ? anims[1] : "");
198 }
199 
200 } // End of namespace KotOR2
201 
202 } // End of namespace Engines
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
Common::UString args
Definition: console.h:218
void cmdStopMusic(const CommandLine &cl)
Definition: console.cpp:150
A room within a Star Wars: Knights of the Old Republic II - The Sith Lords area.
Room * getRoom()
Get a room the object is in.
Definition: object.cpp:144
void cmdPlayAnim(const CommandLine &cl)
Definition: console.cpp:188
The context handling the gameplay in Star Wars: Knights of the Old Republic II - The Sith Lords...
static UString getExtension(const UString &p)
Return a file name&#39;s extension.
Definition: filepath.cpp:93
The global config manager.
void playMusic(const Common::UString &music="")
Overwrite all currently playing music.
Definition: game.cpp:117
Area * getCurrentArea()
Return the area the PC is currently in.
Definition: module.cpp:643
void cmdShowWalkmesh(const CommandLine &cl)
Definition: console.cpp:162
bool equalsIgnoreCase(const UString &str) const
Definition: ustring.cpp:218
std::list< UString >::const_iterator const_iterator
Definition: filelist.h:37
void cmdGetPCRoom(const CommandLine &cl)
Definition: console.cpp:170
The context holding a Star Wars: Knights of the Old Republic II - The Sith Lords area.
void load(const Common::UString &module, const Common::UString &entryLocation="", ObjectType entryLocationType=kObjectTypeAll)
Load a module.
Definition: module.cpp:103
void cmdExitModule(const CommandLine &cl)
Definition: console.cpp:116
KotOR2Engine * _engine
Definition: console.h:45
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
Console(KotOR2Engine &engine)
Definition: console.cpp:50
Game & getGame()
Return the context running the actual game.
Definition: kotor2.cpp:111
#define UNUSED(x)
Definition: system.h:170
Basic Aurora graphics types.
Utility templates and functions.
static void getModules(std::vector< Common::UString > &modules)
Return a list of all modules.
Definition: game.cpp:155
void cmdLoadModule(const CommandLine &cl)
Definition: console.cpp:128
const std::vector< Common::UString > & getRoomsVisibleFrom(const Common::UString &room) const
Definition: area.cpp:668
Module & getModule()
Return the module context.
Definition: game.cpp:63
const char * kSystemFontMono
Identifier used for the monospaced system font.
Definition: fontman.cpp:41
Creature * getPC()
Return the currently playing PC.
Definition: module.cpp:147
Star Wars: Knights of the Old Republic II - The Sith Lords (debug) console.
void printList(const std::vector< Common::UString > &list, size_t maxSize=0)
Definition: console.cpp:1479
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
void cmdShowTriggers(const CommandLine &cl)
Definition: console.cpp:166
void stopMusic()
Force all currently playing music stopped.
Definition: game.cpp:129
The context needed to run a Star Wars: Knights of the Old Republic II - The Sith Lords module...
Unicode string handling.
std::vector< Common::UString > _modules
All known modules.
Definition: console.h:48
static UString getStem(const UString &p)
Return a file name&#39;s stem.
Definition: filepath.cpp:87
Common::UString getResRef() const
Definition: room.cpp:60
A list of files.
Definition: filelist.h:35
void cmdPlayMusic(const CommandLine &cl)
Definition: console.cpp:154
void printf(const char *s,...) GCC_PRINTF(2
Definition: console.cpp:1093
const_iterator begin() const
Return a const_iterator pointing to the beginning of the list.
Definition: filelist.cpp:94
A list of files.
void cmdListMusic(const CommandLine &cl)
Definition: console.cpp:145
const Common::UString & getName() const
Return the module&#39;s name.
Definition: module.cpp:639
virtual void updateCaches()
Definition: console.cpp:1122
void printCommandHelp(const Common::UString &cmd)
Definition: console.cpp:1391
void split(iterator splitPoint, UString &left, UString &right, bool remove=false) const
Definition: ustring.cpp:621
void cmdListRoomsVisibleFrom(const CommandLine &cl)
Definition: console.cpp:175
std::vector< Common::UString > _music
All known music resources.
Definition: console.h:49
void cmdFlyCam(const CommandLine &cl)
Definition: console.cpp:158
T MAX(T a, T b)
Definition: util.h:71
void setArguments(const Common::UString &cmd, const std::vector< Common::UString > &args)
Definition: console.cpp:1565
void exit()
Exit the currently running module.
Definition: module.cpp:159
Engine class handling Star Wars: Knights of the Old Republic II - The Sith Lords. ...
void playAnimationOnActiveObject(const Common::UString &baseAnim, const Common::UString &headAnim)
Definition: module.cpp:740
bool registerCommand(const Common::UString &cmd, const CommandCallback &callback, const Common::UString &help)
Definition: console.cpp:1576
The global resource manager for Aurora resources.
Utility class for manipulating file paths.
void cmdListModules(const CommandLine &cl)
Definition: console.cpp:121
const_iterator end() const
Return a const_iterator pointing past the end of the list.
Definition: filelist.cpp:98
static UString findSubDirectory(const UString &directory, const UString &subDirectory, bool caseInsensitive=false)
Find a directory&#39;s subdirectory.
Definition: filepath.cpp:318