finish return values for the legacy api, add sim.saveStamp and sim.loadStamp

This commit is contained in:
jacob1 2013-05-15 13:51:45 -04:00
parent 94d21a1679
commit dfc33aaeea
8 changed files with 77 additions and 14 deletions

View File

@ -1854,7 +1854,12 @@ int luatpt_active_menu(lua_State* l)
int luatpt_decorations_enable(lua_State* l) int luatpt_decorations_enable(lua_State* l)
{ {
int decostate; 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->SetDecoration(decostate==0?false:true);
luacon_model->UpdateQuickOptions(); luacon_model->UpdateQuickOptions();
return 0; return 0;
@ -1863,14 +1868,19 @@ int luatpt_decorations_enable(lua_State* l)
int luatpt_heat(lua_State* l) int luatpt_heat(lua_State* l)
{ {
int heatstate; 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); luacon_sim->legacy_enable = (heatstate==1?0:1);
return 0; return 0;
} }
int luatpt_cmode_set(lua_State* l) 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) if (cmode == 11)
cmode = 0; cmode = 0;
if (cmode >= 0 && cmode <= 10) if (cmode >= 0 && cmode <= 10)
@ -1893,8 +1903,13 @@ int luatpt_setdebug(lua_State* l)
} }
int luatpt_setfpscap(lua_State* l) int luatpt_setfpscap(lua_State* l)
{ {
int fpscap = luaL_optint(l, 1, 0); int fpscap = luaL_optint(l, 1, -1);
if (fpscap < 2) if (fpscap == -1)
{
lua_pushinteger(l, ui::Engine::Ref().FpsLimit);
return 1;
}
else if (fpscap < 2)
return luaL_error(l, "fps cap too small"); return luaL_error(l, "fps cap too small");
ui::Engine::Ref().FpsLimit = fpscap; ui::Engine::Ref().FpsLimit = fpscap;
return 0; return 0;

View File

@ -456,6 +456,8 @@ void LuaScriptInterface::initSimulationAPI()
{"createWallBox", simulation_createWallBox}, {"createWallBox", simulation_createWallBox},
{"floodWalls", simulation_floodWalls}, {"floodWalls", simulation_floodWalls},
{"clearSim", simulation_clearSim}, {"clearSim", simulation_clearSim},
{"saveStamp", simulation_saveStamp},
{"loadStamp", simulation_loadStamp},
{NULL, NULL} {NULL, NULL}
}; };
luaL_register(l, "simulation", simulationAPIMethods); luaL_register(l, "simulation", simulationAPIMethods);
@ -1094,6 +1096,47 @@ int LuaScriptInterface::simulation_clearSim(lua_State * l)
return 0; 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);
int h = luaL_optint(l,4,YRES);
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)
{
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);
return 1;
}
//// Begin Renderer API //// Begin Renderer API

View File

@ -73,6 +73,8 @@ class LuaScriptInterface: public CommandInterface
static int simulation_createWallBox(lua_State * l); static int simulation_createWallBox(lua_State * l);
static int simulation_floodWalls(lua_State * l); static int simulation_floodWalls(lua_State * l);
static int simulation_clearSim(lua_State * l); static int simulation_clearSim(lua_State * l);
static int simulation_saveStamp(lua_State * l);
static int simulation_loadStamp(lua_State * l);
//Renderer //Renderer
void initRendererAPI(); void initRendererAPI();

View File

