@@ -305,39 +305,15 @@ int CLuaEngineDefs::EngineLoadIFP ( lua_State* luaVM )
305
305
// Is this a legal filepath?
306
306
if ( CResourceManager::ParseResourcePathInput ( strFile, pResource, &strPath ) )
307
307
{
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 )
338
310
{
339
- argStream.SetCustomError ( strFile, " Block name already exists" );
311
+ // Return the IFP element
312
+ lua_pushelement ( luaVM, pIFP.get ( ) );
313
+ return 1 ;
340
314
}
315
+ else
316
+ argStream.SetCustomError ( strFile, " Error loading IFP" );
341
317
}
342
318
else
343
319
argStream.SetCustomError ( strFile, " Bad file path" );
@@ -526,27 +502,10 @@ int CLuaEngineDefs::EngineReplaceAnimation ( lua_State* luaVM )
526
502
527
503
if ( !argStream.HasErrors () )
528
504
{
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 ;
550
509
}
551
510
}
552
511
if ( argStream.HasErrors () )
@@ -560,23 +519,22 @@ int CLuaEngineDefs::EngineReplaceAnimation ( lua_State* luaVM )
560
519
int CLuaEngineDefs::EngineRestoreAnimation ( lua_State* luaVM )
561
520
{
562
521
CClientEntity * pEntity = nullptr ;
563
- bool bRestoreAllAnimations = false ;
564
- bool bRestoreBlockAnimations = false ;
522
+ CIFPEngine::eRestoreAnimation eRestoreType = CIFPEngine::eRestoreAnimation::SINGLE;
565
523
SString strInternalBlockName = " " ;
566
524
SString strInternalAnimName = " " ;
567
525
568
526
CScriptArgReader argStream ( luaVM );
569
527
argStream.ReadUserData ( pEntity );
570
528
if ( argStream.NextIsNil ( ) || argStream.NextIsNone ( ) )
571
529
{
572
- bRestoreAllAnimations = true ;
530
+ eRestoreType = CIFPEngine::eRestoreAnimation::ALL ;
573
531
}
574
532
else
575
533
{
576
534
argStream.ReadString ( strInternalBlockName );
577
535
if ( argStream.NextIsNil ( ) || argStream.NextIsNone ( ) )
578
536
{
579
- bRestoreBlockAnimations = true ;
537
+ eRestoreType = CIFPEngine::eRestoreAnimation::BLOCK ;
580
538
}
581
539
else
582
540
{
@@ -586,44 +544,10 @@ int CLuaEngineDefs::EngineRestoreAnimation ( lua_State* luaVM )
586
544
587
545
if ( !argStream.HasErrors () )
588
546
{
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 ;
627
551
}
628
552
}
629
553
if ( argStream.HasErrors () )
0 commit comments