diff options
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/imgui.cpp | 8 | ||||
| -rw-r--r-- | editor/inspect-types.cpp | 2 | ||||
| -rw-r--r-- | editor/scenery-editor.cpp | 23 | ||||
| -rw-r--r-- | editor/update.cpp | 7 |
4 files changed, 29 insertions, 11 deletions
diff --git a/editor/imgui.cpp b/editor/imgui.cpp index 05396414..652b33a5 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -153,12 +153,12 @@ void app::do_popup_menu() if (auto b1 = begin_popup(SCENERY_POPUP_NAME)) { - auto iter = sc->iter(); - if (ImGui::MenuItem("Activate", nullptr, false, sc->can_activate(iter))) - sc->activate(iter); + const auto i = sc->index(); + if (ImGui::MenuItem("Activate", nullptr, false, sc->can_activate(i))) + sc->activate(i); if (auto next_rot = sc->atlas->next_rotation_from(sc->r); ImGui::MenuItem("Rotate", nullptr, false, next_rot != sc->r)) - sc->rotate(iter, next_rot); + sc->rotate(i, next_rot); ImGui::Separator(); diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp index ead95c08..75450085 100644 --- a/editor/inspect-types.cpp +++ b/editor/inspect-types.cpp @@ -32,7 +32,7 @@ struct entity_accessors<scenery> { }, entity::type<rotation>::field{"rotation"_s, [](const scenery& x) { return x.r; }, - [](scenery& x, rotation r) { x.rotate(x.iter(), r); }, + [](scenery& x, rotation r) { x.rotate(x.index(), r); }, }, entity::type<std::uint16_t>::field{"frame"_s, [](const scenery& x) { return x.frame; }, diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp index 73705056..1165219d 100644 --- a/editor/scenery-editor.cpp +++ b/editor/scenery-editor.cpp @@ -79,8 +79,27 @@ bool scenery_editor::is_anything_selected() const void scenery_editor::place_tile(world& w, global_coords pos, const scenery_& s) { auto [c, t] = w[pos]; - // todo check collision at pos - auto sc = w.make_entity<scenery>(pos, s.proto); + if (!s) + { + // don't regen colliders + const auto px = Vector2(pos.local()) * TILE_SIZE2; + const auto es = c.entities(); + for (auto i = es.size()-1; i != (std::size_t)-1; i--) + { + const auto& e = *es[i]; + if (e.type != entity_type::scenery) + continue; + auto center = Vector2(e.coord.local())*TILE_SIZE2 + Vector2(e.offset) + Vector2(e.bbox_offset), + min = center - Vector2(e.bbox_size/2), max = min + Vector2(e.bbox_size); + if (px >= min && px <= max) + c.remove_entity(i); + } + } + else + { + // todo check collision at pos + w.make_entity<scenery>(pos, s.proto); + } c.mark_scenery_modified(); } diff --git a/editor/update.cpp b/editor/update.cpp index 6107cfa6..470e8b9f 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -69,7 +69,7 @@ void app::do_mouse_up_down(std::uint8_t button, bool is_down, int mods) if (button == mouse_button_left) { if (auto* cl = find_clickable_scenery(*cursor.pixel)) - return (void)cl->e->activate(cl->e->iter()); + return (void)cl->e->activate(cl->e->index()); } // TODO it should open on mouseup if still on the same item as on mousedown else if (button == mouse_button_right) @@ -110,7 +110,7 @@ void app::do_rotate(bool backward) auto r = backward ? e.atlas->prev_rotation_from(e.r) : e.atlas->next_rotation_from(e.r); if (r != e.r) { - e.rotate(e.iter(), r); + e.rotate(e.index(), r); e.chunk().mark_scenery_modified(); } } @@ -190,9 +190,8 @@ void app::update_world(float dt) const auto size = es.size(); for (auto i = size-1; i != (std::size_t)-1; i--) { - auto iter = es.cbegin() + std::ptrdiff_t(i); auto& e = *es[i]; - c.with_scenery_update(e, [&] { return e.update(iter, dt); }); + c.with_scenery_update(e, [&] { return e.update(i, dt); }); } } } |
