Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ const CompactEventsFunctionParametersEditor: React.ComponentType<{
const moveParameter = React.useCallback(
(oldIndex: number, newIndex: number) => {
const parameters = eventsFunction.getParameters();

// const sentence = eventsFunction.getSentence()
if (eventsBasedBehavior) {
if (onMoveBehaviorEventsParameter)
onMoveBehaviorEventsParameter(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @flow
export const remapSentenceParamIndices = (
sentence: string,
oldIndex: number,
newIndex: number,
offset: number
): string => {
return sentence.replace(/_PARAM(\d+)_/g, (match, digits) => {
const index = parseInt(digits, 10);
let finalIndex = index;
if (index < offset) {
finalIndex = index;
} else if (index === oldIndex + offset) {
finalIndex = newIndex + offset;
} else if (index > offset + oldIndex && index <= offset + newIndex) {
finalIndex = index - 1;
} else if (index >= offset + newIndex && index < offset + oldIndex) {
finalIndex = index + 1;
}
return `_PARAM${finalIndex}_`;
});
};
40 changes: 39 additions & 1 deletion newIDE/app/src/EventsFunctionsExtensionEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import PropertyListEditor, {
import type { EventPath } from '../Utils/EventPath';
import type { SearchFilterParams } from '../Utils/Search';
import { type VariableDialogOpeningProps } from '../VariablesList/VariablesEditorDialog';
import { remapSentenceParamIndices } from './EventsFunctionConfigurationEditor/SentenceParameterRemapping';

const gd: libGDevelop = global.gd;

Expand Down Expand Up @@ -609,6 +610,13 @@ export default class EventsFunctionsExtensionEditor extends React.Component<
newIndex + ParametersIndexOffsets.FreeFunction
);

this._remapEventsFunctionSentence(
eventsFunction,
oldIndex,
newIndex,
ParametersIndexOffsets.FreeFunction
);

done(true);
};

Expand All @@ -620,7 +628,6 @@ export default class EventsFunctionsExtensionEditor extends React.Component<
done: boolean => void
) => {
// Don't ask for user confirmation as this change is easy to revert.

const { project, eventsFunctionsExtension } = this.props;
gd.WholeProjectRefactorer.moveBehaviorEventsFunctionParameter(
project,
Expand All @@ -631,6 +638,13 @@ export default class EventsFunctionsExtensionEditor extends React.Component<
newIndex
);

this._remapEventsFunctionSentence(
eventsFunction,
oldIndex,
newIndex,
ParametersIndexOffsets.BehaviorFunction
);

done(true);
};

Expand All @@ -653,9 +667,33 @@ export default class EventsFunctionsExtensionEditor extends React.Component<
newIndex
);

this._remapEventsFunctionSentence(
eventsFunction,
oldIndex,
newIndex,
ParametersIndexOffsets.ObjectFunction
);

done(true);
};

_remapEventsFunctionSentence = (
eventsFunction: gdEventsFunction,
oldIndex: number,
newIndex: number,
offset: number
): void => {
const sentence = eventsFunction.getSentence();
if (sentence) {
const newSentence = remapSentenceParamIndices(
sentence,
oldIndex,
newIndex,
offset
);
eventsFunction.setSentence(newSentence);
}
};
_onDeleteEventsFunction = (
eventsFunction: gdEventsFunction,
cb: boolean => void
Expand Down