@@ -49,86 +49,78 @@ module.exports = {
49
49
}
50
50
if ( propertyName === 'shapeDimensionA' ) {
51
51
newValue = parseFloat ( newValue ) ;
52
- if ( newValue < 0 ) newValue = 0 ;
52
+ if ( newValue !== newValue ) return false ;
53
53
behaviorContent . shapeDimensionA = newValue ;
54
54
return true ;
55
55
}
56
56
if ( propertyName === 'shapeDimensionB' ) {
57
57
newValue = parseFloat ( newValue ) ;
58
- if ( newValue < 0 ) newValue = 0 ;
58
+ if ( newValue !== newValue ) return false ;
59
59
behaviorContent . shapeDimensionB = newValue ;
60
60
return true ;
61
61
}
62
62
if ( propertyName === 'shapeOffsetX' ) {
63
- behaviorContent . shapeOffsetX = parseFloat ( newValue ) ;
63
+ newValue = parseFloat ( newValue ) ;
64
+ if ( newValue !== newValue ) return false ;
65
+ behaviorContent . shapeOffsetX = newValue ;
64
66
return true ;
65
67
}
66
68
if ( propertyName === 'shapeOffsetY' ) {
67
- behaviorContent . shapeOffsetY = parseFloat ( newValue ) ;
69
+ newValue = parseFloat ( newValue ) ;
70
+ if ( newValue !== newValue ) return false ;
71
+ behaviorContent . shapeOffsetY = newValue ;
72
+ return true ;
73
+ }
74
+ if ( propertyName === 'polygonOrigin' ) {
75
+ behaviorContent . polygonOrigin = newValue ;
76
+ return true ;
77
+ }
78
+ if ( propertyName === 'vertices' ) {
79
+ behaviorContent . vertices = JSON . parse ( newValue ) ;
68
80
return true ;
69
81
}
70
82
if ( propertyName === 'density' ) {
71
- newValue = parseFloat ( newValue ) ;
72
- if ( newValue < 0 ) newValue = 0 ;
73
- behaviorContent . density = newValue ;
83
+ behaviorContent . density = parseFloat ( newValue ) ;
74
84
return true ;
75
85
}
76
86
if ( propertyName === 'friction' ) {
77
87
newValue = parseFloat ( newValue ) ;
78
- if ( newValue < 0 ) newValue = 0 ;
88
+ if ( newValue !== newValue ) return false ;
79
89
behaviorContent . friction = newValue ;
80
90
return true ;
81
91
}
82
92
if ( propertyName === 'restitution' ) {
83
93
newValue = parseFloat ( newValue ) ;
84
- if ( newValue < 0 ) newValue = 0 ;
94
+ if ( newValue !== newValue ) return false ;
85
95
behaviorContent . restitution = newValue ;
86
96
return true ;
87
97
}
88
98
if ( propertyName === 'linearDamping' ) {
89
- behaviorContent . linearDamping = parseFloat ( newValue ) ;
99
+ newValue = parseFloat ( newValue ) ;
100
+ if ( newValue !== newValue ) return false ;
101
+ behaviorContent . linearDamping = newValue ;
90
102
return true ;
91
103
}
92
104
if ( propertyName === 'angularDamping' ) {
93
- behaviorContent . angularDamping = parseFloat ( newValue ) ;
105
+ newValue = parseFloat ( newValue ) ;
106
+ if ( newValue !== newValue ) return false ;
107
+ behaviorContent . angularDamping = newValue ;
94
108
return true ;
95
109
}
96
110
if ( propertyName === 'gravityScale' ) {
97
- behaviorContent . gravityScale = parseFloat ( newValue ) ;
111
+ newValue = parseFloat ( newValue ) ;
112
+ if ( newValue !== newValue ) return false ;
113
+ behaviorContent . gravityScale = newValue ;
98
114
return true ;
99
115
}
100
116
if ( propertyName === 'layers' ) {
101
- // The given binary string is reverse, fix it
102
- newValue = newValue
103
- . split ( '' )
104
- . reverse ( )
105
- . join ( '' ) ;
106
- // Convert it into a decimal
107
- newValue = parseInt ( newValue , 2 ) ;
108
- // If it can't be converted, cancel the edit
109
- if ( isNaN ( newValue ) ) return false ;
110
- // Layers minimum and maximum values
111
- if ( newValue < 0 ) newValue = 0 ;
112
- if ( newValue > 65535 ) newValue = 65535 ; // 65535 is the decimal form of 1111111111111111 (16 layer bits flagged)
113
- // Save the valid decimal
114
- behaviorContent . layers = newValue ;
117
+ behaviorContent . layers = parseInt ( newValue ) ;
115
118
return true ;
116
119
}
117
120
if ( propertyName === 'masks' ) {
118
- // Same than layers
119
- newValue = newValue
120
- . split ( '' )
121
- . reverse ( )
122
- . join ( '' ) ;
123
- newValue = parseInt ( newValue , 2 ) ;
124
- if ( isNaN ( newValue ) ) return false ;
125
- if ( newValue < 0 ) newValue = 0 ;
126
- if ( newValue > 65535 ) newValue = 65535 ;
127
- behaviorContent . masks = newValue ;
121
+ behaviorContent . masks = parseInt ( newValue ) ;
128
122
return true ;
129
123
}
130
-
131
- return false ;
132
124
} ;
133
125
physics2Behavior . getProperties = function ( behaviorContent ) {
134
126
var behaviorProperties = new gd . MapStringPropertyDescriptor ( ) ;
@@ -169,8 +161,8 @@ module.exports = {
169
161
. setLabel ( 'Shape' )
170
162
. addExtraInfo ( 'Box' )
171
163
. addExtraInfo ( 'Circle' )
172
- // .addExtraInfo("Polygon") Needs an editor to be useful
173
164
. addExtraInfo ( 'Edge' )
165
+ . addExtraInfo ( 'Polygon' )
174
166
) ;
175
167
behaviorProperties . set (
176
168
'shapeDimensionA' ,
@@ -196,6 +188,21 @@ module.exports = {
196
188
. setType ( 'Number' )
197
189
. setLabel ( 'Shape Offset Y' )
198
190
) ;
191
+ behaviorProperties . set (
192
+ 'polygonOrigin' ,
193
+ new gd . PropertyDescriptor ( behaviorContent . polygonOrigin || 'Center' )
194
+ . setType ( 'Choice' )
195
+ . setLabel ( 'Polygon Origin' )
196
+ . addExtraInfo ( 'Center' )
197
+ . addExtraInfo ( 'Origin' )
198
+ . addExtraInfo ( 'TopLeft' )
199
+ ) ;
200
+ behaviorProperties . set (
201
+ 'vertices' ,
202
+ new gd . PropertyDescriptor (
203
+ JSON . stringify ( behaviorContent . vertices || [ ] )
204
+ ) . setLabel ( 'Vertices' )
205
+ ) ;
199
206
behaviorProperties . set (
200
207
'density' ,
201
208
new gd . PropertyDescriptor ( behaviorContent . density . toString ( 10 ) )
@@ -232,38 +239,22 @@ module.exports = {
232
239
. setType ( 'Number' )
233
240
. setLabel ( 'Gravity Scale' )
234
241
) ;
235
-
236
- // Waiting for a layers/masks editor
237
- /*
238
- // Transform the layers number into a binary string
239
- var layers = behaviorContent.layers.toString(2);
240
- // Reverse the string (so the first layer bit is shown at the left)
241
- layers = layers
242
- .split('')
243
- .reverse()
244
- .join('');
245
- // Add zeros until the total size is 16
246
- if (layers.length < 16) layers = layers + '0'.repeat(16 - layers.length);
247
- // Expose the converted string
248
242
behaviorProperties . set (
249
243
'layers' ,
250
- new gd.PropertyDescriptor(layers).setLabel('Layers')
244
+ new gd . PropertyDescriptor ( behaviorContent . layers . toString ( 10 ) )
245
+ . setType ( 'Number' )
246
+ . setLabel ( 'Layers' )
251
247
) ;
252
- // Same than layers
253
- var masks = behaviorContent.masks.toString(2);
254
- masks = masks
255
- .split('')
256
- .reverse()
257
- .join('');
258
- if (masks.length < 16) masks = masks + '0'.repeat(16 - masks.length);
259
248
behaviorProperties . set (
260
249
'masks' ,
261
- new gd.PropertyDescriptor(masks).setLabel('Masks')
250
+ new gd . PropertyDescriptor ( behaviorContent . masks . toString ( 10 ) )
251
+ . setType ( 'Number' )
252
+ . setLabel ( 'Masks' )
262
253
) ;
263
- */
264
254
265
255
return behaviorProperties ;
266
256
} ;
257
+
267
258
physics2Behavior . setRawJSONContent (
268
259
JSON . stringify ( {
269
260
type : 'Dynamic' ,
@@ -275,6 +266,8 @@ module.exports = {
275
266
shapeDimensionB : 0 ,
276
267
shapeOffsetX : 0 ,
277
268
shapeOffsetY : 0 ,
269
+ polygonOrigin : 'Center' ,
270
+ vertices : [ ] ,
278
271
density : 1.0 ,
279
272
friction : 0.3 ,
280
273
restitution : 0.1 ,
@@ -293,23 +286,27 @@ module.exports = {
293
286
newValue
294
287
) {
295
288
if ( propertyName === 'gravityX' ) {
296
- sharedContent . gravityX = parseInt ( newValue , 10 ) ;
289
+ newValue = parseFloat ( newValue ) ;
290
+ if ( newValue !== newValue ) return false ;
291
+ behaviorContent . gravityX = newValue ;
297
292
return true ;
298
293
}
299
294
if ( propertyName === 'gravityY' ) {
300
- sharedContent . gravityY = parseInt ( newValue , 10 ) ;
295
+ newValue = parseFloat ( newValue ) ;
296
+ if ( newValue !== newValue ) return false ;
297
+ behaviorContent . gravityY = newValue ;
301
298
return true ;
302
299
}
303
300
if ( propertyName === 'scaleX' ) {
304
301
newValue = parseInt ( newValue , 10 ) ;
305
- if ( newValue <= 0 ) newValue = 1 ;
306
- sharedContent . scaleX = newValue ;
302
+ if ( newValue !== newValue ) return false ;
303
+ behaviorContent . scaleX = newValue ;
307
304
return true ;
308
305
}
309
306
if ( propertyName === 'scaleY' ) {
310
307
newValue = parseInt ( newValue , 10 ) ;
311
- if ( newValue <= 0 ) newValue = 1 ;
312
- sharedContent . scaleY = newValue ;
308
+ if ( newValue !== newValue ) return false ;
309
+ behaviorContent . scaleY = newValue ;
313
310
return true ;
314
311
}
315
312
@@ -721,7 +718,7 @@ module.exports = {
721
718
t (
722
719
'Modify an object shape scale. It affects custom shape dimensions and shape offset, if custom dimensions are not set the body will be scaled automatically to the object size.'
723
720
) ,
724
- t ( 'Do to _PARAM2__PARAM3_ to the shape scale of _PARAM0_' ) ,
721
+ t ( 'Do _PARAM2__PARAM3_ to the shape scale of _PARAM0_' ) ,
725
722
t ( 'Body settings' ) ,
726
723
'res/physics24.png' ,
727
724
'res/physics16.png'
0 commit comments