mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 22:07:55 +01:00
Editor: track names outside of ASCII listed, not renamed; every name the editor gives is plain ASCII (#376)
* feat(editor): track names with characters outside of ASCII changed to ASCII when a scenery is opened for editing, with a 20 s warning in the middle of the screen
Tracks, and events named after a track (<track>:event0), are still found by their old names, so events, trainsets and memory cells keep working.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ
* chore(editor): the brush and the ASCII track names cleaned up for Sonar (init-statements, std::numbers::pi, ranges, the dab of the stroke and the settings of many models in functions of their own)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ
* chore(editor): the rest of the Sonar notes of the PRs (bytes as numbers, std::format, no copy of the old track name, no shadowed names, try_emplace, deduced template arguments)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ
* feat(editor): the track names outside of ASCII listed, not renamed; the names the editor gives are ASCII only
Reworked after the reviews of maj00r and jerrrrycho and the proposal on the PR: renaming the tracks of
existing sceneries as they're opened, and then chasing every reference to the old names, broke references
it couldn't reach (memory cells in files the editor doesn't write, folded names colliding, the parameters
of includes naming events and cells, names outside of Latin folding to underscores), and its fallback ran
in the game too. So:
- Nothing is renamed when a scenery is opened for editing. The tracks whose names have characters outside of
ASCII are listed in the log, and the status line says how many there are and that they work as they are.
- Tools -> "Track names outside of ASCII..." opens the list: each name as it reads, its ASCII form, whether
that form is taken (by another path, or another name giving the same), whether the name comes from a
parameter of an include, and whether its file is one the editor writes. It changes nothing; a track is
renamed, if at all, by hand in its properties, where the cells, includes and events it touches are shown.
- editor_track::name_valid() refuses a name with characters outside of ASCII, so every name the editor gives
(the track properties, the switches, the stations) is plain ASCII.
- The game is as on master: no folded lookups of paths or events (path_table::find, FindEventAscii and the
map behind it are gone), so a reference to a missing name is reported as before and never binds to
another track. The big warning in the middle of the screen is gone with the renaming it announced.
ascii_name (plain, fold, readable) and its tests stay, for the list.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QRgQ1K1Qu7TCsa74zsNURd
* fix(editor): the switch tool takes no name outside of ASCII
The Name field of the switch tool went straight to switch_name_for_new(), so a typed name such as łąka1 became the name of
the new switch and of its drive events, outside the check of editor_track::name_valid(). A letter outside of ASCII is now
refused as it's typed, with the reason name_valid() gives.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(editor): the switch, turntable and SRK station code fields drop letters outside of ASCII as they're typed; the include-named tracks said where they're renamed
A character filter (ImGuiInputTextFlags_CallbackCharFilter) keeps the refused letter out of the field, so it no longer shows while the switch name is typed. The turntable name and the SRK station code go into track names too and get the same filter. The window of the track names outside of ASCII says that a track named by an include parameter is renamed through that parameter, not in the track properties.
* Revert "fix(physicslog): no road-vehicle logs, formatting on the writer, a slow disk and the closing kept short (#408)"
This reverts commit d6c3593520.
* fix(editor): a letter outside ASCII refused in the turntable name goes to the status line as an error, as in the switch tool
The nit of the review of #376 (jerrrrycho, 21.11): the turntable tool set its own status only,
while the switch tool reports the same refusal through refused(), which also puts it in the
status line of the editor as an error. The text is the same.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QRgQ1JTXWSz4YufC1QZtrY
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: jerrrrycho <jurek.pakula@gmail.com>
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
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/.
|
||||
*/
|
||||
|
||||
// the tracks whose names have letters outside of ASCII: listed, nothing renamed. The names the sceneries have go on working as they
|
||||
// always did, in the editor and in the game; the editor gives no new name outside of ASCII (editor_track::name_valid)
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "application/editormode.h"
|
||||
#include "application/editoruilayer.h"
|
||||
#include "editor/editorFormat.hpp"
|
||||
#include "editor/editorTrack.hpp"
|
||||
#include "scene/scenelayers.h"
|
||||
#include "simulation/simulation.h"
|
||||
#include "utilities/Globals.h"
|
||||
#include "utilities/Logs.h"
|
||||
#include "utilities/asciiname.h"
|
||||
#include "utilities/translation.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <format>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// the tracks listed: the lanes take their names from their road, the removed ones are gone
|
||||
bool listed(TTrack const *Track)
|
||||
{
|
||||
return Track != nullptr && false == Track->m_editorremoved && (Track->iCategoryFlag & 0x80) == 0 && Track->m_road == nullptr && false == Track->name().empty() &&
|
||||
false == ascii_name::plain(Track->name());
|
||||
}
|
||||
|
||||
char const *yes_no(bool const Value)
|
||||
{
|
||||
return Value ? STR_C("yes") : STR_C("no");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void editor_mode::check_track_names(bool const Report)
|
||||
{
|
||||
m_track_names.clear();
|
||||
std::vector<TTrack const *> found;
|
||||
std::map<std::string, int> folded; // how many of the names listed give each ASCII name
|
||||
for (auto const *track : simulation::Paths.sequence())
|
||||
{
|
||||
if (false == listed(track))
|
||||
continue;
|
||||
found.push_back(track);
|
||||
++folded[ascii_name::fold(track->name())];
|
||||
}
|
||||
for (auto const *track : found)
|
||||
{
|
||||
track_name_entry entry;
|
||||
entry.name = ascii_name::readable(track->name());
|
||||
entry.ascii = ascii_name::fold(track->name());
|
||||
// another path named so already, or another name listed giving the same
|
||||
auto const *other{simulation::Paths.find(entry.ascii)};
|
||||
entry.clash = (other != nullptr && other != track && false == other->m_editorremoved) || folded[entry.ascii] > 1;
|
||||
entry.include = track->from_template() && editor_track::uses_of_name(*track).includes > 0;
|
||||
entry.written = track->from_template() ? entry.include : scene::Layers.editable(track);
|
||||
m_track_names.push_back(std::move(entry));
|
||||
}
|
||||
if (false == Report || m_track_names.empty())
|
||||
return;
|
||||
for (auto const &entry : m_track_names)
|
||||
WriteLog(std::format(R"(Editor: track "{}" has characters outside of ASCII in its name; in ASCII "{}"{})", entry.name, entry.ascii, entry.clash ? ", a name taken already" : ""));
|
||||
ui()->set_status(format(STR_C("%zu track names have characters outside of ASCII; they work as they are, the list is in Tools"), m_track_names.size()));
|
||||
}
|
||||
|
||||
void editor_mode::render_track_names_window()
|
||||
{
|
||||
if (false == m_track_names_open)
|
||||
return;
|
||||
ImGui::SetNextWindowSize(ImVec2(620.0f * Global.ui_scale, 380.0f * Global.ui_scale), ImGuiCond_FirstUseEver);
|
||||
if (false == ImGui::Begin((std::string(STR_C("Track names outside of ASCII")) + "###tracknamesascii").c_str(), &m_track_names_open))
|
||||
{
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
ImGui::TextWrapped("%s", STR_C("These names work as they are and nothing here changes them. New names given in the editor are ASCII only. To give one of these tracks an ASCII name, rename it in the track properties: the memory cells and the includes which name it go along, the events named after it are listed there. A track named by a parameter of an include (From an include: yes) can't be renamed there: change that parameter in the line of the scenery which puts the include."));
|
||||
if (ImGui::SmallButton(STR_C("Check again")))
|
||||
check_track_names(false);
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled(STR_C("Tracks: %zu"), m_track_names.size());
|
||||
auto constexpr flags{ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollY | ImGuiTableFlags_Resizable};
|
||||
if (ImGui::BeginTable("##tracknamesascii", 5, flags))
|
||||
{
|
||||
ImGui::TableSetupScrollFreeze(0, 1);
|
||||
ImGui::TableSetupColumn(STR_C("Name"));
|
||||
ImGui::TableSetupColumn(STR_C("In ASCII"));
|
||||
ImGui::TableSetupColumn(STR_C("Taken"));
|
||||
ImGui::TableSetupColumn(STR_C("From an include"));
|
||||
ImGui::TableSetupColumn(STR_C("In a file the editor writes"));
|
||||
ImGui::TableHeadersRow();
|
||||
for (auto const &entry : m_track_names)
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted(entry.name.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted(entry.ascii.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted(yes_no(entry.clash));
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted(yes_no(entry.include));
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted(yes_no(entry.written));
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
Reference in New Issue
Block a user