Skip to content

Commit

Permalink
#5788: Implement "PlacePlayerStart" command
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 29, 2021
1 parent 09721b8 commit 551bc8a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
42 changes: 41 additions & 1 deletion radiantcore/selection/algorithm/Entity.cpp
Expand Up @@ -4,6 +4,7 @@
#include "i18n.h"
#include "itransformable.h"
#include "ieclass.h"
#include "iundo.h"
#include "selectionlib.h"
#include "iregistry.h"
#include "inamespace.h"
Expand All @@ -25,7 +26,11 @@ namespace selection
namespace algorithm
{

const char* const GKEY_BIND_KEY("/defaults/bindKey");
constexpr const char* const GKEY_BIND_KEY("/defaults/bindKey");
constexpr const char* const PLAYERSTART_CLASSNAME = "info_player_start";
// Angle key for the player start
constexpr const char* const ANGLE_KEY_NAME = "angle";
constexpr const char* const DEFAULT_ANGLE = "90"; // north

void setEntityKeyValue(const scene::INodePtr& node, const std::string& key, const std::string& value)
{
Expand Down Expand Up @@ -306,5 +311,40 @@ void deselectItemsByModelCmd(const cmd::ArgumentList& args)
deselectItemsByModel(args[0].getString());
}

void placePlayerStart(const cmd::ArgumentList& args)
{
if (args.size() != 1)
{
rWarning() << "Usage: PlacePlayerStart <position:vector3>" << std::endl;
return;
}

auto position = args[0].getVector3();

UndoableCommand command(_("Place Player Start"));

EntityNodeFindByClassnameWalker walker(PLAYERSTART_CLASSNAME);
GlobalSceneGraph().root()->traverse(walker);

auto playerStartEntity = walker.getEntity();

if (playerStartEntity == nullptr)
{
// Create the player start entity
auto eclass = GlobalEntityClassManager().findClass(PLAYERSTART_CLASSNAME);
if (!eclass) throw cmd::ExecutionNotPossible(_("Could not find the info_player_start entityDef"));

auto playerStartNode = GlobalEntityModule().createEntity(eclass);
scene::addNodeToContainer(playerStartNode, GlobalSceneGraph().root());

playerStartEntity = &playerStartNode->getEntity();

// Set a default angle
playerStartEntity->setKeyValue(ANGLE_KEY_NAME, DEFAULT_ANGLE);
}

playerStartEntity->setKeyValue("origin", string::to_string(position));
}

} // namespace algorithm
} // namespace selection
3 changes: 3 additions & 0 deletions radiantcore/selection/algorithm/Entity.h
Expand Up @@ -48,5 +48,8 @@ void deselectItemsByModel(const std::string& model);
void selectItemsByModelCmd(const cmd::ArgumentList& args);
void deselectItemsByModelCmd(const cmd::ArgumentList& args);

// Command target: PlacePlayerStart <origin>
void placePlayerStart(const cmd::ArgumentList& args);

} // namespace algorithm
} // namespace selection
1 change: 1 addition & 0 deletions radiantcore/selection/algorithm/General.cpp
Expand Up @@ -1062,6 +1062,7 @@ void registerCommands()

GlobalCommandSystem().addCommand("ConnectSelection", connectSelectedEntities);
GlobalCommandSystem().addCommand("BindSelection", bindEntities);
GlobalCommandSystem().addCommand("PlacePlayerStart", placePlayerStart, { cmd::ARGTYPE_VECTOR3 });
GlobalCommandSystem().addCommand("SetEntityKeyValue", setEntityKeyValueOnSelection, { cmd::ARGTYPE_STRING, cmd::ARGTYPE_STRING });
GlobalCommandSystem().addCommand("CreateCurveNURBS", createCurveNURBS);
GlobalCommandSystem().addCommand("CreateCurveCatmullRom", createCurveCatmullRom);
Expand Down

0 comments on commit 551bc8a

Please sign in to comment.