animates a named property of the specified game object or component * * This is only supported for numerical properties. If the node property is already being * animated, that animation will be canceled and replaced by the new one. * * If a `complete_function` (lua function) is specified, that function will be called when the animation has completed. * By starting a n
| 1612 | * ``` |
| 1613 | */ |
| 1614 | int Script_Animate(lua_State* L) |
| 1615 | { |
| 1616 | int top = lua_gettop(L); |
| 1617 | (void)top; |
| 1618 | |
| 1619 | DM_HASH_REVERSE_MEM(hash_ctx, 256); |
| 1620 | ScriptInstance* i = ScriptInstance_Check(L); |
| 1621 | Instance* instance = i->m_Instance; |
| 1622 | dmMessage::URL sender; |
| 1623 | dmScript::GetURL(L, &sender); |
| 1624 | dmMessage::URL target; |
| 1625 | dmScript::ResolveURL(L, 1, &target, &sender); |
| 1626 | HCollection collection = dmGameObject::GetCollection(instance); |
| 1627 | if (target.m_Socket != dmGameObject::GetMessageSocket(collection)) |
| 1628 | { |
| 1629 | luaL_error(L, "go.animate can only animate instances within the same collection."); |
| 1630 | } |
| 1631 | dmhash_t property_id = 0; |
| 1632 | if (lua_isstring(L, 2)) |
| 1633 | { |
| 1634 | property_id = dmHashString64(lua_tostring(L, 2)); |
| 1635 | } |
| 1636 | else |
| 1637 | { |
| 1638 | property_id = dmScript::CheckHash(L, 2); |
| 1639 | } |
| 1640 | dmGameObject::HInstance target_instance = dmGameObject::GetInstanceFromIdentifier(collection, target.m_Path); |
| 1641 | if (target_instance == 0) |
| 1642 | return luaL_error(L, "Could not find any instance with id '%s'.", dmHashReverseSafe64Alloc(&hash_ctx, target.m_Path)); |
| 1643 | lua_Integer playback = luaL_checkinteger(L, 3); |
| 1644 | if (playback >= PLAYBACK_COUNT) |
| 1645 | return luaL_error(L, "invalid playback mode when starting an animation"); |
| 1646 | dmGameObject::PropertyVar property_var; |
| 1647 | dmGameObject::PropertyResult result = dmGameObject::LuaToVar(L, 4, property_var); |
| 1648 | if (result != PROPERTY_RESULT_OK) |
| 1649 | { |
| 1650 | return luaL_error(L, "only numerical values can be used as target values for animation"); |
| 1651 | } |
| 1652 | |
| 1653 | dmEasing::Curve curve; |
| 1654 | if (lua_isnumber(L, 5)) |
| 1655 | { |
| 1656 | curve.type = (dmEasing::Type)luaL_checkinteger(L, 5); |
| 1657 | if (curve.type >= dmEasing::TYPE_COUNT) |
| 1658 | return luaL_error(L, "invalid easing constant"); |
| 1659 | } |
| 1660 | else if (dmScript::IsVector(L, 5)) |
| 1661 | { |
| 1662 | curve.type = dmEasing::TYPE_FLOAT_VECTOR; |
| 1663 | curve.vector = dmScript::CheckVector(L, 5); |
| 1664 | |
| 1665 | lua_pushvalue(L, 5); |
| 1666 | curve.release_callback = LuaCurveRelease; |
| 1667 | curve.userdata1 = L; |
| 1668 | curve.userdata2 = (void*)(uintptr_t)dmScript::Ref(L, LUA_REGISTRYINDEX); |
| 1669 | } |
| 1670 | else |
| 1671 | { |
nothing calls this directly
no test coverage detected