From 9ff017f1d4c1502fca9797aa4b38351c97e57982 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 2 Mar 2024 10:20:40 +0100 Subject: a --- editor/app.cpp | 46 +--------------------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) (limited to 'editor/app.cpp') diff --git a/editor/app.cpp b/editor/app.cpp index 5e06d93a..dafea3d9 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -30,51 +30,7 @@ const cursor_state& app::cursor_state() { return cursor; } shared_ptr_wrapper app::ensure_player_character(world& w) { - if (_character_id) - { - std::shared_ptr tmp; - if (auto C = w.find_object(_character_id); C && C->type() == object_type::critter) - { - auto ptr = std::static_pointer_cast(C); - return {ptr}; - } - } - _character_id = 0; - - auto id = (object_id)-1; - - shared_ptr_wrapper ret; - - for (const auto& [coord, c] : w.chunks()) - { - for (const auto& e_ : c.objects()) - { - const auto& e = *e_; - if (e.type() == object_type::critter) - { - const auto& C = static_cast(e); - if (C.playable) - { - id = std::min(id, C.id); - ret.ptr = std::static_pointer_cast(e_); - } - } - } - } - - if (id != (object_id)-1) - _character_id = id; - else - { - critter_proto cproto; - cproto.name = "Player"_s; - cproto.speed = 10; - cproto.playable = true; - ret.ptr = w.make_object(w.make_id(), global_coords{}, cproto); - _character_id = ret.ptr->id; - } - fm_debug_assert(ret.ptr); - return ret; + return w.ensure_player_character(_character_id); } void app::reset_world(class world&& w_) -- cgit v1.2.3