From 088eeaa743d5e88ae39329238bc78e9da144f605 Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Sat, 7 Nov 2026 12:32:02 +0100 Subject: [PATCH] fix(editor): a scenery saved under another name keeps one file of turntable controls, not the old one beside its own (#251) The editor writes the turntable controls on each save to _obrotnice.scm and includes it. A copy of a scenery, saved under another name, still included the file of the scenery it came from. Its save wrote a file of its own and included it too, so each turntable had its events twice. Now the save leaves out of the scenery the other files of turntable controls it includes, told by the line the editor writes at their start. Their files stay on the disk, for the scenery they were made for. A file of turntables made by hand, without that line, stays included. Co-authored-by: maj00r --- application/editormodeturntable.cpp | 32 ++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/application/editormodeturntable.cpp b/application/editormodeturntable.cpp index e6b78d9ef..76b70b575 100644 --- a/application/editormodeturntable.cpp +++ b/application/editormodeturntable.cpp @@ -19,6 +19,7 @@ http://mozilla.org/MPL/2.0/. #include "scene/scenelayers.h" #include "simulation/simulation.h" #include "utilities/Globals.h" +#include "utilities/Logs.h" #include "utilities/translation.h" #include "utilities/utilities.h" #include "world/Track.h" @@ -186,6 +187,20 @@ void label(screen_projection const &Projection, glm::dvec3 const &Point, std::st drawlist->AddText(ImVec2(at.x + 12.f, at.y), IM_COL32(255, 255, 255, 235), Text.c_str()); } +// the first line of the file of the turntable controls, which tells it from the files of the scenery made by hand +char const *const kControlsHeader{"// made by the scenery editor on each save: T turns each turntable to its next position, Shift+T to the previous one"}; + +// true if the file is one of the turntable controls the editor writes +bool controls_file(std::string const &Path) +{ + std::ifstream input{Path, std::ios_base::binary}; + std::string first; + std::getline(input, first); + if (false == first.empty() && first.back() == '\r') + first.pop_back(); + return first == kControlsHeader; +} + } // namespace void editor_mode::scan_turntables() @@ -1143,7 +1158,7 @@ bool editor_mode::turntable_controls(std::vector &Rootstatements) auto const exists{std::filesystem::exists(path, error)}; if (tables == 0 && false == exists) return false; - auto const content{"// made by the scenery editor on each save: T turns each turntable to its next position, Shift+T to the previous one\r\n" + text.str()}; + auto const content{std::string{kControlsHeader} + "\r\n" + text.str()}; std::string current; { std::ifstream input{path, std::ios_base::binary}; @@ -1154,6 +1169,21 @@ bool editor_mode::turntable_controls(std::vector &Rootstatements) std::ofstream output{path, std::ios_base::binary | std::ios_base::trunc}; output << content; } + // the controls written for this scenery under another name, the file it was copied from, give way to these: with both + // included each turntable would have its events twice. their files stay on the disk, for the scenery they were made for + for (std::size_t handle = 1; handle <= scene::Layers.size(); ++handle) + { + auto const layer{static_cast(handle)}; + if (false == scene::Layers.listed(layer) || scene::Layers.layer(layer).removed) + continue; + auto name{scene::Layers.layer(layer).name}; + std::replace(name.begin(), name.end(), '\\', '/'); + auto const lower{ToLower(name)}; + if (lower == ToLower(file) || lower.ends_with("/" + ToLower(file)) || false == lower.ends_with("_obrotnice.scm")) + continue; + if (controls_file(Global.asCurrentSceneryPath + scene::Layers.layer(layer).name) && scene::Layers.remove(layer)) + WriteLog("Editor: " + name + " left out of the scenery, the turntable controls are in " + file + " now"); + } auto included{m_turntable_included}; for (std::size_t handle = 1; handle <= scene::Layers.size() && false == included; ++handle) {