Navigation Menu

Skip to content

Commit

Permalink
Reinstate inversion of inclusion of pressure when shift is held
Browse files Browse the repository at this point in the history
This feature was removed temporarily in a407aba.

Whether pressure is included when saving or loading is
determined as follows:

 * load-like operations (which invoke Simulation::Load) always
   include pressure;
 * save-like operations (which invoke Simulation::Save) include
   pressure if the Simulation.IncludePressure preference node
   is true;
 * finally the state of the shift key inverts the decision.
  • Loading branch information
LBPHacker committed Jul 16, 2019
1 parent a407aba commit dbd5999
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -106,7 +106,7 @@ Command Line
| ---------------------- | ------------------------------------------------ | ---------------------------------------------------- |
| `scale:SIZE` | Change window scale factor | `scale:2` |
| `kiosk` | Fullscreen mode | |
| `proxy\:SERVER[:PORT]` | Proxy server to use | `proxy\:wwwcache.lancs.ac.uk:8080` |
| `proxy:SERVER[:PORT]` | Proxy server to use | `proxy:wwwcache.lancs.ac.uk:8080` |
| `open FILE` | Opens the file as a stamp or game save | |
| `ddir DIRECTORY` | Directory used for saving stamps and preferences | |
| `ptsave:SAVEID[#NAME]` | Open online save, used by ptsave: URLs | `ptsave:2198#Destroyable_city_5_wth_metro~dima-gord` |
29 changes: 15 additions & 14 deletions src/gui/game/GameController.cpp
Expand Up @@ -83,14 +83,15 @@ class GameController::SearchCallback: public ControllerCallback
GameController * cc;
public:
SearchCallback(GameController * cc_) { cc = cc_; }

