Skip to content

Commit

Permalink
Implemented RespawnSelected command.
Browse files Browse the repository at this point in the history
  • Loading branch information
stgatilov committed Aug 22, 2020
1 parent c0663f4 commit 297f88f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 25 additions & 1 deletion radiant/gameconnection/GameConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "inode.h"
#include "ientity.h"
#include "map/Map.h"
#include "selection/RadiantSelectionSystem.h"
#include "modulesystem/StaticModule.h"
#include <sigc++/signal.h>

Expand Down Expand Up @@ -173,6 +174,7 @@ const StringSet& GameConnection::getDependencies() const {
_dependencies.insert(MODULE_COMMANDSYSTEM);
_dependencies.insert(MODULE_MAP);
_dependencies.insert(MODULE_SCENEGRAPH);
_dependencies.insert(MODULE_SELECTIONSYSTEM);
}
return _dependencies;
}
Expand All @@ -186,7 +188,9 @@ module::StaticModule<GameConnection> gameConnectionModule;
//-------------------------------------------------------------

std::string GameConnection::composeConExecRequest(std::string consoleLine) {
assert(consoleLine.find('\n') == std::string::npos);
//remove trailing spaces/EOLs
while (!consoleLine.empty() && isspace(consoleLine.back()))
consoleLine.pop_back();
return actionPreamble("conexec") + "content:\n" + consoleLine + "\n";
}

Expand Down Expand Up @@ -306,6 +310,26 @@ void GameConnection::togglePauseGame() {
executeRequest(text);
}

void GameConnection::respawnSelectedEntities() {
if (!connect())
return;
std::set<std::string> selectedEntityNames;
GlobalSelectionSystem().foreachSelected([&selectedEntityNames](const scene::INodePtr &node) -> void {
//Node_isEntity
if (Entity* entity = Node_getEntity(node)) {
const std::string &name = entity->getKeyValue("name");
if (!name.empty()) {
selectedEntityNames.insert(name);
}
}
});
std::string command;
for (const std::string &name : selectedEntityNames)
command += "respawn " + name + "\n";
std::string text = composeConExecRequest(command);
executeRequest(text);
}

void GameConnection::reloadMap() {
if (!connect())
return;
Expand Down
2 changes: 2 additions & 0 deletions radiant/gameconnection/GameConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class GameConnection :

//pause game if it is live, unpause if it is paused
void togglePauseGame();
//respawn all entities in the current selection set
void respawnSelectedEntities();

//ask TDM to reload .map file from disk
void reloadMap();
Expand Down

0 comments on commit 297f88f

Please sign in to comment.