Support keeping item when placing zoomer on it

This commit is contained in:
Nikita Lisitsa 2024-08-20 18:49:44 +03:00
parent 4e7cb64d20
commit 19bfac68b7

View file

@ -561,25 +561,34 @@ namespace gmtk
sink(world, c, m);
}
void destroy_tile_entity(map & map, ecs::handle entity)
std::optional<card_type> destroy_tile_entity(map & map, ecs::handle entity)
{
auto acc = map.world->get(entity);
if (acc.contains<source>() || acc.contains<lab>())
return;
return std::nullopt;
std::optional<card_type> result;
if (acc.contains<crossing>())
map.put_card(card_type::crossing);
{
result = card_type::crossing;
}
else if (acc.contains<zoomer>())
{
map.put_card(card_type::zoomer);
result = card_type::zoomer;
}
else if (auto t = acc.get_if<transformer>())
{
map.put_card(transformer_to_card(t->type));
result = transformer_to_card(t->type);
}
if (result)
map.put_card(*result);
map.world->destroy(entity);
return result;
}
void clear_tile(map & map, location const & l)
@ -1490,10 +1499,16 @@ namespace gmtk
{
built_sound();
destroy_tile_entity(map_, *entity);
auto dcard = destroy_tile_entity(map_, *entity);
place_card(map_, *active_card_, *selected_);
if (*active_card_ == card_type::zoomer && dcard)
{
map_.take_card(*dcard);
place_card(map_, *dcard, selected_->down());
}
active_card_ = std::nullopt;
auto e = map_.world->index<path_index>().get(selected_->down());