lua simulation api functions for creating particles, walls, boxes, and walls
This commit is contained in:
parent
18ddb7a155
commit
431f5a0083
@ -447,6 +447,15 @@ void LuaScriptInterface::initSimulationAPI()
|
||||
{"velocityX", simulation_velocityX},
|
||||
{"velocityY", simulation_velocityY},
|
||||
{"gravMap", simulation_gravMap},
|
||||
{"createParts", simulation_createParts},
|
||||
{"createLine", simulation_createLine},
|
||||
{"createBox", simulation_createBox},
|
||||
{"floodParts", simulation_floodParts},
|
||||
{"createWalls", simulation_createWalls},
|
||||
{"createWallLine", simulation_createWallLine},
|
||||
{"createWallBox", simulation_createWallBox},
|
||||
{"floodWalls", simulation_floodWalls},
|
||||
{"clearSim", simulation_clearSim},
|
||||
{NULL, NULL}
|
||||
};
|
||||
luaL_register(l, "simulation", simulationAPIMethods);
|
||||
@ -914,6 +923,178 @@ int LuaScriptInterface::simulation_gravMap(lua_State* l)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaScriptInterface::simulation_createParts(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 c = luaL_optint(l,5,luacon_model->GetActiveTool(0)->GetToolID());
|
||||
int brush = luaL_optint(l,6,CIRCLE_BRUSH);
|
||||
//int flags = luaL_optint(l,7,get_brush_flags());
|
||||
if (x < 0 || x > XRES || y < 0 || y > YRES)
|
||||
return luaL_error(l, "Coordinates out of range (%d,%d)", x, y);
|
||||
if (c < 0 || c >= PT_NUM || !luacon_sim->elements[c].Enabled)
|
||||
return luaL_error(l, "Unrecognised element number '%d'", c);
|
||||
|
||||
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->CreateParts(x, y, c, brushList[brush]);
|
||||
lua_pushinteger(l, ret);
|
||||
brushList[brush]->SetRadius(tempRadius);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaScriptInterface::simulation_createLine(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 c = luaL_optint(l,7,luacon_model->GetActiveTool(0)->GetToolID());
|
||||
int brush = luaL_optint(l,8,CIRCLE_BRUSH);
|
||||
//int flags = luaL_optint(l,9,get_brush_flags());
|
||||
if (x1 < 0 || x1 > XRES || y1 < 0 || y1 > YRES)
|
||||
return luaL_error(l, "Starting coordinates out of range (%d,%d)", x1, y1);
|
||||
if (x2 < 0 || x2 > XRES || y2 < 0 || y2 > YRES)
|
||||
return luaL_error(l, "Ending Coordinates out of range (%d,%d)", x2, y2);
|
||||
if (c < 0 || c >= PT_NUM || !luacon_sim->elements[c].Enabled)
|
||||
return luaL_error(l, "Unrecognised element number '%d'", c);
|
||||
|
||||
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->CreateLine(x1, y1, x2, y2, c, brushList[brush]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaScriptInterface::simulation_createBox(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 c = luaL_optint(l,5,luacon_model->GetActiveTool(0)->GetToolID());
|
||||
//int flags = luaL_optint(l,6,get_brush_flags());
|
||||
if (x1 < 0 || x1 > XRES || y1 < 0 || y1 > YRES)
|
||||
return luaL_error(l, "Starting coordinates out of range (%d,%d)", x1, y1);
|
||||
if (x2 < 0 || x2 > XRES || y2 < 0 || y2 > YRES)
|
||||
return luaL_error(l, "Ending Coordinates out of range (%d,%d)", x2, y2);
|
||||
if (c < 0 || c >= PT_NUM || !luacon_sim->elements[c].Enabled)
|
||||
return luaL_error(l, "Unrecognised element number '%d'", c);
|
||||
|
||||
luacon_sim->CreateBox(x1, y1, x2, y2, c, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaScriptInterface::simulation_floodParts(lua_State * l)
|
||||
{
|
||||
int x = luaL_optint(l,1,-1);
|
||||
int y = luaL_optint(l,2,-1);
|
||||
int c = luaL_optint(l,3,luacon_model->GetActiveTool(0)->GetToolID());
|
||||
int cm = luaL_optint(l,4,-1);
|
||||
int bm = luaL_optint(l,5,-1);
|
||||
//int flags = luaL_optint(l,6,0);
|
||||
if (x < 0 || x > XRES || y < 0 || y > YRES)
|
||||
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
|
||||
if (c < 0 || c >= PT_NUM || !luacon_sim->elements[c].Enabled)
|
||||
return luaL_error(l, "Unrecognised element number '%d'", c);
|
||||
int ret = luacon_sim->FloodParts(x, y, c, cm, bm, 0);
|
||||
lua_pushinteger(l, ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaScriptInterface::simulation_createWalls(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 c = luaL_optint(l,5,-1);
|
||||
//int flags = luaL_optint(l,6,get_brush_flags());
|
||||
if (x < 0 || x > XRES || y < 0 || y > YRES)
|
||||
return luaL_error(l, "Coordinates out of range (%d,%d)", x, y);
|
||||
if (c < 0 || c >= UI_WALLCOUNT)
|
||||
return luaL_error(l, "Unrecognised wall id '%d'", c);
|
||||
|
||||
int ret = luacon_sim->CreateWalls(x, y, rx, ry, c, 0);
|
||||
lua_pushinteger(l, ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaScriptInterface::simulation_createWallLine(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 c = luaL_optint(l,7,-1);
|
||||
//int flags = luaL_optint(l,8,get_brush_flags());
|
||||
if (x1 < 0 || x1 > XRES || y1 < 0 || y1 > YRES)
|
||||
return luaL_error(l, "Starting coordinates out of range (%d,%d)", x1, y1);
|
||||
if (x2 < 0 || x2 > XRES || y2 < 0 || y2 > YRES)
|
||||
return luaL_error(l, "Ending Coordinates out of range (%d,%d)", x2, y2);
|
||||
if (c < 0 || c >= UI_WALLCOUNT)
|
||||
return luaL_error(l, "Unrecognised wall id '%d'", c);
|
||||
|
||||
luacon_sim->CreateWallLine(x1, y1, x2, y2, rx, ry, c, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaScriptInterface::simulation_createWallBox(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 c = luaL_optint(l,5,luacon_model->GetActiveTool(0)->GetToolID());
|
||||
//int flags = luaL_optint(l,6,get_brush_flags());
|
||||
if (x1 < 0 || x1 > XRES || y1 < 0 || y1 > YRES)
|
||||
return luaL_error(l, "Starting coordinates out of range (%d,%d)", x1, y1);
|
||||
if (x2 < 0 || x2 > XRES || y2 < 0 || y2 > YRES)
|
||||
return luaL_error(l, "Ending Coordinates out of range (%d,%d)", x2, y2);
|
||||
if (c < 0 || c >= UI_WALLCOUNT)
|
||||
return luaL_error(l, "Unrecognised wall id '%d'", c);
|
||||
|
||||
luacon_sim->CreateWallBox(x1, y1, x2, y2, c, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaScriptInterface::simulation_floodWalls(lua_State * l)
|
||||
{
|
||||
int x = luaL_optint(l,1,-1);
|
||||
int y = luaL_optint(l,2,-1);
|
||||
int c = luaL_optint(l,3,luacon_model->GetActiveTool(0)->GetToolID());
|
||||
int cm = luaL_optint(l,4,-1);
|
||||
int bm = luaL_optint(l,5,-1);
|
||||
//int flags = luaL_optint(l,6,0);
|
||||
if (x < 0 || x > XRES || y < 0 || y > YRES)
|
||||
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
|
||||
if (c < 0 || c >= UI_WALLCOUNT)
|
||||
return luaL_error(l, "Unrecognised wall id '%d'", c);
|
||||
int ret = luacon_sim->FloodWalls(x, y, c, cm, bm, 0);
|
||||
lua_pushinteger(l, ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaScriptInterface::simulation_clearSim(lua_State * l)
|
||||
{
|
||||
luacon_sim->clear_sim();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//// Begin Renderer API
|
||||
|
||||
void LuaScriptInterface::initRendererAPI()
|
||||
|
@ -64,6 +64,15 @@ class LuaScriptInterface: public CommandInterface
|
||||
static int simulation_velocityY(lua_State * l);
|
||||
static int simulation_gravMap(lua_State * l);
|
||||
static int simulation_ambientHeat(lua_State * l);
|
||||
static int simulation_createParts(lua_State * l);
|
||||
static int simulation_createLine(lua_State * l);
|
||||
static int simulation_createBox(lua_State * l);
|
||||
static int simulation_floodParts(lua_State * l);
|
||||
static int simulation_createWalls(lua_State * l);
|
||||
static int simulation_createWallLine(lua_State * l);
|
||||
static int simulation_createWallBox(lua_State * l);
|
||||
static int simulation_floodWalls(lua_State * l);
|
||||
static int simulation_clearSim(lua_State * l);
|
||||
|
||||
//Renderer
|
||||
void initRendererAPI();
|
||||
|
@ -1306,7 +1306,7 @@ void GameController::Vote(int direction)
|
||||
|
||||
void GameController::ChangeBrush()
|
||||
{
|
||||
gameModel->SetBrush(gameModel->GetBrushID()+1);
|
||||
gameModel->SetBrushID(gameModel->GetBrushID()+1);
|
||||
BrushChanged(gameModel->GetBrushID(), gameModel->GetBrush()->GetRadius().X, gameModel->GetBrush()->GetRadius().Y);
|
||||
}
|
||||
|
||||
|
@ -292,7 +292,7 @@ void GameModel::BuildMenus()
|
||||
//Build menu for GOL types
|
||||
for(int i = 0; i < NGOL; i++)
|
||||
{
|
||||
Tool * tempTool = new GolTool(i, 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 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));
|
||||
menuList[SC_LIFE]->AddTool(tempTool);
|
||||
}
|
||||
|
||||
@ -424,12 +424,17 @@ Brush * GameModel::GetBrush()
|
||||
return brushList[currentBrush];
|
||||
}
|
||||
|
||||
vector<Brush*> GameModel::GetBrushList()
|
||||
{
|
||||
return brushList;
|
||||
}
|
||||
|
||||
int GameModel::GetBrushID()
|
||||
{
|
||||
return currentBrush;
|
||||
}
|
||||
|
||||
void GameModel::SetBrush(int i)
|
||||
void GameModel::SetBrushID(int i)
|
||||
{
|
||||
currentBrush = i%brushList.size();
|
||||
notifyBrushChanged();
|
||||
@ -511,6 +516,7 @@ Menu * GameModel::GetActiveMenu()
|
||||
return activeMenu;
|
||||
}
|
||||
|
||||
//Get an element tool from an element ID
|
||||
Tool * GameModel::GetElementTool(int elementID)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
|
@ -105,8 +105,6 @@ public:
|
||||
GameModel();
|
||||
~GameModel();
|
||||
|
||||
Tool * GetToolFromIdentifier(std::string identifier);
|
||||
|
||||
void SetEdgeMode(int edgeMode);
|
||||
int GetEdgeMode();
|
||||
|
||||
@ -136,26 +134,29 @@ public:
|
||||
|
||||
void UpdateQuickOptions();
|
||||
|
||||
Tool * GetActiveTool(int selection);
|
||||
void SetActiveTool(int selection, Tool * tool);
|
||||
void SetToolStrength(float value);
|
||||
float GetToolStrength();
|
||||
|
||||
Tool * GetLastTool();
|
||||
void SetLastTool(Tool * newTool);
|
||||
Tool * GetToolFromIdentifier(std::string identifier);
|
||||
Tool * GetElementTool(int elementID);
|
||||
vector<Tool*> GetToolList();
|
||||
vector<Tool*> GetUnlistedTools();
|
||||
|
||||
Brush * GetBrush();
|
||||
vector<Brush*> GetBrushList();
|
||||
int GetBrushID();
|
||||
void SetBrushID(int i);
|
||||
|
||||
void SetVote(int direction);
|
||||
SaveInfo * GetSave();
|
||||
SaveFile * GetSaveFile();
|
||||
Brush * GetBrush();
|
||||
void SetSave(SaveInfo * newSave);
|
||||
void SetSaveFile(SaveFile * newSave);
|
||||
void AddObserver(GameView * observer);
|
||||
|
||||
//Get an element tool from an element ID
|
||||
Tool * GetElementTool(int elementID);
|
||||
|
||||
Tool * GetActiveTool(int selection);
|
||||
void SetActiveTool(int selection, Tool * tool);
|
||||
|
||||
bool GetPaused();
|
||||
void SetPaused(bool pauseState);
|
||||
bool GetDecoration();
|
||||
@ -166,16 +167,12 @@ public:
|
||||
void ShowGravityGrid(bool showGrid);
|
||||
void ClearSimulation();
|
||||
vector<Menu*> GetMenuList();
|
||||
vector<Tool*> GetUnlistedTools();
|
||||
vector<Tool*> GetToolList();
|
||||
vector<QuickOption*> GetQuickOptions();
|
||||
void SetActiveMenu(Menu * menu);
|
||||
Menu * GetActiveMenu();
|
||||
void FrameStep(int frames);
|
||||
User GetUser();
|
||||
void SetUser(User user);
|
||||
void SetBrush(int i);
|
||||
int GetBrushID();
|
||||
Simulation * GetSimulation();
|
||||
Renderer * GetRenderer();
|
||||
void SetZoomEnabled(bool enabled);
|
||||
|
@ -117,16 +117,16 @@ GolTool::GolTool(int id, string name, string description, int r, int g, int b, s
|
||||
}
|
||||
GolTool::~GolTool() {}
|
||||
void GolTool::Draw(Simulation * sim, Brush * brush, ui::Point position){
|
||||
sim->CreateParts(position.X, position.Y, PT_LIFE|(toolID<<8), brush);
|
||||
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, PT_LIFE|(toolID<<8), brush);
|
||||
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, PT_LIFE|(toolID<<8), 0);
|
||||
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, PT_LIFE|(toolID<<8), -1, -1, 0);
|
||||
sim->FloodParts(position.X, position.Y, toolID, -1, -1, 0);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user