From 4f01130ecc2d85e29d9e32e01fb5b0c51ed08fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Sun, 23 Feb 2020 23:14:51 +0100 Subject: [PATCH] Restrict saved version to 95.0 if signs with macros are present --- src/client/GameSave.cpp | 14 ++++++++++++++ src/simulation/Sign.cpp | 24 ++++++++++++++++++++++-- src/simulation/Sign.h | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 8cda279bf..3f245c607 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -2457,6 +2457,20 @@ char * GameSave::serialiseOPS(unsigned int & dataLength) } } + for (size_t i = 0; i < signs.size(); i++) + { + if(signs[i].text.length() && signs[i].x>=0 && signs[i].x<=fullW && signs[i].y>=0 && signs[i].y<=fullH) + { + int x, y, w, h; + bool v95 = false; + signs[i].getDisplayText(nullptr, x, y, w, h, true, &v95); + if (v95) + { + RESTRICTVERSION(95, 0); + } + } + } + bson b; b.data = NULL; auto bson_deleter = [](bson * b) { bson_destroy(b); }; diff --git a/src/simulation/Sign.cpp b/src/simulation/Sign.cpp index 27fe8e932..4ba5446e8 100644 --- a/src/simulation/Sign.cpp +++ b/src/simulation/Sign.cpp @@ -11,7 +11,7 @@ sign::sign(String text_, int x_, int y_, Justification justification_): { } -String sign::getDisplayText(Simulation *sim, int &x0, int &y0, int &w, int &h, bool colorize) +String sign::getDisplayText(Simulation *sim, int &x0, int &y0, int &w, int &h, bool colorize, bool *v95) { String drawable_text; auto si = std::make_pair(0, Type::Normal); @@ -31,7 +31,7 @@ String sign::getDisplayText(Simulation *sim, int &x0, int &y0, int &w, int &h, b Particle const *part = nullptr; float pressure = 0.0f; float aheat = 0.0f; - if (x >= 0 && x < XRES && y >= 0 && y < YRES) + if (sim && x >= 0 && x < XRES && y >= 0 && y < YRES) { if (sim->photons[y][x]) { @@ -58,34 +58,54 @@ String sign::getDisplayText(Simulation *sim, int &x0, int &y0, int &w, int &h, b if (between_curlies == "t" || between_curlies == "temp") { formatted_text << Format::Precision(Format::ShowPoint(part ? part->temp - 273.15f : 0.0f), 2); + // * We would really only need to do this if the sign used the new + // keyword "temp" or if the text was more than just "{t}", but 95.0 + // upgrades such signs at load time anyway. + // * The same applies to "{p}" and "{aheat}" signs. + if (v95) + *v95 = true; } else if (between_curlies == "p" || between_curlies == "pres") { formatted_text << Format::Precision(Format::ShowPoint(pressure), 2); + if (v95) + *v95 = true; } else if (between_curlies == "a" || between_curlies == "aheat") { formatted_text << Format::Precision(Format::ShowPoint(aheat), 2); + if (v95) + *v95 = true; } else if (between_curlies == "type") { formatted_text << (part ? sim->BasicParticleInfo(*part) : (formatted_text.Size() ? String::Build("empty") : String::Build("Empty"))); + if (v95) + *v95 = true; } else if (between_curlies == "ctype") { formatted_text << (part ? ((part->ctype && sim->IsValidElement(part->ctype)) ? sim->ElementResolve(part->ctype, -1) : String::Build(part->ctype)) : (formatted_text.Size() ? String::Build("empty") : String::Build("Empty"))); + if (v95) + *v95 = true; } else if (between_curlies == "life") { formatted_text << (part ? part->life : 0); + if (v95) + *v95 = true; } else if (between_curlies == "tmp") { formatted_text << (part ? part->tmp : 0); + if (v95) + *v95 = true; } else if (between_curlies == "tmp2") { formatted_text << (part ? part->tmp2 : 0); + if (v95) + *v95 = true; } else { diff --git a/src/simulation/Sign.h b/src/simulation/Sign.h index 66dc052aa..1eae163d9 100644 --- a/src/simulation/Sign.h +++ b/src/simulation/Sign.h @@ -31,7 +31,7 @@ struct sign String text; sign(String text_, int x_, int y_, Justification justification_); - String getDisplayText(Simulation *sim, int &x, int &y, int &w, int &h, bool colorize = true); + String getDisplayText(Simulation *sim, int &x, int &y, int &w, int &h, bool colorize = true, bool *v95 = nullptr); std::pair split(); };