Skip to content

Commit a36c0f2

Browse files
committed
Put type options into hashobj
1 parent 2e1c621 commit a36c0f2

File tree

2 files changed

+50
-43
lines changed

2 files changed

+50
-43
lines changed

js/scripts/prop-types.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ _.extend(BufferMorphAttributes.prototype, BaseType.prototype, {
181181
},
182182
});
183183

184-
function Bool(defaultValue, nullable) {
185-
this.nullable = nullable === true;
184+
function Bool(defaultValue, options) {
185+
options = options || {};
186+
this.nullable = options.nullable === true;
186187
this.defaultValue = defaultValue;
187188
}
188189
_.extend(Bool.prototype, BaseType.prototype, {
@@ -195,8 +196,9 @@ _.extend(Bool.prototype, BaseType.prototype, {
195196
},
196197
});
197198

198-
function Int(defaultValue, nullable) {
199-
this.nullable = nullable === true;
199+
function Int(defaultValue, options) {
200+
options = options || {};
201+
this.nullable = options.nullable === true;
200202
this.defaultValue = (defaultValue === null || defaultValue === undefined) && !this.nullable ? 0 : defaultValue ;
201203
}
202204
_.extend(Int.prototype, BaseType.prototype, {
@@ -207,8 +209,9 @@ _.extend(Int.prototype, BaseType.prototype, {
207209

208210
});
209211

210-
function Float(defaultValue, nullable) {
211-
this.nullable = nullable === true;
212+
function Float(defaultValue, options) {
213+
options = options || {};
214+
this.nullable = options.nullable === true;
212215
this.defaultValue = (defaultValue === null || defaultValue === undefined) && !this.nullable ? 0.0 : defaultValue;
213216
}
214217
_.extend(Float.prototype, BaseType.prototype, {
@@ -222,8 +225,9 @@ _.extend(Float.prototype, BaseType.prototype, {
222225

223226
});
224227

225-
function StringType(defaultValue, nullable) {
226-
this.nullable = nullable === true;
228+
function StringType(defaultValue, options) {
229+
options = options || {};
230+
this.nullable = options.nullable === true;
227231
this.defaultValue = defaultValue;
228232
}
229233
_.extend(StringType.prototype, BaseType.prototype, {
@@ -234,10 +238,11 @@ _.extend(StringType.prototype, BaseType.prototype, {
234238

235239
});
236240

237-
function Enum(enumTypeName, defaultValue, nullable) {
241+
function Enum(enumTypeName, defaultValue, options) {
242+
options = options || {};
238243
this.enumTypeName = enumTypeName;
239244
this.defaultValue = defaultValue;
240-
this.nullable = nullable === true;
245+
this.nullable = options.nullable === true;
241246
}
242247
_.extend(Enum.prototype, BaseType.prototype, {
243248
getTraitlet: function() {
@@ -249,9 +254,10 @@ _.extend(Enum.prototype, BaseType.prototype, {
249254
},
250255
});
251256

252-
function Color(defaultValue, nullable) {
257+
function Color(defaultValue, options) {
258+
options = options || {};
253259
this.defaultValue = defaultValue || "#ffffff";
254-
this.nullable = nullable === true;
260+
this.nullable = options.nullable === true;
255261
}
256262
_.extend(Color.prototype, BaseType.prototype, {
257263
getTraitlet: function() {
@@ -317,9 +323,10 @@ _.extend(ArrayBufferType.prototype, BaseType.prototype, {
317323
},
318324
});
319325

320-
function DictType(defaultValue={}, nullable) {
326+
function DictType(defaultValue={}, options) {
327+
options = options || {};
321328
this.defaultValue = defaultValue;
322-
this.nullable = nullable === true;
329+
this.nullable = options.nullable === true;
323330
}
324331
_.extend(DictType.prototype, BaseType.prototype, {
325332
getTraitlet: function() {

js/scripts/three-class-config.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = {
3434
AnimationClip: {
3535
relativePath: './animation/AnimationClip',
3636
properties: {
37-
name: new Types.String(null, true),
37+
name: new Types.String(null, {nullable: true}),
3838
duration: new Types.Float(-1.0),
3939
tracks: new Types.ThreeTypeArray('KeyframeTrack'),
4040
},
@@ -168,7 +168,7 @@ module.exports = {
168168
Controls: {
169169
relativePath: './controls/Controls',
170170
properties: {
171-
controlling: new Types.ThreeType('Object3D', {allowNull: false}),
171+
controlling: new Types.ThreeType('Object3D', {nullable: false}),
172172
},
173173
},
174174
OrbitControls: {
@@ -251,14 +251,14 @@ module.exports = {
251251
superClass: 'Controls',
252252
properties: {
253253
event: new Types.String('click'),
254-
root: new Types.ThreeType('Object3D', {allowNull: true}),
254+
root: new Types.ThreeType('Object3D', {nullable: true}),
255255
all: new Types.Bool(false),
256-
distance: new Types.Float(null, true),
256+
distance: new Types.Float(null, {nullable: true}),
257257
point: new Types.Vector3(0, 0, 0),
258258
face: new Types.Vector3(0, 0, 0),
259259
faceNormal: new Types.Vector3(0, 0, 0),
260260
faceVertices: new Types.VectorArray(),
261-
faceIndex: new Types.Int(null, true),
261+
faceIndex: new Types.Int(null, {nullable: true}),
262262
object: new Types.ThreeType('Object3D', {nullable: true}),
263263
picked: new Types.Array(),
264264
uv: new Types.Vector2(0, 0),
@@ -340,7 +340,7 @@ module.exports = {
340340
morphNormals: new Types.Array(),
341341
skinWeights: new Types.VectorArray(),
342342
skinIndices: new Types.VectorArray(),
343-
_ref_geometry: new Types.ThreeType('Geometry', {allowNull: false}),
343+
_ref_geometry: new Types.ThreeType('Geometry', {nullable: false}),
344344
},
345345
},
346346
PlainBufferGeometry: {
@@ -353,7 +353,7 @@ module.exports = {
353353
// TODO: These likely require special types:
354354
//groups: new Types.GeometryGroup(),
355355
//drawRange: new Types.DrawRange(),
356-
_ref_geometry: new Types.ThreeType(['Geometry', 'BufferGeometry'], {allowNull: false}),
356+
_ref_geometry: new Types.ThreeType(['Geometry', 'BufferGeometry'], {nullable: false}),
357357
},
358358
},
359359
InstancedBufferAttribute: {
@@ -368,7 +368,7 @@ module.exports = {
368368
relativePath: './core/InstancedBufferGeometry',
369369
superClass: 'PlainBufferGeometry',
370370
properties: {
371-
maxInstancedCount: new Types.Int(null, true),
371+
maxInstancedCount: new Types.Int(null, {nullable: true}),
372372
},
373373
},
374374
InstancedInterleavedBuffer: {
@@ -632,9 +632,9 @@ module.exports = {
632632
clippingPlanes: new Types.ThreeTypeArray('Plane'),
633633
clipShadows: new Types.Bool(false),
634634
colorWrite: new Types.Bool(true),
635-
//customDepthMaterial: new Types.ForwardDeclaredThreeType('MeshDepthMaterial', 'pythreejs', {allowNull: true}),
636-
//customDistanceMaterial: new Types.ForwardDeclaredThreeType('MeshDepthMaterial', 'pythreejs', {allowNull: true}),
637-
defines: new Types.Dict(null, true),
635+
//customDepthMaterial: new Types.ForwardDeclaredThreeType('MeshDepthMaterial', 'pythreejs', {nullable: true}),
636+
//customDistanceMaterial: new Types.ForwardDeclaredThreeType('MeshDepthMaterial', 'pythreejs', {nullable: true}),
637+
defines: new Types.Dict(null, {nullable: true}),
638638
depthFunc: new Types.Enum('DepthMode', 'LessEqualDepth'),
639639
depthTest: new Types.Bool(true),
640640
depthWrite: new Types.Bool(true),
@@ -645,7 +645,7 @@ module.exports = {
645645
polygonOffset: new Types.Bool(false),
646646
polygonOffsetFactor: new Types.Float(0),
647647
polygonOffsetUnits: new Types.Float(0),
648-
precision: new Types.String(null, true),
648+
precision: new Types.String(null, {nullable: true}),
649649
premultipliedAlpha: new Types.Bool(false),
650650
dithering: new Types.Bool(false),
651651
flatShading: new Types.Bool(false),
@@ -787,7 +787,7 @@ module.exports = {
787787
properties: {
788788
clearCoat: new Types.Float(0.0),
789789
clearCoatRoughness: new Types.Float(0.0),
790-
defines: new Types.Dict({ 'PHYSICAL': '' }, true),
790+
defines: new Types.Dict({ 'PHYSICAL': '' }, {nullable: true}),
791791
reflectivity: new Types.Float(0.5),
792792
},
793793
},
@@ -801,7 +801,7 @@ module.exports = {
801801
bumpMap: new Types.ThreeType('Texture'),
802802
bumpScale: new Types.Float(1.0),
803803
color: new Types.Color('#ffffff'),
804-
defines: new Types.Dict({ 'STANDARD': '' }, true),
804+
defines: new Types.Dict({ 'STANDARD': '' }, {nullable: true}),
805805
displacementMap: new Types.ThreeType('Texture'),
806806
displacementScale: new Types.Float(1.0),
807807
displacementBias: new Types.Float(0.0),
@@ -1098,8 +1098,8 @@ module.exports = {
10981098
superClass: 'Object3D',
10991099
constructorArgs: [ 'geometry', 'material' ],
11001100
properties: {
1101-
material: new Types.ThreeType('Material', {allowNull: false}),
1102-
geometry: new Types.ThreeType(['Geometry', 'BufferGeometry'], {allowNull: false}),
1101+
material: new Types.ThreeType('Material', {nullable: false}),
1102+
geometry: new Types.ThreeType(['Geometry', 'BufferGeometry'], {nullable: false}),
11031103
drawMode: new Types.Enum('DrawModes', 'TrianglesDrawMode'),
11041104
morphTargetInfluences: new Types.Array(),
11051105
},
@@ -1110,8 +1110,8 @@ module.exports = {
11101110
superClass: 'Object3D',
11111111
constructorArgs: [ 'geometry', 'material' ],
11121112
properties: {
1113-
material: new Types.ThreeType('Material', {allowNull: false}),
1114-
geometry: new Types.ThreeType(['Geometry', 'BufferGeometry'], {allowNull: false}),
1113+
material: new Types.ThreeType('Material', {nullable: false}),
1114+
geometry: new Types.ThreeType(['Geometry', 'BufferGeometry'], {nullable: false}),
11151115
},
11161116
},
11171117
Skeleton: {
@@ -1187,7 +1187,7 @@ module.exports = {
11871187
fog: new Types.ThreeType('Fog'),
11881188
overrideMaterial: new Types.ThreeType('Material'),
11891189
autoUpdate: new Types.Bool(true),
1190-
background: new Types.Color(null, true),
1190+
background: new Types.Color(null, {nullable: true}),
11911191
},
11921192
},
11931193
Texture: {
@@ -1721,8 +1721,8 @@ module.exports = {
17211721
origin: new Types.Vector3(0, 0, 0),
17221722
length: new Types.Float(1.0),
17231723
hex: new Types.Int(0),
1724-
headLength: new Types.Float(null, true),
1725-
headWidth: new Types.Float(null, true),
1724+
headLength: new Types.Float(null, {nullable: true}),
1725+
headWidth: new Types.Float(null, {nullable: true}),
17261726
},
17271727
},
17281728
AxisHelper: {
@@ -1738,7 +1738,7 @@ module.exports = {
17381738
superClass: 'Object3D', // Should really be LineSegments, but we don't want to sync geometry/material
17391739
properties: {
17401740
object: new Types.ThreeType('Object3D'),
1741-
color: new Types.Color(null, true),
1741+
color: new Types.Color(null, {nullable: true}),
17421742
},
17431743
constructorArgs: ['object', 'color'],
17441744
propsDefinedByThree: ['matrixAutoUpdate']
@@ -1747,7 +1747,7 @@ module.exports = {
17471747
superClass: 'Object3D', // Should really be LineSegments, but we don't want to sync geometry/material
17481748
properties: {
17491749
box: new Types.ThreeType('Box3'),
1750-
color: new Types.Color('yellow', true),
1750+
color: new Types.Color('yellow', {nullable: true}),
17511751
},
17521752
constructorArgs: ['box', 'color'],
17531753
},
@@ -1766,7 +1766,7 @@ module.exports = {
17661766
properties: {
17671767
light: new Types.ThreeType('DirectionalLight'),
17681768
size: new Types.Float(1.0),
1769-
color: new Types.Color(null, true),
1769+
color: new Types.Color(null, {nullable: true}),
17701770
},
17711771
constructorArgs: ['light', 'size', 'color'],
17721772
propsDefinedByThree: ['matrixAutoUpdate']
@@ -1800,7 +1800,7 @@ module.exports = {
18001800
properties: {
18011801
light: new Types.ThreeType('HemisphereLight'),
18021802
size: new Types.Float(1.0),
1803-
color: new Types.Color(null, true),
1803+
color: new Types.Color(null, {nullable: true}),
18041804
},
18051805
constructorArgs: ['light', 'size', 'color'],
18061806
propsDefinedByThree: ['matrixAutoUpdate']
@@ -1810,7 +1810,7 @@ module.exports = {
18101810
properties: {
18111811
plane: new Types.ThreeType('Plane'),
18121812
size: new Types.Float(1.0),
1813-
color: new Types.Color('yellow', true),
1813+
color: new Types.Color('yellow', {nullable: true}),
18141814
},
18151815
constructorArgs: ['plane', 'size', 'color'],
18161816
},
@@ -1820,7 +1820,7 @@ module.exports = {
18201820
properties: {
18211821
light: new Types.ThreeType('PointLight'),
18221822
sphereSize: new Types.Float(1.0),
1823-
color: new Types.Color(null, true),
1823+
color: new Types.Color(null, {nullable: true}),
18241824
},
18251825
constructorArgs: ['light', 'sphereSize', 'color'],
18261826
propsDefinedByThree: ['matrixAutoUpdate']
@@ -1843,7 +1843,7 @@ module.exports = {
18431843
superClass: 'Object3D',
18441844
properties: {
18451845
light: new Types.ThreeType('RectAreaLight'),
1846-
color: new Types.Color(null, true),
1846+
color: new Types.Color(null, {nullable: true}),
18471847
},
18481848
constructorArgs: ['light', 'color'],
18491849
},
@@ -1860,7 +1860,7 @@ module.exports = {
18601860
superClass: 'Object3D',
18611861
properties: {
18621862
light: new Types.ThreeType('SpotLight'),
1863-
color: new Types.Color(null, true),
1863+
color: new Types.Color(null, {nullable: true}),
18641864
},
18651865
constructorArgs: ['light', 'color'],
18661866
propsDefinedByThree: ['matrixAutoUpdate']

0 commit comments

Comments
 (0)