Archived
1
Fork 0

Add ability to load console commands from a cfg file

This commit is contained in:
Joshua Goins 2022-02-21 17:37:27 -05:00
parent 4f75d09eaf
commit e03d0eceac
3 changed files with 14 additions and 0 deletions

View file

@ -6,6 +6,8 @@
#include <variant>
#include <string>
#include "path.hpp"
namespace prism::console {
enum class argument_type {
String,
@ -55,6 +57,8 @@ namespace prism::console {
std::vector<argument_type> argument_types;
};
void load_cfg(const prism::path& path);
void
register_command(std::string_view name, argument_format expected_format, function_ptr function);

View file

@ -6,6 +6,7 @@
#include "log.hpp"
#include "string_utils.hpp"
#include "file.hpp"
struct registered_command {
registered_command(const prism::console::argument_format format, const prism::console::function_ptr function) : expected_format(format), function(function) {}
@ -29,6 +30,14 @@ struct RegisteredVariable {
static std::unordered_map<std::string, RegisteredVariable> registered_variables;
void prism::console::load_cfg(const prism::path& path) {
auto file = prism::open_file(path);
auto stream = file->read_as_stream();
for (std::string line; getline( stream, line );) {
prism::console::parse_and_invoke_command(line);
}
}
void prism::console::register_command(const std::string_view name, const prism::console::argument_format expected_format, const prism::console::function_ptr function) {
registered_commands.try_emplace(name.data(), registered_command(expected_format, function));
}

View file

@ -0,0 +1 @@
rs_aa false