diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 892e73121..ed3498115 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -161,6 +161,7 @@ void GameSave::InitData() void GameSave::InitVars() { majorVersion = 0; + minorVersion = 0; waterEEnabled = false; legacyEnable = false; gravityEnable = false; @@ -567,6 +568,7 @@ void GameSave::readOPS(char * data, int dataLength) unsigned int blockX, blockY, blockW, blockH, fullX, fullY, fullW, fullH; int savedVersion = inputData[4]; majorVersion = savedVersion; + minorVersion = 0; bool fakeNewerVersion = false; // used for development builds only bson b; @@ -676,6 +678,17 @@ void GameSave::readOPS(char * data, int dataLength) if (!strcmp(bson_iterator_key(&signiter), "text") && bson_iterator_type(&signiter) == BSON_STRING) { tempSign.text = format::CleanString(ByteString(bson_iterator_string(&signiter)).FromUtf8(), true, true, true).Substr(0, 45); + if (majorVersion < 94 || (majorVersion == 94 && minorVersion < 2)) + { + if (tempSign.text == "{t}") + { + tempSign.text = "Temp: {t}"; + } + else if (tempSign.text == "{p}") + { + tempSign.text = "Pressure: {p}"; + } + } } else if (!strcmp(bson_iterator_key(&signiter), "justification") && bson_iterator_type(&signiter) == BSON_INT) { @@ -767,6 +780,28 @@ void GameSave::readOPS(char * data, int dataLength) } } } + else if (!strcmp(bson_iterator_key(&iter), "origin")) + { + if (bson_iterator_type(&iter) == BSON_OBJECT) + { + bson_iterator subiter; + bson_iterator_subiterator(&iter, &subiter); + while (bson_iterator_next(&subiter)) + { + if (bson_iterator_type(&subiter) == BSON_INT) + { + if (!strcmp(bson_iterator_key(&subiter), "minorVersion")) + { + minorVersion = bson_iterator_int(&subiter); + } + } + } + } + else + { + fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&iter)); + } + } else if (!strcmp(bson_iterator_key(&iter), "minimumVersion")) { if (bson_iterator_type(&iter) == BSON_OBJECT) @@ -1331,6 +1366,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) throw ParseException(ParseException::WrongVersion, "Save from newer version"); ver = saveData[4]; majorVersion = saveData[4]; + minorVersion = 0; if (ver<34) { @@ -1929,6 +1965,14 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) memcpy(tempSignText, data+p, x); tempSignText[x] = 0; tempSign.text = format::CleanString(ByteString(tempSignText).FromUtf8(), true, true, true).Substr(0, 45); + if (tempSign.text == "{t}") + { + tempSign.text = "Temp: {t}"; + } + else if (tempSign.text == "{p}") + { + tempSign.text = "Pressure: {p}"; + } tempSigns.push_back(tempSign); p += x; } diff --git a/src/client/GameSave.h b/src/client/GameSave.h index e24325b85..c4993389e 100644 --- a/src/client/GameSave.h +++ b/src/client/GameSave.h @@ -73,7 +73,7 @@ public: int blockWidth, blockHeight; bool fromNewerVersion; - int majorVersion; + int majorVersion, minorVersion; bool hasPressure; bool hasAmbientHeat; diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 56c559bd5..5b558bf69 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -1568,6 +1568,24 @@ void GameController::ClearSim() gameModel->ClearSimulation(); } +String GameController::ElementResolve(int type, int ctype) +{ + if (gameModel && gameModel->GetSimulation()) + { + return gameModel->GetSimulation()->ElementResolve(type, ctype); + } + return ""; +} + +String GameController::BasicParticleInfo(Particle const &sample_part) +{ + if (gameModel && gameModel->GetSimulation()) + { + return gameModel->GetSimulation()->BasicParticleInfo(sample_part); + } + return ""; +} + void GameController::ReloadSim() { if(gameModel->GetSave() && gameModel->GetSave()->GetGameSave()) @@ -1582,18 +1600,6 @@ void GameController::ReloadSim() } } -String GameController::ElementResolve(int type, int ctype) -{ - if(gameModel && gameModel->GetSimulation()) - { - if (type == PT_LIFE && ctype >= 0 && ctype < NGOL) - return gameModel->GetSimulation()->gmenu[ctype].name; - else if (type >= 0 && type < PT_NUM) - return gameModel->GetSimulation()->elements[type].Name; - } - return ""; -} - bool GameController::IsValidElement(int type) { if(gameModel && gameModel->GetSimulation()) diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index 764336722..50a7bb550 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -148,6 +148,7 @@ public: ui::Point PointTranslate(ui::Point point); ui::Point NormaliseBlockCoord(ui::Point point); String ElementResolve(int type, int ctype); + String BasicParticleInfo(Particle const &sample_part); bool IsValidElement(int type); String WallName(int type); int Record(bool record); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index dd2000ff9..039442649 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -2288,11 +2288,24 @@ void GameView::OnDraw() if (showDebug) { if (type == PT_LAVA && c->IsValidElement(ctype)) + { sampleInfo << "Molten " << c->ElementResolve(ctype, -1); + } else if ((type == PT_PIPE || type == PT_PPIP) && c->IsValidElement(ctype)) - sampleInfo << c->ElementResolve(type, -1) << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]); + { + if (ctype == PT_LAVA && c->IsValidElement((int)sample.particle.pavg[1])) + { + sampleInfo << c->ElementResolve(type, -1) << " with molten " << c->ElementResolve((int)sample.particle.pavg[1], -1); + } + else + { + sampleInfo << c->ElementResolve(type, -1) << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]); + } + } else if (type == PT_LIFE) + { sampleInfo << c->ElementResolve(type, ctype); + } else if (type == PT_FILT) { sampleInfo << c->ElementResolve(type, ctype); @@ -2341,14 +2354,7 @@ void GameView::OnDraw() } else { - if (type == PT_LAVA && c->IsValidElement(ctype)) - sampleInfo << "Molten " << c->ElementResolve(ctype, -1); - else if ((type == PT_PIPE || type == PT_PPIP) && c->IsValidElement(ctype)) - sampleInfo << c->ElementResolve(type, -1) << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]); - else if (type == PT_LIFE) - sampleInfo << c->ElementResolve(type, ctype); - else - sampleInfo << c->ElementResolve(type, ctype); + sampleInfo << c->BasicParticleInfo(sample.particle); sampleInfo << ", Temp: " << sample.particle.temp - 273.15f << " C"; sampleInfo << ", Pressure: " << sample.AirPressure; } diff --git a/src/simulation/Sign.cpp b/src/simulation/Sign.cpp index 11cb273f3..3b5f903f1 100644 --- a/src/simulation/Sign.cpp +++ b/src/simulation/Sign.cpp @@ -11,46 +11,6 @@ sign::sign(String text_, int x_, int y_, Justification justification_): { } -String sign::getText(Simulation *sim) -{ - if (text[0] && text[0] == '{') - { - if (text == "{p}") - { - float pressure = 0.0f; - if (x >= 0 && x < XRES && y >= 0 && y < YRES) - pressure = sim->pv[y/CELL][x/CELL]; - return String::Build("Pressure: ", Format::Precision(Format::ShowPoint(pressure), 2)); - } - else if (text == "{aheat}") - { - float aheat = 0.0f; - if (x >= 0 && x < XRES && y >= 0 && y < YRES) - aheat = sim->hv[y/CELL][x/CELL]; - return String::Build(Format::Precision(Format::ShowPoint(aheat - 273.15f), 2)); - } - else if (text == "{t}") - { - if (x >= 0 && x < XRES && y >= 0 && y < YRES && sim->pmap[y][x]) - return String::Build("Temp: ", Format::Precision(Format::ShowPoint(sim->parts[ID(sim->pmap[y][x])].temp - 273.15f), 2)); - else - return String::Build("Temp: ", Format::Precision(Format::ShowPoint(0), 2)); - } - else - { - int pos = splitsign(text); - if (pos) - return text.Between(pos + 1, text.size() - 1); - else - return text; - } - } - else - { - return text; - } -} - void sign::pos(String signText, int & x0, int & y0, int & w, int & h) { w = Graphics::textwidth(signText.c_str()) + 5; @@ -102,3 +62,88 @@ int sign::splitsign(String str, String::value_type *type) } return 0; } + +String sign::getText(Simulation *sim) +{ + if (text.find('{') == text.npos) + { + return text; + } + + if (int pos = splitsign(text)) + { + return text.Between(pos + 1, text.size() - 1); + } + + Particle const *part = nullptr; + float pressure = 0.0f; + float aheat = 0.0f; + if (x >= 0 && x < XRES && y >= 0 && y < YRES) + { + if (sim->photons[y][x]) + { + part = &(sim->parts[ID(sim->photons[y][x])]); + } + else if (sim->pmap[y][x]) + { + part = &(sim->parts[ID(sim->pmap[y][x])]); + } + pressure = sim->pv[y/CELL][x/CELL]; + aheat = sim->hv[y/CELL][x/CELL] - 273.15f; + } + + String remaining_text = text; + StringBuilder formatted_text; + while (auto split_left_curly = remaining_text.SplitBy('{')) + { + String after_left_curly = split_left_curly.After(); + if (auto split_right_curly = after_left_curly.SplitBy('}')) + { + formatted_text << split_left_curly.Before(); + remaining_text = split_right_curly.After(); + String between_curlies = split_right_curly.Before(); + if (between_curlies == "t" || between_curlies == "temp") + { + formatted_text << Format::Precision(Format::ShowPoint(part ? part->temp - 273.15f : 0.0f), 2); + } + else if (between_curlies == "p" || between_curlies == "pres") + { + formatted_text << Format::Precision(Format::ShowPoint(pressure), 2); + } + else if (between_curlies == "a" || between_curlies == "aheat") + { + formatted_text << Format::Precision(Format::ShowPoint(aheat), 2); + } + else if (between_curlies == "type") + { + formatted_text << (part ? sim->BasicParticleInfo(*part) : (formatted_text.Size() ? "empty" : "Empty")); + } + else if (between_curlies == "ctype") + { + formatted_text << ((part && part->ctype && sim->IsValidElement(part->ctype)) ? sim->ElementResolve(part->ctype, -1) : (formatted_text.Size() ? "empty" : "Empty")); + } + else if (between_curlies == "life") + { + formatted_text << (part ? part->life : 0); + } + else if (between_curlies == "tmp") + { + formatted_text << (part ? part->tmp : 0); + } + else if (between_curlies == "tmp2") + { + formatted_text << (part ? part->tmp2 : 0); + } + else + { + formatted_text << '{' << between_curlies << '}'; + } + } + else + { + break; + } + } + formatted_text << remaining_text; + return formatted_text.Build(); +} diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 89e36b13b..b3305563f 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -5532,3 +5532,44 @@ Simulation::Simulation(): grav->gravity_mask(); } + +String Simulation::ElementResolve(int type, int ctype) +{ + if (type == PT_LIFE && ctype >= 0 && ctype < NGOL) + { + return gmenu[ctype].name; + } + else if (type >= 0 && type < PT_NUM) + { + return elements[type].Name; + } + return "Empty"; +} + +String Simulation::BasicParticleInfo(Particle const &sample_part) +{ + StringBuilder sampleInfo; + int type = sample_part.type; + int ctype = sample_part.ctype; + int pavg1int = (int)sample_part.pavg[1]; + if (type == PT_LAVA && ctype && IsValidElement(ctype)) + { + sampleInfo << "Molten " << ElementResolve(ctype, -1); + } + else if ((type == PT_PIPE || type == PT_PPIP) && ctype && IsValidElement(ctype)) + { + if (ctype == PT_LAVA && pavg1int && IsValidElement(pavg1int)) + { + sampleInfo << ElementResolve(type, -1) << " with molten " << ElementResolve(pavg1int, -1); + } + else + { + sampleInfo << ElementResolve(type, -1) << " with " << ElementResolve(ctype, pavg1int); + } + } + else + { + sampleInfo << ElementResolve(type, ctype); + } + return sampleInfo.Build(); +} diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index eb6f90414..481fbe8b7 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -224,6 +224,9 @@ public: { return std::fmod(x, y) + (x>=0 ? 0 : y); } + + String ElementResolve(int type, int ctype); + String BasicParticleInfo(Particle const &sample_part); }; #endif /* SIMULATION_H */