From b963bfb503c93aed5fc79eb196318341cf436b9d Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 20 Aug 2024 15:29:53 +0300 Subject: [PATCH] Better belts removal --- source/application.cpp | 44 ++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/source/application.cpp b/source/application.cpp index 4611bc9..4e171f7 100644 --- a/source/application.cpp +++ b/source/application.cpp @@ -1494,29 +1494,27 @@ namespace gmtk sink(*map_.world, belt[3], belt[2]); auto & index = map_.world->index(); - for (int i = 0; i < 3; ++i) + + ecs::handle e[4]; + for (int i = 0; i <= 3; ++i) + e[i] = index.get(belt[i]); + + auto & sv = map_.world->get(e[0]).get(); + + if (sv.belts_to.contains(e[1])) { - auto p = belt[i]; - auto q = belt[i + 1]; - - auto s = index.get(p); - auto t = index.get(q); - - auto & sv = map_.world->get(s).get(); - - if (sv.belts_to.contains(t)) - { - remove_belt(*map_.world, s, t); - if (tutorial_state_ <= 1) - tutorial_state_ = 2; - } - else - { - if (remove_belt(*map_.world, t, s)) - if (tutorial_state_ <= 1) - tutorial_state_ = 2; - add_belt(*map_.world, s, t); - } + for (int i = 0; i < 3; ++i) + remove_belt(*map_.world, e[i], e[i + 1]); + } + else if (sv.belts_from.contains(e[1])) + { + for (int i = 0; i < 3; ++i) + remove_belt(*map_.world, e[i + 1], e[i]); + } + else + { + for (int i = 0; i < 3; ++i) + add_belt(*map_.world, e[i], e[i + 1]); } if (tutorial_state_ <= 0) @@ -2049,7 +2047,7 @@ namespace gmtk if (map_.world->get(e0).get().belts_to.contains(e1)) c = {244, 160, 160, 255}; else if (map_.world->get(e0).get().belts_from.contains(e1)) - c = {244, 244, 160, 255}; + c = {244, 160, 160, 255}; float w = 0.25f * std::pow(3.f, 1.f - selected_->level) / 2.f; painter_.line(selected_->center(), belt_start_->center(), w, c, true);