summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacob1 <jfu614@gmail.com>2013-05-16 23:33:30 (GMT)
committer jacob1 <jfu614@gmail.com>2013-05-16 23:33:30 (GMT)
commit027649e85894b688d271d9b736d5ca204304de29 (patch)
tree881e5ae7d289546fb100d9b4c926e9e33d61e40a /src
parent6f8e2c03456552bdd54355606b8b8389f884c06d (diff)
downloadpowder-027649e85894b688d271d9b736d5ca204304de29.zip
powder-027649e85894b688d271d9b736d5ca204304de29.tar.gz
lua simulation api functions for drawing with tools / deco
Diffstat (limited to 'src')
-rw-r--r--src/cat/LuaScriptInterface.cpp164
-rw-r--r--src/cat/LuaScriptInterface.h6
-rw-r--r--src/gui/game/GameModel.cpp2
-rw-r--r--src/gui/game/Tool.cpp22
-rw-r--r--src/gui/game/Tool.h11
-rw-r--r--src/simulation/Simulation.cpp2
-rw-r--r--src/simulation/Simulation.h2
7 files changed, 171 insertions, 38 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index e066d6e..f9239f9 100644
--- a/src/cat/LuaScriptInterface.cpp
+++ b/src/cat/LuaScriptInterface.cpp
@@ -455,6 +455,12 @@ void LuaScriptInterface::initSimulationAPI()
{"createWallLine", simulation_createWallLine},
{"createWallBox", simulation_createWallBox},
{"floodWalls", simulation_floodWalls},
+ {"toolBrush", simulation_toolBrush},
+ {"toolLine", simulation_toolLine},
+ {"toolBox", simulation_toolBox},
+ {"decoBrush", simulation_decoBrush},
+ {"decoLine", simulation_decoLine},
+ {"decoBox", simulation_decoBox},
{"clearSim", simulation_clearSim},
{"saveStamp", simulation_saveStamp},
{"loadStamp", simulation_loadStamp},
@@ -476,6 +482,20 @@ void LuaScriptInterface::initSimulationAPI()
lua_pushinteger(l, MAX_TEMP); lua_setfield(l, simulationAPI, "MAX_TEMP");
lua_pushinteger(l, MIN_TEMP); lua_setfield(l, simulationAPI, "MIN_TEMP");
+ lua_pushinteger(l, 0); lua_setfield(l, simulationAPI, "TOOL_HEAT");
+ lua_pushinteger(l, 1); lua_setfield(l, simulationAPI, "TOOL_COOL");
+ lua_pushinteger(l, 2); lua_setfield(l, simulationAPI, "TOOL_VAC");
+ lua_pushinteger(l, 3); lua_setfield(l, simulationAPI, "TOOL_AIR");
+ lua_pushinteger(l, 4); lua_setfield(l, simulationAPI, "TOOL_PGRV");
+ lua_pushinteger(l, 5); lua_setfield(l, simulationAPI, "TOOL_NGRV");
+ lua_pushinteger(l, DECO_DRAW); lua_setfield(l, simulationAPI, "DECO_DRAW");
+ lua_pushinteger(l, DECO_CLEAR); lua_setfield(l, simulationAPI, "DECO_CLEAR");
+ lua_pushinteger(l, DECO_ADD); lua_setfield(l, simulationAPI, "DECO_ADD");
+ lua_pushinteger(l, DECO_SUBTRACT); lua_setfield(l, simulationAPI, "DECO_SUBTRACT");
+ lua_pushinteger(l, DECO_MULTIPLY); lua_setfield(l, simulationAPI, "DECO_MULTIPLY");
+ lua_pushinteger(l, DECO_DIVIDE); lua_setfield(l, simulationAPI, "DECO_DIVIDE");
+ lua_pushinteger(l, DECO_SMUDGE); lua_setfield(l, simulationAPI, "DECO_SMUDGE");
+
//Declare FIELD_BLAH constants
std::vector<StructProperty> particlePropertiesV = Particle::GetProperties();
particlePropertiesCount = 0;
@@ -936,14 +956,14 @@ int LuaScriptInterface::simulation_createParts(lua_State * l)
int flags = luaL_optint(l,7,0);
vector<Brush*> brushList = luacon_model->GetBrushList();
- if (brush < 0 || brush > brushList.size())
+ if (brush < 0 || brush >= brushList.size())
return luaL_error(l, "Invalid brush id '%d'", brush);
ui::Point tempRadius = brushList[brush]->GetRadius();
brushList[brush]->SetRadius(ui::Point(rx, ry));
int ret = luacon_sim->CreateParts(x, y, c, brushList[brush]);
- lua_pushinteger(l, ret);
brushList[brush]->SetRadius(tempRadius);
+ lua_pushinteger(l, ret);
return 1;
}
@@ -960,7 +980,7 @@ int LuaScriptInterface::simulation_createLine(lua_State * l)
int flags = luaL_optint(l,9,0);
vector<Brush*> brushList = luacon_model->GetBrushList();
- if (brush < 0 || brush > brushList.size())
+ if (brush < 0 || brush >= brushList.size())
return luaL_error(l, "Invalid brush id '%d'", brush);
ui::Point tempRadius = brushList[brush]->GetRadius();
brushList[brush]->SetRadius(ui::Point(rx, ry));
@@ -1059,6 +1079,144 @@ int LuaScriptInterface::simulation_floodWalls(lua_State * l)
return 1;
}
+int LuaScriptInterface::simulation_toolBrush(lua_State * l)
+{
+ int x = luaL_optint(l,1,-1);
+ int y = luaL_optint(l,2,-1);
+ int rx = luaL_optint(l,3,5);
+ int ry = luaL_optint(l,4,5);
+ int tool = luaL_optint(l,5,0);
+ int brush = luaL_optint(l,6,CIRCLE_BRUSH);
+ float strength = luaL_optnumber(l,7,1.0f);
+ if (tool < 0 || tool >= luacon_sim->tools.size())
+ return luaL_error(l, "Invalid tool id '%d'", tool);
+
+ vector<Brush*> brushList = luacon_model->GetBrushList();
+ if (brush < 0 || brush >= brushList.size())
+ return luaL_error(l, "Invalid brush id '%d'", brush);
+ ui::Point tempRadius = brushList[brush]->GetRadius();
+ brushList[brush]->SetRadius(ui::Point(rx, ry));
+
+ int ret = luacon_sim->ToolBrush(x, y, tool, brushList[brush], strength);
+ brushList[brush]->SetRadius(tempRadius);
+ lua_pushinteger(l, ret);
+ return 1;
+}
+
+int LuaScriptInterface::simulation_toolLine(lua_State * l)
+{
+ int x1 = luaL_optint(l,1,-1);
+ int y1 = luaL_optint(l,2,-1);
+ int x2 = luaL_optint(l,3,-1);
+ int y2 = luaL_optint(l,4,-1);
+ int rx = luaL_optint(l,5,5);
+ int ry = luaL_optint(l,6,5);
+ int tool = luaL_optint(l,7,0);
+ int brush = luaL_optint(l,8,CIRCLE_BRUSH);
+ float strength = luaL_optnumber(l,9,1.0f);
+ if (tool < 0 || tool >= luacon_sim->tools.size())
+ return luaL_error(l, "Invalid tool id '%d'", tool);
+
+ vector<Brush*> brushList = luacon_model->GetBrushList();
+ if (brush < 0 || brush >= brushList.size())
+ return luaL_error(l, "Invalid brush id '%d'", brush);
+ ui::Point tempRadius = brushList[brush]->GetRadius();
+ brushList[brush]->SetRadius(ui::Point(rx, ry));
+
+ luacon_sim->ToolLine(x1, y1, x2, y2, tool, brushList[brush], strength);
+ brushList[brush]->SetRadius(tempRadius);
+ return 0;
+}
+
+int LuaScriptInterface::simulation_toolBox(lua_State * l)
+{
+ int x1 = luaL_optint(l,1,-1);
+ int y1 = luaL_optint(l,2,-1);
+ int x2 = luaL_optint(l,3,-1);
+ int y2 = luaL_optint(l,4,-1);
+ int tool = luaL_optint(l,5,0);
+ float strength = luaL_optnumber(l,6,1.0f);
+ if (tool < 0 || tool >= luacon_sim->tools.size())
+ return luaL_error(l, "Invalid tool id '%d'", tool);
+
+ luacon_sim->ToolBox(x1, y1, x2, y2, tool, strength);
+ return 0;
+}
+
+int LuaScriptInterface::simulation_decoBrush(lua_State * l)
+{
+ int x = luaL_optint(l,1,-1);
+ int y = luaL_optint(l,2,-1);
+ int rx = luaL_optint(l,3,5);
+ int ry = luaL_optint(l,4,5);
+ int r = luaL_optint(l,5,255);
+ int g = luaL_optint(l,6,255);
+ int b = luaL_optint(l,7,255);
+ int a = luaL_optint(l,8,255);
+ int tool = luaL_optint(l,9,DECO_DRAW);
+ int brush = luaL_optint(l,10,CIRCLE_BRUSH);
+ if (tool < 0 || tool >= luacon_sim->tools.size())
+ return luaL_error(l, "Invalid tool id '%d'", tool);
+
+ vector<Brush*> brushList = luacon_model->GetBrushList();
+ if (brush < 0 || brush >= brushList.size())
+ return luaL_error(l, "Invalid brush id '%d'", brush);
+ ui::Point tempRadius = brushList[brush]->GetRadius();
+ brushList[brush]->SetRadius(ui::Point(rx, ry));
+
+ luacon_sim->ApplyDecorationPoint(x, y, r, g, b, a, tool, brushList[brush]);
+ brushList[brush]->SetRadius(tempRadius);
+ return 0;
+}
+
+int LuaScriptInterface::simulation_decoLine(lua_State * l)
+{
+ int x1 = luaL_optint(l,1,-1);
+ int y1 = luaL_optint(l,2,-1);
+ int x2 = luaL_optint(l,3,-1);
+ int y2 = luaL_optint(l,4,-1);
+ int rx = luaL_optint(l,5,5);
+ int ry = luaL_optint(l,6,5);
+ int r = luaL_optint(l,7,255);
+ int g = luaL_optint(l,8,255);
+ int b = luaL_optint(l,9,255);
+ int a = luaL_optint(l,10,255);
+ int tool = luaL_optint(l,11,DECO_DRAW);
+ int brush = luaL_optint(l,12,CIRCLE_BRUSH);
+ if (tool < 0 || tool >= luacon_sim->tools.size())
+ return luaL_error(l, "Invalid tool id '%d'", tool);
+
+ vector<Brush*> brushList = luacon_model->GetBrushList();
+ if (brush < 0 || brush >= brushList.size())
+ return luaL_error(l, "Invalid brush id '%d'", brush);
+ ui::Point tempRadius = brushList[brush]->GetRadius();
+ brushList[brush]->SetRadius(ui::Point(rx, ry));
+
+ luacon_sim->ApplyDecorationLine(x1, y1, x2, y2, r, g, b, a, tool, brushList[brush]);
+ brushList[brush]->SetRadius(tempRadius);
+ return 0;
+}
+
+int LuaScriptInterface::simulation_decoBox(lua_State * l)
+{
+ int x1 = luaL_optint(l,1,-1);
+ int y1 = luaL_optint(l,2,-1);
+ int x2 = luaL_optint(l,3,-1);
+ int y2 = luaL_optint(l,4,-1);
+ int rx = luaL_optint(l,5,5);
+ int ry = luaL_optint(l,6,5);
+ int r = luaL_optint(l,7,255);
+ int g = luaL_optint(l,8,255);
+ int b = luaL_optint(l,9,255);
+ int a = luaL_optint(l,10,255);
+ int tool = luaL_optint(l,11,0);
+ if (tool < 0 || tool >= luacon_sim->tools.size())
+ return luaL_error(l, "Invalid tool id '%d'", tool);
+
+ luacon_sim->ApplyDecorationBox(x1, y1, x2, y2, r, g, b, a, tool);
+ return 0;
+}
+
int LuaScriptInterface::simulation_clearSim(lua_State * l)
{
luacon_sim->clear_sim();
diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h
index c002f41..953d695 100644
--- a/src/cat/LuaScriptInterface.h
+++ b/src/cat/LuaScriptInterface.h
@@ -72,6 +72,12 @@ class LuaScriptInterface: public CommandInterface
static int simulation_createWallLine(lua_State * l);
static int simulation_createWallBox(lua_State * l);
static int simulation_floodWalls(lua_State * l);
+ static int simulation_toolBrush(lua_State * l);
+ static int simulation_toolLine(lua_State * l);
+ static int simulation_toolBox(lua_State * l);
+ static int simulation_decoBrush(lua_State * l);
+ static int simulation_decoLine(lua_State * l);
+ static int simulation_decoBox(lua_State * l);
static int simulation_clearSim(lua_State * l);
static int simulation_saveStamp(lua_State * l);
static int simulation_loadStamp(lua_State * l);
diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp
index aecd0eb..b57a7cb 100644
--- a/src/gui/game/GameModel.cpp
+++ b/src/gui/game/GameModel.cpp
@@ -292,7 +292,7 @@ void GameModel::BuildMenus()
//Build menu for GOL types
for(int i = 0; i < NGOL; i++)
{
- Tool * tempTool = new GolTool(PT_LIFE|(i<<8), sim->gmenu[i].name, std::string(sim->gmenu[i].description), PIXR(sim->gmenu[i].colour), PIXG(sim->gmenu[i].colour), PIXB(sim->gmenu[i].colour), "DEFAULT_PT_LIFE_"+std::string(sim->gmenu[i].name));
+ Tool * tempTool = new ElementTool(PT_LIFE|(i<<8), sim->gmenu[i].name, std::string(sim->gmenu[i].description), PIXR(sim->gmenu[i].colour), PIXG(sim->gmenu[i].colour), PIXB(sim->gmenu[i].colour), "DEFAULT_PT_LIFE_"+std::string(sim->gmenu[i].name));
menuList[SC_LIFE]->AddTool(tempTool);
}
diff --git a/src/gui/game/Tool.cpp b/src/gui/game/Tool.cpp
index e33b0ce..df99e57 100644
--- a/src/gui/game/Tool.cpp
+++ b/src/gui/game/Tool.cpp
@@ -45,7 +45,7 @@ void Tool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Po
sim->ToolLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush, strength);
}
void Tool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
- sim->ToolBox(position1.X, position1.Y, position2.X, position2.Y, toolID, brush, strength);
+ sim->ToolBox(position1.X, position1.Y, position2.X, position2.Y, toolID, strength);
}
void Tool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {};
@@ -110,26 +110,6 @@ void WallTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {
sim->FloodWalls(position.X, position.Y, toolID, -1, -1, 0);
}
-
-GolTool::GolTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int)):
- Tool(id, name, description, r, g, b, identifier, textureGen)
-{
-}
-GolTool::~GolTool() {}
-void GolTool::Draw(Simulation * sim, Brush * brush, ui::Point position){
- sim->CreateParts(position.X, position.Y, toolID, brush);
-}
-void GolTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging) {
- sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush);
-}
-void GolTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
- sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID, 0);
-}
-void GolTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {
- sim->FloodParts(position.X, position.Y, toolID, -1, -1, 0);
-}
-
-
WindTool::WindTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int)):
Tool(id, name, description, r, g, b, identifier, textureGen)
{
diff --git a/src/gui/game/Tool.h b/src/gui/game/Tool.h
index ea38fbc..df4e5cc 100644
--- a/src/gui/game/Tool.h
+++ b/src/gui/game/Tool.h
@@ -158,17 +158,6 @@ public:
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position);
};
-class GolTool: public Tool
-{
-public:
- GolTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
- virtual ~GolTool();
- virtual void Draw(Simulation * sim, Brush * brush, ui::Point position);
- virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false);
- virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2);
- virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position);
-};
-
class WindTool: public Tool
{
public:
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index cf8f149..4289016 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -1213,7 +1213,7 @@ void Simulation::ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBru
}
}
}
-void Simulation::ToolBox(int x1, int y1, int x2, int y2, int tool, Brush * cBrush, float strength)
+void Simulation::ToolBox(int x1, int y1, int x2, int y2, int tool, float strength)
{
int i, j;
if (x1>x2)
diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h
index 5387f85..1b27bc7 100644
--- a/src/simulation/Simulation.h
+++ b/src/simulation/Simulation.h
@@ -160,7 +160,7 @@ public:
int Tool(int x, int y, int tool, float strength = 1.0f);
int ToolBrush(int x, int y, int tool, Brush * cBrush, float strength = 1.0f);
void ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBrush, float strength = 1.0f);
- void ToolBox(int x1, int y1, int x2, int y2, int tool, Brush * cBrush, float strength = 1.0f);
+ void ToolBox(int x1, int y1, int x2, int y2, int tool, float strength = 1.0f);
void CreateBox(int x1, int y1, int x2, int y2, int c, int flags);
int FloodINST(int x, int y, int fullc, int cm);