Elaztek Developer Hub
Blamite Game Engine - blam!  00453.06.08.26.0624.blamite
The core library for the Blamite Game Engine.
set_camera.hpp
Go to the documentation of this file.
1 #include "../console.h"
2 
3 #include <set>
4 
8 
10 {
17  {
18  public:
20  {
21  name = "set_camera";
22  description = "sets the specified camera object as the active camera";
23  syntax = "set_camera <string>";
24 
26  }
27 
28  BlamResult Execute(std::vector<std::string> args)
29  {
30  if (args.size() == 0)
31  {
32  return BlamResult::Error_Command_WrongArgumentCount;
33  }
34 
35  std::string camera_name = "";
36 
37  for (std::string arg : args)
38  {
39  camera_name += arg;
40  }
41 
42  camera_name = camera_name.substr(0, camera_name.size());
43 
45 
46  if (!world)
47  {
48  Blam::Logger::LogEvent("cannot set camera: no world state initialized", WSV_ERROR);
49  return BlamResult::Success_OK;
50  }
51 
52  if (camera_name == "#NULL")
53  {
54  world->SetActiveCamera(nullptr);
55  Blam::Logger::LogEvent("detached active camera");
56  return BlamResult::Success_OK;
57  }
58 
59  BlamWorldObject* object = world->GetObjectByName(camera_name, true);
60 
61  if (!object)
62  {
63  Blam::Logger::LogEvent("cannot set camera: no object with name '" + camera_name + "'", WSV_ERROR);
64  return BlamResult::Success_OK;
65  }
66 
67  if (object->type != BlamWorldObjectType::Tag)
68  {
69  Blam::Logger::LogEvent("cannot set camera: object '" + camera_name + "' is of wrong object type", WSV_ERROR);
70  return BlamResult::Success_OK;
71  }
72 
73  BlamWorldObject_Tag* tag_object = (BlamWorldObject_Tag*)object;
74 
75  if (!tag_object->tag_data || tag_object->tag_data->tag_class != tag_camr)
76  {
77  Blam::Logger::LogEvent("cannot set camera: object '" + camera_name + "' is not a camera tag", WSV_ERROR);
78  return BlamResult::Success_OK;
79  }
80 
81  world->SetActiveCamera(tag_object);
82  Blam::Logger::LogEvent("changed active camera to '" + camera_name + "'");
83 
84  return BlamResult::Success_OK;
85  }
86  };
87 }
Blam::World::GetWorldState
BLAM BlamWorldState * GetWorldState()
Retrieves the current world state.
Definition: world.cpp:56
object
Definition: object.h:27
tag_camr
#define tag_camr
Definition: camera.h:19
Blam::Logger::LogEvent
BLAM void LogEvent(std::string message)
Logs a message to the log and/or console.
Definition: aliases.cpp:130
BlamConsoleCommand::description
std::string description
An optional description of the command. Shown when using the classify command.
Definition: console.h:36
logger.h
world.h
BlamConsoleCommand
Class used to represent a console command.
Definition: console.h:33
BlamWorldObject_Tag::tag_data
BlamTagData * tag_data
Pointer to the tag data associated with this object.
Definition: world_objects.h:304
BlamWorldObject_Tag
Class representing a tag-based world object.
Definition: world_objects.h:278
Blam::Resources::Console::SetCameraCommand::Execute
BlamResult Execute(std::vector< std::string > args)
Called upon command execution.
Definition: set_camera.hpp:28
BlamConsoleCommand::name
std::string name
The name of the console command.
Definition: console.h:35
BlamWorldState::GetObjectByName
BlamWorldObject * GetObjectByName(std::string name, bool recursive_search=false)
Definition: BlamWorldState.cpp:202
camera.h
BlamWorldObject
Class representing a world object.
Definition: world_objects.h:138
BlamConsoleCommand::syntax
std::string syntax
The syntax information for the command. Shown to the user when using the help command with an argumen...
Definition: console.h:37
BlamConsoleCommand::type
BlamCommandType type
The type of command this is. See #Blam::Resources::Console::BlamCommandType for more information.
Definition: console.h:40
Blam::Resources::Console::SetCameraCommand::SetCameraCommand
SetCameraCommand()
Definition: set_camera.hpp:19
BlamWorldState::SetActiveCamera
void SetActiveCamera(BlamWorldObject_Tag *camera)
Definition: BlamWorldState.cpp:248
Blam::Resources::Console::SetCameraCommand
Class for the set_camera command.
Definition: set_camera.hpp:16
Blam::Resources::Console
Namespace for things relating to the debug console.
Definition: abort.hpp:5
BlamWorldState
Class representing a world state.
Definition: world_objects.h:715
BlamWorldObjectType::Tag
@ Tag
BlamCommandType::Builtin
@ Builtin
A command that is hard-coded into the engine.
BlamTagData::tag_class
std::string tag_class
The tag's short class name.
Definition: tags.h:146