gdcore-tools 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,474 +1,465 @@
1
- const { mapVector } = require('../MapFor');
1
+ const { mapVector } = require("../MapFor");
2
2
 
3
3
  // This file contains the logic to declare extension metadata from
4
4
  // events functions or events based behaviors.
5
5
  // These are basically adapters from EventsFunctionsExtension, and children, to a
6
6
  // real extension declaration (like in `JsExtension.js` or `Extension.cpp` files).
7
7
 
8
- /**
9
- * Declare an extension from an events based extension.
10
- */
11
- const declareExtension = (
12
- extension,
13
- eventsFunctionsExtension
14
- ) => {
15
- extension.setExtensionInformation(
16
- eventsFunctionsExtension.getName(),
17
- eventsFunctionsExtension.getFullName() ||
18
- eventsFunctionsExtension.getName(),
19
- eventsFunctionsExtension.getDescription(),
20
- '',
21
- ''
22
- );
23
- };
24
- module.exports.declareExtension = declareExtension;
25
-
26
- /**
27
- * Declare the behavior for the given
28
- * events based behavior.
29
- */
30
- const declareBehaviorMetadata = (
31
- extension,
32
- eventsBasedBehavior
33
- ) => {
34
- const generatedBehavior = new _GD.BehaviorJsImplementation();
35
-
36
- // The functions below are keeping a reference to eventsBasedBehavior.
37
- // This should be safe as if eventsBasedBehavior is deleted (i.e: the behavior
38
- // is removed from its extension), then extension will be re-generated.
39
-
40
- // Declare the properties of the behavior:
41
-
42
- // $FlowExpectedError - we're creating a behavior
43
- generatedBehavior.updateProperty = function(
44
- behaviorContent,
45
- propertyName,
46
- newValue
47
- ) {
48
- let propertyFound = false;
49
- mapVector(eventsBasedBehavior.getPropertyDescriptors(), property => {
50
- if (property.getName() === propertyName) {
51
- propertyFound = true;
52
- const element = behaviorContent.addChild(propertyName);
53
- const propertyType = property.getType();
54
-
55
- if (propertyType === 'String' || propertyType === 'Choice') {
56
- element.setStringValue(newValue);
57
- } else if (propertyType === 'Number') {
58
- element.setDoubleValue(parseFloat(newValue));
59
- } else if (propertyType === 'Boolean') {
60
- element.setBoolValue(newValue === '1');
61
- }
62
- }
63
- });
64
-
65
- return propertyFound;
66
- };
67
-
68
- // $FlowExpectedError - we're creating a behavior
69
- generatedBehavior.getProperties = function(behaviorContent) {
70
- var behaviorProperties = new _GD.MapStringPropertyDescriptor();
71
- mapVector(eventsBasedBehavior.getPropertyDescriptors(), property => {
72
- const newProperty = property.toPropertyDescriptor();
73
- const propertyType = newProperty.getType();
74
-
75
- if (behaviorContent.hasChild(property.getName())) {
76
- if (propertyType === 'String' || propertyType === 'Choice') {
77
- newProperty.setValue(
78
- behaviorContent.getChild(property.getName()).getStringValue()
79
- );
80
- } else if (propertyType === 'Number') {
81
- newProperty.setValue(
82
- '' + behaviorContent.getChild(property.getName()).getDoubleValue()
83
- );
84
- } else if (propertyType === 'Boolean') {
85
- newProperty.setValue(
86
- behaviorContent.getChild(property.getName()).getBoolValue()
87
- ? 'true'
88
- : 'false'
89
- );
90
- }
91
- } else {
92
- // No value was serialized for this property. `newProperty`
93
- // will have the default value coming from `property`.
94
- }
95
-
96
- behaviorProperties.set(property.getName(), newProperty);
97
- });
98
-
99
- return behaviorProperties;
100
- };
101
-
102
- // $FlowExpectedError - we're creating a behavior
103
- generatedBehavior.initializeContent = function(behaviorContent) {
104
- mapVector(eventsBasedBehavior.getPropertyDescriptors(), property => {
105
- const element = behaviorContent.addChild(property.getName());
106
- const propertyType = property.getType();
107
-
108
- if (propertyType === 'String' || propertyType === 'Choice') {
109
- element.setStringValue(property.getValue());
110
- } else if (propertyType === 'Number') {
111
- element.setDoubleValue(parseFloat(property.getValue()) || 0);
112
- } else if (propertyType === 'Boolean') {
113
- element.setBoolValue(property.getValue() === 'true');
114
- }
115
- });
116
- };
8
+ module.exports = (gd) => {
9
+ const helpers = {};
117
10
 
118
- return extension
119
- .addBehavior(
120
- eventsBasedBehavior.getName(),
121
- eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
122
- eventsBasedBehavior.getName(), // Default name is the name
123
- eventsBasedBehavior.getDescription(),
124
- '',
125
- 'res/function24.png',
126
- eventsBasedBehavior.getName(), // Class name is the name, actually unused
127
- generatedBehavior,
128
- new _GD.BehaviorsSharedData()
129
- )
130
- .setObjectType(eventsBasedBehavior.getObjectType());
131
- };
132
- module.exports.declareBehaviorMetadata = declareBehaviorMetadata;
133
-
134
- /**
135
- * Check if the name of the function is the name of a lifecycle function (for events-based behaviors),
136
- * that will be called automatically by the game engine.
137
- */
138
- const isBehaviorLifecycleEventsFunction = (functionName ) => {
139
- return (
140
- [
141
- 'onCreated',
142
- 'onActivate',
143
- 'onDeActivate',
144
- 'doStepPreEvents',
145
- 'doStepPostEvents',
146
- 'onDestroy',
147
- // Compatibility with GD <= 5.0 beta 75
148
- 'onOwnerRemovedFromScene',
149
- // end of compatibility code
150
- ].indexOf(functionName) !== -1
151
- );
152
- };
153
- module.exports.isBehaviorLifecycleEventsFunction = isBehaviorLifecycleEventsFunction;
154
-
155
- /**
156
- * Check if the name of the function is the name of a lifecycle function (for events-based extensions),
157
- * that will be called automatically by the game engine.
158
- */
159
- const isExtensionLifecycleEventsFunction = (functionName ) => {
160
- return _GD.EventsFunctionsExtension.isExtensionLifecycleEventsFunction(
161
- functionName
162
- );
163
- };
164
- module.exports.isExtensionLifecycleEventsFunction = isExtensionLifecycleEventsFunction;
165
-
166
- /**
167
- * Declare the instruction (action/condition) or expression for the given
168
- * (free) events function.
169
- */
170
- const declareInstructionOrExpressionMetadata = (
171
- extension ,
172
- eventsFunctionsExtension ,
173
- eventsFunction
174
- ) => {
175
- const functionType = eventsFunction.getFunctionType();
176
- if (functionType === _GD.EventsFunction.Expression) {
177
- return extension.addExpression(
178
- eventsFunction.getName(),
179
- eventsFunction.getFullName() || eventsFunction.getName(),
180
- eventsFunction.getDescription() || eventsFunction.getFullName(),
181
- eventsFunctionsExtension.getFullName() ||
182
- eventsFunctionsExtension.getName(),
183
- 'res/function.png'
184
- );
185
- } else if (functionType === _GD.EventsFunction.StringExpression) {
186
- return extension.addStrExpression(
187
- eventsFunction.getName(),
188
- eventsFunction.getFullName() || eventsFunction.getName(),
189
- eventsFunction.getDescription() || eventsFunction.getFullName(),
190
- eventsFunctionsExtension.getFullName() ||
191
- eventsFunctionsExtension.getName(),
192
- 'res/function.png'
193
- );
194
- } else if (functionType === _GD.EventsFunction.Condition) {
195
- return extension.addCondition(
196
- eventsFunction.getName(),
197
- eventsFunction.getFullName() || eventsFunction.getName(),
198
- eventsFunction.getDescription() || eventsFunction.getFullName(),
199
- eventsFunction.getSentence(),
200
- eventsFunctionsExtension.getFullName() ||
201
- eventsFunctionsExtension.getName(),
202
- 'res/function.png',
203
- 'res/function24.png'
204
- );
205
- } else {
206
- return extension.addAction(
207
- eventsFunction.getName(),
208
- eventsFunction.getFullName() || eventsFunction.getName(),
209
- eventsFunction.getDescription() || eventsFunction.getFullName(),
210
- eventsFunction.getSentence(),
11
+ /**
12
+ * Declare an extension from an events based extension.
13
+ */
14
+ const declareExtension = (extension, eventsFunctionsExtension) => {
15
+ extension.setExtensionInformation(
16
+ eventsFunctionsExtension.getName(),
211
17
  eventsFunctionsExtension.getFullName() ||
212
18
  eventsFunctionsExtension.getName(),
213
- 'res/function.png',
214
- 'res/function24.png'
215
- );
216
- }
217
- };
218
- module.exports.declareInstructionOrExpressionMetadata = declareInstructionOrExpressionMetadata;
219
-
220
- /**
221
- * Declare the instruction (action/condition) or expression for the given
222
- * behavior events function.
223
- */
224
- const declareBehaviorInstructionOrExpressionMetadata = (
225
- behaviorMetadata ,
226
- eventsBasedBehavior ,
227
- eventsFunction
228
- ) => {
229
- const functionType = eventsFunction.getFunctionType();
230
- if (functionType === _GD.EventsFunction.Expression) {
231
- return behaviorMetadata.addExpression(
232
- eventsFunction.getName(),
233
- eventsFunction.getFullName() || eventsFunction.getName(),
234
- eventsFunction.getDescription() || eventsFunction.getFullName(),
235
- eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
236
- 'res/function.png'
237
- );
238
- } else if (functionType === _GD.EventsFunction.StringExpression) {
239
- return behaviorMetadata.addStrExpression(
240
- eventsFunction.getName(),
241
- eventsFunction.getFullName() || eventsFunction.getName(),
242
- eventsFunction.getDescription() || eventsFunction.getFullName(),
243
- eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
244
- 'res/function.png'
245
- );
246
- } else if (functionType === _GD.EventsFunction.Condition) {
247
- // Use the new "scoped" way to declare an instruction, because
248
- // we want to prevent any conflict between free functions and
249
- // behaviors (that can totally have functions with the same name).
250
- return behaviorMetadata.addScopedCondition(
251
- eventsFunction.getName(),
252
- eventsFunction.getFullName() || eventsFunction.getName(),
253
- eventsFunction.getDescription() || eventsFunction.getFullName(),
254
- eventsFunction.getSentence(),
255
- eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
256
- 'res/function.png',
257
- 'res/function24.png'
258
- );
259
- } else {
260
- // Use the new "scoped" way to declare an instruction, because
261
- // we want to prevent any conflict between free functions and
262
- // behaviors (that can totally have functions with the same name).
263
- return behaviorMetadata.addScopedAction(
264
- eventsFunction.getName(),
265
- eventsFunction.getFullName() || eventsFunction.getName(),
266
- eventsFunction.getDescription() || eventsFunction.getFullName(),
267
- eventsFunction.getSentence(),
268
- eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
269
- 'res/function.png',
270
- 'res/function24.png'
271
- );
272
- }
273
- };
274
- module.exports.declareBehaviorInstructionOrExpressionMetadata = declareBehaviorInstructionOrExpressionMetadata;
275
-
276
-
277
-
278
-
279
- /**
280
- * Declare the instructions (actions/conditions) and expressions for the
281
- * properties of the given events based behavior.
282
- * This is akin to what would happen by manually declaring a JS extension
283
- * (see `JsExtension.js` files of extensions).
284
- */
285
- const declareBehaviorPropertiesInstructionAndExpressions = (
286
- behaviorMetadata,
287
- eventsBasedBehavior
288
- ) => {
289
- const addObjectAndBehaviorParameters = (
290
- instructionOrExpression
291
- ) => {
292
- // By convention, first parameter is always the object:
293
- instructionOrExpression.addParameter(
294
- 'object',
295
- 'Object',
296
- '', // See below for adding the extra information
297
- false
19
+ eventsFunctionsExtension.getDescription(),
20
+ "",
21
+ ""
298
22
  );
23
+ };
24
+ helpers.declareExtension = declareExtension;
25
+
26
+ /**
27
+ * Declare the behavior for the given
28
+ * events based behavior.
29
+ */
30
+ const declareBehaviorMetadata = (extension, eventsBasedBehavior) => {
31
+ const generatedBehavior = new gd.BehaviorJsImplementation();
32
+
33
+ // The functions below are keeping a reference to eventsBasedBehavior.
34
+ // This should be safe as if eventsBasedBehavior is deleted (i.e: the behavior
35
+ // is removed from its extension), then extension will be re-generated.
36
+
37
+ // Declare the properties of the behavior:
38
+
39
+ // $FlowExpectedError - we're creating a behavior
40
+ generatedBehavior.updateProperty = function (
41
+ behaviorContent,
42
+ propertyName,
43
+ newValue
44
+ ) {
45
+ let propertyFound = false;
46
+ mapVector(eventsBasedBehavior.getPropertyDescriptors(), (property) => {
47
+ if (property.getName() === propertyName) {
48
+ propertyFound = true;
49
+ const element = behaviorContent.addChild(propertyName);
50
+ const propertyType = property.getType();
51
+
52
+ if (propertyType === "String" || propertyType === "Choice") {
53
+ element.setStringValue(newValue);
54
+ } else if (propertyType === "Number") {
55
+ element.setDoubleValue(parseFloat(newValue));
56
+ } else if (propertyType === "Boolean") {
57
+ element.setBoolValue(newValue === "1");
58
+ }
59
+ }
60
+ });
61
+
62
+ return propertyFound;
63
+ };
64
+
65
+ // $FlowExpectedError - we're creating a behavior
66
+ generatedBehavior.getProperties = function (behaviorContent) {
67
+ var behaviorProperties = new gd.MapStringPropertyDescriptor();
68
+ mapVector(eventsBasedBehavior.getPropertyDescriptors(), (property) => {
69
+ const newProperty = property.toPropertyDescriptor();
70
+ const propertyType = newProperty.getType();
71
+
72
+ if (behaviorContent.hasChild(property.getName())) {
73
+ if (propertyType === "String" || propertyType === "Choice") {
74
+ newProperty.setValue(
75
+ behaviorContent.getChild(property.getName()).getStringValue()
76
+ );
77
+ } else if (propertyType === "Number") {
78
+ newProperty.setValue(
79
+ "" + behaviorContent.getChild(property.getName()).getDoubleValue()
80
+ );
81
+ } else if (propertyType === "Boolean") {
82
+ newProperty.setValue(
83
+ behaviorContent.getChild(property.getName()).getBoolValue()
84
+ ? "true"
85
+ : "false"
86
+ );
87
+ }
88
+ } else {
89
+ // No value was serialized for this property. `newProperty`
90
+ // will have the default value coming from `property`.
91
+ }
299
92
 
300
- // Manually add the "extra info" without relying on addParameter
301
- // as this method is prefixing the value passed with the extension namespace (this
302
- // was done to ease extension declarations when dealing with object).
303
- instructionOrExpression
304
- .getParameter(instructionOrExpression.getParametersCount() - 1)
305
- .setExtraInfo(eventsBasedBehavior.getObjectType());
306
-
307
- // By convention, second parameter is always the behavior:
308
- instructionOrExpression.addParameter(
309
- 'behavior',
310
- 'Behavior',
311
- eventsBasedBehavior.getName(),
312
- false
313
- );
93
+ behaviorProperties.set(property.getName(), newProperty);
94
+ });
314
95
 
315
- // All property actions/conditions/expressions are private, meaning
316
- // they can only be used from the behavior events.
317
- instructionOrExpression.setPrivate();
96
+ return behaviorProperties;
97
+ };
318
98
 
319
- return instructionOrExpression;
320
- };
99
+ // $FlowExpectedError - we're creating a behavior
100
+ generatedBehavior.initializeContent = function (behaviorContent) {
101
+ mapVector(eventsBasedBehavior.getPropertyDescriptors(), (property) => {
102
+ const element = behaviorContent.addChild(property.getName());
103
+ const propertyType = property.getType();
321
104
 
322
- mapVector(eventsBasedBehavior.getPropertyDescriptors(), property => {
323
- const propertyType = property.getType();
324
- const propertyName = property.getName();
325
- const getterName = _GD.BehaviorCodeGenerator.getBehaviorPropertyGetterName(
326
- propertyName
105
+ if (propertyType === "String" || propertyType === "Choice") {
106
+ element.setStringValue(property.getValue());
107
+ } else if (propertyType === "Number") {
108
+ element.setDoubleValue(parseFloat(property.getValue()) || 0);
109
+ } else if (propertyType === "Boolean") {
110
+ element.setBoolValue(property.getValue() === "true");
111
+ }
112
+ });
113
+ };
114
+
115
+ return extension
116
+ .addBehavior(
117
+ eventsBasedBehavior.getName(),
118
+ eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
119
+ eventsBasedBehavior.getName(), // Default name is the name
120
+ eventsBasedBehavior.getDescription(),
121
+ "",
122
+ "res/function24.png",
123
+ eventsBasedBehavior.getName(), // Class name is the name, actually unused
124
+ generatedBehavior,
125
+ new gd.BehaviorsSharedData()
126
+ )
127
+ .setObjectType(eventsBasedBehavior.getObjectType());
128
+ };
129
+ helpers.declareBehaviorMetadata = declareBehaviorMetadata;
130
+
131
+ /**
132
+ * Check if the name of the function is the name of a lifecycle function (for events-based behaviors),
133
+ * that will be called automatically by the game engine.
134
+ */
135
+ const isBehaviorLifecycleEventsFunction = (functionName) => {
136
+ return (
137
+ [
138
+ "onCreated",
139
+ "onActivate",
140
+ "onDeActivate",
141
+ "doStepPreEvents",
142
+ "doStepPostEvents",
143
+ "onDestroy",
144
+ // Compatibility with GD <= 5.0 beta 75
145
+ "onOwnerRemovedFromScene",
146
+ // end of compatibility code
147
+ ].indexOf(functionName) !== -1
327
148
  );
328
- const setterName = _GD.BehaviorCodeGenerator.getBehaviorPropertySetterName(
329
- propertyName
149
+ };
150
+ helpers.isBehaviorLifecycleEventsFunction = isBehaviorLifecycleEventsFunction;
151
+
152
+ /**
153
+ * Check if the name of the function is the name of a lifecycle function (for events-based extensions),
154
+ * that will be called automatically by the game engine.
155
+ */
156
+ const isExtensionLifecycleEventsFunction = (functionName) => {
157
+ return gd.EventsFunctionsExtension.isExtensionLifecycleEventsFunction(
158
+ functionName
330
159
  );
331
- const propertyLabel =
332
- property.getLabel() || `${propertyName} property`;
333
-
334
- if (propertyType === 'String' || propertyType === 'Choice') {
335
- addObjectAndBehaviorParameters(
336
- behaviorMetadata.addStrExpression(
337
- _GD.EventsBasedBehavior.getPropertyExpressionName(propertyName),
338
- propertyLabel,
339
- propertyLabel,
340
- eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
341
- 'res/function.png'
160
+ };
161
+ helpers.isExtensionLifecycleEventsFunction =
162
+ isExtensionLifecycleEventsFunction;
163
+
164
+ /**
165
+ * Declare the instruction (action/condition) or expression for the given
166
+ * (free) events function.
167
+ */
168
+ const declareInstructionOrExpressionMetadata = (
169
+ extension,
170
+ eventsFunctionsExtension,
171
+ eventsFunction
172
+ ) => {
173
+ const functionType = eventsFunction.getFunctionType();
174
+ if (functionType === gd.EventsFunction.Expression) {
175
+ return extension.addExpression(
176
+ eventsFunction.getName(),
177
+ eventsFunction.getFullName() || eventsFunction.getName(),
178
+ eventsFunction.getDescription() || eventsFunction.getFullName(),
179
+ eventsFunctionsExtension.getFullName() ||
180
+ eventsFunctionsExtension.getName(),
181
+ "res/function.png"
182
+ );
183
+ } else if (functionType === gd.EventsFunction.StringExpression) {
184
+ return extension.addStrExpression(
185
+ eventsFunction.getName(),
186
+ eventsFunction.getFullName() || eventsFunction.getName(),
187
+ eventsFunction.getDescription() || eventsFunction.getFullName(),
188
+ eventsFunctionsExtension.getFullName() ||
189
+ eventsFunctionsExtension.getName(),
190
+ "res/function.png"
191
+ );
192
+ } else if (functionType === gd.EventsFunction.Condition) {
193
+ return extension.addCondition(
194
+ eventsFunction.getName(),
195
+ eventsFunction.getFullName() || eventsFunction.getName(),
196
+ eventsFunction.getDescription() || eventsFunction.getFullName(),
197
+ eventsFunction.getSentence(),
198
+ eventsFunctionsExtension.getFullName() ||
199
+ eventsFunctionsExtension.getName(),
200
+ "res/function.png",
201
+ "res/function24.png"
202
+ );
203
+ } else {
204
+ return extension.addAction(
205
+ eventsFunction.getName(),
206
+ eventsFunction.getFullName() || eventsFunction.getName(),
207
+ eventsFunction.getDescription() || eventsFunction.getFullName(),
208
+ eventsFunction.getSentence(),
209
+ eventsFunctionsExtension.getFullName() ||
210
+ eventsFunctionsExtension.getName(),
211
+ "res/function.png",
212
+ "res/function24.png"
213
+ );
214
+ }
215
+ };
216
+ helpers.declareInstructionOrExpressionMetadata =
217
+ declareInstructionOrExpressionMetadata;
218
+
219
+ /**
220
+ * Declare the instruction (action/condition) or expression for the given
221
+ * behavior events function.
222
+ */
223
+ const declareBehaviorInstructionOrExpressionMetadata = (
224
+ behaviorMetadata,
225
+ eventsBasedBehavior,
226
+ eventsFunction
227
+ ) => {
228
+ const functionType = eventsFunction.getFunctionType();
229
+ if (functionType === gd.EventsFunction.Expression) {
230
+ return behaviorMetadata.addExpression(
231
+ eventsFunction.getName(),
232
+ eventsFunction.getFullName() || eventsFunction.getName(),
233
+ eventsFunction.getDescription() || eventsFunction.getFullName(),
234
+ eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
235
+ "res/function.png"
236
+ );
237
+ } else if (functionType === gd.EventsFunction.StringExpression) {
238
+ return behaviorMetadata.addStrExpression(
239
+ eventsFunction.getName(),
240
+ eventsFunction.getFullName() || eventsFunction.getName(),
241
+ eventsFunction.getDescription() || eventsFunction.getFullName(),
242
+ eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
243
+ "res/function.png"
244
+ );
245
+ } else if (functionType === gd.EventsFunction.Condition) {
246
+ // Use the new "scoped" way to declare an instruction, because
247
+ // we want to prevent any conflict between free functions and
248
+ // behaviors (that can totally have functions with the same name).
249
+ return behaviorMetadata.addScopedCondition(
250
+ eventsFunction.getName(),
251
+ eventsFunction.getFullName() || eventsFunction.getName(),
252
+ eventsFunction.getDescription() || eventsFunction.getFullName(),
253
+ eventsFunction.getSentence(),
254
+ eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
255
+ "res/function.png",
256
+ "res/function24.png"
257
+ );
258
+ } else {
259
+ // Use the new "scoped" way to declare an instruction, because
260
+ // we want to prevent any conflict between free functions and
261
+ // behaviors (that can totally have functions with the same name).
262
+ return behaviorMetadata.addScopedAction(
263
+ eventsFunction.getName(),
264
+ eventsFunction.getFullName() || eventsFunction.getName(),
265
+ eventsFunction.getDescription() || eventsFunction.getFullName(),
266
+ eventsFunction.getSentence(),
267
+ eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
268
+ "res/function.png",
269
+ "res/function24.png"
270
+ );
271
+ }
272
+ };
273
+ helpers.declareBehaviorInstructionOrExpressionMetadata =
274
+ declareBehaviorInstructionOrExpressionMetadata;
275
+
276
+ /**
277
+ * Declare the instructions (actions/conditions) and expressions for the
278
+ * properties of the given events based behavior.
279
+ * This is akin to what would happen by manually declaring a JS extension
280
+ * (see `JsExtension.js` files of extensions).
281
+ */
282
+ const declareBehaviorPropertiesInstructionAndExpressions = (
283
+ behaviorMetadata,
284
+ eventsBasedBehavior
285
+ ) => {
286
+ const addObjectAndBehaviorParameters = (instructionOrExpression) => {
287
+ // By convention, first parameter is always the object:
288
+ instructionOrExpression.addParameter(
289
+ "object",
290
+ "Object",
291
+ "", // See below for adding the extra information
292
+ false
293
+ );
294
+
295
+ // Manually add the "extra info" without relying on addParameter
296
+ // as this method is prefixing the value passed with the extension namespace (this
297
+ // was done to ease extension declarations when dealing with object).
298
+ instructionOrExpression
299
+ .getParameter(instructionOrExpression.getParametersCount() - 1)
300
+ .setExtraInfo(eventsBasedBehavior.getObjectType());
301
+
302
+ // By convention, second parameter is always the behavior:
303
+ instructionOrExpression.addParameter(
304
+ "behavior",
305
+ "Behavior",
306
+ eventsBasedBehavior.getName(),
307
+ false
308
+ );
309
+
310
+ // All property actions/conditions/expressions are private, meaning
311
+ // they can only be used from the behavior events.
312
+ instructionOrExpression.setPrivate();
313
+
314
+ return instructionOrExpression;
315
+ };
316
+
317
+ mapVector(eventsBasedBehavior.getPropertyDescriptors(), (property) => {
318
+ const propertyType = property.getType();
319
+ const propertyName = property.getName();
320
+ const getterName =
321
+ gd.BehaviorCodeGenerator.getBehaviorPropertyGetterName(propertyName);
322
+ const setterName =
323
+ gd.BehaviorCodeGenerator.getBehaviorPropertySetterName(propertyName);
324
+ const propertyLabel = property.getLabel() || `${propertyName} property`;
325
+
326
+ if (propertyType === "String" || propertyType === "Choice") {
327
+ addObjectAndBehaviorParameters(
328
+ behaviorMetadata.addStrExpression(
329
+ gd.EventsBasedBehavior.getPropertyExpressionName(propertyName),
330
+ propertyLabel,
331
+ propertyLabel,
332
+ eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
333
+ "res/function.png"
334
+ )
342
335
  )
343
- )
344
- .getCodeExtraInformation()
345
- .setFunctionName(getterName);
346
-
347
- addObjectAndBehaviorParameters(
348
- behaviorMetadata.addScopedCondition(
349
- _GD.EventsBasedBehavior.getPropertyConditionName(propertyName),
350
- propertyLabel,
351
- `Compare the content of ${propertyLabel}`,
352
- `the property ${propertyName}`,
353
- eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
354
- 'res/function32.png',
355
- 'res/function.png'
336
+ .getCodeExtraInformation()
337
+ .setFunctionName(getterName);
338
+
339
+ addObjectAndBehaviorParameters(
340
+ behaviorMetadata.addScopedCondition(
341
+ gd.EventsBasedBehavior.getPropertyConditionName(propertyName),
342
+ propertyLabel,
343
+ `Compare the content of ${propertyLabel}`,
344
+ `the property ${propertyName}`,
345
+ eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
346
+ "res/function32.png",
347
+ "res/function.png"
348
+ )
356
349
  )
357
- )
358
- .useStandardRelationalOperatorParameters('string')
359
- .getCodeExtraInformation()
360
- .setFunctionName(getterName);
361
-
362
- addObjectAndBehaviorParameters(
363
- behaviorMetadata.addScopedAction(
364
- _GD.EventsBasedBehavior.getPropertyActionName(propertyName),
365
- propertyLabel,
366
- `Change the content of ${propertyLabel}`,
367
- `the property ${propertyName}`,
368
- eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
369
- 'res/function32.png',
370
- 'res/function.png'
350
+ .useStandardRelationalOperatorParameters("string")
351
+ .getCodeExtraInformation()
352
+ .setFunctionName(getterName);
353
+
354
+ addObjectAndBehaviorParameters(
355
+ behaviorMetadata.addScopedAction(
356
+ gd.EventsBasedBehavior.getPropertyActionName(propertyName),
357
+ propertyLabel,
358
+ `Change the content of ${propertyLabel}`,
359
+ `the property ${propertyName}`,
360
+ eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
361
+ "res/function32.png",
362
+ "res/function.png"
363
+ )
371
364
  )
372
- )
373
- .useStandardOperatorParameters('string')
374
- .getCodeExtraInformation()
375
- .setFunctionName(setterName)
376
- .setManipulatedType('string')
377
- .setGetter(getterName);
378
- } else if (propertyType === 'Number') {
379
- addObjectAndBehaviorParameters(
380
- behaviorMetadata.addExpression(
381
- _GD.EventsBasedBehavior.getPropertyExpressionName(propertyName),
382
- propertyLabel,
383
- propertyLabel,
384
- eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
385
- 'res/function.png'
365
+ .useStandardOperatorParameters("string")
366
+ .getCodeExtraInformation()
367
+ .setFunctionName(setterName)
368
+ .setManipulatedType("string")
369
+ .setGetter(getterName);
370
+ } else if (propertyType === "Number") {
371
+ addObjectAndBehaviorParameters(
372
+ behaviorMetadata.addExpression(
373
+ gd.EventsBasedBehavior.getPropertyExpressionName(propertyName),
374
+ propertyLabel,
375
+ propertyLabel,
376
+ eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
377
+ "res/function.png"
378
+ )
386
379
  )
387
- )
388
- .getCodeExtraInformation()
389
- .setFunctionName(getterName);
390
-
391
- addObjectAndBehaviorParameters(
392
- behaviorMetadata.addScopedCondition(
393
- _GD.EventsBasedBehavior.getPropertyConditionName(propertyName),
394
- propertyLabel,
395
- `Compare the value of ${propertyLabel}`,
396
- `the property ${propertyName}`,
397
- eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
398
- 'res/function32.png',
399
- 'res/function.png'
380
+ .getCodeExtraInformation()
381
+ .setFunctionName(getterName);
382
+
383
+ addObjectAndBehaviorParameters(
384
+ behaviorMetadata.addScopedCondition(
385
+ gd.EventsBasedBehavior.getPropertyConditionName(propertyName),
386
+ propertyLabel,
387
+ `Compare the value of ${propertyLabel}`,
388
+ `the property ${propertyName}`,
389
+ eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
390
+ "res/function32.png",
391
+ "res/function.png"
392
+ )
400
393
  )
401
- )
402
- .useStandardRelationalOperatorParameters('number')
403
- .getCodeExtraInformation()
404
- .setFunctionName(getterName);
405
-
406
- addObjectAndBehaviorParameters(
407
- behaviorMetadata.addScopedAction(
408
- _GD.EventsBasedBehavior.getPropertyActionName(propertyName),
409
- propertyLabel,
410
- `Change the value of ${propertyLabel}`,
411
- `the property ${propertyName}`,
412
- eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
413
- 'res/function32.png',
414
- 'res/function.png'
394
+ .useStandardRelationalOperatorParameters("number")
395
+ .getCodeExtraInformation()
396
+ .setFunctionName(getterName);
397
+
398
+ addObjectAndBehaviorParameters(
399
+ behaviorMetadata.addScopedAction(
400
+ gd.EventsBasedBehavior.getPropertyActionName(propertyName),
401
+ propertyLabel,
402
+ `Change the value of ${propertyLabel}`,
403
+ `the property ${propertyName}`,
404
+ eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
405
+ "res/function32.png",
406
+ "res/function.png"
407
+ )
415
408
  )
416
- )
417
- .useStandardOperatorParameters('number')
418
- .getCodeExtraInformation()
419
- .setFunctionName(setterName)
420
- .setGetter(getterName);
421
- } else if (propertyType === 'Boolean') {
422
- addObjectAndBehaviorParameters(
423
- behaviorMetadata.addScopedCondition(
424
- _GD.EventsBasedBehavior.getPropertyConditionName(propertyName),
425
- propertyLabel,
426
- `Check the value of ${propertyLabel}`,
427
- `Property ${propertyName} of _PARAM0_ is true`,
428
- eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
429
- 'res/function32.png',
430
- 'res/function.png'
409
+ .useStandardOperatorParameters("number")
410
+ .getCodeExtraInformation()
411
+ .setFunctionName(setterName)
412
+ .setGetter(getterName);
413
+ } else if (propertyType === "Boolean") {
414
+ addObjectAndBehaviorParameters(
415
+ behaviorMetadata.addScopedCondition(
416
+ gd.EventsBasedBehavior.getPropertyConditionName(propertyName),
417
+ propertyLabel,
418
+ `Check the value of ${propertyLabel}`,
419
+ `Property ${propertyName} of _PARAM0_ is true`,
420
+ eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
421
+ "res/function32.png",
422
+ "res/function.png"
423
+ )
431
424
  )
432
- )
433
- .getCodeExtraInformation()
434
- .setFunctionName(getterName);
435
-
436
- addObjectAndBehaviorParameters(
437
- behaviorMetadata.addScopedAction(
438
- _GD.EventsBasedBehavior.getPropertyActionName(propertyName),
439
- propertyLabel,
440
- `Update the value of ${propertyLabel}`,
441
- `Set property ${propertyName} of _PARAM0_ to _PARAM2_`,
442
- eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
443
- 'res/function32.png',
444
- 'res/function.png'
425
+ .getCodeExtraInformation()
426
+ .setFunctionName(getterName);
427
+
428
+ addObjectAndBehaviorParameters(
429
+ behaviorMetadata.addScopedAction(
430
+ gd.EventsBasedBehavior.getPropertyActionName(propertyName),
431
+ propertyLabel,
432
+ `Update the value of ${propertyLabel}`,
433
+ `Set property ${propertyName} of _PARAM0_ to _PARAM2_`,
434
+ eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
435
+ "res/function32.png",
436
+ "res/function.png"
437
+ )
445
438
  )
446
- )
447
- .addParameter('yesorno', `New value to set`, '', false)
448
- .getCodeExtraInformation()
449
- .setFunctionName(setterName);
450
- }
451
- });
452
- };
439
+ .addParameter("yesorno", `New value to set`, "", false)
440
+ .getCodeExtraInformation()
441
+ .setFunctionName(setterName);
442
+ }
443
+ });
444
+ };
453
445
 
454
- module.exports.declareBehaviorPropertiesInstructionAndExpressions = declareBehaviorPropertiesInstructionAndExpressions;
455
-
456
- /**
457
- * Add to the instruction (action/condition) or expression the parameters
458
- * expected by the events function.
459
- */
460
- const declareEventsFunctionParameters = (
461
- eventsFunction ,
462
- instructionOrExpression
463
- ) => {
464
- mapVector(
465
- eventsFunction.getParameters(),
466
- (parameter ) => {
446
+ helpers.declareBehaviorPropertiesInstructionAndExpressions =
447
+ declareBehaviorPropertiesInstructionAndExpressions;
448
+
449
+ /**
450
+ * Add to the instruction (action/condition) or expression the parameters
451
+ * expected by the events function.
452
+ */
453
+ const declareEventsFunctionParameters = (
454
+ eventsFunction,
455
+ instructionOrExpression
456
+ ) => {
457
+ mapVector(eventsFunction.getParameters(), (parameter) => {
467
458
  if (!parameter.isCodeOnly()) {
468
459
  instructionOrExpression.addParameter(
469
460
  parameter.getType(),
470
461
  parameter.getDescription(),
471
- '', // See below for adding the extra information
462
+ "", // See below for adding the extra information
472
463
  parameter.isOptional()
473
464
  );
474
465
  instructionOrExpression.setParameterLongDescription(
@@ -477,7 +468,7 @@ const declareEventsFunctionParameters = (
477
468
  } else {
478
469
  instructionOrExpression.addCodeOnlyParameter(
479
470
  parameter.getType(),
480
- '' // See below for adding the extra information
471
+ "" // See below for adding the extra information
481
472
  );
482
473
  }
483
474
  // Manually add the "extra info" without relying on addParameter (or addCodeOnlyParameter)
@@ -486,11 +477,13 @@ const declareEventsFunctionParameters = (
486
477
  instructionOrExpression
487
478
  .getParameter(instructionOrExpression.getParametersCount() - 1)
488
479
  .setExtraInfo(parameter.getExtraInfo());
489
- }
490
- );
480
+ });
481
+
482
+ // By convention, latest parameter is always the eventsFunctionContext of the calling function
483
+ // (if any).
484
+ instructionOrExpression.addCodeOnlyParameter("eventsFunctionContext", "");
485
+ };
486
+ helpers.declareEventsFunctionParameters = declareEventsFunctionParameters;
491
487
 
492
- // By convention, latest parameter is always the eventsFunctionContext of the calling function
493
- // (if any).
494
- instructionOrExpression.addCodeOnlyParameter('eventsFunctionContext', '');
488
+ return helpers;
495
489
  };
496
- module.exports.declareEventsFunctionParameters = declareEventsFunctionParameters;