diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-02 10:20:40 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-02 10:20:40 +0100 |
| commit | 9ff017f1d4c1502fca9797aa4b38351c97e57982 (patch) | |
| tree | 5b122d52ddec31c988e23a70531a968466e73bf6 /editor/app.cpp | |
| parent | 58d95d559276b556f584411d5c3ea0a986f3fbc4 (diff) | |
a
Diffstat (limited to 'editor/app.cpp')
| -rw-r--r-- | editor/app.cpp | 46 |
1 files changed, 1 insertions, 45 deletions
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<critter> app::ensure_player_character(world& w) { - if (_character_id) - { - std::shared_ptr<critter> tmp; - if (auto C = w.find_object(_character_id); C && C->type() == object_type::critter) - { - auto ptr = std::static_pointer_cast<critter>(C); - return {ptr}; - } - } - _character_id = 0; - - auto id = (object_id)-1; - - shared_ptr_wrapper<critter> 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<const critter&>(e); - if (C.playable) - { - id = std::min(id, C.id); - ret.ptr = std::static_pointer_cast<critter>(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<critter>(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_) |
