Skip to content

Commit

Permalink
spawn logical door entities on grid and uncrashing
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Oct 6, 2023
1 parent de6f81a commit d055481
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/injected/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,11 @@ std::string spawned_type()

int32_t spawn_entityitem(EntityItem to_spawn, bool s, bool set_last = true)
{
static const ENT_TYPE also_snap[] = {
to_id("ENT_TYPE_LOGICAL_DOOR"),
to_id("ENT_TYPE_LOGICAL_BLACKMARKET_DOOR"),
to_id("ENT_TYPE_LOGICAL_PLATFORM_SPAWNER"),
};
bool flip = g_vx < -0.04f;
std::pair<float, float> cpos = UI::click_position(g_x, g_y);
if (to_spawn.name.find("ENT_TYPE_CHAR") != std::string::npos)
Expand All @@ -1332,7 +1337,11 @@ int32_t spawn_entityitem(EntityItem to_spawn, bool s, bool set_last = true)
else if (to_spawn.name.find("ENT_TYPE_LIQUID") == std::string::npos)
{
bool snap = options["snap_to_grid"];
if (to_spawn.name.find("ENT_TYPE_FLOOR") != std::string::npos)
if (std::find(std::begin(also_snap), std::end(also_snap), to_spawn.id) != std::end(also_snap))
{
snap = true;
}
else if (to_spawn.name.find("ENT_TYPE_FLOOR") != std::string::npos)
{
snap = true;
g_vx = 0;
Expand Down Expand Up @@ -1383,12 +1392,18 @@ int32_t spawn_entityitem(EntityItem to_spawn, bool s, bool set_last = true)
callbacks.push_back(cb);
}
}
else if (flip)
if (flip)
{
auto ent = get_entity_ptr(spawned);
if (ent)
ent->flags |= (1U << 16);
}
if (to_spawn.id == also_snap[0])
{
auto ent = get_entity_ptr(spawned)->as<LogicalDoor>();
ent->door_type = to_id("ENT_TYPE_FLOOR_DOOR_LAYER");
ent->platform_type = to_id("ENT_TYPE_FLOOR_DOOR_PLATFORM");
}
if (!lock_entity && set_last)
g_last_id = spawned;
return spawned;
Expand Down

0 comments on commit d055481

Please sign in to comment.