From 889870345539cc4dd0f098b976ba555916f17aff Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 16 Aug 2023 22:49:54 +0200 Subject: editor: don't allow entities on top of one another There are still workarounds for when this is actually desirable. --- editor/draw.cpp | 4 ++++ editor/editor.cpp | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'editor') diff --git a/editor/draw.cpp b/editor/draw.cpp index 9060f865..aa8cc5f0 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -20,6 +20,7 @@ void app::draw_cursor() { constexpr float LINE_WIDTH = 2; auto& shader = M->shader(); + auto& w = M->world(); const auto inactive_color = 0xff00ffff_rgbaf; if (cursor.tile && !cursor.in_imgui) @@ -56,6 +57,9 @@ void app::draw_cursor() auto [_f, _w, anim_mesh] = M->meshes(); const auto offset = Vector3i(Vector2i(sel.offset), 0); const auto pos = cursor.tile->to_signed3()*iTILE_SIZE + offset; + auto [ch, t] = w[*cursor.tile]; + if (!ch.can_place_entity(sel, cursor.tile->local())) + shader.set_tint({1, 0, 1, 0.5f}); anim_mesh.draw(shader, *sel.atlas, sel.r, sel.frame, Vector3(pos), 1); } } diff --git a/editor/editor.cpp b/editor/editor.cpp index 1b0611e1..a1de4b4f 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -110,7 +110,8 @@ void editor::on_click_(world& world, global_coords pos, button b) default: break; case button::place: if (const auto& sel = mode->get_selected()) - mode->place_tile(world, pos, sel, *_app); + if (auto [ch, t] = world[pos]; ch.can_place_entity(sel.proto, pos.local())) + mode->place_tile(world, pos, sel, *_app); break; case button::remove: mode->place_tile(world, pos, {}, *_app); -- cgit v1.2.3