Permalink
Browse files

make tpt.selected* and tpt.brushx/y writable (replaces simstate branch)

  • Loading branch information...
jacob1 committed Aug 19, 2014
1 parent 5ab1aa6 commit f8782338d7cf962281e615c107f25b95e0a2288e
@@ -351,6 +351,12 @@ void GameController::AdjustBrushSize(int direction, bool logarithmic, bool xAxis
BrushChanged(gameModel->GetBrushID(), gameModel->GetBrush()->GetRadius().X, gameModel->GetBrush()->GetRadius().Y);
}
void GameController::SetBrushSize(ui::Point newSize)
{
gameModel->GetBrush()->SetRadius(newSize);
BrushChanged(gameModel->GetBrushID(), gameModel->GetBrush()->GetRadius().X, gameModel->GetBrush()->GetRadius().Y);
}
void GameController::AdjustZoomSize(int direction, bool logarithmic)
{
int newSize;
@@ -81,6 +81,7 @@ class GameController: public ClientListener
void SetZoomEnabled(bool zoomEnable);
void SetZoomPosition(ui::Point position);
void AdjustBrushSize(int direction, bool logarithmic = false, bool xAxis = false, bool yAxis = false);
void SetBrushSize(ui::Point newSize);
void AdjustZoomSize(int direction, bool logarithmic = false);
void ToolClick(int toolSelection, ui::Point point);
void DrawPoints(int toolSelection, queue<ui::Point> & pointQueue);
@@ -588,26 +588,14 @@ int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel)
return mpcontinue;
}
int luacon_step(int mx, int my, std::string selectl, std::string selectr, std::string selectalt, std::string selectreplace, int bsx, int bsy)
int luacon_step(int mx, int my)
{
int i, j, callret;
lua_State* l=luacon_ci->l;
lua_pushinteger(l, bsy);
lua_pushinteger(l, bsx);
lua_pushstring(l, selectreplace.c_str());
lua_pushstring(l, selectalt.c_str());
lua_pushstring(l, selectr.c_str());
lua_pushstring(l, selectl.c_str());
lua_pushinteger(l, my);
lua_pushinteger(l, mx);
lua_setfield(l, tptProperties, "mousex");
lua_setfield(l, tptProperties, "mousey");
lua_setfield(l, tptProperties, "selectedl");
lua_setfield(l, tptProperties, "selectedr");
lua_setfield(l, tptProperties, "selecteda");
lua_setfield(l, tptProperties, "selectedreplace");
lua_setfield(l, tptProperties, "brushx");
lua_setfield(l, tptProperties, "brushy");
lua_pushstring(l, "stepfunctions");
lua_rawget(l, LUA_REGISTRYINDEX);
if(!lua_istable(l, -1))
@@ -21,7 +21,7 @@ extern int tptElements; //Table for TPT element names
extern int tptParts, tptPartsMeta, tptElementTransitions, tptPartsCData, tptPartMeta, tptPart, cIndex;
void luacon_hook(lua_State *L, lua_Debug *ar);
int luacon_step(int mx, int my, std::string , std::string selectr, std::string selectedalt, std::string selectedreplace, int bsx, int bsy);
int luacon_step(int mx, int my);
int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel);
int luacon_keyevent(int key, int modifier, int event);
int luacon_eval(const char *command);
@@ -73,6 +73,18 @@ int atPanic(lua_State *l)
throw std::runtime_error("Unprotected lua panic: " + std::string(lua_tostring(l, -1)));
}
int TptIndexClosure(lua_State *l)
{
LuaScriptInterface *lsi = (LuaScriptInterface *)lua_touserdata(l, lua_upvalueindex(1));
return lsi->tpt_index(l);
}
int TptNewindexClosure(lua_State *l)
{
LuaScriptInterface *lsi = (LuaScriptInterface *)lua_touserdata(l, lua_upvalueindex(1));
return lsi->tpt_newIndex(l);
}
LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
CommandInterface(c, m),
currentCommand(false),
@@ -214,14 +226,6 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
lua_setfield(l, tptProperties, "mousex");
lua_pushinteger(l, 0);
lua_setfield(l, tptProperties, "mousey");
lua_pushstring(l, "DEFAULT_PT_DUST");
lua_setfield(l, tptProperties, "selectedl");
lua_pushstring(l, "DEFAULT_PT_NONE");
lua_setfield(l, tptProperties, "selectedr");
lua_pushstring(l, "DEFAULT_PT_NONE");
lua_setfield(l, tptProperties, "selecteda");
lua_pushstring(l, "DEFAULT_PT_NONE");
lua_setfield(l, tptProperties, "selectedreplace");
lua_newtable(l);
tptPropertiesVersion = lua_gettop(l);
@@ -332,6 +336,16 @@ tpt.partsdata = nil");
lua_gr_func[i] = 0;
}
//make tpt.* a metatable
lua_newtable(l);
lua_pushlightuserdata(l, this);
lua_pushcclosure(l, TptIndexClosure, 1);
lua_setfield(l, -2, "__index");
lua_pushlightuserdata(l, this);
lua_pushcclosure(l, TptNewindexClosure, 1);
lua_setfield(l, -2, "__newindex");
lua_setmetatable(l, -2);
}
void LuaScriptInterface::Init()
@@ -351,6 +365,79 @@ void LuaScriptInterface::SetWindow(ui::Window * window)
Window = window;
}
int LuaScriptInterface::tpt_index(lua_State *l)
{
std::string key = luaL_checkstring(l, 2);
if (!key.compare("selectedl"))
return lua_pushstring(l, luacon_selectedl.c_str()), 1;
if (!key.compare("selectedr"))
return lua_pushstring(l, luacon_selectedr.c_str()), 1;
if (!key.compare("selecteda"))
return lua_pushstring(l, luacon_selectedalt.c_str()), 1;
if (!key.compare("selectedreplace"))
return lua_pushstring(l, luacon_selectedreplace.c_str()), 1;
if (!key.compare("brushx"))
return lua_pushnumber(l, luacon_brushx), 1;
if (!key.compare("brushy"))
return lua_pushnumber(l, luacon_brushy), 1;
if (!key.compare("brushID"))
return lua_pushnumber(l, m->GetBrushID()), 1;
//if not a special key, return the value in the table
return lua_rawget(l, 1), 1;
}
int LuaScriptInterface::tpt_newIndex(lua_State *l)
{
std::string key = luaL_checkstring(l, 2);
if (!key.compare("selectedl"))
{
Tool *t = m->GetToolFromIdentifier(luaL_checkstring(l, 3));
if (t)
c->SetActiveTool(0, t);
else
luaL_error(l, "Invalid tool identifier: %s", lua_tostring(l, 3));
}
else if (!key.compare("selectedr"))
{
Tool *t = m->GetToolFromIdentifier(luaL_checkstring(l, 3));
if (t)
c->SetActiveTool(1, t);
else
luaL_error(l, "Invalid tool identifier: %s", lua_tostring(l, 3));
}
else if (!key.compare("selecteda"))
{
Tool *t = m->GetToolFromIdentifier(luaL_checkstring(l, 3));
if (t)
c->SetActiveTool(2, t);
else
luaL_error(l, "Invalid tool identifier: %s", lua_tostring(l, 3));
}
else if (!key.compare("selectedreplace"))
{
Tool *t = m->GetToolFromIdentifier(luaL_checkstring(l, 3));
if( t)
c->SetActiveTool(3, t);
else
luaL_error(l, "Invalid tool identifier: %s", lua_tostring(l, 3));
}
else if (!key.compare("brushx"))
c->SetBrushSize(ui::Point(luaL_checkinteger(l, 3), luacon_brushy));
else if (!key.compare("brushy"))
c->SetBrushSize(ui::Point(luacon_brushx, luaL_checkinteger(l, 3)));
else if (!key.compare("brushID"))
{
m->SetBrushID(luaL_checkinteger(l, 3));
c->BrushChanged(m->GetBrushID(), luacon_brushx, luacon_brushy);
}
else
{
//if not a special key, set a value in the table
return lua_rawset(l, 1), 1;
}
}
//// Begin Interface API
void LuaScriptInterface::initInterfaceAPI()
@@ -2906,7 +2993,7 @@ void LuaScriptInterface::OnTick()
ui::Engine::Ref().LastTick(gettime());
if(luacon_mousedown)
luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS, 0);
luacon_step(luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_selectedalt, luacon_selectedreplace, luacon_brushx, luacon_brushy);
luacon_step(luacon_mousex, luacon_mousey);
}
int LuaScriptInterface::Command(std::string command)
@@ -146,6 +146,9 @@ class LuaScriptInterface: public CommandInterface
static int fileSystem_copy(lua_State * l);
public:
int tpt_index(lua_State *l);
int tpt_newIndex(lua_State *l);
ui::Window * Window;
lua_State *l;
LuaScriptInterface(GameController * c, GameModel * m);
@@ -42,7 +42,7 @@ Element_RPEL::Element_RPEL()
HighTemperature = ITH;
HighTemperatureTransition = NT;
Update = &Element_REPL::update;
Update = &Element_RPEL::update;
}

0 comments on commit f878233

Please sign in to comment.