18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 17:37:09 +01:00

Merge branch 'feat/editor-project-file' into ui/editor-consistency

This commit is contained in:
maj00r
2026-11-29 22:37:09 +01:00
5 changed files with 56 additions and 21 deletions
+3 -7
View File
@@ -148,8 +148,8 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co
}
if (command == "nmtsettings")
{
// as the terrain panel changes them, kept with the editor the next frame (keep_nmt_settings); the terrain while laying at
// once, as its chip keeps it
// as the terrain panel changes them, kept with the editor the next frame (keep_nmt_settings); the terrain while laying and
// the area for the run only, the settings of the tester's own editor left as they are
auto &state{m_nmt_state};
std::string key;
double value{0.0};
@@ -170,11 +170,7 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co
else if (key == "fitted")
state.fitted = value != 0.0;
else if (key == "grow")
{
state.grow = value != 0.0;
EditorSettings.terrain_while_laying(state.grow);
EditorSettings.save();
}
state.grow = value != 0.0; // for the run only, as area: the setting isn't touched, so the tester's own file stays as it was
else if (key == "area")
m_area_terrain.run_only = value != 0.0; // for the run only: the setting isn't touched, so no save keeps it
}
+17 -13
View File
@@ -209,13 +209,16 @@ class record
fail(std::format("'{}' isn't a profile of the norms", text));
return norms::profile_id::plk;
}
// the rest of the line as it is written, the blanks between the words kept as one
// the rest of the line as it is written, from its next word to its last, the blanks between the words as they are: joined with one
// blank, a reason of two blanks came back changed after a save and a load
std::string rest()
{
std::string result;
for (; false == done(); ++m_at)
result += (result.empty() ? "" : " ") + std::string{m_words[m_at]};
return result;
if (done())
return {};
auto const first{m_words[m_at]};
auto const last{m_words.back()};
m_at = m_words.size();
return std::string(first.data(), static_cast<std::size_t>(last.data() + last.size() - first.data()));
}
void finish()
{
@@ -425,6 +428,15 @@ read_result read(std::string_view const Text)
continue;
}
record words{text};
// the section kept for the anchors is written back as it was read, its blank lines and its comments too
if (in == section::anchors)
{
if (words.peek() == "end" && words_of(text).size() == 1)
in = section::top;
else
project.anchors.emplace_back(text);
continue;
}
if (words.empty() || words.peek().front() == '#')
continue;
if (false == versioned)
@@ -448,14 +460,6 @@ read_result read(std::string_view const Text)
continue;
}
auto const keyword{words.peek()};
if (in == section::anchors)
{
if (keyword == "end" && words_of(text).size() == 1)
in = section::top;
else
project.anchors.emplace_back(text);
continue;
}
words.next("");
if (in == section::turnouts)
{
+9 -1
View File
@@ -217,7 +217,15 @@ class reader
m_output.files.push_back(std::move(file));
return;
}
// a file including itself, on its own or through others, would never end
// a file including itself, on its own or through others, would never end: not read again while it's being read
if (auto const reading{std::ranges::find_if(m_frames, [this, &file](frame const &Frame) { return same_file(m_output.files[Frame.file].name, file.name); })};
reading != m_frames.end())
{
file.missing = true;
m_output.problems.push_back(file.name + " includes itself, included from " + m_output.files[Parent].name + " line " + std::to_string(Line));
m_output.files.push_back(std::move(file));
return;
}
if (m_frames.size() >= kDepth)
{
file.missing = true;
+14
View File
@@ -145,6 +145,13 @@ TEST_CASE("project file: the golden file read and written back comes out the sam
CHECK(project.anchors.empty());
REQUIRE(project.legacy.size() == 3);
CHECK(project.legacy[1].why == "a compound curve");
// the reason as it was written, its blanks kept, read and written back the same
auto spaced{golden};
spaced.replace(spaced.find("why a compound curve"), 20, "why a compound curve");
auto const reason{project::read(spaced)};
REQUIRE_MESSAGE(reason.project.has_value(), notes_of(reason));
CHECK(reason.project->legacy[1].why == "a compound curve");
CHECK(project::write(*reason.project) == spaced);
CHECK(project.legacy[1].lines == std::vector<std::string>{"alignment 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000", "", "end"});
CHECK(project.legacy[2].mark == 'r');
// the line ends of windows read the same
@@ -224,6 +231,13 @@ TEST_CASE("project file: the section kept for the anchors is written back as it
REQUIRE_MESSAGE(read.project.has_value(), notes_of(read));
CHECK(read.project->anchors == std::vector<std::string>{"anchor 1 line 1 chainage 120.5 offset -3.2"});
CHECK(project::write(*read.project) == text);
// its blank lines and its comments kept too, as the rest of the section
auto commented{text};
commented.replace(commented.find("anchors\n"), 8, "anchors\n\n# by hand\n \n");
auto const kept{project::read(commented)};
REQUIRE_MESSAGE(kept.project.has_value(), notes_of(kept));
CHECK(kept.project->anchors == std::vector<std::string>{"", "# by hand", " ", "anchor 1 line 1 chainage 120.5 offset -3.2"});
CHECK(project::write(*kept.project) == commented);
// a record the turnouts haven't
auto turnouts{text};
turnouts.replace(turnouts.find("turnouts\nend\n"), 13, "turnouts\nturnout 1 type Rz%2060E1-500-1:12 at 0 0 0\nend\n");
+13
View File
@@ -7,6 +7,7 @@
#include "doctest.h"
#include "editor/project/scenarioIndex.hpp"
#include "editor/project/sceneryText.hpp"
#include "scratch.h"
#include <format>
#include <string>
@@ -114,6 +115,18 @@ TEST_CASE("scenario index: the scenery read as the simulator reads it, the inclu
CHECK_FALSE(missing.uses_map());
}
TEST_CASE("scenario index: a file including itself, on its own or through another one, is told and not read again") {
test::scratch_folder const folder{"scenery_text_cycle"};
folder.write("petla.scn", "node -1 0 a memcell 0 0 0 endmemcell\ninclude petla/druga.scm end\n");
folder.write("petla/druga.scm", "node -1 0 b memcell 0 0 0 endmemcell\ninclude PETLA.scn end\n");
auto const scenery{scenery_text::read(folder.root(), "petla.scn")};
REQUIRE(scenery.problems.size() == 1);
CHECK(scenery.problems.front() == "PETLA.scn includes itself, included from petla/druga.scm line 2");
REQUIRE(scenery.files.size() == 3);
CHECK(scenery.files[2].missing);
CHECK(std::ranges::count(scenery.statements, std::string{"node"}, &scenery_text::statement::keyword) == 2);
}
TEST_CASE("scenario index: the words of the text as the parser splits them") {
auto const tokens{scenery_text::split("node -1 0 a;track // a comment\n\"two words\" /* a\ncomment */ endtrack//glued\nx")};
REQUIRE(tokens.size() == 8);