From d71250fab0b8469668e2174a2eb1a9e9c3420f10 Mon Sep 17 00:00:00 2001 From: HatjigeorgiouDimitri Date: Tue, 17 Jan 2017 11:21:04 +0100 Subject: [PATCH] ScriptNode and print function added to console --- CMakeLists.txt | 1 + src/sparrowshell/scriptnode.cpp | 26 ++++++++++++++++++++++++++ src/sparrowshell/scriptnode.h | 19 +++++++++++++++++++ src/sparrowshell/sparrowshell.cpp | 4 ++++ src/sparrowshell/sparrowshell.h | 2 ++ 5 files changed, 52 insertions(+) create mode 100644 src/sparrowshell/scriptnode.cpp create mode 100644 src/sparrowshell/scriptnode.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f555a87..148b207 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,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") diff --git a/src/sparrowshell/scriptnode.cpp b/src/sparrowshell/scriptnode.cpp new file mode 100644 index 0000000..d9a98aa --- /dev/null +++ b/src/sparrowshell/scriptnode.cpp @@ -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); +} diff --git a/src/sparrowshell/scriptnode.h b/src/sparrowshell/scriptnode.h new file mode 100644 index 0000000..2c5a702 --- /dev/null +++ b/src/sparrowshell/scriptnode.h @@ -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 diff --git a/src/sparrowshell/sparrowshell.cpp b/src/sparrowshell/sparrowshell.cpp index b1096b6..33f9b8c 100644 --- a/src/sparrowshell/sparrowshell.cpp +++ b/src/sparrowshell/sparrowshell.cpp @@ -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" @@ -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); //Create mesh for scrollbar m_scrollbar = new ShellScrollBar(this); + 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 @@ -140,6 +143,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; diff --git a/src/sparrowshell/sparrowshell.h b/src/sparrowshell/sparrowshell.h index 3612a2b..1e7ff81 100644 --- a/src/sparrowshell/sparrowshell.h +++ b/src/sparrowshell/sparrowshell.h @@ -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;