mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-28 10:20:04 +02:00
some new sim and ren lua api functions
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
#include "gui/dialogues/TextPrompt.h"
|
#include "gui/dialogues/TextPrompt.h"
|
||||||
#include "gui/dialogues/ConfirmPrompt.h"
|
#include "gui/dialogues/ConfirmPrompt.h"
|
||||||
#include "simulation/Simulation.h"
|
#include "simulation/Simulation.h"
|
||||||
|
#include "simulation/Air.h"
|
||||||
#include "ToolClasses.h"
|
#include "ToolClasses.h"
|
||||||
#include "gui/game/GameModel.h"
|
#include "gui/game/GameModel.h"
|
||||||
#include "gui/game/Tool.h"
|
#include "gui/game/Tool.h"
|
||||||
@@ -469,6 +470,13 @@ void LuaScriptInterface::initSimulationAPI()
|
|||||||
{"loadStamp", simulation_loadStamp},
|
{"loadStamp", simulation_loadStamp},
|
||||||
{"loadSave", simulation_loadSave},
|
{"loadSave", simulation_loadSave},
|
||||||
{"adjustCoords", simulation_adjustCoords},
|
{"adjustCoords", simulation_adjustCoords},
|
||||||
|
{"prettyPowders", simulation_prettyPowders},
|
||||||
|
{"gravityGrid", simulation_gravityGrid},
|
||||||
|
{"edgeMode", simulation_edgeMode},
|
||||||
|
{"gravityMode", simulation_gravityMode},
|
||||||
|
{"airMode", simulation_airMode},
|
||||||
|
{"waterEqualisation", simulation_waterEqualisation},
|
||||||
|
{"waterEqualization", simulation_waterEqualisation},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
luaL_register(l, "simulation", simulationAPIMethods);
|
luaL_register(l, "simulation", simulationAPIMethods);
|
||||||
@@ -1317,6 +1325,86 @@ int LuaScriptInterface::simulation_adjustCoords(lua_State * l)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::simulation_prettyPowders(lua_State * l)
|
||||||
|
{
|
||||||
|
int acount = lua_gettop(l);
|
||||||
|
if (acount == 0)
|
||||||
|
{
|
||||||
|
lua_pushnumber(l, luacon_sim->pretty_powder);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int prettyPowder = luaL_optint(l, 1, 0);
|
||||||
|
luacon_sim->pretty_powder = prettyPowder;
|
||||||
|
luacon_model->UpdateQuickOptions();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::simulation_gravityGrid(lua_State * l)
|
||||||
|
{
|
||||||
|
int acount = lua_gettop(l);
|
||||||
|
if (acount == 0)
|
||||||
|
{
|
||||||
|
lua_pushnumber(l, luacon_model->GetGravityGrid());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int gravityGrid = luaL_optint(l, 1, -1);
|
||||||
|
luacon_model->ShowGravityGrid(gravityGrid);
|
||||||
|
luacon_model->UpdateQuickOptions();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::simulation_edgeMode(lua_State * l)
|
||||||
|
{
|
||||||
|
int acount = lua_gettop(l);
|
||||||
|
if (acount == 0)
|
||||||
|
{
|
||||||
|
lua_pushnumber(l, luacon_model->GetEdgeMode());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int edgeMode = luaL_optint(l, 1, -1);
|
||||||
|
luacon_model->SetEdgeMode(edgeMode);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::simulation_gravityMode(lua_State * l)
|
||||||
|
{
|
||||||
|
int acount = lua_gettop(l);
|
||||||
|
if (acount == 0)
|
||||||
|
{
|
||||||
|
lua_pushnumber(l, luacon_sim->gravityMode);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int gravityMode = luaL_optint(l, 1, -1);
|
||||||
|
luacon_sim->gravityMode = gravityMode;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::simulation_airMode(lua_State * l)
|
||||||
|
{
|
||||||
|
int acount = lua_gettop(l);
|
||||||
|
if (acount == 0)
|
||||||
|
{
|
||||||
|
lua_pushnumber(l, luacon_sim->air->airMode);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int airMode = luaL_optint(l, 1, -1);
|
||||||
|
luacon_sim->air->airMode = airMode;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::simulation_waterEqualisation(lua_State * l)
|
||||||
|
{
|
||||||
|
int acount = lua_gettop(l);
|
||||||
|
if (acount == 0)
|
||||||
|
{
|
||||||
|
lua_pushnumber(l, luacon_sim->water_equal_test);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int waterMode = luaL_optint(l, 1, -1);
|
||||||
|
luacon_sim->water_equal_test = waterMode;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//// Begin Renderer API
|
//// Begin Renderer API
|
||||||
|
|
||||||
@@ -1328,7 +1416,9 @@ void LuaScriptInterface::initRendererAPI()
|
|||||||
{"displayModes", renderer_displayModes},
|
{"displayModes", renderer_displayModes},
|
||||||
{"colourMode", renderer_colourMode},
|
{"colourMode", renderer_colourMode},
|
||||||
{"colorMode", renderer_colourMode}, //Duplicate of above to make Americans happy
|
{"colorMode", renderer_colourMode}, //Duplicate of above to make Americans happy
|
||||||
{"decorations", renderer_decorations},
|
{"decorations", renderer_decorations}, //renderer_debugHUD
|
||||||
|
{"grid", renderer_grid},
|
||||||
|
{"debugHUD", renderer_debugHUD},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
luaL_register(l, "renderer", rendererAPIMethods);
|
luaL_register(l, "renderer", rendererAPIMethods);
|
||||||
@@ -1486,6 +1576,32 @@ int LuaScriptInterface::renderer_decorations(lua_State * l)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::renderer_grid(lua_State * l)
|
||||||
|
{
|
||||||
|
int acount = lua_gettop(l);
|
||||||
|
if (acount == 0)
|
||||||
|
{
|
||||||
|
lua_pushnumber(l, luacon_ren->GetGridSize());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int grid = luaL_optint(l, 1, -1);
|
||||||
|
luacon_ren->SetGridSize(grid);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::renderer_debugHUD(lua_State * l)
|
||||||
|
{
|
||||||
|
int acount = lua_gettop(l);
|
||||||
|
if (acount == 0)
|
||||||
|
{
|
||||||
|
lua_pushnumber(l, luacon_controller->GetDebugHUD());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int debug = luaL_optint(l, 1, -1);
|
||||||
|
luacon_controller->SetDebugHUD(debug);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void LuaScriptInterface::initElementsAPI()
|
void LuaScriptInterface::initElementsAPI()
|
||||||
{
|
{
|
||||||
//Methods
|
//Methods
|
||||||
|
@@ -84,6 +84,12 @@ class LuaScriptInterface: public CommandInterface
|
|||||||
static int simulation_loadStamp(lua_State * l);
|
static int simulation_loadStamp(lua_State * l);
|
||||||
static int simulation_loadSave(lua_State * l);
|
static int simulation_loadSave(lua_State * l);
|
||||||
static int simulation_adjustCoords(lua_State * l);
|
static int simulation_adjustCoords(lua_State * l);
|
||||||
|
static int simulation_prettyPowders(lua_State * l);
|
||||||
|
static int simulation_gravityGrid(lua_State * l);
|
||||||
|
static int simulation_edgeMode(lua_State * l);
|
||||||
|
static int simulation_gravityMode(lua_State * l);
|
||||||
|
static int simulation_airMode(lua_State * l);
|
||||||
|
static int simulation_waterEqualisation(lua_State * l);
|
||||||
|
|
||||||
//Renderer
|
//Renderer
|
||||||
void initRendererAPI();
|
void initRendererAPI();
|
||||||
@@ -91,6 +97,8 @@ class LuaScriptInterface: public CommandInterface
|
|||||||
static int renderer_displayModes(lua_State * l);
|
static int renderer_displayModes(lua_State * l);
|
||||||
static int renderer_colourMode(lua_State * l);
|
static int renderer_colourMode(lua_State * l);
|
||||||
static int renderer_decorations(lua_State * l);
|
static int renderer_decorations(lua_State * l);
|
||||||
|
static int renderer_grid(lua_State * l);
|
||||||
|
static int renderer_debugHUD(lua_State * l);
|
||||||
|
|
||||||
//Elements
|
//Elements
|
||||||
static pim::VirtualMachine * updateVirtualMachines[PT_NUM];
|
static pim::VirtualMachine * updateVirtualMachines[PT_NUM];
|
||||||
|
@@ -661,7 +661,7 @@ bool GameController::KeyPress(int key, Uint16 character, bool shift, bool ctrl,
|
|||||||
SwitchGravity();
|
SwitchGravity();
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
gameView->ToggleDebug();
|
gameView->SetDebugHUD(!gameView->GetDebugHUD());
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
gameView->BeginStampSelection();
|
gameView->BeginStampSelection();
|
||||||
@@ -932,6 +932,16 @@ bool GameController::GetHudEnable()
|
|||||||
return gameView->GetHudEnable();
|
return gameView->GetHudEnable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameController::SetDebugHUD(bool hudState)
|
||||||
|
{
|
||||||
|
gameView->SetDebugHUD(hudState);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GameController::GetDebugHUD()
|
||||||
|
{
|
||||||
|
return gameView->GetDebugHUD();
|
||||||
|
}
|
||||||
|
|
||||||
void GameController::SetActiveColourPreset(int preset)
|
void GameController::SetActiveColourPreset(int preset)
|
||||||
{
|
{
|
||||||
gameModel->SetActiveColourPreset(preset);
|
gameModel->SetActiveColourPreset(preset);
|
||||||
|
@@ -101,6 +101,8 @@ public:
|
|||||||
void ShowGravityGrid();
|
void ShowGravityGrid();
|
||||||
void SetHudEnable(bool hudState);
|
void SetHudEnable(bool hudState);
|
||||||
bool GetHudEnable();
|
bool GetHudEnable();
|
||||||
|
void SetDebugHUD(bool hudState);
|
||||||
|
bool GetDebugHUD();
|
||||||
void SetActiveMenu(int menuID);
|
void SetActiveMenu(int menuID);
|
||||||
std::vector<Menu*> GetMenuList();
|
std::vector<Menu*> GetMenuList();
|
||||||
void SetActiveTool(int toolSelection, Tool * tool);
|
void SetActiveTool(int toolSelection, Tool * tool);
|
||||||
|
@@ -595,6 +595,18 @@ bool GameView::GetHudEnable()
|
|||||||
return showHud;
|
return showHud;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameView::SetDebugHUD(bool mode)
|
||||||
|
{
|
||||||
|
showDebug = mode;
|
||||||
|
if (ren)
|
||||||
|
ren->debugLines = showDebug;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GameView::GetDebugHUD()
|
||||||
|
{
|
||||||
|
return showDebug;
|
||||||
|
}
|
||||||
|
|
||||||
ui::Point GameView::GetMousePosition()
|
ui::Point GameView::GetMousePosition()
|
||||||
{
|
{
|
||||||
return mousePosition;
|
return mousePosition;
|
||||||
@@ -1201,13 +1213,6 @@ void GameView::OnMouseWheel(int x, int y, int d)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::ToggleDebug()
|
|
||||||
{
|
|
||||||
showDebug = !showDebug;
|
|
||||||
if (ren)
|
|
||||||
ren->debugLines = showDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameView::BeginStampSelection()
|
void GameView::BeginStampSelection()
|
||||||
{
|
{
|
||||||
selectMode = SelectStamp;
|
selectMode = SelectStamp;
|
||||||
|
@@ -131,10 +131,11 @@ public:
|
|||||||
void SetSample(SimulationSample sample);
|
void SetSample(SimulationSample sample);
|
||||||
void SetHudEnable(bool hudState);
|
void SetHudEnable(bool hudState);
|
||||||
bool GetHudEnable();
|
bool GetHudEnable();
|
||||||
|
void SetDebugHUD(bool mode);
|
||||||
|
bool GetDebugHUD();
|
||||||
bool CtrlBehaviour(){ return ctrlBehaviour; }
|
bool CtrlBehaviour(){ return ctrlBehaviour; }
|
||||||
bool ShiftBehaviour(){ return shiftBehaviour; }
|
bool ShiftBehaviour(){ return shiftBehaviour; }
|
||||||
void ExitPrompt();
|
void ExitPrompt();
|
||||||
void ToggleDebug();
|
|
||||||
SelectMode GetSelectMode() { return selectMode; }
|
SelectMode GetSelectMode() { return selectMode; }
|
||||||
void BeginStampSelection();
|
void BeginStampSelection();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user