2021-09-02 23:48:09 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "lua/Lua.h"
|
|
|
|
#include "util/Types.h"
|
2021-10-11 12:46:57 -07:00
|
|
|
#include "util/EventEmitter.h"
|
2021-09-02 23:48:09 -07:00
|
|
|
|
|
|
|
class Input;
|
|
|
|
class LocalLuaParser;
|
|
|
|
|
|
|
|
namespace Api::Usertype {
|
|
|
|
class KeyObserver {
|
|
|
|
public:
|
|
|
|
KeyObserver(Input& input, LocalLuaParser& parser): input(input), parser(parser), id(ID_NEXT++) {}
|
|
|
|
|
|
|
|
~KeyObserver();
|
|
|
|
|
|
|
|
void start();
|
|
|
|
|
|
|
|
void stop();
|
|
|
|
|
2021-09-04 00:25:34 -07:00
|
|
|
const string& getBuffer();
|
|
|
|
void setBuffer(const string& buffer);
|
|
|
|
|
2021-09-02 23:48:09 -07:00
|
|
|
static void bind(sol::state& lua, sol::table& core, Input& input, LocalLuaParser& parser);
|
|
|
|
|
|
|
|
private:
|
2021-09-04 00:25:34 -07:00
|
|
|
usize id = 0;
|
|
|
|
bool active = false;
|
|
|
|
|
|
|
|
string buffer {};
|
|
|
|
|
2021-09-02 23:48:09 -07:00
|
|
|
sol::protected_function on_press = sol::nil;
|
|
|
|
sol::protected_function on_release = sol::nil;
|
|
|
|
sol::protected_function on_change = sol::nil;
|
|
|
|
|
|
|
|
Input& input;
|
|
|
|
LocalLuaParser& parser;
|
2021-10-11 12:46:57 -07:00
|
|
|
vec<ListenerRef> listeners {};
|
2021-09-02 23:48:09 -07:00
|
|
|
|
|
|
|
static usize ID_NEXT;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|