Permalink
Browse files

hold shift when saving or loading stamps to not save / load pressure, c…

…loses #491
  • Loading branch information...
jacob1 committed Aug 3, 2017
1 parent 99c568f commit 6931f3552018786734ff0ef3ef8d56b796b4d4cc
@@ -327,13 +327,13 @@ std::string GameController::GetSignText(int signID)
return gameModel->GetSimulation()->signs[signID].text;
}
void GameController::PlaceSave(ui::Point position)
void GameController::PlaceSave(ui::Point position, bool includePressure)
{
GameSave *placeSave = gameModel->GetPlaceSave();
if (placeSave)
{
HistorySnapshot();
if (!gameModel->GetSimulation()->Load(position.X, position.Y, placeSave))
if (!gameModel->GetSimulation()->Load(position.X, position.Y, placeSave, includePressure))
{
gameModel->SetPaused(placeSave->paused | gameModel->GetPaused());
Client::Ref().MergeStampAuthorInfo(placeSave->authors);
@@ -567,10 +567,10 @@ void GameController::ToolClick(int toolSelection, ui::Point point)
activeTool->Click(sim, cBrush, point);
}
std::string GameController::StampRegion(ui::Point point1, ui::Point point2)
std::string GameController::StampRegion(ui::Point point1, ui::Point point2, bool includePressure)
{
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, includePressure);
if(newSave)
{
newSave->paused = gameModel->GetPaused();
@@ -586,10 +586,10 @@ std::string GameController::StampRegion(ui::Point point1, ui::Point point2)
}
}
void GameController::CopyRegion(ui::Point point1, ui::Point point2)
void GameController::CopyRegion(ui::Point point1, ui::Point point2, bool includePressure)
{
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, includePressure);
if(newSave)
{
Json::Value clipboardInfo;
@@ -604,9 +604,9 @@ void GameController::CopyRegion(ui::Point point1, ui::Point point2)
}
}
void GameController::CutRegion(ui::Point point1, ui::Point point2)
void GameController::CutRegion(ui::Point point1, ui::Point point2, bool includePressure)
{
CopyRegion(point1, point2);
CopyRegion(point1, point2, includePressure);
gameModel->GetSimulation()->clear_area(point1.X, point1.Y, point2.X-point1.X, point2.Y-point1.Y);
}
@@ -89,9 +89,9 @@ class GameController: public ClientListener
void DrawRect(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);
std::string StampRegion(ui::Point point1, ui::Point point2);
void CopyRegion(ui::Point point1, ui::Point point2);
void CutRegion(ui::Point point1, ui::Point point2);
std::string StampRegion(ui::Point point1, ui::Point point2, bool includePressure);
void CopyRegion(ui::Point point1, ui::Point point2, bool includePressure);
void CutRegion(ui::Point point1, ui::Point point2, bool includePressure);
void Update();
void SetPaused(bool pauseState);
void SetPaused();
@@ -133,7 +133,7 @@ class GameController: public ClientListener
void OpenStamps();
void OpenElementSearch();
void OpenColourPicker();
void PlaceSave(ui::Point position);
void PlaceSave(ui::Point position, bool includePressure);
void ClearSim();
void ReloadSim();
void Vote(int direction);
@@ -1253,7 +1253,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
if (thumbY+(placeSaveThumb->Height) >= YRES)
thumbY = YRES-placeSaveThumb->Height;
c->PlaceSave(ui::Point(thumbX, thumbY));
c->PlaceSave(ui::Point(thumbX, thumbY), !shiftBehaviour);
}
}
else
@@ -1263,11 +1263,11 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
int x1 = (selectPoint2.X<selectPoint1.X) ? selectPoint2.X : selectPoint1.X;
int y1 = (selectPoint2.Y<selectPoint1.Y) ? selectPoint2.Y : selectPoint1.Y;
if (selectMode ==SelectCopy)
c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2));
c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2), !shiftBehaviour);
else if (selectMode == SelectCut)
c->CutRegion(ui::Point(x1, y1), ui::Point(x2, y2));
c->CutRegion(ui::Point(x1, y1), ui::Point(x2, y2), !shiftBehaviour);
else if (selectMode == SelectStamp)
c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2));
c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2), !shiftBehaviour);
}
}
selectMode = SelectNone;
@@ -1680,17 +1680,19 @@ int LuaScriptInterface::simulation_saveStamp(lua_State * l)
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));
int includePressure = luaL_optint(l,5,1);
std::string name = luacon_controller->StampRegion(ui::Point(x, y), ui::Point(x+w, y+h), includePressure);
lua_pushstring(l, name.c_str());
return 1;
}
int LuaScriptInterface::simulation_loadStamp(lua_State * l)
{
int i = -1, x, y;
int i = -1;
SaveFile * tempfile = NULL;
x = luaL_optint(l,2,0);
y = luaL_optint(l,3,0);
int x = luaL_optint(l,2,0);
int y = luaL_optint(l,3,0);
int includePressure = luaL_optint(l,4,1);
if (lua_isstring(l, 1)) //Load from 10 char name, or full filename
{
const char * filename = luaL_optstring(l, 1, "");
@@ -1707,7 +1709,7 @@ int LuaScriptInterface::simulation_loadStamp(lua_State * l)
if (tempfile)
{
if (!luacon_sim->Load(x, y, tempfile->GetGameSave()))
if (!luacon_sim->Load(x, y, tempfile->GetGameSave(), includePressure))
{
//luacon_sim->sys_pause = (tempfile->GetGameSave()->paused | luacon_model->GetPaused())?1:0;
lua_pushinteger(l, 1);
@@ -26,12 +26,12 @@
#include "lua/LuaScriptHelper.h"
#endif
int Simulation::Load(GameSave * save)
int Simulation::Load(GameSave * save, bool includePressure)
{
return Load(0, 0, save);
return Load(0, 0, save, includePressure);
}
int Simulation::Load(int fullX, int fullY, GameSave * save)
int Simulation::Load(int fullX, int fullY, GameSave * save, bool includePressure)
{
int blockX, blockY, x, y, r;
@@ -207,11 +207,14 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
fvx[saveBlockY+blockY][saveBlockX+blockX] = save->fanVelX[saveBlockY][saveBlockX];
fvy[saveBlockY+blockY][saveBlockX+blockX] = save->fanVelY[saveBlockY][saveBlockX];
}
pv[saveBlockY+blockY][saveBlockX+blockX] = save->pressure[saveBlockY][saveBlockX];
vx[saveBlockY+blockY][saveBlockX+blockX] = save->velocityX[saveBlockY][saveBlockX];
vy[saveBlockY+blockY][saveBlockX+blockX] = save->velocityY[saveBlockY][saveBlockX];
if (save->hasAmbientHeat)
hv[saveBlockY+blockY][saveBlockX+blockX] = save->ambientHeat[saveBlockY][saveBlockX];
if (includePressure)
{
pv[saveBlockY+blockY][saveBlockX+blockX] = save->pressure[saveBlockY][saveBlockX];
vx[saveBlockY+blockY][saveBlockX+blockX] = save->velocityX[saveBlockY][saveBlockX];
vy[saveBlockY+blockY][saveBlockX+blockX] = save->velocityY[saveBlockY][saveBlockX];
if (save->hasAmbientHeat)
hv[saveBlockY+blockY][saveBlockX+blockX] = save->ambientHeat[saveBlockY][saveBlockX];
}
}
}
@@ -221,12 +224,12 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
return 0;
}
GameSave * Simulation::Save()
GameSave * Simulation::Save(bool includePressure)
{
return Save(0, 0, XRES-1, YRES-1);
return Save(0, 0, XRES-1, YRES-1, includePressure);
}
GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2)
GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2, bool includePressure)
{
int blockX, blockY, blockX2, blockY2, blockW, blockH;
//Normalise incoming coords
@@ -310,11 +313,14 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2)
newSave->fanVelX[saveBlockY][saveBlockX] = fvx[saveBlockY+blockY][saveBlockX+blockX];
newSave->fanVelY[saveBlockY][saveBlockX] = fvy[saveBlockY+blockY][saveBlockX+blockX];
}
newSave->pressure[saveBlockY][saveBlockX] = pv[saveBlockY+blockY][saveBlockX+blockX];
newSave->velocityX[saveBlockY][saveBlockX] = vx[saveBlockY+blockY][saveBlockX+blockX];
newSave->velocityY[saveBlockY][saveBlockX] = vy[saveBlockY+blockY][saveBlockX+blockX];
newSave->ambientHeat[saveBlockY][saveBlockX] = hv[saveBlockY+blockY][saveBlockX+blockX];
newSave->hasAmbientHeat = true;
if (includePressure)
{
newSave->pressure[saveBlockY][saveBlockX] = pv[saveBlockY+blockY][saveBlockX+blockX];
newSave->velocityX[saveBlockY][saveBlockX] = vx[saveBlockY+blockY][saveBlockX+blockX];
newSave->velocityY[saveBlockY][saveBlockX] = vy[saveBlockY+blockY][saveBlockX+blockX];
newSave->ambientHeat[saveBlockY][saveBlockX] = hv[saveBlockY+blockY][saveBlockX+blockX];
newSave->hasAmbientHeat = true;
}
}
}
@@ -114,10 +114,10 @@ class Simulation
int sandcolour;
int sandcolour_frame;
int Load(GameSave * save);
int Load(int x, int y, GameSave * save);
GameSave * Save();
GameSave * Save(int x1, int y1, int x2, int y2);
int Load(GameSave * save, bool includePressure = true);
int Load(int x, int y, GameSave * save, bool includePressure = true);
GameSave * Save(bool includePressure = true);
GameSave * Save(int x1, int y1, int x2, int y2, bool includePressure = true);
void SaveSimOptions(GameSave * gameSave);
SimulationSample GetSample(int x, int y);

0 comments on commit 6931f35

Please sign in to comment.