mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-07-21 01:25:32 -04:00
75bfa5cb45
- Global or scene variables can be used with a unique action and condition. - Object variables can be used with a unique action and condition. - Variables need to be declared following the same logic as the new expression syntax. - Local variable can be declared on events - Extensions have their own variables - Show a diagnostic report when a preview is launched and there are missing scene variables, object variables or behaviors. - This is especially useful if external events are shared between several scenes.
128 lines
4.0 KiB
JavaScript
128 lines
4.0 KiB
JavaScript
const initializeGDevelopJs = require('../../Binaries/embuild/GDevelop.js/libGD.js');
|
|
const { makeMinimalGDJSMock } = require('../TestUtils/GDJSMocks.js');
|
|
const {
|
|
generateCompiledEventsFromSerializedEvents,
|
|
} = require('../TestUtils/CodeGenerationHelpers.js');
|
|
|
|
describe('libGD.js - GDJS Code Generation integration tests', function () {
|
|
let gd = null;
|
|
beforeAll(async () => {
|
|
gd = await initializeGDevelopJs();
|
|
});
|
|
|
|
const generateAndRunVariableAffectationWithConditions = (
|
|
conditions
|
|
) => {
|
|
const serializerElement = gd.Serializer.fromJSObject([
|
|
{
|
|
type: 'BuiltinCommonInstructions::Standard',
|
|
conditions,
|
|
actions: [
|
|
{
|
|
type: { value: 'ModVarScene' },
|
|
parameters: ['SuccessVariable', '=', '1'],
|
|
},
|
|
],
|
|
events: [],
|
|
},
|
|
]);
|
|
|
|
const runCompiledEvents = generateCompiledEventsFromSerializedEvents(
|
|
gd,
|
|
serializerElement,
|
|
{ logCode: false }
|
|
);
|
|
|
|
const { gdjs, runtimeScene } = makeMinimalGDJSMock();
|
|
runCompiledEvents(gdjs, runtimeScene, []);
|
|
return runtimeScene;
|
|
};
|
|
|
|
it('can generate a string comparison condition that is true', function () {
|
|
const runtimeScene = generateAndRunVariableAffectationWithConditions(
|
|
[
|
|
{
|
|
type: { inverted: false, value: 'BuiltinCommonInstructions::CompareStrings' },
|
|
parameters: ['"Same value"', '=', '"Same value"'],
|
|
},
|
|
]
|
|
);
|
|
|
|
expect(runtimeScene.getVariables().has('SuccessVariable')).toBe(true);
|
|
expect(
|
|
runtimeScene.getVariables().get('SuccessVariable').getAsNumber()
|
|
).toBe(1);
|
|
});
|
|
|
|
it('can generate a string comparison condition that is false', function () {
|
|
const runtimeScene = generateAndRunVariableAffectationWithConditions(
|
|
[
|
|
{
|
|
type: { inverted: false, value: 'BuiltinCommonInstructions::CompareStrings' },
|
|
parameters: ['"Not the same"', '=', '"Different"'],
|
|
},
|
|
]
|
|
);
|
|
|
|
expect(runtimeScene.getVariables().has('SuccessVariable')).toBe(false);
|
|
});
|
|
|
|
it('can generate a string comparison inverted condition that is false', function () {
|
|
const runtimeScene = generateAndRunVariableAffectationWithConditions(
|
|
[
|
|
{
|
|
type: { inverted: true, value: 'BuiltinCommonInstructions::CompareStrings' },
|
|
parameters: ['"Same value"', '=', '"Same value"'],
|
|
},
|
|
]
|
|
);
|
|
|
|
expect(runtimeScene.getVariables().has('SuccessVariable')).toBe(false);
|
|
});
|
|
|
|
it('can generate a string comparison inverted condition that is true', function () {
|
|
const runtimeScene = generateAndRunVariableAffectationWithConditions(
|
|
[
|
|
{
|
|
type: { inverted: true, value: 'BuiltinCommonInstructions::CompareStrings' },
|
|
parameters: ['"Not the same"', '=', '"Different"'],
|
|
},
|
|
]
|
|
);
|
|
|
|
expect(runtimeScene.getVariables().has('SuccessVariable')).toBe(true);
|
|
expect(
|
|
runtimeScene.getVariables().get('SuccessVariable').getAsNumber()
|
|
).toBe(1);
|
|
});
|
|
|
|
it('can generate a string comparison condition that is true with a contains operator', function () {
|
|
const runtimeScene = generateAndRunVariableAffectationWithConditions(
|
|
[
|
|
{
|
|
type: { inverted: false, value: 'BuiltinCommonInstructions::CompareStrings' },
|
|
parameters: ['"Hello world!"', 'contains', '"world"'],
|
|
},
|
|
]
|
|
);
|
|
|
|
expect(runtimeScene.getVariables().has('SuccessVariable')).toBe(true);
|
|
expect(
|
|
runtimeScene.getVariables().get('SuccessVariable').getAsNumber()
|
|
).toBe(1);
|
|
});
|
|
|
|
it('can generate a string comparison condition that is false with a contains operator', function () {
|
|
const runtimeScene = generateAndRunVariableAffectationWithConditions(
|
|
[
|
|
{
|
|
type: { inverted: false, value: 'BuiltinCommonInstructions::CompareStrings' },
|
|
parameters: ['"Hello world!"', 'contains', '"Hi!"'],
|
|
},
|
|
]
|
|
);
|
|
|
|
expect(runtimeScene.getVariables().has('SuccessVariable')).toBe(false);
|
|
});
|
|
});
|