diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-05-02 16:34:05 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-05-02 22:35:39 +0200 |
commit | 6abcd7d52cda334c58ec999d212491fc24f13c9d (patch) | |
tree | 86998508afe8eb7447ad70a2d5beebdbc9995a8f /editor | |
parent | 03b67a512ec9ef1cf5c337aa5c47a5a76d4a8a61 (diff) |
script lifecycle mostly implemented
Diffstat (limited to 'editor')
-rw-r--r-- | editor/app.cpp | 34 | ||||
-rw-r--r-- | editor/app.hpp | 2 | ||||
-rw-r--r-- | editor/ctor.cpp | 9 | ||||
-rw-r--r-- | editor/imgui.cpp | 3 | ||||
-rw-r--r-- | editor/scenery-editor.cpp | 9 | ||||
-rw-r--r-- | editor/vobj-editor.cpp | 6 |
6 files changed, 41 insertions, 22 deletions
diff --git a/editor/app.cpp b/editor/app.cpp index c8c5aa0f..36d4ad1b 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -31,30 +31,46 @@ shared_ptr_wrapper<critter> app::ensure_player_character(world& w) { return w.ensure_player_character(_character_id); } - -void app::reset_world(class world&& wʹ) +void app::reset_world() { - if (!M) - return; + if (M) + reset_world(world{}); +} +void app::reset_world_pre() +{ + auto& w = M->world(); + w.finish_scripts(); _editor->on_release(); //_editor->clear_selection(); kill_popups(true); tested_light_chunk = {}; tests_reset_mode(); - clear_keys(); - const auto pixel = cursor.pixel; - cursor = {}; _character_id = 0; _render_vobjs = true; _render_all_z_levels = true; _timestamp = 0; + const auto pixel = cursor.pixel; + cursor = {}; + cursor.pixel = pixel; +} - auto& w = M->reset_world(move(wʹ)); +void app::reset_world_post() +{ + auto& w = M->world(); w.collect(true); ensure_player_character(w); - update_cursor_tile(pixel); + update_cursor_tile(cursor.pixel); + w.init_scripts(); +} + +void app::reset_world(class world&& wʹ) +{ + fm_assert(M); + reset_world_pre(); + M->reset_world(move(wʹ)); + reset_world_post(); } int app::exec() diff --git a/editor/app.hpp b/editor/app.hpp index 32d6ce56..4476fb91 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -100,6 +100,8 @@ private: void maybe_initialize_chunk(const chunk_coords_& pos, chunk& c) override; void maybe_initialize_chunk_(const chunk_coords_& pos, chunk& c); void update_character(Ns dt); + void reset_world_pre(); + void reset_world_post(); void reset_world(); void reset_world(class world&& w); diff --git a/editor/ctor.cpp b/editor/ctor.cpp index 6e7e435f..a10f94cf 100644 --- a/editor/ctor.cpp +++ b/editor/ctor.cpp @@ -18,7 +18,7 @@ app::app(fm_settings&& opts) : keys_{InPlaceInit, 0u}, key_modifiers{} { - reset_world(); + reset_world_post(); auto& w = M->world(); constexpr chunk_coords_ coord{0, 0, 0}; maybe_initialize_chunk_(coord, w[coord]); @@ -29,12 +29,7 @@ app::app(fm_settings&& opts) : app::~app() { + reset_world_pre(); } -void app::reset_world() -{ - reset_world(world{}); -} - - } // namespace floormat diff --git a/editor/imgui.cpp b/editor/imgui.cpp index f35f6329..c8b0dcbd 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -389,8 +389,9 @@ void app::do_popup_menu() e.rotate(i, next_rot); if (ImGui::MenuItem("Delete", nullptr, false)) { - //e.on_destroy(eʹ, false); + e.destroy_script_pre(eʹ, script_destroy_reason::kill); e.chunk().remove_object(e.index()); + e.destroy_script_post(); } } else diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp index 55e194bf..b472fca5 100644 --- a/editor/scenery-editor.cpp +++ b/editor/scenery-editor.cpp @@ -5,6 +5,8 @@ #include "src/RTree-search.hpp" #include "src/rotation.inl" #include "app.hpp" +#include "src/scenery.hpp" + #include <Magnum/Math/Range.h> namespace floormat { @@ -94,8 +96,9 @@ start: for (auto i = 0uz; i < sz; i++) if (const auto eʹ = es[i]; eʹ->id == id) { - //eʹ->on_destroy(eʹ, false); + eʹ->destroy_script_pre(eʹ, script_destroy_reason::kill); c.remove_object(i); + eʹ->destroy_script_post(); goto start; } break; @@ -103,8 +106,8 @@ start: } else { - // todo check collision at pos - w.make_scenery(w.make_id(), pos, scenery_proto(s.proto)); + auto sc = w.make_scenery(w.make_id(), pos, scenery_proto(s.proto)); + sc->init_script(sc); } } diff --git a/editor/vobj-editor.cpp b/editor/vobj-editor.cpp index 52365fd5..916f303b 100644 --- a/editor/vobj-editor.cpp +++ b/editor/vobj-editor.cpp @@ -53,9 +53,11 @@ start: while (auto id = a.get_object_colliding_with_cursor()) { for (auto i = (int)(es.size()-1); i >= 0; i--) { - if (const auto eʹ = es[i]; eʹ->id == id) + const auto eʹ = es[i]; + if (eʹ->id == id && eʹ->is_virtual()) { - //eʹ->on_destroy(eʹ); + eʹ->destroy_script_pre(eʹ, script_destroy_reason::kill); + eʹ->destroy_script_post(); c.remove_object((unsigned)i); goto start; } |