Add ability to load console commands from a cfg file
This commit is contained in:
parent
4f75d09eaf
commit
e03d0eceac
3 changed files with 14 additions and 0 deletions
|
@ -6,6 +6,8 @@
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "path.hpp"
|
||||||
|
|
||||||
namespace prism::console {
|
namespace prism::console {
|
||||||
enum class argument_type {
|
enum class argument_type {
|
||||||
String,
|
String,
|
||||||
|
@ -55,6 +57,8 @@ namespace prism::console {
|
||||||
std::vector<argument_type> argument_types;
|
std::vector<argument_type> argument_types;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void load_cfg(const prism::path& path);
|
||||||
|
|
||||||
void
|
void
|
||||||
register_command(std::string_view name, argument_format expected_format, function_ptr function);
|
register_command(std::string_view name, argument_format expected_format, function_ptr function);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
#include "string_utils.hpp"
|
#include "string_utils.hpp"
|
||||||
|
#include "file.hpp"
|
||||||
|
|
||||||
struct registered_command {
|
struct registered_command {
|
||||||
registered_command(const prism::console::argument_format format, const prism::console::function_ptr function) : expected_format(format), function(function) {}
|
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;
|
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) {
|
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));
|
registered_commands.try_emplace(name.data(), registered_command(expected_format, function));
|
||||||
}
|
}
|
||||||
|
|
1
example/data/render_options.cfg
Normal file
1
example/data/render_options.cfg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
rs_aa false
|
Reference in a new issue