This commit is contained in:
Lendemor 2017-01-19 14:18:30 +01:00
commit 006b6fdb01
5 changed files with 52 additions and 2 deletions

View File

@ -18,6 +18,7 @@ set(IS_LIBRARY True)
set(USE_RENDERER True)
set(USE_INPUT True)
set(USE_BULLET True)
set(USE_SOL2 True)
set(SFML_MODULES audio graphics)
set(CMAKE_TEMPLATE_PATH "../CMakeTemplate")

View File

@ -0,0 +1,26 @@
#include "scriptnode.h"
#include "engine.h"
#include "sparrowshell/sparrowshell.h"
#include "stdio.h"
#define LUASETFUN(var) s.set_function(#var,&ScriptNode::var,this)
ScriptNode::ScriptNode()
{
LUASETFUN(print);
printf("c is love\n");
}
void ScriptNode::update(){
static bool test = true;
if(test)
test=false;
}
void ScriptNode::print(std::string to_prit){
this->getEngine().getShell()->out(to_prit.append("\n"));
}
void ScriptNode::execute(std::string to_execute){
s.script(to_execute);
}

View File

@ -0,0 +1,19 @@
#ifndef SCRIPTNODE_H
#define SCRIPTNODE_H
#include "scene/graphicalnode.h"
#include "sol.hpp"
class ScriptNode : public GraphicalNode
{
sol::state s;
public:
ScriptNode();
void update();
void print(std::string);
void execute(std::string);
};
#endif // SCRIPTNODE_H

View File

@ -5,6 +5,7 @@
#include "scene/meshnode.h"
#include "scene/textnode.h"
#include "scene/gui/backgroundnode.h"
#include "scriptnode.h"
#include "mesh.h"
#include "phongmaterial.h"
@ -45,13 +46,13 @@ SparrowShell::SparrowShell(sf::Window* window):
// m_background->setVisible(true);
//Create mesh for scrollbar
m_scrollbar = new ShellScrollBar(this);
// m_scrollbar->setVisible(true);
// m_buffer->setVisible(true);
m_script = new ScriptNode();
this->addChild(m_background);
this->addChild(m_buffer);
this->addChild(m_scrollbar);
this->addChild(m_script);
}
// write string str in shell
@ -147,6 +148,7 @@ void SparrowShell::updateTextInput()
if (m_input_string != ""){
out(m_input_string);
//DIMITRI : Take m_input_string here and send it to LUA :D
m_script->execute(m_input_string);
}
m_input_string.clear();
m_input_cursor_pos = 0;

View File

@ -15,6 +15,7 @@ class MeshNode;
class TextNode;
class ShellBuffer;
class BackGroundNode;
class ScriptNode;
namespace sf {
class Window;
@ -32,6 +33,7 @@ private:
BackGroundNode* m_background;
ShellBuffer* m_buffer;
ShellScrollBar* m_scrollbar;
ScriptNode * m_script;
glm::vec3 m_text_color;
std::string m_input_string;