mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-08 18:50:34 +01:00
fix(editor): a signal goes to the other side of the track and turns around
Dragging a standing signal over the track takes it to the other side; the side used to come from where the signal stood, so it never crossed. The selected signal gets "To the other side" and "Turn around": the first mirrors it over the axis facing the same trains, the second turns it to the trains of the other direction and moves its event to the other event list of the path. Either one swaps a head leaning to the track for its counterpart, and an include keeps the template its directive names, so undo brings the old file back too.
This commit is contained in:
@@ -50,7 +50,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
editor_mode::selftest_result editor_mode::selftest_signal(std::string const &command, std::istringstream &words)
|
||||
{
|
||||
if (command == "signal" || command == "signalmove" || command == "signaldelete" || command == "signalrename" || command == "signalprobe")
|
||||
if (command == "signal" || command == "signalmove" || command == "signaldelete" || command == "signalrename" || command == "signalprobe" || command == "signalflip" || command == "signalturn")
|
||||
{
|
||||
auto values{selftest_values(words)};
|
||||
show_track_tab(track_tab::signals);
|
||||
@@ -107,29 +107,40 @@ editor_mode::selftest_result editor_mode::selftest_signal(std::string const &com
|
||||
else if (command == "signalmove")
|
||||
{
|
||||
auto const *standing{standing_named(values["name"])};
|
||||
auto const *item{standing != nullptr ? signal_template_of(standing->include.file) : nullptr};
|
||||
if (item == nullptr)
|
||||
auto *track{simulation::Paths.find(values["track"])};
|
||||
if (standing == nullptr || track == nullptr || track->m_paths.empty())
|
||||
{
|
||||
WriteLog("SELFTEST signalmove: no signal " + values["name"]);
|
||||
WriteLog("SELFTEST signalmove: no signal " + values["name"] + " or no track " + values["track"]);
|
||||
return selftest_result::handled;
|
||||
}
|
||||
auto const yaw{glm::radians(standing->include.yaw + 180.0)};
|
||||
glm::dvec2 const travel{std::sin(yaw), std::cos(yaw)};
|
||||
signal_spot probe;
|
||||
if (false == spot_on(*item, 1, 1, probe))
|
||||
auto const path{std::clamp(values.count("path") ? std::stoi(values["path"]) : 0, 0, static_cast<int>(track->m_paths.size()) - 1)};
|
||||
auto const at{values.count("at") ? std::stod(values["at"]) : 0.5};
|
||||
geometry::bezier const curve{track->m_paths[path]};
|
||||
auto point{curve.point(at)};
|
||||
auto const sided{values.count("side") != 0};
|
||||
auto side{values["side"] == "left" ? -1 : 1};
|
||||
if (values.count("off"))
|
||||
{
|
||||
WriteLog("SELFTEST signalmove: no such track " + values["track"]);
|
||||
return selftest_result::handled;
|
||||
auto const tangent{glm::normalize(glm::dvec2{curve.first(at).x, curve.first(at).z})};
|
||||
auto const off{std::stod(values["off"])};
|
||||
point += glm::dvec3{-tangent.y * off, 0.0, tangent.x * off};
|
||||
side = 0;
|
||||
}
|
||||
auto const facing{glm::dot(probe.travel, travel) >= 0.0 ? 1 : -1};
|
||||
auto const sideoftravel{glm::dot(geometry::plan_of(standing->include.location) - geometry::plan_of(standing->spot.axis), glm::dvec2{-travel.y, travel.x}) >= 0.0 ? 1 : -1};
|
||||
else if (signal_spot home; false == sided && signal_standing_spot(*standing, home))
|
||||
side = home.side * (home.list == 2 ? 1 : -1);
|
||||
signal_select(standing->include.instance);
|
||||
tool.moving = true;
|
||||
tool.moved_valid = spot_on(*item, facing, sideoftravel * facing, tool.moved);
|
||||
tool.moved_valid = signal_drop_at(*standing, *track, path, point, side, tool.moved);
|
||||
tool.pressed = {-1000.f, -1000.f};
|
||||
signal_release();
|
||||
WriteLog("SELFTEST signalmove: " + tool.status);
|
||||
}
|
||||
else if (command == "signalflip" || command == "signalturn")
|
||||
{
|
||||
auto const *standing{standing_named(values["name"])};
|
||||
auto const done{standing != nullptr && (command == "signalflip" ? signal_flip(standing->include.instance) : signal_turn(standing->include.instance))};
|
||||
WriteLog("SELFTEST " + command + " " + values["name"] + (done ? ": " : ": failed, ") + tool.status);
|
||||
}
|
||||
else if (command == "signaldelete")
|
||||
{
|
||||
auto const *standing{standing_named(values["name"])};
|
||||
|
||||
Reference in New Issue
Block a user