summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacob1 <jfu614@gmail.com>2013-01-08 02:05:58 (GMT)
committer jacob1 <jfu614@gmail.com>2013-01-08 02:05:58 (GMT)
commit158b05402348f6eae3ed08f40676c1b8adf0b268 (patch)
tree2810c368e25d27ccf5e086935073ba501332e938 /src
parent986173af4c1aec6308ea6f6f2e126b65eeaf37a3 (diff)
downloadpowder-158b05402348f6eae3ed08f40676c1b8adf0b268.zip
powder-158b05402348f6eae3ed08f40676c1b8adf0b268.tar.gz
fix tpt.selectedl/r/a, but it returns the string identifier now instead of an id
Diffstat (limited to 'src')
-rw-r--r--src/cat/CommandInterface.h2
-rw-r--r--src/cat/LegacyLuaAPI.cpp8
-rw-r--r--src/cat/LuaScriptHelper.h2
-rw-r--r--src/cat/LuaScriptInterface.cpp31
-rw-r--r--src/cat/LuaScriptInterface.h6
-rw-r--r--src/game/GameController.cpp6
6 files changed, 45 insertions, 10 deletions
diff --git a/src/cat/CommandInterface.h b/src/cat/CommandInterface.h
index e6119d3..5b9c31f 100644
--- a/src/cat/CommandInterface.h
+++ b/src/cat/CommandInterface.h
@@ -14,6 +14,7 @@
class GameModel;
class GameController;
+class Tool;
class CommandInterface {
protected:
std::string lastError;
@@ -28,6 +29,7 @@ public:
void Log(LogType type, std::string message);
//void AttachGameModel(GameModel * m);
virtual bool OnBrushChanged(int brushType, int rx, int ry) {return true;}
+ virtual bool OnActiveToolChanged(int toolSelection, Tool * tool) {return true;}
virtual bool OnMouseMove(int x, int y, int dx, int dy) {return true;}
virtual bool OnMouseDown(int x, int y, unsigned button) {return true;}
virtual bool OnMouseUp(int x, int y, unsigned button) {return true;}
diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp
index 80a7f82..90baaa2 100644
--- a/src/cat/LegacyLuaAPI.cpp
+++ b/src/cat/LegacyLuaAPI.cpp
@@ -535,18 +535,20 @@ int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel){
return mpcontinue;
}
-int luacon_step(int mx, int my, int selectl, int selectr, int bsx, int bsy){
+int luacon_step(int mx, int my, std::string selectl, std::string selectr, std::string selectalt, int bsx, int bsy){
int tempret = 0, tempb, i, callret;
lua_pushinteger(luacon_ci->l, bsy);
lua_pushinteger(luacon_ci->l, bsx);
- lua_pushinteger(luacon_ci->l, selectr);
- lua_pushinteger(luacon_ci->l, selectl);
+ lua_pushstring(luacon_ci->l, selectalt.c_str());
+ lua_pushstring(luacon_ci->l, selectr.c_str());
+ lua_pushstring(luacon_ci->l, selectl.c_str());
lua_pushinteger(luacon_ci->l, my);
lua_pushinteger(luacon_ci->l, mx);
lua_setfield(luacon_ci->l, tptProperties, "mousex");
lua_setfield(luacon_ci->l, tptProperties, "mousey");
lua_setfield(luacon_ci->l, tptProperties, "selectedl");
lua_setfield(luacon_ci->l, tptProperties, "selectedr");
+ lua_setfield(luacon_ci->l, tptProperties, "selecteda");
lua_setfield(luacon_ci->l, tptProperties, "brushx");
lua_setfield(luacon_ci->l, tptProperties, "brushy");
for(i = 0; i<6; i++){
diff --git a/src/cat/LuaScriptHelper.h b/src/cat/LuaScriptHelper.h
index 17678d5..1b771e4 100644
--- a/src/cat/LuaScriptHelper.h
+++ b/src/cat/LuaScriptHelper.h
@@ -31,7 +31,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, int selectl, int selectr, int bsx, int bsy);
+int luacon_step(int mx, int my, std::string , std::string selectr, std::string selectedalt, int bsx, int bsy);
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(char *command);
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index 5954c4b..49f1d70 100644
--- a/src/cat/LuaScriptInterface.cpp
+++ b/src/cat/LuaScriptInterface.cpp
@@ -22,6 +22,7 @@
#include "dialogues/ConfirmPrompt.h"
#include "simulation/Simulation.h"
#include "game/GameModel.h"
+#include "game/Tool.h"
#include "LuaScriptHelper.h"
#include "client/HTTP.h"
@@ -78,7 +79,16 @@ int tptParts, tptPartsMeta, tptElementTransitions, tptPartsCData, tptPartMeta, t
LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
CommandInterface(c, m),
currentCommand(false),
- legacy(new TPTScriptInterface(c, m))
+ legacy(new TPTScriptInterface(c, m)),
+ luacon_mousex(0),
+ luacon_mousey(0),
+ luacon_mousebutton(0),
+ luacon_brushx(0),
+ luacon_brushy(0),
+ luacon_selectedl(""),
+ luacon_selectedr(""),
+ luacon_selectedalt(""),
+ luacon_mousedown(false)
{
luacon_model = m;
luacon_sim = m->GetSimulation();
@@ -190,10 +200,12 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
lua_setfield(l, tptProperties, "mousex");
lua_pushinteger(l, 0);
lua_setfield(l, tptProperties, "mousey");
- lua_pushinteger(l, 0);
+ lua_pushstring(l, "");
lua_setfield(l, tptProperties, "selectedl");
- lua_pushinteger(l, 0);
+ lua_pushstring(l, "");
lua_setfield(l, tptProperties, "selectedr");
+ lua_pushstring(l, "");
+ lua_setfield(l, tptProperties, "selecteda");
lua_newtable(l);
tptPropertiesVersion = lua_gettop(l);
@@ -1621,6 +1633,17 @@ bool LuaScriptInterface::OnBrushChanged(int brushType, int rx, int ry)
return true;
}
+bool LuaScriptInterface::OnActiveToolChanged(int toolSelection, Tool * tool)
+{
+ if (toolSelection == 0)
+ luacon_selectedl = tool->GetIdentifier();
+ else if (toolSelection == 1)
+ luacon_selectedr = tool->GetIdentifier();
+ else if (toolSelection == 2)
+ luacon_selectedalt = tool->GetIdentifier();
+ return true;
+}
+
bool LuaScriptInterface::OnMouseMove(int x, int y, int dx, int dy)
{
luacon_mousex = x;
@@ -1675,7 +1698,7 @@ void LuaScriptInterface::OnTick()
ui::Engine::Ref().LastTick(clock());
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_brushx, luacon_brushy);
+ luacon_step(luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_selectedalt, luacon_brushx, luacon_brushy);
}
int LuaScriptInterface::Command(std::string command)
diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h
index bf7d277..616398a 100644
--- a/src/cat/LuaScriptInterface.h
+++ b/src/cat/LuaScriptInterface.h
@@ -27,7 +27,7 @@ namespace pim
{
class VirtualMachine;
}
-
+class Tool;
//Because lua only has bindings for C, we're going to have to go outside "outside" the LuaScriptInterface, this means we can only have one instance :(
@@ -47,7 +47,8 @@ namespace pim
class TPTScriptInterface;
class LuaScriptInterface: public CommandInterface
{
- int luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_mousebutton, luacon_brushx, luacon_brushy;
+ int luacon_mousex, luacon_mousey, luacon_mousebutton, luacon_brushx, luacon_brushy;
+ std::string luacon_selectedl, luacon_selectedr, luacon_selectedalt;
bool luacon_mousedown;
bool currentCommand;
TPTScriptInterface * legacy;
@@ -110,6 +111,7 @@ public:
lua_State *l;
LuaScriptInterface(GameController * c, GameModel * m);
virtual bool OnBrushChanged(int brushType, int rx, int ry);
+ virtual bool OnActiveToolChanged(int toolSelection, Tool * tool);
virtual bool OnMouseMove(int x, int y, int dx, int dy);
virtual bool OnMouseDown(int x, int y, unsigned button);
virtual bool OnMouseUp(int x, int y, unsigned button);
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 373388d..2ec2cfc 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -146,6 +146,11 @@ GameController::GameController():
commandInterface = new LuaScriptInterface(this, gameModel);//new TPTScriptInterface();
((LuaScriptInterface*)commandInterface)->SetWindow(gameView);
+
+ commandInterface->OnBrushChanged(gameModel->GetBrushID(), gameModel->GetBrush()->GetRadius().X, gameModel->GetBrush()->GetRadius().X);
+ commandInterface->OnActiveToolChanged(0, gameModel->GetActiveTool(0));
+ commandInterface->OnActiveToolChanged(1, gameModel->GetActiveTool(1));
+ commandInterface->OnActiveToolChanged(2, gameModel->GetActiveTool(2));
//sim = new Simulation();
Client::Ref().AddListener(this);
@@ -917,6 +922,7 @@ void GameController::SetActiveMenu(Menu * menu)
void GameController::SetActiveTool(int toolSelection, Tool * tool)
{
+ commandInterface->OnActiveToolChanged(toolSelection, tool);
gameModel->SetActiveTool(toolSelection, tool);
gameModel->GetRenderer()->gravityZonesEnabled = false;
gameModel->SetLastTool(tool);