From 275cb79a1857fff08ce1b642bbfab6d7377bcaef Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 20 Oct 2023 12:33:00 +0200 Subject: aa --- editor/app.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'editor/app.cpp') diff --git a/editor/app.cpp b/editor/app.cpp index a2ffc9f4..7c42e98c 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -17,6 +17,17 @@ namespace floormat { +struct Optional cursor_state::point() const +{ + if (tile) + return {InPlaceInit, *tile, *subpixel}; + else + return {}; +} + +floormat_main& app::main() { return *M; } +const cursor_state& app::cursor_state() { return cursor; } + app::app(fm_settings&& opts) : M{floormat_main::create(*this, Utility::move(opts))}, _tests{tests_data_::make()} @@ -40,15 +51,17 @@ void app::reset_world() reset_world(world{}); } -void app::ensure_player_character(world& w) +std::shared_ptr app::ensure_player_character(world& w) { if (_character_id) if (auto C = w.find_object(_character_id); C && C->type() == object_type::critter) - return; + return std::static_pointer_cast(C); _character_id = 0; auto id = (object_id)-1; + std::shared_ptr ret; + for (const auto& [coord, c] : w.chunks()) { for (const auto& e_ : c.objects()) @@ -58,7 +71,10 @@ void app::ensure_player_character(world& w) { const auto& C = static_cast(e); if (C.playable) + { id = std::min(id, C.id); + ret = std::static_pointer_cast(e_); + } } } } @@ -70,8 +86,11 @@ void app::ensure_player_character(world& w) critter_proto cproto; cproto.name = "Player"_s; cproto.playable = true; - _character_id = w.make_object(w.make_id(), global_coords{}, cproto)->id; + ret = w.make_object(w.make_id(), global_coords{}, cproto); + _character_id = ret->id; } + fm_debug_assert(ret); + return ret; } void app::reset_world(struct world&& w_) -- cgit v1.2.3