Elaztek Developer Hub
Blamite Game Engine - Tool (Library)
A command-line utility that aids in the creation of Blamite Cache (.map) Files.
ChooseProjectCommand.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Strings/components/logger/logger.h>
4 #include <Strings/components/utils/io/io.h>
5 #include <Strings/components/utils/converters/converters.h>
6 #include <HEKGuerilla/components/projects/projects.h>
7 
8 #include "../ToolCommand.hpp"
9 #include "../console.h"
10 
11 #ifdef TOOL_LIB_EXPORTS
12 #define TOOL_LIB_API __declspec(dllexport)
13 #else
14 #define TOOL_LIB_API __declspec(dllimport)
15 #endif
16 
24 {
25 public:
27  {
28  command = "choose-project";
29  syntax = "choose-project <id>";
30  description = "selects a project by id. use list-projects to view available projects and their associated ids.";
31  }
32 
33  int execute(std::vector<std::string> args)
34  {
35  if (args.size() == 0)
36  {
37  BlamStrings::Logger::LogEvent("not enough arguments provided - you must specify a project id", WSV_WARNING);
38  return -1;
39  }
40 
41  if (!BlamStrings::Converters::IsStringInt(args.at(0)))
42  {
43  BlamStrings::Logger::LogEvent("invalid arguments provided - id must be an integer", WSV_WARNING);
44  return -1;
45  }
46 
47  int id = BlamStrings::Converters::StringToInt(args.at(0));
48 
49  Guerilla::Projects::LoadProjects();
50  std::vector<BlamProject*> projects = Guerilla::Projects::GetLoadedProjects();
51 
52  if (id < 0 || id >= projects.size())
53  {
54  BlamStrings::Logger::LogEvent("invalid arguments provided - id must be between 0 and " + std::to_string(projects.size() - 1), WSV_WARNING);
55  return -1;
56  }
57 
58  std::string dir = projects.at(id)->project_root;
59 
60  if (BlamStrings::Utils::IO::CreateNewFile(".TOOL_PROJECT_ROOT", dir))
61  {
62  BlamStrings::Logger::LogEvent("successfully set project root to '" + dir + "'");
63  }
64  else
65  {
66  BlamStrings::Logger::LogEvent("could not change project root: CreateNewFile() returned false", WSV_WARNING);
67  return -1;
68  }
69 
70  return 0;
71  }
72 };
ChooseProjectCommand
Class for the choose-project command.
Definition: ChooseProjectCommand.hpp:23
ChooseProjectCommand::execute
int execute(std::vector< std::string > args)
Executes the command.
Definition: ChooseProjectCommand.hpp:33
ToolCommand::syntax
std::string syntax
The syntax of the command. This should include the command name, as well as any arguments.
Definition: ToolCommand.hpp:19
ChooseProjectCommand::ChooseProjectCommand
ChooseProjectCommand()
Definition: ChooseProjectCommand.hpp:26
ToolCommand::command
std::string command
The name of the command.
Definition: ToolCommand.hpp:18
ToolCommand
Base class representing a Tool command.
Definition: ToolCommand.hpp:15
ToolCommand::description
std::string description
A description of the command.
Definition: ToolCommand.hpp:20