18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 18:47:06 +01:00
Files
maszyna/editor/project/projectGenerated.hpp
T
maj00r c912ed2ab1 feat(editor): the tracks the generator wrote kept by their checksums, a track changed by hand marking its line
Continues E3 (editor-tracks-domain.md §9, "Ręczna zmiana wygenerowanego węzła ... wykrywana po sumie kontrolnej"): the generated
section of the project file and what the scenery files hold of it now. Nothing of the editor writes the tracks yet (E4).

- generated: a record a track the generator wrote, its name, its line, the file it's written into and the FNV-1a checksum (64 bits)
  of its text as the simulator reads it: the words joined by one blank, the comments left out, so the line ends and the blanks
  another tool writes aren't a change; the switch track of a turnout kept by the main track of the turnout.
    track l1_s11 line 1 file trasa/tory.scm sum 0123456789abcdef
    switch t1 line 2 file trasa/tory.scm sum 00000000000000ff
    hand 3
  record_generated() puts the pieces of a line, or the switch track of a turnout, in the place of the ones the project had of it;
  find_hand_changes() looks the names up in the text of the files now: a text of another checksum, or a track gone, or a file which
  can't be read; mark_hand_changes() marks their lines changed by hand (hand <line>, kept by the file), may_overwrite() tells the
  editor to leave them, until the line is written again by the editor (the author decided).
- editor/project/sceneryText: the text of the scenery files read as cParser and state_serializer read it, with no scene: the words
  (blanks and semicolons between them, // and /* */ comments, the quotes), the node of a name and its words up to the end word of its
  type, and the statements of a scenery with its includes followed relative to the scenery folder (the words of each file taken as
  they're needed, the includes no deeper than 32), the parameters of a template in place of (p1)..., the placement of origin, rotate
  and scale at each include, the terrain files passed over for a binary terrain. The scenario index and the migration read the files
  with it.

Tests: U: two lines generated into one file among other nodes: as written nothing is changed, through the project file too; the speed
of a track of the second line edited: that line and that track told, marked changed by hand once, kept by the file, the first line
not; written again, not marked. The switch track of a turnout: its speed edited marks its main track. Blanks doubled, the line ends of
windows and comments inside a track aren't a change; a track taken away, a file which can't be read are. The node of a name found by
the words.
2026-11-23 13:11:46 +01:00

55 lines
2.6 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "editor/layout/layoutGenerator.hpp"
#include "editor/project/projectFile.hpp"
#include <cstdint>
#include <functional>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <vector>
// The nodes of the simulator the generator wrote, kept in the project file by their names with the checksums of their text, and what the
// scenery files hold of them now (editor-tracks-domain.md §9): a track changed outside the editor, or taken away, marks its line changed
// by hand, and the editor doesn't write over it until the author decides.
namespace project
{
// FNV-1a, 64 bits, of the text as the simulator reads it: the words joined by one blank each, the comments left out, so the line ends
// and the blanks another tool writes don't count as a change
std::uint64_t checksum(std::string_view const Text);
// the tracks of the line as the generator made them, written into the file, take the place of the ones the project had of the line
void record_generated(document &Project, layout::generated_line const &Line, std::string const &File);
// the switch track of the turnout as the generator made it, written into the file, takes the place of the one the project had of it; it's
// kept by the main track of the turnout (Project.network has the turnout), which a change of it by hand marks
void record_generated(document &Project, layout::generated_turnout const &Turnout, std::string const &File);
struct hand_change
{
layout::line_id line{layout::line_id::none};
std::string name;
std::string file;
bool missing{false}; // the file has no node of the name any more, or the file can't be read
};
// the generated nodes against the text of the files now: Files gives the text of a file by its name in the project, none where it can't be
// read. The ones whose text isn't the one written, in the order of the project
std::vector<hand_change> find_hand_changes(document const &Project, std::function<std::optional<std::string>(std::string const &)> const &Files);
// their lines marked as changed by hand in the project; the lines newly marked
std::set<layout::line_id> mark_hand_changes(document &Project, std::vector<hand_change> const &Changes);
// the editor may write the tracks of the line again: none of them was changed by hand, or the author decided to write over them
bool may_overwrite(document const &Project, layout::line_id const Line);
} // namespace project