@ -949,6 +949,8 @@ void Client::MoveStampToFront(std::string stampID)
SaveFile * Client::GetStamp(std::string stampID) SaveFile * Client::GetStamp(std::string stampID)
{ {
std::string stampFile = std::string(STAMPS_DIR PATH_SEP + stampID + ".stm"); std::string stampFile = std::string(STAMPS_DIR PATH_SEP + stampID + ".stm");
if (!FileExists(stampFile))
stampFile = stampID;
if(FileExists(stampFile)) if(FileExists(stampFile))
{ {
SaveFile * file = new SaveFile(stampID); SaveFile * file = new SaveFile(stampID);

View File

@ -509,17 +509,20 @@ void GameController::ToolClick(int toolSelection, ui::Point point)
activeTool->Click(sim, cBrush, point); activeTool->Click(sim, cBrush, point);
} }
void GameController::StampRegion(ui::Point point1, ui::Point point2) std::string GameController::StampRegion(ui::Point point1, ui::Point point2)
{ {
GameSave * newSave; GameSave * newSave;
newSave = gameModel->GetSimulation()->Save(point1.X, point1.Y, point2.X, point2.Y); newSave = gameModel->GetSimulation()->Save(point1.X, point1.Y, point2.X, point2.Y);
if(newSave) if(newSave)
{ {
newSave->paused = gameModel->GetPaused(); newSave->paused = gameModel->GetPaused();
gameModel->AddStamp(newSave); return gameModel->AddStamp(newSave);
} }
else else
{
new ErrorMessage("Could not create stamp", "Error generating save file"); new ErrorMessage("Could not create stamp", "Error generating save file");
return "";
}
} }
void GameController::CopyRegion(ui::Point point1, ui::Point point2) void GameController::CopyRegion(ui::Point point1, ui::Point point2)

View File

@ -90,7 +90,7 @@ public:
void DrawRect(int toolSelection, ui::Point point1, ui::Point point2); void DrawRect(int toolSelection, ui::Point point1, ui::Point point2);
void DrawLine(int toolSelection, ui::Point point1, ui::Point point2); void DrawLine(int toolSelection, ui::Point point1, ui::Point point2);
void DrawFill(int toolSelection, ui::Point point); void DrawFill(int toolSelection, ui::Point point);
void StampRegion(ui::Point point1, ui::Point point2); std::string StampRegion(ui::Point point1, ui::Point point2);
void CopyRegion(ui::Point point1, ui::Point point2); void CopyRegion(ui::Point point1, ui::Point point2);
void CutRegion(ui::Point point1, ui::Point point2); void CutRegion(ui::Point point1, ui::Point point2);
void Update(); void Update();

View File

@ -348,10 +348,8 @@ void GameModel::BuildMenus()
//Set default menu //Set default menu
activeMenu = SC_POWDERS; activeMenu = SC_POWDERS;
if(lastMenu != -1) //What is this? ... if(lastMenu != -1)
{
activeMenu = lastMenu; activeMenu = lastMenu;
}
if(activeMenu != -1) if(activeMenu != -1)
toolList = menuList[activeMenu]->GetToolList(); toolList = menuList[activeMenu]->GetToolList();
@ -882,12 +880,12 @@ void GameModel::SetPlaceSave(GameSave * save)
notifyPlaceSaveChanged(); notifyPlaceSaveChanged();
} }
void GameModel::AddStamp(GameSave * save) std::string GameModel::AddStamp(GameSave * save)
{ {
if(stamp) if(stamp)
delete stamp; delete stamp;
stamp = save; stamp = save;
Client::Ref().AddStamp(save); return Client::Ref().AddStamp(save);
} }
void GameModel::SetClipboard(GameSave * save) void GameModel::SetClipboard(GameSave * save)

View File

@ -186,7 +186,7 @@ public:
void SetZoomWindowPosition(ui::Point position); void SetZoomWindowPosition(ui::Point position);
ui::Point GetZoomWindowPosition(); ui::Point GetZoomWindowPosition();
void SetStamp(GameSave * newStamp); void SetStamp(GameSave * newStamp);
void AddStamp(GameSave * save); std::string AddStamp(GameSave * save);
void SetClipboard(GameSave * save); void SetClipboard(GameSave * save);
void SetPlaceSave(GameSave * save); void SetPlaceSave(GameSave * save);
void Log(string message); void Log(string message);