@@ -305,39 +305,15 @@ int CLuaEngineDefs::EngineLoadIFP ( lua_State* luaVM )
305305 // Is this a legal filepath?
306306 if ( CResourceManager::ParseResourcePathInput ( strFile, pResource, &strPath ) )
307307 {
308- // Grab the resource root entity
309- CClientEntity* pRoot = pResource->GetResourceIFPRoot ();
310-
311- // Check whether the IFP blockname exists or not
312- if ( g_pClientGame->GetIFPPointerFromMap ( strBlockName ) == nullptr )
313- {
314- // Create a IFP element
315- std::shared_ptr < CClientIFP > pIFP ( new CClientIFP ( m_pManager, INVALID_ELEMENT_ID ) );
316-
317- // Try to load the IFP file
318- if ( pIFP->LoadIFP ( strPath, strBlockName ) )
319- {
320- // We can use the map to retrieve correct IFP by block name later
321- g_pClientGame->InsertIFPPointerToMap ( strBlockName, pIFP );
322-
323- // Success loading the file. Set parent to IFP root
324- pIFP->SetParent ( pRoot );
325-
326- // Return the IFP element
327- lua_pushelement ( luaVM, pIFP.get ( ) );
328- return 1 ;
329- }
330- else
331- {
332- // Delete it again
333- // delete pIFP;
334- argStream.SetCustomError ( strFile, " Error loading IFP" );
335- }
336- }
337- else
308+ std::shared_ptr < CClientIFP > pIFP = CIFPEngine::EngineLoadIFP ( pResource, m_pManager, strPath, strBlockName );
309+ if ( pIFP != nullptr )
338310 {
339- argStream.SetCustomError ( strFile, " Block name already exists" );
311+ // Return the IFP element
312+ lua_pushelement ( luaVM, pIFP.get ( ) );
313+ return 1 ;
340314 }
315+ else
316+ argStream.SetCustomError ( strFile, " Error loading IFP" );
341317 }
342318 else
343319 argStream.SetCustomError ( strFile, " Bad file path" );
@@ -526,27 +502,10 @@ int CLuaEngineDefs::EngineReplaceAnimation ( lua_State* luaVM )
526502
527503 if ( !argStream.HasErrors () )
528504 {
529- if ( IS_PED ( pEntity ) )
530- {
531- CClientPed& Ped = static_cast < CClientPed& > ( *pEntity );
532-
533- CAnimBlock * pInternalBlock = g_pGame->GetAnimManager ()->GetAnimationBlock ( strInternalBlockName );
534- std::shared_ptr < CClientIFP > pCustomIFP = g_pClientGame->GetIFPPointerFromMap ( strCustomBlockName );
535- if ( pInternalBlock && pCustomIFP )
536- {
537- CAnimBlendHierarchy * pInternalAnimHierarchy = g_pGame->GetAnimManager ()->GetAnimation ( strInternalAnimName, pInternalBlock );
538- CAnimBlendHierarchySAInterface * pCustomAnimHierarchyInterface = pCustomIFP->GetAnimationHierarchy ( strCustomAnimName );
539- if ( pInternalAnimHierarchy && pCustomAnimHierarchyInterface )
540- {
541- Ped.ReplaceAnimation ( pInternalAnimHierarchy, pCustomIFP, pCustomAnimHierarchyInterface );
542- lua_pushboolean ( luaVM, true );
543- return 1 ;
544- }
545- else
546- argStream.SetCustomError ( " Incorrect Animation name" );
547- }
548- else
549- argStream.SetCustomError ( " Incorrect Block name" );
505+ if ( CIFPEngine::EngineReplaceAnimation ( pEntity, strInternalBlockName, strInternalAnimName, strCustomBlockName, strCustomAnimName ) )
506+ {
507+ lua_pushboolean ( luaVM, true );
508+ return 1 ;
550509 }
551510 }
552511 if ( argStream.HasErrors () )
@@ -560,23 +519,22 @@ int CLuaEngineDefs::EngineReplaceAnimation ( lua_State* luaVM )
560519int CLuaEngineDefs::EngineRestoreAnimation ( lua_State* luaVM )
561520{
562521 CClientEntity * pEntity = nullptr ;
563- bool bRestoreAllAnimations = false ;
564- bool bRestoreBlockAnimations = false ;
522+ CIFPEngine::eRestoreAnimation eRestoreType = CIFPEngine::eRestoreAnimation::SINGLE;
565523 SString strInternalBlockName = " " ;
566524 SString strInternalAnimName = " " ;
567525
568526 CScriptArgReader argStream ( luaVM );
569527 argStream.ReadUserData ( pEntity );
570528 if ( argStream.NextIsNil ( ) || argStream.NextIsNone ( ) )
571529 {
572- bRestoreAllAnimations = true ;
530+ eRestoreType = CIFPEngine::eRestoreAnimation::ALL ;
573531 }
574532 else
575533 {
576534 argStream.ReadString ( strInternalBlockName );
577535 if ( argStream.NextIsNil ( ) || argStream.NextIsNone ( ) )
578536 {
579- bRestoreBlockAnimations = true ;
537+ eRestoreType = CIFPEngine::eRestoreAnimation::BLOCK ;
580538 }
581539 else
582540 {
@@ -586,44 +544,10 @@ int CLuaEngineDefs::EngineRestoreAnimation ( lua_State* luaVM )
586544
587545 if ( !argStream.HasErrors () )
588546 {
589- if ( IS_PED ( pEntity ) )
590- {
591- CClientEntity & Entity = *pEntity;
592- CClientPed& Ped = static_cast < CClientPed& > ( Entity );
593-
594- if ( bRestoreAllAnimations )
595- {
596- Ped.RestoreAllAnimations ( );
597- lua_pushboolean ( luaVM, true );
598- return 1 ;
599- }
600- else
601- {
602- CAnimBlock * pInternalBlock = g_pGame->GetAnimManager ()->GetAnimationBlock ( strInternalBlockName );
603- if ( pInternalBlock )
604- {
605- if ( bRestoreBlockAnimations )
606- {
607- Ped.RestoreAnimations ( *pInternalBlock );
608- lua_pushboolean ( luaVM, true );
609- return 1 ;
610- }
611- else
612- {
613- CAnimBlendHierarchy * pInternalAnimHierarchy = g_pGame->GetAnimManager ()->GetAnimation ( strInternalAnimName, pInternalBlock );
614- if ( pInternalAnimHierarchy )
615- {
616- Ped.RestoreAnimation ( pInternalAnimHierarchy );
617- lua_pushboolean ( luaVM, true );
618- return 1 ;
619- }
620- else
621- argStream.SetCustomError ( " Incorrect Animation name" );
622- }
623- }
624- else
625- argStream.SetCustomError ( " Incorrect Block name" );
626- }
547+ if ( CIFPEngine::EngineRestoreAnimation ( pEntity, strInternalBlockName, strInternalAnimName, eRestoreType ) )
548+ {
549+ lua_pushboolean ( luaVM, true );
550+ return 1 ;
627551 }
628552 }
629553 if ( argStream.HasErrors () )
0 commit comments