@@ -1072,6 +1072,85 @@ TEST_CASE("WholeProjectRefactorer::ApplyRefactoringForVariablesContainer",
1072
1072
REQUIRE (instance.GetVariables ().Get (" MyRenamedVariable" ).GetValue () == 456 );
1073
1073
}
1074
1074
1075
+ SECTION (" Can rename an object variable (in events-based object)" ) {
1076
+ gd::Project project;
1077
+ gd::Platform platform;
1078
+ SetupProjectWithDummyPlatform (project, platform);
1079
+
1080
+ auto &eventsExtension =
1081
+ project.InsertNewEventsFunctionsExtension (" MyEventsExtension" , 0 );
1082
+ auto &eventsBasedObject = eventsExtension.GetEventsBasedObjects ().InsertNew (
1083
+ " MyEventsBasedObject" , 0 );
1084
+ auto &object = eventsBasedObject.GetObjects ().InsertNewObject (
1085
+ project, " MyExtension::Sprite" , " MyChildObject" , 0 );
1086
+ object.GetVariables ().InsertNew (" MyVariable" ).SetValue (123 );
1087
+ auto &instance =
1088
+ eventsBasedObject.GetInitialInstances ().InsertNewInitialInstance ();
1089
+ instance.SetObjectName (" MyChildObject" );
1090
+ instance.GetVariables ().InsertNew (" MyVariable" ).SetValue (456 );
1091
+
1092
+ auto &variant = eventsBasedObject.GetVariants ().InsertVariant (
1093
+ eventsBasedObject.GetDefaultVariant (), 0 );
1094
+ gd::InitialInstance *variantInstance = nullptr ;
1095
+ eventsBasedObject.GetInitialInstances ().IterateOverInstances (
1096
+ [&variantInstance](gd::InitialInstance &instance) {
1097
+ variantInstance = &instance;
1098
+ });
1099
+
1100
+ auto &objectFunction =
1101
+ eventsBasedObject.GetEventsFunctions ().GetEventsFunction (
1102
+ " MyObjectEventsFunction" );
1103
+ gd::StandardEvent &event = dynamic_cast <gd::StandardEvent &>(
1104
+ objectFunction.GetEvents ().InsertNewEvent (
1105
+ project, " BuiltinCommonInstructions::Standard" ));
1106
+
1107
+ {
1108
+ gd::Instruction action;
1109
+ action.SetType (" SetNumberObjectVariable" );
1110
+ action.SetParametersCount (4 );
1111
+ action.SetParameter (0 , gd::Expression (" MyChildObject" ));
1112
+ action.SetParameter (1 , gd::Expression (" MyVariable" ));
1113
+ action.SetParameter (2 , gd::Expression (" =" ));
1114
+ action.SetParameter (3 , gd::Expression (" MyChildObject.MyVariable" ));
1115
+ event.GetActions ().Insert (action);
1116
+ }
1117
+
1118
+ // Do the changes and launch the refactoring.
1119
+ object.GetVariables ().ResetPersistentUuid ();
1120
+ gd::SerializerElement originalSerializedVariables;
1121
+ object.GetVariables ().SerializeTo (originalSerializedVariables);
1122
+
1123
+ object.GetVariables ().Rename (" MyVariable" , " MyRenamedVariable" );
1124
+ auto changeset =
1125
+ gd::WholeProjectRefactorer::ComputeChangesetForVariablesContainer (
1126
+ originalSerializedVariables, object.GetVariables ());
1127
+
1128
+ REQUIRE (changeset.oldToNewVariableNames .size () == 1 );
1129
+
1130
+ gd::WholeProjectRefactorer::ApplyRefactoringForObjectVariablesContainer (
1131
+ project, object.GetVariables (), eventsBasedObject.GetInitialInstances (),
1132
+ object.GetName (), changeset, originalSerializedVariables);
1133
+ gd::ObjectVariableHelper::ApplyChangesToVariants (
1134
+ eventsBasedObject, " MyChildObject" , changeset);
1135
+
1136
+ REQUIRE (event.GetActions ()[0 ].GetParameter (1 ).GetPlainString () ==
1137
+ " MyRenamedVariable" );
1138
+ REQUIRE (event.GetActions ()[0 ].GetParameter (3 ).GetPlainString () ==
1139
+ " MyChildObject.MyRenamedVariable" );
1140
+ REQUIRE (instance.GetVariables ().Get (" MyRenamedVariable" ).GetValue () == 456 );
1141
+
1142
+ REQUIRE (eventsBasedObject.GetObjects ().HasObjectNamed (" MyChildObject" ));
1143
+ REQUIRE (eventsBasedObject.GetObjects ()
1144
+ .GetObject (" MyChildObject" )
1145
+ .GetVariables ()
1146
+ .Get (" MyRenamedVariable" )
1147
+ .GetValue () == 456 );
1148
+ REQUIRE (variantInstance != nullptr );
1149
+ REQUIRE (
1150
+ variantInstance->GetVariables ().Get (" MyRenamedVariable" ).GetValue () ==
1151
+ 456 );
1152
+ }
1153
+
1075
1154
SECTION (" Can delete an object variable" ) {
1076
1155
gd::Project project;
1077
1156
gd::Platform platform;
0 commit comments