@@ -5371,15 +5371,8 @@ std::vector<double> interpolate(double start, double end, double duration, const
5371
5371
}
5372
5372
5373
5373
bool Game_Interpreter::CommandAnimateVariable (lcf::rpg::EventCommand const & com) {
5374
- // CommandInterpolateVariable ("typeStart/typeEnd",[useVarTarget, target, useVarStart, start, useVarEnd, end, useVarDuration, duration])
5374
+ // $InterpolateVariable ("typeStart/typeEnd",[useVarTarget, target, useVarStart, start, useVarEnd, end, useVarDuration, duration])
5375
5375
5376
- auto * frame = GetFramePtr ();
5377
- const auto & list = frame->commands ;
5378
- auto & index = frame->current_command ;
5379
-
5380
- int i = frame->current_command + 1 ;
5381
-
5382
- // Extract parameters: target, start, end, and duration for the animation
5383
5376
int32_t target = ValueOrVariable (com.parameters [0 ], com.parameters [1 ]);
5384
5377
int32_t start = ValueOrVariable (com.parameters [2 ], com.parameters [3 ]);
5385
5378
int32_t end = ValueOrVariable (com.parameters [4 ], com.parameters [5 ]);
@@ -5389,13 +5382,12 @@ bool Game_Interpreter::CommandAnimateVariable(lcf::rpg::EventCommand const& com)
5389
5382
lcf::rpg::EventCommand waitCom;
5390
5383
waitCom.code = int (Cmd::Wait);
5391
5384
5392
- lcf::rpg::EventCommand updateVarCom ;
5393
- updateVarCom .code = int (Cmd::ControlVars);
5394
- std::vector<int32_t > updateVarParams = { 0 , static_cast <int32_t >(target), 0 , 0 , 0 , static_cast <int32_t >(end) };
5395
- updateVarCom .parameters = lcf::DBArray<int32_t >(updateVarParams .begin (), updateVarParams .end ());
5385
+ lcf::rpg::EventCommand animatedCom ;
5386
+ animatedCom .code = int (Cmd::ControlVars);
5387
+ std::vector<int32_t > animatedVarParams = { 0 , static_cast <int32_t >(target), 0 , 0 , 0 , static_cast <int32_t >(end) };
5388
+ animatedCom .parameters = lcf::DBArray<int32_t >(animatedVarParams .begin (), animatedVarParams .end ());
5396
5389
5397
- lcf::rpg::EventCommand branchCom;
5398
- branchCom.code = int (Cmd::ShowChoiceOption);
5390
+ std::vector<lcf::rpg::EventCommand> cmdList;
5399
5391
5400
5392
// Extract easing information
5401
5393
std::string easeStart = ToString (com.string );
@@ -5408,41 +5400,21 @@ bool Game_Interpreter::CommandAnimateVariable(lcf::rpg::EventCommand const& com)
5408
5400
easeStart = easeStart.substr (0 , pos);
5409
5401
}
5410
5402
5411
- // Check if new commands don't exist in the timeline yet
5412
- if (!(i < frame->commands .size () && frame->commands .at (i).code == int (Cmd::ShowChoiceOption))) {
5413
- // Insert animation commands
5414
- Output::Debug (" inserting animation commands" );
5415
- std::vector<double > interpolatedValues = interpolate (start, end, duration, easeStart, easeEnd);
5416
-
5417
- // Insert ShowChoiceOption command
5418
- // This helps me isolating all the "keyframes" commands inside a nested commands, it also helps to avoid creating a repeated list.
5419
- // It's problematic when "start", "end" and "duration" are variables.
5420
- frame->commands .insert (frame->commands .begin () + i, branchCom);
5421
- i++;
5422
-
5423
- // Insert updateVarCom and waitCom commands for each interpolated value
5424
- for (int value : interpolatedValues) {
5425
- updateVarParams.back () = value;
5426
- updateVarCom.parameters = lcf::DBArray<int32_t >(updateVarParams.begin (), updateVarParams.end ());
5427
- updateVarCom.indent = com.indent + 1 ;
5403
+ // Insert animation commands
5404
+ std::vector<double > interpolatedValues = interpolate (start, end, duration, easeStart, easeEnd);
5428
5405
5429
- frame-> commands . insert (frame-> commands . begin () + i, updateVarCom);
5430
- i++;
5431
- frame-> commands . insert (frame-> commands . begin () + i, waitCom) ;
5432
- i++ ;
5433
- }
5406
+ // Insert animatedCom and waitCom commands for each interpolated value
5407
+ for ( int value : interpolatedValues) {
5408
+ animatedVarParams. back () = value ;
5409
+ animatedCom. parameters = lcf::DBArray< int32_t >(animatedVarParams. begin (), animatedVarParams. end ()) ;
5410
+ animatedCom. indent = com. indent + 1 ;
5434
5411
5435
- // Insert ShowChoiceEnd command
5436
- branchCom.code = int (Cmd::ShowChoiceEnd);
5437
- frame->commands .insert (frame->commands .begin () + i, branchCom);
5438
- i++;
5439
- }
5440
- else {
5441
- Output::Debug (" Animated Commands Already Exists" );
5412
+ cmdList.push_back (animatedCom);
5413
+ cmdList.push_back (waitCom);
5442
5414
}
5443
5415
5444
5416
// Update current_command index and return true to indicate success
5445
- frame-> current_command = index + 2 ;
5446
- return false ;
5417
+ Push (cmdList, 0 , false ) ;
5418
+ return true ;
5447
5419
}
5448
5420
0 commit comments