mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Compare commits
1 Commits
toon-mater
...
feature/ex
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4279e5c8be |
3
newIDE/app/flow-typed/libGD.js
vendored
3
newIDE/app/flow-typed/libGD.js
vendored
@@ -6,6 +6,8 @@ type EmscriptenObject = Object & {
|
||||
ptr: Number
|
||||
};
|
||||
|
||||
declare type libGD = any;
|
||||
|
||||
declare type gdPlatform = EmscriptenObject;
|
||||
declare type gdPlatformExtension = EmscriptenObject;
|
||||
|
||||
@@ -28,6 +30,7 @@ declare type gdEventsFunction = EmscriptenObject;
|
||||
|
||||
declare type gdInstruction = EmscriptenObject;
|
||||
declare type gdInstructionMetadata = EmscriptenObject;
|
||||
declare type gdMapStringInstructionMetadata = EmscriptenObject;
|
||||
declare type gdInstructionsList = EmscriptenObject;
|
||||
declare type gdParameterMetadata = EmscriptenObject;
|
||||
declare type gdExpression = EmscriptenObject;
|
||||
|
59
newIDE/app/scripts/extract-all-extensions-information.js
Normal file
59
newIDE/app/scripts/extract-all-extensions-information.js
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Launch this script to re-generate the files containing the list of extensions
|
||||
* being used by each example.
|
||||
*/
|
||||
const gd = require('../public/libGD.js')();
|
||||
const makeExtensionsLoader = require('./lib/LocalJsExtensionsLoader');
|
||||
const { enumerateInstructions } = require('./lib/EnumerateInstructions');
|
||||
const { enumerateExpressions } = require('./lib/EnumerateExpressions');
|
||||
const fs = require('fs');
|
||||
var shell = require('shelljs');
|
||||
|
||||
shell.exec('node import-GDJS-Runtime.js');
|
||||
gd.initializePlatforms(); //TODO: Useless or not?
|
||||
|
||||
const outputFile = './test.json';
|
||||
|
||||
const writeFile = object => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const content = [
|
||||
`// This file is generated by update-examples-extensions-usage-from-resources-examples.js script`,
|
||||
`// prettier-ignore`,
|
||||
`module.exports = ${JSON.stringify(object, null, 2)};`,
|
||||
``,
|
||||
].join('\n');
|
||||
fs.writeFile(outputFile, content, err => {
|
||||
if (err) return reject(err);
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const noopTranslationFunction = str => str;
|
||||
const extensionsLoader = makeExtensionsLoader({ gd, filterExamples: true });
|
||||
extensionsLoader
|
||||
.loadAllExtensions(noopTranslationFunction)
|
||||
.then(loadingResults => {
|
||||
console.info('Loaded extensions', loadingResults);
|
||||
})
|
||||
.then(() => {
|
||||
const allActions = enumerateInstructions(gd, false);
|
||||
const allConditions = enumerateInstructions(gd, true);
|
||||
const allStringExpressions = enumerateExpressions(gd, 'string');
|
||||
const allNumberExpressions = enumerateExpressions(gd, 'number');
|
||||
|
||||
return {
|
||||
allActions,
|
||||
allConditions,
|
||||
allStringExpressions,
|
||||
allNumberExpressions,
|
||||
};
|
||||
})
|
||||
.then(allMetadata => {
|
||||
return writeFile(allMetadata);
|
||||
})
|
||||
.then(
|
||||
() => console.info('Done.'),
|
||||
err => console.error('Error while writing output', err)
|
||||
);
|
1
newIDE/app/scripts/lib/EnumerateExpressions.js
Normal file
1
newIDE/app/scripts/lib/EnumerateExpressions.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('../../src/EventsSheet/InstructionEditor/InstructionOrExpressionSelector/EnumerateExpressions');
|
1
newIDE/app/scripts/lib/EnumerateInstructions.js
Normal file
1
newIDE/app/scripts/lib/EnumerateInstructions.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('../../src/EventsSheet/InstructionEditor/InstructionOrExpressionSelector/EnumerateInstructions');
|
@@ -1,7 +1,9 @@
|
||||
// @flow
|
||||
import { type InstructionOrExpressionInformation } from './InstructionOrExpressionInformation.flow.js';
|
||||
const gd = global.gd;
|
||||
// Note: this file does not use export/imports and use Flow comments to allow its usage from Node.js
|
||||
|
||||
/*flow-include
|
||||
import { type InstructionOrExpressionInformation } from './InstructionOrExpressionInformation.flow.js';
|
||||
*/
|
||||
const GROUP_DELIMITER = '/';
|
||||
|
||||
const enumerateExtensionExpressions = (
|
||||
@@ -9,7 +11,7 @@ const enumerateExtensionExpressions = (
|
||||
expressions,
|
||||
objectMetadata,
|
||||
behaviorMetadata
|
||||
): Array<InstructionOrExpressionInformation> => {
|
||||
) /*: Array<InstructionOrExpressionInformation>*/ => {
|
||||
const allExpressions = [];
|
||||
|
||||
//Get the map containing the metadata of the expression provided by the extension...
|
||||
@@ -53,7 +55,7 @@ const enumerateExtensionExpressions = (
|
||||
return allExpressions;
|
||||
};
|
||||
|
||||
export const enumerateExpressions = (type: string) => {
|
||||
const enumerateExpressions = (gd /*: libGD */, type /*: string*/) => {
|
||||
const freeExpressions = [];
|
||||
const objectsExpressions = [];
|
||||
const behaviorsExpressions = [];
|
||||
@@ -139,10 +141,10 @@ export const enumerateExpressions = (type: string) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const filterExpressions = (
|
||||
list: Array<InstructionOrExpressionInformation>,
|
||||
searchText: string
|
||||
): Array<InstructionOrExpressionInformation> => {
|
||||
const filterExpressions = (
|
||||
list /*: Array<InstructionOrExpressionInformation>*/,
|
||||
searchText /*: string*/
|
||||
) /*: Array<InstructionOrExpressionInformation>*/ => {
|
||||
if (!searchText) return list;
|
||||
const lowercaseSearchText = searchText.toLowerCase();
|
||||
|
||||
@@ -153,3 +155,5 @@ export const filterExpressions = (
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = { enumerateExpressions, filterExpressions };
|
||||
|
@@ -4,10 +4,12 @@ import {
|
||||
} from './EnumerateExpressions';
|
||||
import { createTree } from './CreateTree';
|
||||
import isObject from 'lodash/isObject';
|
||||
const gd = global.gd;
|
||||
|
||||
describe('EnumerateObjects', () => {
|
||||
it('can enumerate and filter expressions', () => {
|
||||
const { freeExpressions, objectsExpressions } = enumerateExpressions(
|
||||
gd,
|
||||
'number'
|
||||
);
|
||||
|
||||
@@ -42,7 +44,7 @@ describe('EnumerateObjects', () => {
|
||||
return obj;
|
||||
};
|
||||
|
||||
const { objectsExpressions } = enumerateExpressions('number');
|
||||
const { objectsExpressions } = enumerateExpressions(gd, 'number');
|
||||
expect(stripMetadata(createTree(objectsExpressions))).toMatchObject({
|
||||
'Common expressions for all objects': {
|
||||
Angle: {
|
||||
|
@@ -1,13 +1,15 @@
|
||||
// @flow
|
||||
import { type InstructionOrExpressionInformation } from './InstructionOrExpressionInformation.flow.js';
|
||||
const gd = global.gd;
|
||||
// Note: this file does not use export/imports and use Flow comments to allow its usage from Node.js
|
||||
|
||||
/*flow-include
|
||||
import type { InstructionOrExpressionInformation } from './InstructionOrExpressionInformation.flow.js';
|
||||
*/
|
||||
const GROUP_DELIMITER = '/';
|
||||
|
||||
const enumerateExtensionInstructions = (
|
||||
groupPrefix: string,
|
||||
extensionInstructions
|
||||
): Array<InstructionOrExpressionInformation> => {
|
||||
groupPrefix /*: string*/,
|
||||
extensionInstructions /*: gdMapStringInstructionMetadata */
|
||||
) /*: Array<InstructionOrExpressionInformation>*/ => {
|
||||
//Get the map containing the metadata of the instructions provided by the extension...
|
||||
var instructionsTypes = extensionInstructions.keys();
|
||||
const allInstructions = [];
|
||||
@@ -34,9 +36,10 @@ const enumerateExtensionInstructions = (
|
||||
return allInstructions;
|
||||
};
|
||||
|
||||
export const enumerateInstructions = (
|
||||
isCondition: boolean
|
||||
): Array<InstructionOrExpressionInformation> => {
|
||||
const enumerateInstructions = (
|
||||
gd /*: libGD */,
|
||||
isCondition /*: boolean*/
|
||||
) /*: Array<InstructionOrExpressionInformation>*/ => {
|
||||
let allInstructions = [];
|
||||
|
||||
const allExtensions = gd
|
||||
@@ -96,3 +99,5 @@ export const enumerateInstructions = (
|
||||
|
||||
return allInstructions;
|
||||
};
|
||||
|
||||
module.exports = { enumerateInstructions };
|
@@ -1,9 +1,10 @@
|
||||
import { createTree } from './CreateTree';
|
||||
import { enumerateInstructions } from './EnumerateInstructions';
|
||||
const gd = global.gd;
|
||||
|
||||
describe('EnumerateInstructions', () => {
|
||||
it('can enumerate instructions being conditions', () => {
|
||||
const instructions = enumerateInstructions(true);
|
||||
const instructions = enumerateInstructions(gd, true);
|
||||
|
||||
// Test for the proper presence of a few conditions
|
||||
expect(instructions).toEqual(
|
||||
@@ -28,7 +29,7 @@ describe('EnumerateInstructions', () => {
|
||||
});
|
||||
|
||||
it('can enumerate instructions being actions', () => {
|
||||
const instructions = enumerateInstructions(false);
|
||||
const instructions = enumerateInstructions(gd, false);
|
||||
|
||||
// Test for the proper presence of a few actions
|
||||
expect(instructions).toEqual(
|
||||
@@ -48,7 +49,7 @@ describe('EnumerateInstructions', () => {
|
||||
});
|
||||
|
||||
it('can create the tree of instructions', () => {
|
||||
const instructions = enumerateInstructions('number');
|
||||
const instructions = enumerateInstructions(gd, 'number');
|
||||
expect(createTree(instructions)).toMatchObject({
|
||||
Advanced: {
|
||||
'Trigger once while true': {
|
||||
|
@@ -4,6 +4,7 @@ import { enumerateExpressions } from './EnumerateExpressions';
|
||||
import InstructionOrExpressionSelector from './index';
|
||||
import { createTree, type InstructionOrExpressionTreeNode } from './CreateTree';
|
||||
import { type InstructionOrExpressionInformation } from './InstructionOrExpressionInformation.flow.js';
|
||||
const gd = global.gd;
|
||||
|
||||
export default class ExpressionSelector extends Component<*, {||}> {
|
||||
instructionsInfo: Array<InstructionOrExpressionInformation> = [];
|
||||
@@ -14,7 +15,7 @@ export default class ExpressionSelector extends Component<*, {||}> {
|
||||
};
|
||||
|
||||
componentWillMount() {
|
||||
const { allExpressions } = enumerateExpressions(this.props.expressionType);
|
||||
const { allExpressions } = enumerateExpressions(gd, this.props.expressionType);
|
||||
this.instructionsInfo = allExpressions;
|
||||
this.instructionsInfoTree = createTree(allExpressions);
|
||||
}
|
||||
|
@@ -2,8 +2,10 @@
|
||||
import React, { Component } from 'react';
|
||||
import InstructionOrExpressionSelector from './index';
|
||||
import { createTree, type InstructionOrExpressionTreeNode } from './CreateTree';
|
||||
import { enumerateInstructions } from './EnumerateInstructions';
|
||||
import { type InstructionOrExpressionInformation } from './InstructionOrExpressionInformation.flow.js';
|
||||
const { enumerateInstructions } = require('./EnumerateInstructions');
|
||||
console.log(enumerateInstructions);
|
||||
const gd = global.gd;
|
||||
|
||||
type Props = {
|
||||
isCondition: boolean,
|
||||
@@ -15,7 +17,7 @@ export default class InstructionSelector extends Component<Props, {||}> {
|
||||
instructionsInfoTree: ?InstructionOrExpressionTreeNode = null;
|
||||
|
||||
componentWillMount() {
|
||||
const allInstructions = enumerateInstructions(this.props.isCondition);
|
||||
const allInstructions = enumerateInstructions(gd, this.props.isCondition);
|
||||
this.instructionsInfo = allInstructions;
|
||||
this.instructionsInfoTree = createTree(allInstructions);
|
||||
}
|
||||
|
@@ -4,13 +4,14 @@ import {
|
||||
enumerateExpressions,
|
||||
filterExpressions,
|
||||
} from '../../InstructionEditor/InstructionOrExpressionSelector/EnumerateExpressions';
|
||||
const gd = global.gd;
|
||||
|
||||
describe('HelpButton', () => {
|
||||
const {
|
||||
freeExpressions,
|
||||
objectsExpressions,
|
||||
behaviorsExpressions,
|
||||
} = enumerateExpressions('number');
|
||||
} = enumerateExpressions(gd, 'number');
|
||||
|
||||
it('properly format a free function, with one or more arguments', () => {
|
||||
const countExpression = filterExpressions(freeExpressions, 'Count')[0];
|
||||
|
@@ -1,4 +1,5 @@
|
||||
// Note: this file don't use export/imports nor Flow to allow its usage from Node.js
|
||||
// @flow
|
||||
// Note: this file does not use export/imports and use Flow comments to allow its usage from Node.js
|
||||
|
||||
const optionalRequire = require('../../Utils/OptionalRequire.js');
|
||||
const electron = optionalRequire('electron');
|
||||
|
Reference in New Issue
Block a user