diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-08-16 22:49:54 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-08-16 22:49:54 +0200 |
commit | 889870345539cc4dd0f098b976ba555916f17aff (patch) | |
tree | 28dbd15ec0f97b2beda2b0174c1ac19a8742b113 /editor | |
parent | 125cb3c0feb94e51b830957fb44ccc709b6afa61 (diff) |
editor: don't allow entities on top of one another
There are still workarounds for when this is actually desirable.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/draw.cpp | 4 | ||||
-rw-r--r-- | editor/editor.cpp | 3 |
2 files changed, 6 insertions, 1 deletions
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); |