From 69b5bed15b38d26c8840c083bfecaf74cf098ea4 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sun, 18 Aug 2024 23:53:52 +0300 Subject: [PATCH] Add crossing --- source/application.cpp | 58 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/source/application.cpp b/source/application.cpp index 67a783d..c5bab4d 100644 --- a/source/application.cpp +++ b/source/application.cpp @@ -191,6 +191,11 @@ namespace gmtk transformer_type type; }; + struct crossing + { + psemek_ecs_declare_uuid("crossing") + }; + struct zoomer { psemek_ecs_declare_uuid("zoomer") @@ -525,6 +530,17 @@ namespace gmtk draw_transformer(v.location, t.type, false); }); + map.world.apply([&](vertex const & v, crossing const &) + { + auto wbox = v.location.bbox(-0.2f); + auto sbox = v.location.bbox(-0.3f); + + gfx::color_rgba color{64, 64, 64, 255}; + + painter.rect({wbox[0], sbox[1]}, color); + painter.rect({sbox[0], wbox[1]}, color); + }); + map.world.apply([&](vertex const & v, lab const & l) { painter.rect(v.location.bbox(-0.2f), {128, 192, 255, 255}); @@ -748,6 +764,17 @@ namespace gmtk } } + if (event.down && event.key == app::keycode::T) + { + if (selected_ && !map_.world.index().find(*selected_)) + { + map_.world.create( + vertex{*selected_}, + crossing{} + ); + } + } + if (event.down && event.key == app::keycode::Z) { if (selected_ && !map_.world.index().find(*selected_)) @@ -892,8 +919,8 @@ namespace gmtk if (i.target) { { - auto & v = map_.world.get(map_.world.index().get(i.start)).get(); - if (!v.belts_to.contains(i.target)) + auto & v = map_.world.get(i.target).get(); + if (v.belts_from.empty() && v.belts_to.empty()) { map_.world.detach(i.target); map_.world.destroy(entity); @@ -933,6 +960,33 @@ namespace gmtk return; } + if (map_.world.get(*cell).contains()) + { + auto c = i.start.up().down(); + auto d = c.coords - i.start.coords; + auto n = c.moved(d); + + auto & index = map_.world.index(); + + auto se = index.get(i.start); + auto ce = index.get(c); + auto ne = index.get(n); + + if (map_.world.get(se).get().belts_to.contains(ce)) + { + if (map_.world.get(ce).get().belts_to.contains(ne) && !map_.world.get(ne).contains()) + { + i.target = ne; + map_.world.attach(ne, occupied{entity}); + } + else + { + map_.world.attach(se, occupied{entity}); + } + return; + } + } + if (map_.world.get(*cell).get_if()) { auto se = map_.world.index().get(i.start);