Reinstate inversion of inclusion of pressure when shift is held

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.
This commit is contained in:
Tamás Bálint Misius
2019-07-16 18:32:58 +02:00
parent a407aba087
commit dbd5999d1c
6 changed files with 24 additions and 23 deletions

View File

@@ -106,7 +106,7 @@ Command Line
| ---------------------- | ------------------------------------------------ | ---------------------------------------------------- | | ---------------------- | ------------------------------------------------ | ---------------------------------------------------- |
| `scale:SIZE` | Change window scale factor | `scale:2` | | `scale:SIZE` | Change window scale factor | `scale:2` |
| `kiosk` | Fullscreen mode | | | `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 | | | `open FILE` | Opens the file as a stamp or game save | |
| `ddir DIRECTORY` | Directory used for saving stamps and preferences | | | `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` | | `ptsave:SAVEID[#NAME]` | Open online save, used by ptsave: URLs | `ptsave:2198#Destroyable_city_5_wth_metro~dima-gord` |

View File

@@ -83,6 +83,7 @@ class GameController::SearchCallback: public ControllerCallback
GameController * cc; GameController * cc;
public: public:
SearchCallback(GameController * cc_) { cc = cc_; } SearchCallback(GameController * cc_) { cc = cc_; }
void ControllerExit() override void ControllerExit() override
{ {
if(cc->search->GetLoadedSave()) if(cc->search->GetLoadedSave())
@@ -90,7 +91,7 @@ public:
try try
{ {
cc->HistorySnapshot(); cc->HistorySnapshot();
cc->gameModel->SetSave(cc->search->GetLoadedSave()); cc->gameModel->SetSave(cc->search->GetLoadedSave(), cc->gameView->ShiftBehaviour());
cc->search->ReleaseLoadedSave(); cc->search->ReleaseLoadedSave();
} }
catch(GameModelException & ex) catch(GameModelException & ex)
@@ -372,7 +373,7 @@ void GameController::PlaceSave(ui::Point position)
if (placeSave) if (placeSave)
{ {
HistorySnapshot(); 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()); gameModel->SetPaused(placeSave->paused | gameModel->GetPaused());
Client::Ref().MergeStampAuthorInfo(placeSave->authors); Client::Ref().MergeStampAuthorInfo(placeSave->authors);
@@ -610,7 +611,7 @@ void GameController::ToolClick(int toolSelection, ui::Point point)
ByteString GameController::StampRegion(ui::Point point1, ui::Point point2) 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) if(newSave)
{ {
newSave->paused = gameModel->GetPaused(); newSave->paused = gameModel->GetPaused();
@@ -629,7 +630,7 @@ ByteString 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)
{ {
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) if(newSave)
{ {
Json::Value clipboardInfo; Json::Value clipboardInfo;
@@ -1259,7 +1260,7 @@ void GameController::OpenSearch(String searchText)
void GameController::OpenLocalSaveWindow(bool asCurrent) void GameController::OpenLocalSaveWindow(bool asCurrent)
{ {
Simulation * sim = gameModel->GetSimulation(); Simulation * sim = gameModel->GetSimulation();
GameSave * gameSave = sim->Save(gameModel->GetIncludePressure()); GameSave * gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour());
if(!gameSave) if(!gameSave)
{ {
new ErrorMessage("Error", "Unable to build save."); new ErrorMessage("Error", "Unable to build save.");
@@ -1286,7 +1287,7 @@ void GameController::OpenLocalSaveWindow(bool asCurrent)
virtual ~LocalSaveCallback() {} virtual ~LocalSaveCallback() {}
void FileSaved(SaveFile* file) override void FileSaved(SaveFile* file) override
{ {
c->gameModel->SetSaveFile(file); c->gameModel->SetSaveFile(file, c->gameView->ShiftBehaviour());
} }
}; };
@@ -1302,7 +1303,7 @@ void GameController::OpenLocalSaveWindow(bool asCurrent)
Client::Ref().SaveAuthorInfo(&localSaveInfo); Client::Ref().SaveAuthorInfo(&localSaveInfo);
gameSave->authors = localSaveInfo; gameSave->authors = localSaveInfo;
gameModel->SetSaveFile(&tempSave); gameModel->SetSaveFile(&tempSave, gameView->ShiftBehaviour());
Client::Ref().MakeDirectory(LOCAL_SAVE_DIR); Client::Ref().MakeDirectory(LOCAL_SAVE_DIR);
std::vector<char> saveData = gameSave->Serialise(); std::vector<char> saveData = gameSave->Serialise();
if (saveData.size() == 0) if (saveData.size() == 0)
@@ -1317,13 +1318,13 @@ void GameController::OpenLocalSaveWindow(bool asCurrent)
void GameController::LoadSaveFile(SaveFile * file) void GameController::LoadSaveFile(SaveFile * file)
{ {
gameModel->SetSaveFile(file); gameModel->SetSaveFile(file, gameView->ShiftBehaviour());
} }
void GameController::LoadSave(SaveInfo * save) void GameController::LoadSave(SaveInfo * save)
{ {
gameModel->SetSave(save); gameModel->SetSave(save, gameView->ShiftBehaviour());
} }
void GameController::OpenSavePreview(int saveID, int saveDate, bool instant) void GameController::OpenSavePreview(int saveID, int saveDate, bool instant)
@@ -1478,7 +1479,7 @@ void GameController::OpenSaveWindow()
if(gameModel->GetUser().UserID) if(gameModel->GetUser().UserID)
{ {
Simulation * sim = gameModel->GetSimulation(); Simulation * sim = gameModel->GetSimulation();
GameSave * gameSave = sim->Save(gameModel->GetIncludePressure()); GameSave * gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour());
if(!gameSave) if(!gameSave)
{ {
new ErrorMessage("Error", "Unable to build save."); new ErrorMessage("Error", "Unable to build save.");
@@ -1525,7 +1526,7 @@ void GameController::SaveAsCurrent()
if(gameModel->GetSave() && gameModel->GetUser().UserID && gameModel->GetUser().Username == gameModel->GetSave()->GetUserName()) if(gameModel->GetSave() && gameModel->GetUser().UserID && gameModel->GetUser().Username == gameModel->GetSave()->GetUserName())
{ {
Simulation * sim = gameModel->GetSimulation(); Simulation * sim = gameModel->GetSimulation();
GameSave * gameSave = sim->Save(gameModel->GetIncludePressure()); GameSave * gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour());
if(!gameSave) if(!gameSave)
{ {
new ErrorMessage("Error", "Unable to build save."); new ErrorMessage("Error", "Unable to build save.");
@@ -1587,7 +1588,7 @@ void GameController::ChangeBrush()
void GameController::ClearSim() void GameController::ClearSim()
{ {
HistorySnapshot(); HistorySnapshot();
gameModel->SetSave(NULL); gameModel->SetSave(NULL, false);
gameModel->ClearSimulation(); gameModel->ClearSimulation();
} }
@@ -1614,12 +1615,12 @@ void GameController::ReloadSim()
if(gameModel->GetSave() && gameModel->GetSave()->GetGameSave()) if(gameModel->GetSave() && gameModel->GetSave()->GetGameSave())
{ {
HistorySnapshot(); HistorySnapshot();
gameModel->SetSave(gameModel->GetSave()); gameModel->SetSave(gameModel->GetSave(), gameView->ShiftBehaviour());
} }
else if(gameModel->GetSaveFile() && gameModel->GetSaveFile()->GetGameSave()) else if(gameModel->GetSaveFile() && gameModel->GetSaveFile()->GetGameSave())
{ {
HistorySnapshot(); HistorySnapshot();
gameModel->SetSaveFile(gameModel->GetSaveFile()); gameModel->SetSaveFile(gameModel->GetSaveFile(), gameView->ShiftBehaviour());
} }
} }

View File

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

View File

@@ -162,8 +162,8 @@ public:
void SetVote(int direction); void SetVote(int direction);
SaveInfo * GetSave(); SaveInfo * GetSave();
SaveFile * GetSaveFile(); SaveFile * GetSaveFile();
void SetSave(SaveInfo * newSave); void SetSave(SaveInfo * newSave, bool invertIncludePressure);
void SetSaveFile(SaveFile * newSave); void SetSaveFile(SaveFile * newSave, bool invertIncludePressure);
void AddObserver(GameView * observer); void AddObserver(GameView * observer);
bool GetPaused(); bool GetPaused();

View File

@@ -410,7 +410,7 @@ OptionsView::OptionsView():
includePressure = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Include Pressure", ""); includePressure = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Include Pressure", "");
autowidth(includePressure); autowidth(includePressure);
includePressure->SetActionCallback(new IncludePressureAction(this)); 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); autowidth(tempLabel);
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;

View File

@@ -1681,7 +1681,7 @@ int LuaScriptInterface::simulation_loadStamp(lua_State * l)
if (tempfile) 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; //luacon_sim->sys_pause = (tempfile->GetGameSave()->paused | luacon_model->GetPaused())?1:0;
lua_pushinteger(l, 1); lua_pushinteger(l, 1);