mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
[WIP] Fix Expression object/behavior functions formatting and BehaviorField
This commit is contained in:
@@ -100,6 +100,9 @@ export class InstructionOrExpressionSelector extends Component {
|
||||
primaryText={instructionInfo.displayedName}
|
||||
secondaryText={instructionInfo.fullGroupName}
|
||||
value={instructionInfo.type}
|
||||
onClick={() => {
|
||||
this.props.onChoose(instructionInfo.type, instructionInfo);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
@@ -77,7 +77,7 @@ export default class BehaviorField extends Component {
|
||||
this.setState({ errorText: this.getError() });
|
||||
};
|
||||
|
||||
componentWillUpdate() {
|
||||
componentDidUpdate() {
|
||||
const { instructionOrExpression } = this.props;
|
||||
if (
|
||||
!instructionOrExpression ||
|
||||
@@ -85,16 +85,8 @@ export default class BehaviorField extends Component {
|
||||
)
|
||||
return;
|
||||
|
||||
const objectName = instructionOrExpression.getParameter(0);
|
||||
this._behaviorNames = gd
|
||||
.getBehaviorsOfObject(
|
||||
this.props.project,
|
||||
this.props.layout,
|
||||
objectName,
|
||||
true
|
||||
)
|
||||
.toJSArray();
|
||||
|
||||
// This is a bit hacky:
|
||||
// force the behavior selection if there is only one selectable behavior
|
||||
if (this._behaviorNames.length === 1) {
|
||||
if (this.props.value !== this._behaviorNames[0]) {
|
||||
this.props.onChange(this._behaviorNames[0]);
|
||||
|
@@ -1,6 +1,23 @@
|
||||
export const formatExpressionCall = (expressionInfo, parameterValues) => {
|
||||
const functionArgs = parameterValues.join(', ');
|
||||
const functionCall = `${expressionInfo.name}(${functionArgs})`;
|
||||
//@flow
|
||||
import { type InstructionOrExpressionInformation } from '../../InstructionOrExpressionSelector/InstructionOrExpressionInformation.flow.js';
|
||||
import { type ParameterValues } from './ExpressionParametersEditorDialog';
|
||||
|
||||
return functionCall;
|
||||
}
|
||||
export const formatExpressionCall = (
|
||||
expressionInfo: InstructionOrExpressionInformation,
|
||||
parameterValues: ParameterValues
|
||||
): string => {
|
||||
if (expressionInfo.objectMetadata) {
|
||||
const [objectName, ...otherParameters] = parameterValues;
|
||||
|
||||
const functionArgs = otherParameters.join(', ');
|
||||
return `${objectName}.${expressionInfo.name}(${functionArgs})`;
|
||||
} else if (expressionInfo.behaviorMetadata) {
|
||||
const [objectName, behaviorName, ...otherParameters] = parameterValues;
|
||||
|
||||
const functionArgs = otherParameters.join(', ');
|
||||
return `${objectName}.${behaviorName}::${expressionInfo.name}(${functionArgs})`;
|
||||
} else {
|
||||
const functionArgs = parameterValues.join(', ');
|
||||
return `${expressionInfo.name}(${functionArgs})`;
|
||||
}
|
||||
};
|
||||
|
@@ -1 +1,56 @@
|
||||
// TODO
|
||||
// @flow
|
||||
import { formatExpressionCall } from './FormatExpressionCall';
|
||||
import {
|
||||
enumerateExpressions,
|
||||
filterExpressions,
|
||||
} from '../../InstructionOrExpressionSelector/EnumerateExpressions';
|
||||
|
||||
describe('HelpButton', () => {
|
||||
const {
|
||||
freeExpressions,
|
||||
objectsExpressions,
|
||||
behaviorsExpressions,
|
||||
} = enumerateExpressions('number');
|
||||
|
||||
it('should properly format a free function', () => {
|
||||
const countExpression = filterExpressions(freeExpressions, 'Count')[0];
|
||||
expect(formatExpressionCall(countExpression, ['MyObject'])).toBe(
|
||||
'Count(MyObject)'
|
||||
);
|
||||
|
||||
const atan2Expression = filterExpressions(freeExpressions, 'atan2')[0];
|
||||
expect(formatExpressionCall(atan2Expression, ['1', '2'])).toBe(
|
||||
'atan2(1, 2)'
|
||||
);
|
||||
});
|
||||
|
||||
it('should properly format an object function', () => {
|
||||
const variableStringExpression = filterExpressions(
|
||||
objectsExpressions,
|
||||
'Variable'
|
||||
)[0];
|
||||
expect(
|
||||
formatExpressionCall(variableStringExpression, ['MyObject', 'Variable1'])
|
||||
).toBe('MyObject.Variable(Variable1)');
|
||||
});
|
||||
|
||||
it('should properly format an object function with an argument', () => {
|
||||
const pointXExpression = filterExpressions(objectsExpressions, 'PointX')[0];
|
||||
expect(
|
||||
formatExpressionCall(pointXExpression, ['MyObject', 'MyPoint'])
|
||||
).toBe('MyObject.PointX(MyPoint)');
|
||||
});
|
||||
|
||||
it('should properly format an object behavior function', () => {
|
||||
const variableStringExpression = filterExpressions(
|
||||
behaviorsExpressions,
|
||||
'JumpSpeed'
|
||||
)[0];
|
||||
expect(
|
||||
formatExpressionCall(variableStringExpression, [
|
||||
'MyObject',
|
||||
'PlatformerObject',
|
||||
])
|
||||
).toBe('MyObject.PlatformerObject::JumpSpeed()');
|
||||
});
|
||||
});
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { enumerateObjects, filterObjectsList } from '../EnumerateObjects';
|
||||
import { makeTestProject } from '../../fixtures/TestProject';
|
||||
import { enumerateObjects, filterObjectsList } from './EnumerateObjects';
|
||||
import { makeTestProject } from '../fixtures/TestProject';
|
||||
const gd = global.gd;
|
||||
|
||||
describe('EnumerateObjects', () => {
|
||||
@@ -12,9 +12,9 @@ describe('EnumerateObjects', () => {
|
||||
allObjectsList,
|
||||
} = enumerateObjects(project, testLayout);
|
||||
|
||||
expect(containerObjectsList).toHaveLength(5);
|
||||
expect(containerObjectsList).toHaveLength(6);
|
||||
expect(projectObjectsList).toHaveLength(2);
|
||||
expect(allObjectsList).toHaveLength(7);
|
||||
expect(allObjectsList).toHaveLength(8);
|
||||
});
|
||||
|
||||
it('can do a case-insensitive search in the lists of objects', () => {
|
@@ -116,6 +116,7 @@ export const makeTestProject = gd => {
|
||||
testLayout.insertObject(tiledSpriteObject, 0);
|
||||
testLayout.insertObject(panelSpriteObject, 0);
|
||||
testLayout.insertObject(spriteObject, 0);
|
||||
testLayout.insertObject(spriteObjectWithBehaviors, 0);
|
||||
|
||||
const group1 = new gd.ObjectGroup();
|
||||
group1.setName('GroupOfSprites');
|
||||
|
@@ -122,7 +122,11 @@ storiesOf('ParameterFields', module)
|
||||
.addDecorator(muiDecorator)
|
||||
.add('ExpressionField', () => (
|
||||
<ValueStateHolder initialValue={'MySpriteObject.X() + MouseX("", 0)'}>
|
||||
<ExpressionField project={project} layout={testLayout} parameterRenderingService={ParameterRenderingService} />
|
||||
<ExpressionField
|
||||
project={project}
|
||||
layout={testLayout}
|
||||
parameterRenderingService={ParameterRenderingService}
|
||||
/>
|
||||
</ValueStateHolder>
|
||||
));
|
||||
|
||||
@@ -212,13 +216,19 @@ storiesOf('EventsSheet', module)
|
||||
storiesOf('ExpressionSelector', module)
|
||||
.addDecorator(muiDecorator)
|
||||
.add('default', () => (
|
||||
<ExpressionSelector selectedType="" onChoose={action('Expression chosen')} />
|
||||
<ExpressionSelector
|
||||
selectedType=""
|
||||
onChoose={action('Expression chosen')}
|
||||
/>
|
||||
));
|
||||
|
||||
storiesOf('InstructionSelector', module)
|
||||
.addDecorator(muiDecorator)
|
||||
.add('default', () => (
|
||||
<InstructionSelector selectedType="" onChoose={action('Instruction chosen')} />
|
||||
<InstructionSelector
|
||||
selectedType=""
|
||||
onChoose={action('Instruction chosen')}
|
||||
/>
|
||||
));
|
||||
|
||||
storiesOf('InstructionEditor', module)
|
||||
|
Reference in New Issue
Block a user