void ControllerExit() override
{
if(cc->search->GetLoadedSave())
{
try
{
cc->HistorySnapshot();
cc->gameModel->SetSave(cc->search->GetLoadedSave());
cc->gameModel->SetSave(cc->search->GetLoadedSave(), cc->gameView->ShiftBehaviour());
cc->search->ReleaseLoadedSave();
}
catch(GameModelException & ex)
Expand Down Expand Up @@ -372,7 +373,7 @@ void GameController::PlaceSave(ui::Point position)
if (placeSave)
{
HistorySnapshot();
if (!gameModel->GetSimulation()->Load(placeSave, Client::Ref().GetPrefBool("Simulation.LoadPressure", true), position.X, position.Y))
if (!gameModel->GetSimulation()->Load(placeSave, !gameView->ShiftBehaviour(), position.X, position.Y))
{
gameModel->SetPaused(placeSave->paused | gameModel->GetPaused());
Client::Ref().MergeStampAuthorInfo(placeSave->authors);
Expand Down Expand Up @@ -610,7 +611,7 @@ void GameController::ToolClick(int toolSelection, ui::Point point)

ByteString GameController::StampRegion(ui::Point point1, ui::Point point2)
{
GameSave * newSave = gameModel->GetSimulation()->Save(gameModel->GetIncludePressure(), point1.X, point1.Y, point2.X, point2.Y);
GameSave * newSave = gameModel->GetSimulation()->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour(), point1.X, point1.Y, point2.X, point2.Y);
if(newSave)
{
newSave->paused = gameModel->GetPaused();
Expand All @@ -629,7 +630,7 @@ ByteString GameController::StampRegion(ui::Point point1, ui::Point point2)

void GameController::CopyRegion(ui::Point point1, ui::Point point2)
{
GameSave * newSave = gameModel->GetSimulation()->Save(gameModel->GetIncludePressure(), point1.X, point1.Y, point2.X, point2.Y);
GameSave * newSave = gameModel->GetSimulation()->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour(), point1.X, point1.Y, point2.X, point2.Y);
if(newSave)
{
Json::Value clipboardInfo;
Expand Down Expand Up @@ -1259,7 +1260,7 @@ void GameController::OpenSearch(String searchText)
void GameController::OpenLocalSaveWindow(bool asCurrent)
{
Simulation * sim = gameModel->GetSimulation();
GameSave * gameSave = sim->Save(gameModel->GetIncludePressure());
GameSave * gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour());
if(!gameSave)
{
new ErrorMessage("Error", "Unable to build save.");
Expand All @@ -1286,7 +1287,7 @@ void GameController::OpenLocalSaveWindow(bool asCurrent)
virtual ~LocalSaveCallback() {}
void FileSaved(SaveFile* file) override
{
c->gameModel->SetSaveFile(file);
c->gameModel->SetSaveFile(file, c->gameView->ShiftBehaviour());
}
};

Expand All @@ -1302,7 +1303,7 @@ void GameController::OpenLocalSaveWindow(bool asCurrent)
Client::Ref().SaveAuthorInfo(&localSaveInfo);
gameSave->authors = localSaveInfo;

gameModel->SetSaveFile(&tempSave);
gameModel->SetSaveFile(&tempSave, gameView->ShiftBehaviour());
Client::Ref().MakeDirectory(LOCAL_SAVE_DIR);
std::vector<char> saveData = gameSave->Serialise();
if (saveData.size() == 0)
Expand All @@ -1317,13 +1318,13 @@ void GameController::OpenLocalSaveWindow(bool asCurrent)

void GameController::LoadSaveFile(SaveFile * file)
{
gameModel->SetSaveFile(file);
gameModel->SetSaveFile(file, gameView->ShiftBehaviour());
}


void GameController::LoadSave(SaveInfo * save)
{
gameModel->SetSave(save);
gameModel->SetSave(save, gameView->ShiftBehaviour());
}

void GameController::OpenSavePreview(int saveID, int saveDate, bool instant)
Expand Down Expand Up @@ -1478,7 +1479,7 @@ void GameController::OpenSaveWindow()
if(gameModel->GetUser().UserID)
{
Simulation * sim = gameModel->GetSimulation();
GameSave * gameSave = sim->Save(gameModel->GetIncludePressure());
GameSave * gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour());
if(!gameSave)
{
new ErrorMessage("Error", "Unable to build save.");
Expand Down Expand Up @@ -1525,7 +1526,7 @@ void GameController::SaveAsCurrent()
if(gameModel->GetSave() && gameModel->GetUser().UserID && gameModel->GetUser().Username == gameModel->GetSave()->GetUserName())
{
Simulation * sim = gameModel->GetSimulation();
GameSave * gameSave = sim->Save(gameModel->GetIncludePressure());
GameSave * gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour());
if(!gameSave)
{
new ErrorMessage("Error", "Unable to build save.");
Expand Down Expand Up @@ -1587,7 +1588,7 @@ void GameController::ChangeBrush()
void GameController::ClearSim()
{
HistorySnapshot();
gameModel->SetSave(NULL);
gameModel->SetSave(NULL, false);
gameModel->ClearSimulation();
}

Expand All @@ -1614,12 +1615,12 @@ void GameController::ReloadSim()
if(gameModel->GetSave() && gameModel->GetSave()->GetGameSave())
{
HistorySnapshot();
gameModel->SetSave(gameModel->GetSave());
gameModel->SetSave(gameModel->GetSave(), gameView->ShiftBehaviour());
}
else if(gameModel->GetSaveFile() && gameModel->GetSaveFile()->GetGameSave())
{
HistorySnapshot();
gameModel->SetSaveFile(gameModel->GetSaveFile());
gameModel->SetSaveFile(gameModel->GetSaveFile(), gameView->ShiftBehaviour());
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/gui/game/GameModel.cpp
Expand Up @@ -635,7 +635,7 @@ SaveInfo * GameModel::GetSave()
return currentSave;
}

void GameModel::SetSave(SaveInfo * newSave)
void GameModel::SetSave(SaveInfo * newSave, bool invertIncludePressure)
{
if(currentSave != newSave)
{
Expand Down Expand Up @@ -664,7 +664,7 @@ void GameModel::SetSave(SaveInfo * newSave)
sim->grav->stop_grav_async();
sim->clear_sim();
ren->ClearAccumulation();
if (!sim->Load(saveData, GetIncludePressure()))
if (!sim->Load(saveData, !invertIncludePressure))
{
// This save was created before logging existed
// Add in the correct info
Expand Down Expand Up @@ -696,7 +696,7 @@ SaveFile * GameModel::GetSaveFile()
return currentFile;
}

void GameModel::SetSaveFile(SaveFile * newSave)
void GameModel::SetSaveFile(SaveFile * newSave, bool invertIncludePressure)
{
if(currentFile != newSave)
{
Expand Down Expand Up @@ -729,7 +729,7 @@ void GameModel::SetSaveFile(SaveFile * newSave)
}
sim->clear_sim();
ren->ClearAccumulation();
if (!sim->Load(saveData, GetIncludePressure()))
if (!sim->Load(saveData, !invertIncludePressure))
{
Client::Ref().OverwriteAuthorInfo(saveData->authors);
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/game/GameModel.h
Expand Up @@ -162,8 +162,8 @@ class GameModel
void SetVote(int direction);
SaveInfo * GetSave();
SaveFile * GetSaveFile();
void SetSave(SaveInfo * newSave);
void SetSaveFile(SaveFile * newSave);
void SetSave(SaveInfo * newSave, bool invertIncludePressure);
void SetSaveFile(SaveFile * newSave, bool invertIncludePressure);
void AddObserver(GameView * observer);

bool GetPaused();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/options/OptionsView.cpp
Expand Up @@ -410,7 +410,7 @@ OptionsView::OptionsView():
includePressure = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Include Pressure", "");
autowidth(includePressure);
includePressure->SetActionCallback(new IncludePressureAction(this));
tempLabel = new ui::Label(ui::Point(includePressure->Position.X+Graphics::textwidth(includePressure->GetText())+20, currentY), ui::Point(1, 16), "\bg- When saving, loading, stamping, etc.");
tempLabel = new ui::Label(ui::Point(includePressure->Position.X+Graphics::textwidth(includePressure->GetText())+20, currentY), ui::Point(1, 16), "\bg- When saving, copying, stamping, etc.");
autowidth(tempLabel);
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
Expand Down
2 changes: 1 addition & 1 deletion src/lua/LuaScriptInterface.cpp
Expand Up @@ -1681,7 +1681,7 @@ int LuaScriptInterface::simulation_loadStamp(lua_State * l)

if (tempfile)
{
if (!luacon_sim->Load(tempfile->GetGameSave(), luacon_model->GetIncludePressure(), x, y))
if (!luacon_sim->Load(tempfile->GetGameSave(), !luacon_controller->GetView()->ShiftBehaviour(), x, y))
{
//luacon_sim->sys_pause = (tempfile->GetGameSave()->paused | luacon_model->GetPaused())?1:0;
lua_pushinteger(l, 1);
Expand Down

0 comments on commit dbd5999

Please sign in to comment.