ScriptNode and print function added to console

This commit is contained in:
HatjigeorgiouDimitri 2017-01-17 11:21:04 +01:00
parent ca797bf3f2
commit d71250fab0
5 changed files with 52 additions and 0 deletions

View File

@ -16,6 +16,7 @@ set(IS_LIBRARY True)
set(USE_RENDERER True) set(USE_RENDERER True)
set(USE_INPUT True) set(USE_INPUT True)
set(USE_BULLET True) set(USE_BULLET True)
set(USE_SOL2 True)
set(SFML_MODULES audio graphics) set(SFML_MODULES audio graphics)
set(CMAKE_TEMPLATE_PATH "../CMakeTemplate") 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/meshnode.h"
#include "scene/textnode.h" #include "scene/textnode.h"
#include "scene/gui/backgroundnode.h" #include "scene/gui/backgroundnode.h"
#include "scriptnode.h"
#include "mesh.h" #include "mesh.h"
#include "phongmaterial.h" #include "phongmaterial.h"
@ -42,10 +43,12 @@ SparrowShell::SparrowShell(sf::Window* window):
m_background = new BackGroundNode(glm::vec2(0),m_dimension,glm::vec3(0.1,0.1,0.1),0.5,SHELL_DEPTH); m_background = new BackGroundNode(glm::vec2(0),m_dimension,glm::vec3(0.1,0.1,0.1),0.5,SHELL_DEPTH);
//Create mesh for scrollbar //Create mesh for scrollbar
m_scrollbar = new ShellScrollBar(this); m_scrollbar = new ShellScrollBar(this);
m_script = new ScriptNode();
this->addChild(m_background); this->addChild(m_background);
this->addChild(m_buffer); this->addChild(m_buffer);
this->addChild(m_scrollbar); this->addChild(m_scrollbar);
this->addChild(m_script);
} }
// write string str in shell // write string str in shell
@ -140,6 +143,7 @@ void SparrowShell::updateTextInput()
if (m_input_string != ""){ if (m_input_string != ""){
out(m_input_string); out(m_input_string);
//DIMITRI : Take m_input_string here and send it to LUA :D //DIMITRI : Take m_input_string here and send it to LUA :D
m_script->execute(m_input_string);
} }
m_input_string.clear(); m_input_string.clear();
m_input_cursor_pos = 0; m_input_cursor_pos = 0;

View File

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