ScriptNode and print function added to console
This commit is contained in:
parent
ca797bf3f2
commit
d71250fab0
@ -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")
|
||||||
|
26
src/sparrowshell/scriptnode.cpp
Normal file
26
src/sparrowshell/scriptnode.cpp
Normal 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);
|
||||||
|
}
|
19
src/sparrowshell/scriptnode.h
Normal file
19
src/sparrowshell/scriptnode.h
Normal 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
|
@ -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;
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user