Support placing crossing on top of factories
This commit is contained in:
parent
775adf6c3b
commit
4e7cb64d20
1 changed files with 66 additions and 50 deletions
|
|
@ -561,13 +561,9 @@ namespace gmtk
|
|||
sink(world, c, m);
|
||||
}
|
||||
|
||||
void clear_tile(map & map, location const & l)
|
||||
void destroy_tile_entity(map & map, ecs::handle entity)
|
||||
{
|
||||
auto entity = map.world->index<index>().find(l);
|
||||
if (!entity)
|
||||
return;
|
||||
|
||||
auto acc = map.world->get(*entity);
|
||||
auto acc = map.world->get(entity);
|
||||
|
||||
if (acc.contains<source>() || acc.contains<lab>())
|
||||
return;
|
||||
|
|
@ -583,6 +579,17 @@ namespace gmtk
|
|||
map.put_card(transformer_to_card(t->type));
|
||||
}
|
||||
|
||||
map.world->destroy(entity);
|
||||
}
|
||||
|
||||
void clear_tile(map & map, location const & l)
|
||||
{
|
||||
auto entity = map.world->index<index>().find(l);
|
||||
if (!entity)
|
||||
return;
|
||||
|
||||
destroy_tile_entity(map, *entity);
|
||||
|
||||
auto & index = map.world->index<path_index>();
|
||||
|
||||
for (int y = 0; y < 3; ++y)
|
||||
|
|
@ -644,8 +651,47 @@ namespace gmtk
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
map.world->destroy(*entity);
|
||||
bool place_card(map & map, card_type type, location const & l)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case card_type::mixer:
|
||||
case card_type::hue_shifter:
|
||||
case card_type::reshaper:
|
||||
map.world->create(
|
||||
vertex{l},
|
||||
transformer{card_to_transformer(type).value()}
|
||||
);
|
||||
return true;
|
||||
case card_type::crossing:
|
||||
map.world->create(
|
||||
vertex{l},
|
||||
crossing{}
|
||||
);
|
||||
return true;
|
||||
case card_type::zoomer:
|
||||
{
|
||||
map.world->create(
|
||||
vertex{l},
|
||||
zoomer{}
|
||||
);
|
||||
|
||||
auto c = l.down();
|
||||
|
||||
sink_belt(*map.world, c.left());
|
||||
sink_belt(*map.world, c.right());
|
||||
sink_belt(*map.world, c.bottom());
|
||||
sink_belt(*map.world, c.top());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
map start_menu_map()
|
||||
|
|
@ -1432,15 +1478,22 @@ namespace gmtk
|
|||
destroy_sound();
|
||||
clear_tile(map_, *selected_);
|
||||
}
|
||||
else if (auto t = map_.world->get(*entity).get_if<transformer>())
|
||||
else
|
||||
{
|
||||
if (auto n = card_to_transformer(*active_card_); n && n != t->type)
|
||||
auto acc = map_.world->get(*entity);
|
||||
auto t = acc.get_if<transformer>();
|
||||
auto n = card_to_transformer(*active_card_);
|
||||
|
||||
if (!acc.contains<zoomer>() && (!t || !n || t->type != *n))
|
||||
{
|
||||
if (map_.take_card(*active_card_))
|
||||
{
|
||||
built_sound();
|
||||
map_.put_card(transformer_to_card(t->type));
|
||||
t->type = *n;
|
||||
|
||||
destroy_tile_entity(map_, *entity);
|
||||
|
||||
place_card(map_, *active_card_, *selected_);
|
||||
|
||||
active_card_ = std::nullopt;
|
||||
|
||||
auto e = map_.world->index<path_index>().get(selected_->down());
|
||||
|
|
@ -1457,44 +1510,7 @@ namespace gmtk
|
|||
{
|
||||
if (map_.take_card(*active_card_))
|
||||
{
|
||||
bool built = false;
|
||||
switch (*active_card_)
|
||||
{
|
||||
case card_type::mixer:
|
||||
case card_type::hue_shifter:
|
||||
case card_type::reshaper:
|
||||
map_.world->create(
|
||||
vertex{*selected_},
|
||||
transformer{card_to_transformer(*active_card_).value()}
|
||||
);
|
||||
built = true;
|
||||
break;
|
||||
case card_type::crossing:
|
||||
map_.world->create(
|
||||
vertex{*selected_},
|
||||
crossing{}
|
||||
);
|
||||
built = true;
|
||||
break;
|
||||
case card_type::zoomer:
|
||||
{
|
||||
map_.world->create(
|
||||
vertex{*selected_},
|
||||
zoomer{}
|
||||
);
|
||||
|
||||
auto c = selected_->down();
|
||||
|
||||
sink_belt(*map_.world, c.left());
|
||||
sink_belt(*map_.world, c.right());
|
||||
sink_belt(*map_.world, c.bottom());
|
||||
sink_belt(*map_.world, c.top());
|
||||
built = true;
|
||||
}
|
||||
break;
|
||||
case card_type::eraser:
|
||||
break;
|
||||
}
|
||||
bool built = place_card(map_, *active_card_, *selected_);
|
||||
|
||||
if (built)
|
||||
{
|
||||
|
|
@ -2099,7 +2115,7 @@ namespace gmtk
|
|||
auto n = card_to_transformer(*active_card_);
|
||||
auto acc = map_.world->get(*entity);
|
||||
auto t = acc.get_if<transformer>();
|
||||
if (n && t && n != t->type)
|
||||
if (*active_card_ != card_type::eraser && (!n || !t || *n != t->type) && !acc.contains<zoomer>())
|
||||
{
|
||||
gfx::color_rgba color = {64, 64, 64, 255};
|
||||
draw_selection(selected_->bbox(), painter_, color, true);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue