Skip to content

Commit 58fc18c

Browse files
jetrotalGhabry
authored andcommitted
AnimateVars - Refactor to use Interpreter's Push( ) command
1 parent abb7f9e commit 58fc18c

File tree

1 file changed

+17
-45
lines changed

1 file changed

+17
-45
lines changed

src/game_interpreter.cpp

+17-45
Original file line numberDiff line numberDiff line change
@@ -5354,15 +5354,8 @@ std::vector<double> interpolate(double start, double end, double duration, const
53545354
}
53555355

53565356
bool Game_Interpreter::CommandEasyRpgAnimateVariable(lcf::rpg::EventCommand const& com) {
5357-
// CommandInterpolateVariable("typeStart/typeEnd",[useVarTarget, target, useVarStart, start, useVarEnd, end, useVarDuration, duration])
5357+
// $InterpolateVariable("typeStart/typeEnd",[useVarTarget, target, useVarStart, start, useVarEnd, end, useVarDuration, duration])
53585358

5359-
auto* frame = GetFramePtr();
5360-
const auto& list = frame->commands;
5361-
auto& index = frame->current_command;
5362-
5363-
int i = frame->current_command + 1;
5364-
5365-
// Extract parameters: target, start, end, and duration for the animation
53665359
int32_t target = ValueOrVariable(com.parameters[0], com.parameters[1]);
53675360
int32_t start = ValueOrVariable(com.parameters[2], com.parameters[3]);
53685361
int32_t end = ValueOrVariable(com.parameters[4], com.parameters[5]);
@@ -5372,13 +5365,12 @@ bool Game_Interpreter::CommandEasyRpgAnimateVariable(lcf::rpg::EventCommand cons
53725365
lcf::rpg::EventCommand waitCom;
53735366
waitCom.code = int(Cmd::Wait);
53745367

5375-
lcf::rpg::EventCommand updateVarCom;
5376-
updateVarCom.code = int(Cmd::ControlVars);
5377-
std::vector<int32_t> updateVarParams = { 0, static_cast<int32_t>(target), 0, 0, 0, static_cast<int32_t>(end) };
5378-
updateVarCom.parameters = lcf::DBArray<int32_t>(updateVarParams.begin(), updateVarParams.end());
5368+
lcf::rpg::EventCommand animatedCom;
5369+
animatedCom.code = int(Cmd::ControlVars);
5370+
std::vector<int32_t> animatedVarParams = { 0, static_cast<int32_t>(target), 0, 0, 0, static_cast<int32_t>(end) };
5371+
animatedCom.parameters = lcf::DBArray<int32_t>(animatedVarParams.begin(), animatedVarParams.end());
53795372

5380-
lcf::rpg::EventCommand branchCom;
5381-
branchCom.code = int(Cmd::ShowChoiceOption);
5373+
std::vector<lcf::rpg::EventCommand> cmdList;
53825374

53835375
// Extract easing information
53845376
std::string easeStart = ToString(com.string);
@@ -5391,41 +5383,21 @@ bool Game_Interpreter::CommandEasyRpgAnimateVariable(lcf::rpg::EventCommand cons
53915383
easeStart = easeStart.substr(0, pos);
53925384
}
53935385

5394-
// Check if new commands don't exist in the timeline yet
5395-
if (!(i < frame->commands.size() && frame->commands.at(i).code == int(Cmd::ShowChoiceOption))) {
5396-
// Insert animation commands
5397-
Output::Debug("inserting animation commands");
5398-
std::vector<double> interpolatedValues = interpolate(start, end, duration, easeStart, easeEnd);
5399-
5400-
// Insert ShowChoiceOption command
5401-
// This helps me isolating all the "keyframes" commands inside a nested commands, it also helps to avoid creating a repeated list.
5402-
// It's problematic when "start", "end" and "duration" are variables.
5403-
frame->commands.insert(frame->commands.begin() + i, branchCom);
5404-
i++;
5405-
5406-
// Insert updateVarCom and waitCom commands for each interpolated value
5407-
for (int value : interpolatedValues) {
5408-
updateVarParams.back() = value;
5409-
updateVarCom.parameters = lcf::DBArray<int32_t>(updateVarParams.begin(), updateVarParams.end());
5410-
updateVarCom.indent = com.indent + 1;
5386+
// Insert animation commands
5387+
std::vector<double> interpolatedValues = interpolate(start, end, duration, easeStart, easeEnd);
54115388

5412-
frame->commands.insert(frame->commands.begin() + i, updateVarCom);
5413-
i++;
5414-
frame->commands.insert(frame->commands.begin() + i, waitCom);
5415-
i++;
5416-
}
5389+
// Insert animatedCom and waitCom commands for each interpolated value
5390+
for (int value : interpolatedValues) {
5391+
animatedVarParams.back() = value;
5392+
animatedCom.parameters = lcf::DBArray<int32_t>(animatedVarParams.begin(), animatedVarParams.end());
5393+
animatedCom.indent = com.indent + 1;
54175394

5418-
// Insert ShowChoiceEnd command
5419-
branchCom.code = int(Cmd::ShowChoiceEnd);
5420-
frame->commands.insert(frame->commands.begin() + i, branchCom);
5421-
i++;
5422-
}
5423-
else {
5424-
Output::Debug("Animated Commands Already Exists");
5395+
cmdList.push_back(animatedCom);
5396+
cmdList.push_back(waitCom);
54255397
}
54265398

54275399
// Update current_command index and return true to indicate success
5428-
frame->current_command = index + 2;
5429-
return false;
5400+
Push(cmdList, 0, false);
5401+
return true;
54305402
}
54315403

0 commit comments

Comments
 (0)