49 lines
1.7 KiB
C++
49 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <map>
|
|
#include <functional>
|
|
|
|
// TODO
|
|
// stuff in namespace "developer" can be disabled and the game must function in
|
|
// exact the same way just without cool debug features.
|
|
namespace developer {
|
|
class DeveloperConsole {
|
|
public:
|
|
class CallbackResult {
|
|
private:
|
|
CallbackResult(bool okay, const std::string &answer);
|
|
|
|
public:
|
|
static CallbackResult createError(const std::string &answer="");
|
|
static CallbackResult createOkay(const std::string &answer="");
|
|
|
|
public:
|
|
// read-only interface to result data
|
|
const bool okay;
|
|
const std::string answer;
|
|
};
|
|
|
|
typedef std::function<CallbackResult(const std::string &cmd)> callback_t;
|
|
|
|
DeveloperConsole();
|
|
|
|
// access functionality over this static singleton attribute to make
|
|
// it really easy and fast to use
|
|
static DeveloperConsole &instance();
|
|
|
|
// register callback for a token.
|
|
// token must not have whitespace in it and not be empty.
|
|
// old callback will be overridden if any
|
|
// return true on succes, false if not saved.
|
|
bool addCallback(const std::string &token, callback_t cb);
|
|
|
|
// dispatch input received over a communication channel.
|
|
CallbackResult dispatchInput(const std::string &token, const std::string &payload);
|
|
|
|
private:
|
|
std::map<std::string, callback_t> m_callbacks;
|
|
};
|
|
|
|
DeveloperConsole::CallbackResult resultOkay();
|
|
}
|