diff options
| author | jacob1 <jfu614@gmail.com> | 2013-05-17 16:44:25 (GMT) |
|---|---|---|
| committer | jacob1 <jfu614@gmail.com> | 2013-05-17 16:44:25 (GMT) |
| commit | 981f6984c2c0f87d54a9c90f4518c69c9ef02ae0 (patch) | |
| tree | 757bd699a23c1fad61e60700265a25feb1a3042c /src/cat | |
| parent | cbd402d8cb6aa699ffde83a1b5b3c2f4fc51baaf (diff) | |
| parent | 77bf649fb4482c86ac1fd9b3233f062b53226007 (diff) | |
| download | powder-981f6984c2c0f87d54a9c90f4518c69c9ef02ae0.zip powder-981f6984c2c0f87d54a9c90f4518c69c9ef02ae0.tar.gz | |
Merge branch 'HEAD' of git@github.com:FacialTurd/The-Powder-Toy.git
Diffstat (limited to 'src/cat')
| -rw-r--r-- | src/cat/LegacyLuaAPI.cpp | 191 | ||||
| -rw-r--r-- | src/cat/LuaBit.cpp | 3 | ||||
| -rw-r--r-- | src/cat/LuaButton.cpp | 4 | ||||
| -rw-r--r-- | src/cat/LuaButton.h | 2 | ||||
| -rw-r--r-- | src/cat/LuaCheckbox.cpp | 4 | ||||
| -rw-r--r-- | src/cat/LuaCheckbox.h | 2 | ||||
| -rw-r--r-- | src/cat/LuaComponent.cpp | 4 | ||||
| -rw-r--r-- | src/cat/LuaComponent.h | 2 | ||||
| -rw-r--r-- | src/cat/LuaLabel.cpp | 4 | ||||
| -rw-r--r-- | src/cat/LuaLabel.h | 2 | ||||
| -rw-r--r-- | src/cat/LuaLuna.h | 2 | ||||
| -rw-r--r-- | src/cat/LuaProgressBar.cpp | 4 | ||||
| -rw-r--r-- | src/cat/LuaProgressBar.h | 2 | ||||
| -rw-r--r-- | src/cat/LuaScriptInterface.cpp | 563 | ||||
| -rw-r--r-- | src/cat/LuaScriptInterface.h | 22 | ||||
| -rw-r--r-- | src/cat/LuaSlider.cpp | 4 | ||||
| -rw-r--r-- | src/cat/LuaSlider.h | 2 | ||||
| -rw-r--r-- | src/cat/LuaTextbox.cpp | 4 | ||||
| -rw-r--r-- | src/cat/LuaTextbox.h | 2 | ||||
| -rw-r--r-- | src/cat/LuaWindow.cpp | 4 | ||||
| -rw-r--r-- | src/cat/LuaWindow.h | 2 |
21 files changed, 687 insertions, 142 deletions
diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp index 4d3c0c8..b9afd7e 100644 --- a/src/cat/LegacyLuaAPI.cpp +++ b/src/cat/LegacyLuaAPI.cpp @@ -1,3 +1,4 @@ +#ifdef LUACONSOLE #include <string> #include <iomanip> #include <vector> @@ -691,14 +692,11 @@ char *luacon_geterror(){ lua_pop(luacon_ci->l, 1); return err; } -/*void luacon_close(){ - lua_close(l); -}*/ //TPT Interface methods int luatpt_test(lua_State* l) { - int testint = 0; + int testint = 0; testint = luaL_optint(l, 1, 0); printf("Test successful, got %d\n", testint); return 0; @@ -862,7 +860,7 @@ int luatpt_error(lua_State* l) } int luatpt_drawtext(lua_State* l) { - char *string; + char *string; int textx, texty, textred, textgreen, textblue, textalpha; textx = luaL_optint(l, 1, 0); texty = luaL_optint(l, 2, 0); @@ -915,7 +913,12 @@ int luatpt_create(lua_State* l) int luatpt_setpause(lua_State* l) { int pausestate; - pausestate = luaL_optint(l, 1, 0); + pausestate = luaL_optint(l, 1, -1); + if (pausestate == -1) + { + lua_pushnumber(l, luacon_model->GetPaused()); + return 1; + } luacon_model->SetPaused(pausestate==0?0:1); return 0; } @@ -923,21 +926,27 @@ int luatpt_setpause(lua_State* l) int luatpt_togglepause(lua_State* l) { luacon_model->SetPaused(!luacon_model->GetPaused()); - //sys_pause=!sys_pause; - return 0; + lua_pushnumber(l, luacon_model->GetPaused()); + return 1; } int luatpt_togglewater(lua_State* l) { luacon_sim->water_equal_test=!luacon_sim->water_equal_test; - return 0; + lua_pushnumber(l, luacon_sim->water_equal_test); + return 1; } int luatpt_setconsole(lua_State* l) { int consolestate; - consolestate = luaL_optint(l, 1, 0); - if (consolestate) + consolestate = luaL_optint(l, 1, -1); + if (consolestate == -1) + { + lua_pushnumber(l, luacon_ci->Window != ui::Engine::Ref().GetWindow()); + return 1; + } + else if (consolestate) luacon_controller->ShowConsole(); else luacon_controller->HideConsole(); @@ -1541,11 +1550,13 @@ int luatpt_get_name(lua_State* l) int luatpt_set_shortcuts(lua_State* l) { - int shortcut = luaL_optint(l, 1, 0); - if (shortcut) - shortcuts = true; - else - shortcuts = false; + int shortcut = luaL_optint(l, 1, -1); + if (shortcut == -1) + { + lua_pushnumber(l, shortcuts); + return 1; + } + shortcuts = shortcut?true:false; return 0; } @@ -1739,104 +1750,139 @@ int luatpt_message_box(lua_State* l) { std::string title = std::string(luaL_optstring(l, 1, "Title")); std::string message = std::string(luaL_optstring(l, 2, "Message")); - int large = luaL_optint(l, 1, 0); + int large = lua_toboolean(l, 3); new InformationMessage(title, message, large); return 0; } int luatpt_get_numOfParts(lua_State* l) { - lua_pushinteger(l, luacon_sim->parts_lastActiveIndex); - return 1; + lua_pushinteger(l, luacon_sim->parts_lastActiveIndex); + return 1; } int luatpt_start_getPartIndex(lua_State* l) { - getPartIndex_curIdx = -1; - return 1; + getPartIndex_curIdx = -1; + return 1; } int luatpt_next_getPartIndex(lua_State* l) { - while(1) - { - getPartIndex_curIdx++; - if(getPartIndex_curIdx >= NPART) - { - getPartIndex_curIdx = 0; - lua_pushboolean(l, 0); - return 1; - } - if(luacon_sim->parts[getPartIndex_curIdx].type) - break; + while(1) + { + getPartIndex_curIdx++; + if(getPartIndex_curIdx >= NPART) + { + getPartIndex_curIdx = 0; + lua_pushboolean(l, 0); + return 1; + } + if(luacon_sim->parts[getPartIndex_curIdx].type) + break; - } + } - lua_pushboolean(l, 1); - return 1; + lua_pushboolean(l, 1); + return 1; } int luatpt_getPartIndex(lua_State* l) { - if(getPartIndex_curIdx < 0) - { - lua_pushinteger(l, 0); - return 1; - } - lua_pushinteger(l, getPartIndex_curIdx); - return 1; + if(getPartIndex_curIdx < 0) + { + lua_pushinteger(l, 0); + return 1; + } + lua_pushinteger(l, getPartIndex_curIdx); + return 1; } int luatpt_hud(lua_State* l) { - int hudstate = luaL_optint(l, 1, 0); - if (hudstate) + int hudstate = luaL_optint(l, 1, -1); + if (hudstate == -1) + { + lua_pushinteger(l, luacon_controller->GetHudEnable()); + return 1; + } + else if (hudstate) luacon_controller->SetHudEnable(1); else luacon_controller->SetHudEnable(0); - return 0; + return 0; } int luatpt_gravity(lua_State* l) { - int gravstate; - gravstate = luaL_optint(l, 1, 0); - if(gravstate) - luacon_sim->grav->start_grav_async(); - else - luacon_sim->grav->stop_grav_async(); - return 0; + int gravstate; + gravstate = luaL_optint(l, 1, -1); + if (gravstate == -1) + { + lua_pushinteger(l, luacon_sim->grav->ngrav_enable); + return 1; + } + else if(gravstate) + luacon_sim->grav->start_grav_async(); + else + luacon_sim->grav->stop_grav_async(); + luacon_model->UpdateQuickOptions(); + return 0; } int luatpt_airheat(lua_State* l) { - int aheatstate; - aheatstate = luaL_optint(l, 1, 0); - luacon_sim->aheat_enable = (aheatstate==0?0:1); - return 0; + int aheatstate; + aheatstate = luaL_optint(l, 1, -1); + if (aheatstate == -1) + { + lua_pushinteger(l, luacon_sim->aheat_enable); + return 1; + } + luacon_sim->aheat_enable = (aheatstate==0?0:1); + luacon_model->UpdateQuickOptions(); + return 0; } int luatpt_active_menu(lua_State* l) { - int menuid; - menuid = luaL_optint(l, 1, -1); - if (menuid < SC_TOTAL && menuid >= 0) - luacon_model->SetActiveMenu(luacon_model->GetMenuList()[menuid]); - else - return luaL_error(l, "Invalid menu"); - return 0; + int menuid; + menuid = luaL_optint(l, 1, -1); + if (menuid == -1) + { + lua_pushinteger(l, luacon_model->GetActiveMenu()); + return 1; + } + if (menuid >= 0 && menuid < SC_TOTAL) + luacon_controller->SetActiveMenu(menuid); + else + return luaL_error(l, "Invalid menu"); + return 0; } int luatpt_decorations_enable(lua_State* l) { int decostate; - decostate = luaL_optint(l, 1, 0); + decostate = luaL_optint(l, 1, -1); + if (decostate == -1) + { + lua_pushinteger(l, luacon_model->GetDecoration()); + return 1; + } luacon_model->SetDecoration(decostate==0?false:true); + luacon_model->UpdateQuickOptions(); return 0; } int luatpt_heat(lua_State* l) { int heatstate; - heatstate = luaL_optint(l, 1, 0); + heatstate = luaL_optint(l, 1, -1); + if (heatstate == -1) + { + lua_pushinteger(l, luacon_sim->legacy_enable); + return 1; + } luacon_sim->legacy_enable = (heatstate==1?0:1); return 0; } int luatpt_cmode_set(lua_State* l) { - int cmode = luaL_optint(l, 1, 0)+1; + int cmode = luaL_optint(l, 1, 3)+1; + if (cmode == 11) + cmode = 0; if (cmode >= 0 && cmode <= 10) luacon_controller->LoadRenderPreset(cmode); else @@ -1857,8 +1903,13 @@ int luatpt_setdebug(lua_State* l) } int luatpt_setfpscap(lua_State* l) { - int fpscap = luaL_optint(l, 1, 0); - if (fpscap < 2) + int fpscap = luaL_optint(l, 1, -1); + if (fpscap == -1) + { + lua_pushinteger(l, ui::Engine::Ref().FpsLimit); + return 1; + } + else if (fpscap < 2) return luaL_error(l, "fps cap too small"); ui::Engine::Ref().FpsLimit = fpscap; return 0; @@ -1937,7 +1988,7 @@ int luatpt_getscript(lua_State* l) luacommand = new char[strlen(filename)+20]; sprintf(luacommand,"dofile(\"%s\")",filename); luaL_dostring (l, luacommand); - } + } fin: if(filedata) free(filedata); @@ -1983,4 +2034,4 @@ int luatpt_screenshot(lua_State* l) Client::Ref().WriteFile(data, filename.str()); return 0; } - +#endif diff --git a/src/cat/LuaBit.cpp b/src/cat/LuaBit.cpp index c55f45a..f1479d0 100644 --- a/src/cat/LuaBit.cpp +++ b/src/cat/LuaBit.cpp @@ -1,3 +1,4 @@ +#ifdef LUACONSOLE /* ** Lua BitOp -- a bit operations library for Lua 5.1/5.2. ** http://bitop.luajit.org/ @@ -189,4 +190,4 @@ int luaopen_bit(lua_State *L) #endif return 1; } - +#endif diff --git a/src/cat/LuaButton.cpp b/src/cat/LuaButton.cpp index 013adac..1b55f89 100644 --- a/src/cat/LuaButton.cpp +++ b/src/cat/LuaButton.cpp @@ -1,3 +1,4 @@ +#ifdef LUACONSOLE extern "C" { #include "lua.h" @@ -111,4 +112,5 @@ void LuaButton::triggerAction() LuaButton::~LuaButton() { -}
\ No newline at end of file +} +#endif diff --git a/src/cat/LuaButton.h b/src/cat/LuaButton.h index 012779d..69a77a4 100644 --- a/src/cat/LuaButton.h +++ b/src/cat/LuaButton.h @@ -30,4 +30,4 @@ public: LuaButton(lua_State * l); ~LuaButton(); -};
\ No newline at end of file +}; diff --git a/src/cat/LuaCheckbox.cpp b/src/cat/LuaCheckbox.cpp index bac5c4e..55c39db 100644 --- a/src/cat/LuaCheckbox.cpp +++ b/src/cat/LuaCheckbox.cpp @@ -1,3 +1,4 @@ +#ifdef LUACONSOLE extern "C" { #include "lua.h" @@ -109,4 +110,5 @@ void LuaCheckbox::triggerAction() LuaCheckbox::~LuaCheckbox() { -}
\ No newline at end of file +} +#endif diff --git a/src/cat/LuaCheckbox.h b/src/cat/LuaCheckbox.h index 479cab2..0f2e8ad 100644 --- a/src/cat/LuaCheckbox.h +++ b/src/cat/LuaCheckbox.h @@ -30,4 +30,4 @@ public: LuaCheckbox(lua_State * l); ~LuaCheckbox(); -};
\ No newline at end of file +}; diff --git a/src/cat/LuaComponent.cpp b/src/cat/LuaComponent.cpp index 75e7a21..028dfb5 100644 --- a/src/cat/LuaComponent.cpp +++ b/src/cat/LuaComponent.cpp @@ -1,3 +1,4 @@ +#ifdef LUACONSOLE extern "C" { #include "lua.h" @@ -79,4 +80,5 @@ LuaComponent::~LuaComponent() if(component->GetParentWindow()) component->GetParentWindow()->RemoveComponent(component); delete component; -}
\ No newline at end of file +} +#endif diff --git a/src/cat/LuaComponent.h b/src/cat/LuaComponent.h index 9e11b12..8e40890 100644 --- a/src/cat/LuaComponent.h +++ b/src/cat/LuaComponent.h @@ -30,4 +30,4 @@ public: ui::Component * GetComponent() { return component; } LuaComponent(lua_State * l); ~LuaComponent(); -};
\ No newline at end of file +}; diff --git a/src/cat/LuaLabel.cpp b/src/cat/LuaLabel.cpp index b08e687..4131918 100644 --- a/src/cat/LuaLabel.cpp +++ b/src/cat/LuaLabel.cpp @@ -1,3 +1,4 @@ +#ifdef LUACONSOLE extern "C" { #include "lua.h" @@ -52,4 +53,5 @@ int LuaLabel::text(lua_State * l) LuaLabel::~LuaLabel() { -}
\ No newline at end of file +} +#endif diff --git a/src/cat/LuaLabel.h b/src/cat/LuaLabel.h index a80ea4f..2653d9c 100644 --- a/src/cat/LuaLabel.h +++ b/src/cat/LuaLabel.h @@ -26,4 +26,4 @@ public: LuaLabel(lua_State * l); ~LuaLabel(); -};
\ No newline at end of file +}; diff --git a/src/cat/LuaLuna.h b/src/cat/LuaLuna.h index 1d5d937..9fa4042 100644 --- a/src/cat/LuaLuna.h +++ b/src/cat/LuaLuna.h @@ -157,4 +157,4 @@ private: lua_pushfstring(L, "%s (%s)", T::className, buff); return 1; } -};
\ No newline at end of file +}; diff --git a/src/cat/LuaProgressBar.cpp b/src/cat/LuaProgressBar.cpp index 08c88ca..787cfcf 100644 --- a/src/cat/LuaProgressBar.cpp +++ b/src/cat/LuaProgressBar.cpp @@ -1,3 +1,4 @@ +#ifdef LUACONSOLE extern "C" { #include "lua.h" @@ -68,4 +69,5 @@ int LuaProgressBar::status(lua_State * l) LuaProgressBar::~LuaProgressBar() { -}
\ No newline at end of file +} +#endif diff --git a/src/cat/LuaProgressBar.h b/src/cat/LuaProgressBar.h index 9de56e7..a27ddee 100644 --- a/src/cat/LuaProgressBar.h +++ b/src/cat/LuaProgressBar.h @@ -27,4 +27,4 @@ public: LuaProgressBar(lua_State * l); ~LuaProgressBar(); -};
\ No newline at end of file +}; diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index 4b2e749..bce6012 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -1,3 +1,4 @@ +#ifdef LUACONSOLE #include <string> #include <iomanip> #include <vector> @@ -14,6 +15,7 @@ #include "gui/dialogues/TextPrompt.h" #include "gui/dialogues/ConfirmPrompt.h" #include "simulation/Simulation.h" +#include "ToolClasses.h" #include "gui/game/GameModel.h" #include "gui/game/Tool.h" #include "LuaScriptHelper.h" @@ -446,6 +448,27 @@ 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}, + {"toolBrush", simulation_toolBrush}, + {"toolLine", simulation_toolLine}, + {"toolBox", simulation_toolBox}, + {"decoBrush", simulation_decoBrush}, + {"decoLine", simulation_decoLine}, + {"decoBox", simulation_decoBox}, + {"decoColor", simulation_decoColor}, + {"decoColour", simulation_decoColor}, + {"clearSim", simulation_clearSim}, + {"saveStamp", simulation_saveStamp}, + {"loadStamp", simulation_loadStamp}, + {"loadSave", simulation_loadSave}, + {"adjustCoords", simulation_adjustCoords}, {NULL, NULL} }; luaL_register(l, "simulation", simulationAPIMethods); @@ -464,6 +487,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, TOOL_HEAT); lua_setfield(l, simulationAPI, "TOOL_HEAT"); + lua_pushinteger(l, TOOL_COOL); lua_setfield(l, simulationAPI, "TOOL_COOL"); + lua_pushinteger(l, TOOL_VAC); lua_setfield(l, simulationAPI, "TOOL_VAC"); + lua_pushinteger(l, TOOL_AIR); lua_setfield(l, simulationAPI, "TOOL_AIR"); + lua_pushinteger(l, TOOL_PGRV); lua_setfield(l, simulationAPI, "TOOL_PGRV"); + lua_pushinteger(l, TOOL_NGRV); 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; @@ -913,6 +950,374 @@ 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,0); + + 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]); + brushList[brush]->SetRadius(tempRadius); + lua_pushinteger(l, ret); + 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,0); + + 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]); + brushList[brush]->SetRadius(tempRadius); + 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,0); + + luacon_sim->CreateBox(x1, y1, x2, y2, c, flags); + 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); + int ret = luacon_sim->FloodParts(x, y, c, cm, bm, flags); + 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,0); + int ry = luaL_optint(l,4,0); + int c = luaL_optint(l,5,8); + int flags = luaL_optint(l,6,0); + 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, flags); + 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,0); + int ry = luaL_optint(l,6,0); + int c = luaL_optint(l,7,8); + int flags = luaL_optint(l,8,0); + 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, flags); + 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,8); + int flags = luaL_optint(l,6,0); + if (c < 0 || c >= UI_WALLCOUNT) + return luaL_error(l, "Unrecognised wall id '%d'", c); + + luacon_sim->CreateWallBox(x1, y1, x2, y2, c, flags); + 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,8); + int cm = luaL_optint(l,4,-1); + int bm = luaL_optint(l,5,-1); + int flags = luaL_optint(l,6,0); + 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, flags); + lua_pushinteger(l, ret); + 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); + + 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); + + 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); + + luacon_sim->ApplyDecorationBox(x1, y1, x2, y2, r, g, b, a, tool); + return 0; +} + +int LuaScriptInterface::simulation_decoColor(lua_State * l) +{ + int acount = lua_gettop(l); + unsigned int color; + if (acount == 0) + { + ui::Colour tempColor = luacon_model->GetColourSelectorColour(); + unsigned int color = (tempColor.Alpha << 24) | PIXRGB(tempColor.Red, tempColor.Green, tempColor.Blue); + lua_pushnumber(l, color); + return 1; + } + else if (acount == 1) + color = (unsigned int)luaL_optnumber(l, 1, 0xFFFF0000); + else + { + int r, g, b, a; + r = luaL_optint(l, 1, 255); + g = luaL_optint(l, 2, 255); + b = luaL_optint(l, 3, 255); + a = luaL_optint(l, 4, 255); + + if (r < 0) r = 0; if (r > 255) r = 255; + if (g < 0) g = 0; if (g > 255) g = 255; + if (b < 0) b = 0; if (b > 255) b = 255; + if (a < 0) a = 0; if (a > 255) a = 255; + + color = (a << 24) + PIXRGB(r, g, b); + } + luacon_model->SetColourSelectorColour(ui::Colour(PIXR(color), PIXG(color), PIXB(color), color >> 24)); + return 0; +} + +int LuaScriptInterface::simulation_clearSim(lua_State * l) +{ + luacon_sim->clear_sim(); + return 0; +} + +int LuaScriptInterface::simulation_saveStamp(lua_State * l) +{ + int x = luaL_optint(l,1,0); + int y = luaL_optint(l,2,0); + int w = luaL_optint(l,3,XRES-1); + int h = luaL_optint(l,4,YRES-1); + std::string name = luacon_controller->StampRegion(ui::Point(x, y), ui::Point(x+w, y+h)); + lua_pushstring(l, name.c_str()); + return 1; +} + +int LuaScriptInterface::simulation_loadStamp(lua_State * l) +{ + int stamp_size, i = -1, j, x, y, ret; + SaveFile * tempfile; + x = luaL_optint(l,2,0); + y = luaL_optint(l,3,0); + if (lua_isnumber(l, 1)) //Load from stamp ID + { + i = luaL_optint(l, 1, 0); + int stampCount = Client::Ref().GetStampsCount(); + if (i < 0 || i >= stampCount) + return luaL_error(l, "Invalid stamp ID: %d", i); + tempfile = Client::Ref().GetStamp(Client::Ref().GetStamps(0, stampCount)[i]); + } + else //Load from 10 char name, or full filename + { + char * filename = (char*)luaL_optstring(l, 1, ""); + tempfile = Client::Ref().GetStamp(filename); + } + if (tempfile) + { + if (luacon_sim->Load(x, y, tempfile->GetGameSave())) + { + //luacon_sim->sys_pause = (tempfile->GetGameSave()->paused | luacon_model->GetPaused())?1:0; + lua_pushinteger(l, 1); + } + else + lua_pushnil(l); + } + else + lua_pushnil(l); + return 1; +} + +int LuaScriptInterface::simulation_loadSave(lua_State * l) +{ + int saveID = luaL_optint(l,1,0); + int history = luaL_optint(l,2,0); //Exact second a previous save was saved + luacon_controller->OpenSavePreview(saveID, history); + return 0; +} + +int LuaScriptInterface::simulation_adjustCoords(lua_State * l) +{ + int x = luaL_optint(l,1,0); + int y = luaL_optint(l,2,0); + ui::Point Coords = luacon_controller->PointTranslate(ui::Point(x, y)); + lua_pushinteger(l, Coords.X); + lua_pushinteger(l, Coords.Y); + return 2; +} + + //// Begin Renderer API void LuaScriptInterface::initRendererAPI() @@ -1694,6 +2099,8 @@ void LuaScriptInterface::initGraphicsAPI() {"drawLine", graphics_drawLine}, {"drawRect", graphics_drawRect}, {"fillRect", graphics_fillRect}, + {"drawCircle", graphics_drawCircle}, + {"fillCircle", graphics_fillCircle}, {NULL, NULL} }; luaL_register(l, "graphics", graphicsAPIMethods); @@ -1722,24 +2129,22 @@ int LuaScriptInterface::graphics_textSize(lua_State * l) int LuaScriptInterface::graphics_drawText(lua_State * l) { - char * text; - int x, y, r, g, b, a; - x = lua_tointeger(l, 1); - y = lua_tointeger(l, 2); - text = (char*)lua_tostring(l, 3); - r = luaL_optint(l, 4, 255); - g = luaL_optint(l, 5, 255); - b = luaL_optint(l, 6, 255); - a = luaL_optint(l, 7, 255); + int x = lua_tointeger(l, 1); + int y = lua_tointeger(l, 2); + char * text = (char*)lua_tostring(l, 3); + int r = luaL_optint(l, 4, 255); + int g = luaL_optint(l, 5, 255); + int b = luaL_optint(l, 6, 255); + int a = luaL_optint(l, 7, 255); if (r<0) r = 0; - if (r>255) r = 255; + else if (r>255) r = 255; if (g<0) g = 0; - if (g>255) g = 255; + else if (g>255) g = 255; if (b<0) b = 0; - if (b>255) b = 255; + else if (b>255) b = 255; if (a<0) a = 0; - if (a>255) a = 255; + else if (a>255) a = 255; luacon_g->drawtext(x, y, text, r, g, b, a); return 0; @@ -1747,73 +2152,121 @@ int LuaScriptInterface::graphics_drawText(lua_State * l) int LuaScriptInterface::graphics_drawLine(lua_State * l) { - int x1, y1, x2, y2, r, g, b, a; - x1 = lua_tointeger(l, 1); - y1 = lua_tointeger(l, 2); - x2 = lua_tointeger(l, 3); - y2 = lua_tointeger(l, 4); - r = luaL_optint(l, 5, 255); - g = luaL_optint(l, 6, 255); - b = luaL_optint(l, 7, 255); - a = luaL_optint(l, 8, 255); + int x1 = lua_tointeger(l, 1); + int y1 = lua_tointeger(l, 2); + int x2 = lua_tointeger(l, 3); + int y2 = lua_tointeger(l, 4); + 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); if (r<0) r = 0; - if (r>255) r = 255; + else if (r>255) r = 255; if (g<0) g = 0; - if (g>255) g = 255; + else if (g>255) g = 255; if (b<0) b = 0; - if (b>255) b = 255; + else if (b>255) b = 255; if (a<0) a = 0; - if (a>255) a = 255; + else if (a>255) a = 255; + luacon_g->draw_line(x1, y1, x2, y2, r, g, b, a); return 0; } int LuaScriptInterface::graphics_drawRect(lua_State * l) { - int x, y, w, h, r, g, b, a; - x = lua_tointeger(l, 1); - y = lua_tointeger(l, 2); - w = lua_tointeger(l, 3); - h = lua_tointeger(l, 4); - r = luaL_optint(l, 5, 255); - g = luaL_optint(l, 6, 255); - b = luaL_optint(l, 7, 255); - a = luaL_optint(l, 8, 255); + int x = lua_tointeger(l, 1); + int y = lua_tointeger(l, 2); + int width = lua_tointeger(l, 3); + int height = lua_tointeger(l, 4); + 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); if (r<0) r = 0; - if (r>255) r = 255; + else if (r>255) r = 255; if (g<0) g = 0; - if (g>255) g = 255; + else if (g>255) g = 255; if (b<0) b = 0; - if (b>255) b = 255; + else if (b>255) b = 255; if (a<0) a = 0; - if (a>255) a = 255; - luacon_g->drawrect(x, y, w, h, r, g, b, a); + else if (a>255) a = 255; + + luacon_g->drawrect(x, y, width, height, r, g, b, a); return 0; } int LuaScriptInterface::graphics_fillRect(lua_State * l) { - int x, y, w, h, r, g, b, a; - x = lua_tointeger(l, 1); - y = lua_tointeger(l, 2); - w = lua_tointeger(l, 3); - h = lua_tointeger(l, 4); - r = luaL_optint(l, 5, 255); - g = luaL_optint(l, 6, 255); - b = luaL_optint(l, 7, 255); - a = luaL_optint(l, 8, 255); + int x = lua_tointeger(l, 1); + int y = lua_tointeger(l, 2); + int width = lua_tointeger(l, 3); + int height = lua_tointeger(l, 4); + 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); + + if (r<0) r = 0; + else if (r>255) r = 255; + if (g<0) g = 0; + else if (g>255) g = 255; + if (b<0) b = 0; + else if (b>255) b = 255; + if (a<0) a = 0; + else if (a>255) a = 255; + + luacon_g->fillrect(x, y, width, height, r, g, b, a); + return 0; +} + +int LuaScriptInterface::graphics_drawCircle(lua_State * l) +{ + int x = lua_tointeger(l, 1); + int y = lua_tointeger(l, 2); + int rx = lua_tointeger(l, 3); + int ry = lua_tointeger(l, 4); + 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); + + if (r<0) r = 0; + else if (r>255) r = 255; + if (g<0) g = 0; + else if (g>255) g = 255; + if (b<0) b = 0; + else if (b>255) b = 255; + if (a<0) a = 0; + else if (a>255) a = 255; + + luacon_g->drawcircle(x, y, abs(rx), abs(ry), r, g, b, a); + return 0; +} + +int LuaScriptInterface::graphics_fillCircle(lua_State * l) +{ + int x = lua_tointeger(l, 1); + int y = lua_tointeger(l, 2); + int rx = lua_tointeger(l, 3); + int ry = lua_tointeger(l, 4); + 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); if (r<0) r = 0; - if (r>255) r = 255; + else if (r>255) r = 255; if (g<0) g = 0; - if (g>255) g = 255; + else if (g>255) g = 255; if (b<0) b = 0; - if (b>255) b = 255; + else if (b>255) b = 255; if (a<0) a = 0; - if (a>255) a = 255; - luacon_g->fillrect(x, y, w, h, r, g, b, a); + else if (a>255) a = 255; + + luacon_g->fillcircle(x, y, abs(rx), abs(ry), r, g, b, a); return 0; } @@ -2199,5 +2652,7 @@ std::string LuaScriptInterface::FormatCommand(std::string command) } LuaScriptInterface::~LuaScriptInterface() { + lua_close(l); delete legacy; } +#endif diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h index 0b9f6f3..0c868d3 100644 --- a/src/cat/LuaScriptInterface.h +++ b/src/cat/LuaScriptInterface.h @@ -64,6 +64,26 @@ 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_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_decoColor(lua_State * l); + static int simulation_clearSim(lua_State * l); + static int simulation_saveStamp(lua_State * l); + static int simulation_loadStamp(lua_State * l); + static int simulation_loadSave(lua_State * l); + static int simulation_adjustCoords(lua_State * l); //Renderer void initRendererAPI(); @@ -100,6 +120,8 @@ class LuaScriptInterface: public CommandInterface static int graphics_drawLine(lua_State * l); static int graphics_drawRect(lua_State * l); static int graphics_fillRect(lua_State * l); + static int graphics_drawCircle(lua_State * l); + static int graphics_fillCircle(lua_State * l); void initFileSystemAPI(); static int fileSystem_list(lua_State * l); diff --git a/src/cat/LuaSlider.cpp b/src/cat/LuaSlider.cpp index ce07ebb..f8505d2 100644 --- a/src/cat/LuaSlider.cpp +++ b/src/cat/LuaSlider.cpp @@ -1,3 +1,4 @@ +#ifdef LUACONSOLE extern "C" { #include "lua.h" @@ -109,4 +110,5 @@ void LuaSlider::triggerOnValueChanged() LuaSlider::~LuaSlider() { -}
\ No newline at end of file +} +#endif diff --git a/src/cat/LuaSlider.h b/src/cat/LuaSlider.h index f9f327e..a1a97c4 100644 --- a/src/cat/LuaSlider.h +++ b/src/cat/LuaSlider.h @@ -30,4 +30,4 @@ public: LuaSlider(lua_State * l); ~LuaSlider(); -};
\ No newline at end of file +}; diff --git a/src/cat/LuaTextbox.cpp b/src/cat/LuaTextbox.cpp index 5721525..89191a6 100644 --- a/src/cat/LuaTextbox.cpp +++ b/src/cat/LuaTextbox.cpp @@ -1,3 +1,4 @@ +#ifdef LUACONSOLE extern "C" { #include "lua.h" @@ -112,4 +113,5 @@ int LuaTextbox::text(lua_State * l) LuaTextbox::~LuaTextbox() { -}
\ No newline at end of file +} +#endif diff --git a/src/cat/LuaTextbox.h b/src/cat/LuaTextbox.h index 437875f..9a45f61 100644 --- a/src/cat/LuaTextbox.h +++ b/src/cat/LuaTextbox.h @@ -30,4 +30,4 @@ public: LuaTextbox(lua_State * l); ~LuaTextbox(); -};
\ No newline at end of file +}; diff --git a/src/cat/LuaWindow.cpp b/src/cat/LuaWindow.cpp index d765d68..84e32e1 100644 --- a/src/cat/LuaWindow.cpp +++ b/src/cat/LuaWindow.cpp @@ -1,3 +1,4 @@ +#ifdef LUACONSOLE extern "C" { #include "lua.h" @@ -590,4 +591,5 @@ LuaWindow::~LuaWindow() if(ui::Engine::Ref().GetWindow() == window) ui::Engine::Ref().CloseWindow(); delete window; -}
\ No newline at end of file +} +#endif diff --git a/src/cat/LuaWindow.h b/src/cat/LuaWindow.h index f48c5f9..187b3dd 100644 --- a/src/cat/LuaWindow.h +++ b/src/cat/LuaWindow.h @@ -79,4 +79,4 @@ public: ui::Window * GetWindow() { return window; } LuaWindow(lua_State * l); ~LuaWindow(); -};
\ No newline at end of file +}; |
