Skip to content

Commit b509686

Browse files
committed
Lua On function check if object exists
Pointer is not over non_walkable_areas
1 parent 76a834c commit b509686

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

src/lua.cpp

+22-16
Original file line numberDiff line numberDiff line change
@@ -351,21 +351,24 @@ void Game::setupLuaFunctions()
351351
[this](const LuaSpineObject &object)
352352
{
353353
std::shared_ptr<SpineObject> obj = getObjectById(object);
354-
auto inter = std::static_pointer_cast<InteractableObject>(obj);
355-
obj->setParent(nullptr);
356-
for (auto it = pointer->attatchedObjects.begin(); it != pointer->attatchedObjects.end();)
354+
if (obj)
357355
{
358-
if ((*it) == nullptr || (*it) == obj)
359-
{
360-
it = pointer->attatchedObjects.erase(it);
361-
}
362-
else
356+
auto inter = std::static_pointer_cast<InteractableObject>(obj);
357+
obj->setParent(nullptr);
358+
for (auto it = pointer->attatchedObjects.begin(); it != pointer->attatchedObjects.end();)
363359
{
364-
++it;
360+
if ((*it) == nullptr || (*it) == obj)
361+
{
362+
it = pointer->attatchedObjects.erase(it);
363+
}
364+
else
365+
{
366+
++it;
367+
}
365368
}
369+
if (inter)
370+
inter->registerToDelete();
366371
}
367-
if (inter)
368-
inter->registerToDelete();
369372
});
370373

371374
/// Get all Spine points from this Spine object
@@ -845,12 +848,15 @@ void Game::setupLuaFunctions()
845848
[this](const LuaSpineObject &object, const LuaSpinePoint &point_name)
846849
{
847850
std::shared_ptr<SpineObject> obj = getObjectById(object);
848-
auto position = obj->getPoint(point_name);
849-
if (position)
851+
if (obj)
850852
{
851-
getDialogManager()->setSpeechBubblePosition(position.value());
852-
(*lua_state)["speech_bubble_position_x"] = position->x;
853-
(*lua_state)["speech_bubble_position_y"] = position->y;
853+
auto position = obj->getPoint(point_name);
854+
if (position)
855+
{
856+
getDialogManager()->setSpeechBubblePosition(position.value());
857+
(*lua_state)["speech_bubble_position_x"] = position->x;
858+
(*lua_state)["speech_bubble_position_y"] = position->y;
859+
}
854860
}
855861
});
856862

src/pointer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ bool Pointer::step(bool)
9494
if (obj->getVisible() &&
9595
!(_game->getInactivLayerBorder() > obj->layer) &&
9696
obj->bounds &&
97-
bool(spine::spSkeletonBounds_containsPointNotMatchingName(obj->bounds, "walkable_area", (float)position.x - (float)obj->getPosition().x, (float)position.y - (float)obj->getPosition().y)))
97+
bool(spine::spSkeletonBounds_containsPointNotMatchingName(obj->bounds, "walkable_area", (float)position.x - (float)obj->getPosition().x, (float)position.y - (float)obj->getPosition().y)) &&
98+
bool(spine::spSkeletonBounds_containsPointNotMatchingName(obj->bounds, "non_walkable_area", (float)position.x - (float)obj->getPosition().x, (float)position.y - (float)obj->getPosition().y)))
9899
{
99100
over = true;
100101
vibrate();

0 commit comments

Comments
 (0)