summaryrefslogtreecommitdiffhomepage
path: root/editor/tests
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-10-20 12:33:00 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-10-20 12:33:00 +0200
commit275cb79a1857fff08ce1b642bbfab6d7377bcaef (patch)
treeb8671ed206fc27d4762779cf64113ef7d9ce8fd9 /editor/tests
parent5be116ea43231c747f09c4d43a75d45984b54a66 (diff)
aa
Diffstat (limited to 'editor/tests')
-rw-r--r--editor/tests/path.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/editor/tests/path.cpp b/editor/tests/path.cpp
new file mode 100644
index 00000000..3b015e27
--- /dev/null
+++ b/editor/tests/path.cpp
@@ -0,0 +1,77 @@
+#include "../tests-private.hpp"
+#include "../app.hpp"
+#include "floormat/main.hpp"
+#include "src/path-search.hpp"
+#include "src/critter.hpp"
+
+namespace floormat::tests {
+
+bool path_test::handle_key(app& a, const key_event& e)
+{
+ return false;
+}
+
+bool path_test::handle_mouse_click(app& a, const mouse_button_event& e)
+{
+ switch (e.button)
+ {
+ case mouse_button_left: {
+ auto& M = a.main();
+ auto& w = M.world();
+ auto& astar = M.astar();
+ auto C = a.ensure_player_character(w);
+ if (auto pt = a.cursor_state().point())
+ {
+ constexpr auto chunk_size = iTILE_SIZE2 * TILE_MAX_DIM;
+ auto pt0 = C->position();
+ auto vec = (pt->coord() - pt0.coord()) * iTILE_SIZE2 * 2 + chunk_size * 3;
+ auto dist = (uint32_t)vec.length();
+ auto res = astar.Dijkstra(w, *pt, pt0, C->id, dist, C->bbox_size, 1);
+ if (res)
+ {
+ active = true;
+ from = pt0;
+ path = res.path();
+ }
+ else
+ {
+ active = false;
+ from = {};
+ path = {};
+ }
+ }
+ return true;
+ }
+ case mouse_button_right:
+ if (active)
+ {
+ *this = {};
+ return true;
+ }
+ return false;
+ default:
+ return false;
+ }
+}
+
+bool path_test::handle_mouse_move(app& a, const mouse_move_event& e)
+{
+ return false;
+}
+
+void path_test::draw_overlay(app& a)
+{
+
+}
+
+void path_test::update_pre(app& a)
+{
+
+}
+
+void path_test::update_post(app& a)
+{
+
+}
+
+} // namespace floormat::tests