test lua & small modif to shell input

This commit is contained in:
Lendemor 2017-08-25 18:14:25 +02:00
parent 93049b41fd
commit 666c39bc03
5 changed files with 29 additions and 16 deletions

View File

@ -8,7 +8,7 @@ class DefaultKeysMap : public IKeysMap
public:
enum{MAIN_ACTION, SECONDARY_ACTION, TERTIARY_ACTION, MOVE_FORWARD, MOVE_BACKWARD, STRAFE_LEFT, STRAFE_RIGHT, JUMP,RUN,
TOGGLE_NOCLIP, TOGGLE_PHYSICS_DEBUG, TOGGLE_CONSOLE,
MOVE_CURSOR_LEFT, MOVE_CURSOR_RIGHT, TOGGLE_MOUSE_CURSOR, LEFT_CLICK,
MOVE_CURSOR_LEFT, MOVE_CURSOR_RIGHT, HISTORY_UP,HISTORY_DOWN, TOGGLE_MOUSE_CURSOR, LEFT_CLICK,
EXIT_GAME,LAST_DEFAULT_ACTION};
DefaultKeysMap(){
@ -26,6 +26,8 @@ public:
keys.push_back( {{TOGGLE_CONSOLE,input::KEYBOARD}, sf::Keyboard::F3, IKeysMap::PRESSED} );
keys.push_back( {{MOVE_CURSOR_LEFT,input::KEYBOARD}, sf::Keyboard::Left, IKeysMap::PRESSED} );
keys.push_back( {{MOVE_CURSOR_RIGHT,input::KEYBOARD}, sf::Keyboard::Right, IKeysMap::PRESSED} );
keys.push_back( {{HISTORY_UP,input::KEYBOARD}, sf::Keyboard::Up, IKeysMap::PRESSED} );
keys.push_back( {{HISTORY_DOWN,input::KEYBOARD}, sf::Keyboard::Down, IKeysMap::PRESSED} );
keys.push_back( {{TOGGLE_MOUSE_CURSOR,input::KEYBOARD}, sf::Keyboard::M, IKeysMap::PRESSED} );
keys.push_back( {{EXIT_GAME,input::KEYBOARD}, sf::Keyboard::Escape,IKeysMap::PRESSED} );
keys.push_back( {{LEFT_CLICK,input::MOUSE}, sf::Mouse::Left, IKeysMap::PRESSED} );
@ -57,7 +59,9 @@ public:
{TOGGLE_CONSOLE,input::KEYBOARD},
{EXIT_GAME,input::KEYBOARD},
{MOVE_CURSOR_LEFT,input::KEYBOARD},
{MOVE_CURSOR_RIGHT,input::KEYBOARD}
{MOVE_CURSOR_RIGHT,input::KEYBOARD},
{HISTORY_UP,input::KEYBOARD},
{HISTORY_DOWN,input::KEYBOARD}
};
}

View File

@ -21,12 +21,19 @@ ScriptNode::ScriptNode()
LUA_SET_FUN(clear);
LUA_SET_FUN(picker);
LUA_SET_FUN(materialEditor);
// m_script["engine"] = getEngine();
m_script.new_usertype<Engine>("Engine",
"time",&Engine::getTime
);
}
void ScriptNode::update(){
static bool test = true;
if(test)
if(test && m_scene!= nullptr){
m_script["engine"] = getEngine();
test=false;
}
}
void ScriptNode::execute(std::string to_execute){

View File

@ -24,7 +24,8 @@ const float SparrowShell::DEFAULT_FONT_SIZE = 16.f;
SparrowShell::SparrowShell(sf::Window* window):
m_buffer(new ShellBuffer(BUFFER_MAX_LENGTH)),
m_text_color(glm::vec3(0.7,1,0.3))
m_text_color(glm::vec3(0.7,1,0.3)),
m_inputActions({NO_ACTION, NO_ACTION, NO_ACTION, NO_ACTION})
{
sf::Vector2u size = window->getSize();
m_dimension = glm::ivec2(size.x,DEFAULT_FONT_SIZE*(BUFFER_DISPLAYED_LINES+1));
@ -122,14 +123,13 @@ void SparrowShell::scrollDown()
}
}
void SparrowShell::setMoveCursorLeftAction(int action)
{
m_input_node->setMoveCursorLeft(action);
}
void SparrowShell::setMoveCursorRightAction(int action)
{
m_input_node->setMoveCursorRight(action);
void SparrowShell::setInputs(int cursor_left, int cursor_right, int history_up, int history_down){
m_inputActions[MOVE_CURSOR_LEFT] = cursor_left;
m_inputActions[MOVE_CURSOR_RIGHT] = cursor_right;
m_inputActions[HISTORY_PREVIOUS] = history_up;
m_inputActions[HISTORY_NEXT] = history_down;
m_input_node->setMoveCursorLeft(cursor_left);
m_input_node->setMoveCursorRight(cursor_right);
}
void SparrowShell::toggleShell()

View File

@ -60,6 +60,10 @@ private:
int m_move_cursor_right;
std::string m_previous_context;
std::vector<int> m_inputActions;
enum ShellAction {MOVE_CURSOR_LEFT=0,MOVE_CURSOR_RIGHT,HISTORY_PREVIOUS,HISTORY_NEXT};
public:
static const unsigned int BUFFER_MAX_LENGTH;
static const unsigned int BUFFER_DISPLAYED_LINES;
@ -82,8 +86,7 @@ public:
unsigned int getIndex(){return m_buffer->getIndex();}
ShellBuffer* getBuffer(){return m_buffer;}
void setMoveCursorLeftAction(int action);
void setMoveCursorRightAction(int action);
void setInputs(int cursor_left, int cursor_right, int history_up, int history_down);
bool isEnabled(){return m_shellEnabled;}

View File

@ -353,8 +353,7 @@ int main(){
//c'est un goup SparrowShell
SparrowShell* shell = engine.getShell();
shell->setMoveCursorLeftAction(DefaultKeysMap::MOVE_CURSOR_LEFT);
shell->setMoveCursorRightAction(DefaultKeysMap::MOVE_CURSOR_RIGHT);
shell->setInputs(DefaultKeysMap::MOVE_CURSOR_LEFT,DefaultKeysMap::MOVE_CURSOR_RIGHT,DefaultKeysMap::HISTORY_UP,DefaultKeysMap::HISTORY_DOWN);
input->addContext(Context("shell",DefaultKeysMap::getShellContext()));
input->updateKeyBindings();