-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathInterfaceDesigner-main.js
5681 lines (4905 loc) · 185 KB
/
InterfaceDesigner-main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
Global available functions. Not an actual object, used only to store all the globally available methods and variables for documentation purposes.
@class (global)
*/
/**
Checks if the object is null or undefined
@function
@memberof (global)
@param {*} ptr The object to be checked
@return {boolean} - true if null or undefined, false otherwise
@example
* if (isNull(someObject))
* console.log("someObject is null");
*/
function isNull(ptr)
{
return (ptr === undefined || ptr === null);
}
/**
Checks if the object is not null nor undefined
@function
@memberof (global)
@param {*} ptr The object to be checked
@return {boolean} - true if not null nor undefined, false otherwise
@example
* if (isNotNull(someObject))
* console.log("someObject is not null");
*/
function isNotNull(ptr)
{
return !isNull(ptr);
}
/**
Main method for wrapping.<br>
For better performance, use this method when wrapping objects from the underlying system. This will create an instance of the wrapped object, or return an existing one.
@function
@memberof (global)
@param {*} instanceType The class that the instance be made of.
@param {*} ptr The object that should be wrapped
@param {...*} [arguments] The arguments that the constructor of `instanceType` be called with
@return {object} - Wrapped object
@example
* var object = new SomeObject();
* var wrappedObject = __(SomeObject, object, params);
*/
function __()
{
var instanceType = arguments[0];
var ptr = arguments[1];
if (ptr.InterfaceDesignerWrapper == undefined)
{
var args = [].slice.call(arguments, 1);
var instance = Object.create(instanceType.prototype);
instanceType.apply(instance, args);
ptr.InterfaceDesignerWrapper = instance;
return instance;
}
else
return ptr.InterfaceDesignerWrapper;
}
var IWrapper = Class.$extend(
/** @lends IWrapper.prototype */
{
/**
Main wrapper interface. Every object in the interface designer is descendant of IWrapper.
Provides the pointer to the main wrapped object, as well as registers and fires callbacks.
@constructs
*/
__init__ : function()
{
this._ptr = null;
this.callbacks = {};
},
/**
Checks if the main wrapped object has expired, i.e. the pointer is not valid anymore
@return {boolean}
*/
expired : function()
{
return isNull(this._ptr);
},
/**
Registers a callback for a custom event of your choice
@param {string} eventType The type of event being registered
@param {Object} context The context of the callback, i.e. the value of `this` pointer inside the body of the callback
@param {Function} callback The callback to be called when the 'eventType' event is fired
*/
registerCallback : function(eventType, context, callback)
{
if (isNull(this.callbacks[eventType]))
this.callbacks[eventType] = [];
this.callbacks[eventType].push({
"context" : context,
"callback" : callback
});
},
/**
Checks if a callback exists for `eventType`.
@param {string} eventType The type of event being checked
@return {boolean} - `true` if at least one callback has been registered, `false` otherwise
*/
isRegistered : function(eventType)
{
return (isNotNull(this.callbacks[eventType]) && this.callbacks[eventType].length !== 0);
},
/**
Unregisters all callbacks.
*/
unregisterAll : function()
{
var callbackKeys = Object.keys(this.callbacks);
for (var i = 0, len = callbackKeys.length; i < len; ++i)
{
var key = callbackKeys[i];
this.callbacks[key].length = 0;
}
this.callbacks = {};
},
/**
Executes the custom event `eventType`
@param {string} eventType The type of event executed
@param {...any} [arguments] The arguments that this callback needs to be called with
*/
callback : function(eventType)
{
if (isNull(this.callbacks[eventType]))
return;
var allRegistered = this.callbacks[eventType];
if (allRegistered.length == 0)
return;
var args = [].slice.call(arguments, 1);
for (var i = 0, len = allRegistered.length; i < len; i++)
{
var context = allRegistered[i].context;
var callback = allRegistered[i].callback;
callback.apply(context, args);
}
}
});
var SceneWrapper = IWrapper.$extend(
/** @lends SceneWrapper.prototype */
{
/**
Wrapper interface for the underlying scene object.<br>
The scene object should provide access to manipulating the scene, such as entities and components, as well as scene events such as entity / component / attribute changes.
@constructs
@extends IWrapper
*/
__init__ : function()
{
this.$super();
/**
String for displaying the entities in UI
@type {string}
@default "entity"
@virtual
*/
this.entityString = "entity";
/**
String for displaying the components in UI
@type {string}
@default "component"
@virtual
*/
this.componentString = "component";
},
/**
Deserialize a scene described as JSON object.<br>
The implementations of this method should re-create a whole scene from a JSON string.
@param {string} jsonObject The JSON as string
@virtual
*/
deserializeFrom : function(jsonObject) {},
/**
Returns all entities present in the scene at the moment.<br>
The implementation should return objects that inherit {@link EntityWrapper}
@virtual
@return {Array} - Array of {@link EntityWrapper} objects.
*/
entities : function() {},
/**
Returns the entity for the given `entityId`.<br>
The implementation should return an object that inherits {@link EntityWrapper}
@param {number} entityId The ID of the entity to be queried
@virtual
@return {?EntityWrapper} - The entity with id `entityId` or `null` if no such entity exists.
*/
entityById : function(entityId) {},
entityByName: function(entityName) {},
/**
Creates an entity.<br>
The implementation should create an entity in the underlying system, then return a wrapped object that inherits {@link EntityWrapper}
@param {number} id A unique ID of the entity to be created. By agreement, a value of 0 should mean that this ID should be generated
@param {string[]} [components] An array of component type names
@param {number} [change=0] Enumeration value of how the scene should react on the change when synchronization is implemented also.
@param {boolean} [replicated=true] If this entity should be replicated to the server in systems where synchronization is implemented.
@param {boolean} [componentsReplicated=true] If this entity's components should be replicated to the server in systems where synchronization is implemented.
@virtual
@return {?EntityWrapper} - The new created entity wrapper object.
*/
createEntity : function(id, components, change, replicated, componentsReplicated) {},
/**
Removes an entity by given ID.<br>
The implementation should remove the entity in the underlying system
@param {number} entityId The ID of the entity to be removed
@virtual
*/
removeEntity : function(entityId) {},
/**
Returns a list of components that are available in the underlying system.<br>
The implementation should get all component types from the underlying system and push them in an array.onization is implemented.
@virtual
@return {string[]} - A list of the component type names available.
*/
registeredComponents : function() {},
/**
Returns if the underlying system allows components that share the same name.
@virtual
@return {boolean} - `true` if components can share a name, `false` otherwise
*/
doesAllowSameNamedComponents : function() {},
/**
Perform a raycast.<br>
The implementation of this method should execute a raycast on the underlying system's renderer.
@param {number} [x] The X screen coordinate. If left out, it will be taken from the current mouse position.
@param {number} [y] The Y screen coordinate. If left out, it will be taken from the current mouse position.
@param {number} [selectionLayer=1] Selection layer that the objects will be checked for.
@virtual
@return {RaycastResultWrapper} - A {@link RaycastResultWrapper} object that contains information about the 3D object that has been intersected with the ray.
*/
doRaycast : function(x, y, selectionLayer) {},
/**
Adds a prefix to the component type name.<br>
The default implementation is that it will return the same component name that is provided as argument.<br>
If the underlying system uses prefixes to differ component type names, this method should be implemented to reflect that.
@param {string} componentName The name of the component
@virtual
@return {string} - Component name with prefix
*/
componentNameWithPrefix : function(componentName)
{
return componentName;
},
/**
Removes a prefix, or modifies the original component type name to be in human-readable format.<br>
The default implementation is that it will return the same component type name that is provided as argument.<br>
If the underlying system uses prefixes or other means to differ component type names, this method should be implemented to trim out the extra.
@param {string} componentName The name of the component
@virtual
@return {string} - Component name with prefix
*/
componentNameInHumanFormat : function(typeName)
{
return typeName;
},
/**
Returns an attribute name from given attribute type ID.<br>
The implementation of this method should provide mapping from attribute type unique ID, to a human-readable attribute name string
@param {number} attrTypeId The attribute type ID
@virtual
@return {string} - Attribute name
*/
attributeTypeToName : function(attrTypeId) {},
/**
Returns a list of all attribute type IDs.<br>
The implementation of this method should provide a list of all attribute type IDs that are used from the underlying system.
@virtual
@return {number[]} - A list of attribute IDs
*/
attributeTypeIds : function() {},
/**
Resets the scene.<br>
The implementation of this method should clear, i.e. remove everything from the scene in the underlying system.
@virtual
*/
reset : function() {},
/**
Unsubscribe from a scene event.<br>
The implementation of this method should unsubscribe from the scene events using the `subscription` object provided, if such mechanism is used.
@param {object} subscription The subscription information.
@virtual
*/
unsubscribe : function(subscription) {},
/**
Returns if the attribute for a given type ID is an atomic value (not array, or object etc). The default implementation returns always false.<br>
The implementation of this method should return a boolean if the attribute is atomic.
@param {number} attrTypeId The attribute type ID.
@virtual
@return {boolean} - true if atomic, false otherwise
*/
isAttributeAtomic : function(attrTypeId)
{
return false;
},
/**
Returns if the attribute for a given type ID is a boolean value (true or false). The default implementation returns always false.<br>
The implementation of this method should return a boolean if the attribute is a boolean.
@param {number} attrTypeId The attribute type ID.
@virtual
@return {boolean} - true if boolean, false otherwise
*/
isAttributeBool : function(attrTypeId)
{
return false;
},
/**
Returns if the attribute for a given type ID is an array. The default implementation returns always false.<br>
The implementation of this method should return a boolean if the attribute is an array.
@param {number} attrTypeId The attribute type ID.
@virtual
@return {boolean} - true if array, false otherwise
*/
isAttributeArray : function(attrTypeId)
{
return false;
},
/**
Returns if the attribute for a given type ID is a Color object. The default implementation returns always false.<br>
The implementation of this method should return a boolean if the attribute is a color object.
@param {number} attrTypeId The attribute type ID.
@virtual
@return {boolean} - true if Color, false otherwise
*/
isAttributeColor : function(attrTypeId)
{
return false;
},
/**
Returns if the attribute for a given type ID is a Transform object. The default implementation returns always false.<br>
The implementation of this method should return a boolean if the attribute is a Transform object.
@param {number} attrTypeId The attribute type ID.
@virtual
@return {boolean} - true if Transform, false otherwise
*/
isAttributeTransform : function(attrTypeId)
{
return false;
},
/**
Returns if the attribute for a given type ID is a tuple of n-elements (commonly referred as Vector2, Vector3 etc). The default implementation returns always false.<br>
The implementation of this method should return a boolean if the attribute is a tuple.
@param {number} attrTypeId The attribute type ID.
@virtual
@return {boolean} - true if tuple, false otherwise
*/
isAttributeTuple : function(attrTypeId)
{
return 0;
},
/**
Returns if the attribute for a given type ID is an enumerated value. The default implementation returns always false.<br>
The implementation of this method should return a boolean if the attribute is a enumeration.
@param {number} attrTypeId The attribute type ID.
@virtual
@return {boolean} - true if enumeration, false otherwise
*/
isAttributeEnum : function(attrTypeId)
{
return false;
},
/**
Registers a callback for an 'entity created' event.<br>
The implementation of this method should internally subscribe to the 'entity created' event internally using the {@link IWrapper} methods for callbacks, and execute the callback when the underlying system fires the event.
@param {object} context The object as context.
@param {function} callback The callback to be called.
@virtual
@return {?object} - A subscription object if available.
*/
entityCreated : function(context, callback) {},
/**
Registers a callback for an 'entity removed' event.<br>
The implementation of this method should internally subscribe to the 'entity removed' event internally using the {@link IWrapper} methods for callbacks, and execute the callback when the underlying system fires the event.
@param {object} context The object as context.
@param {function} callback The callback to be called.
@virtual
@return {?object} - A subscription object if available.
*/
entityRemoved : function(context, callback) {},
/**
Registers a callback for an 'component created' event.<br>
The implementation of this method should internally subscribe to the 'component created' event internally using the {@link IWrapper} methods for callbacks, and execute the callback when the underlying system fires the event.
@param {object} context The object as context.
@param {function} callback The callback to be called.
@virtual
@return {?object} - A subscription object if available.
*/
componentCreated : function(context, callback) {},
/**
Registers a callback for an 'component removed' event.<br>
The implementation of this method should internally subscribe to the 'component removed' event internally using the {@link IWrapper} methods for callbacks, and execute the callback when the underlying system fires the event.
@param {object} context The object as context.
@param {function} callback The callback to be called.
@virtual
@return {?object} - A subscription object if available.
*/
componentRemoved : function(context, callback) {},
/**
Registers a callback for an 'attribute change' event.<br>
The implementation of this method should internally subscribe to the 'attribute change' event internally using the {@link IWrapper} methods for callbacks, and execute the callback when the underlying system fires the event.
@param {object} context The object as context.
@param {function} callback The callback to be called.
@virtual
@return {?object} - A subscription object if available.
*/
attributeChanged : function(context, callback) {},
// Log channels
/**
Log info on developer console
@virtual
@param {string} text The text to be printed in the console
*/
logInfo : function(text) {},
/**
Log warning on developer console
@virtual
@param {string} text The text to be printed in the console
*/
logWarning : function(text) {},
/**
Log error on developer console
@virtual
@param {string} text The text to be printed in the console
*/
logError : function(text) {}
});
var EntityWrapper = IWrapper.$extend(
/** @lends EntityWrapper.prototype */
{
/**
Wrapper interface for an entity object.
The entity object should provide access to manipulating individual entities and its components.
@constructs
@extends IWrapper
*/
__init__ : function(id, name, isLocal, isTemporary)
{
this.$super();
/**
Unique ID of the entity.
@type {number}
@default -1
*/
this.id = isNull(id) ? -1 : id;
/**
Entity name.
@type {string}
@default ""
*/
this.name = isNull(name) ? "" : name;
/**
Local or replicated entity.
@type {boolean}
@default false
*/
this.local = isLocal;
/**
Temporary entity
@type {boolean}
@default false
*/
this.temporary = isTemporary;
},
/**
Returns the parent ID of this entity, or null if not parented
@virtual
@return {?number} - The parent entity ID
*/
parentId : function()
{
return null;
},
/**
Checks if this entity is ancestor of `entityPtr`.<br>
@param {EntityWrapper} entityPtr The potential ancestor to be checked
@virtual
@return {boolean} - true if entity is ancestor of `entityPtr`, false otherwise
*/
isAncestorOf : function(entityPtr)
{
return false;
},
/**
Serialize this entity into a JSON string.<br>
The implementation should take care of the serialization in a way that will ensure it will stick to the {@link EntityWrapper} description.
@virtual
@return {string} - A stringified JSON from this entity
*/
serialize : function() {},
/**
Deserializes given JSON string to this entity.<br>
The implementation should take care of the deserialization in a way that will ensure it will stick to the {@link EntityWrapper} description.
@param {string} jsonObject The JSON string
@virtual
*/
deserialize : function(jsonObject) {},
/**
Sets the entity name.<br>
@param {string} name The desired name for this entity
@virtual
*/
setName : function(name) {},
/**
Returns the entity name.<br>
@return {string} - The current name for this entity
@virtual
*/
getName : function() {},
/**
Returns the number of components that this entity has.<br>
@return {number} - The number of components
@virtual
*/
numberOfComponents : function() {},
/**
Returns an array of all components that this entity has.<br>
@return {ComponentWrapper[]}
@virtual
*/
components : function() {},
/**
Creates a component and sets this entity as its parent.<br>
The implementation of this method should internally create a component to this entity.
@param {string} typeName The type name for this component.
@param {string} [name] The name for the component.
@param {boolean} [isLocal=false] Set to true if the component is to be created local only, meaning that it won't be sent to the server if synchronization is implemented.
@return {?ComponentWrapper} - The new created component, or null if creation fails
@virtual
*/
createComponent : function(typeName, name, isLocal) {},
/**
Checks if the component with given type and name exists.<br>
@param {string} type The type name for this component.
@param {string} [name] The name for the component.
@return {boolean} -
@virtual
*/
hasComponent : function(type, name) {},
/**
Retrieve a component with given type and name.<br>
@param {string} type The type name for this component.
@param {string} [name] The name for the component.
@return {?ComponentWrapper} - The component, or null if not found
@virtual
*/
getComponent : function(type, name) {},
/**
Retrieve a component with given unique ID.<br>
@param {number} componentId The ID for the component.
@return {?ComponentWrapper} - The component, or null if not found
@virtual
*/
componentById : function(componentId) {},
/**
Remove a component with given unique ID.<br>
@param {number} componentId The ID for the component.
@virtual
*/
removeComponent : function(componentId) {},
});
var ComponentWrapper = IWrapper.$extend(
/** @lends ComponentWrapper.prototype */
{
/**
Wrapper interface for a component object.
The component object should provide access to manipulating component attributes and other options.
@constructs
@extends IWrapper
*/
__init__: function(id, name, type, parentId)
{
this.$super();
/**
Unique ID of the component
@type {number}
@default -1
*/
this.id = isNull(id) ? -1 : id;
/**
Name of the component
@type {string}
@default ""
*/
this.name = isNull(name) ? "" : name;
/**
Type name of the component
@type {string}
@default ""
*/
this.typeName = isNull(type) ? "" : type;
/**
Parent entity ID of the component
@type {number}
*/
this.pId = parentId;
},
/**
Returns this component's parent entity unique ID.<br>
@return {number} - The ID of the parent.
@virtual
*/
parentId : function()
{
return this.pId;
},
/**
Returns the component name.<br>
@return {string} - The current name for this component
@virtual
*/
getName : function()
{
return this.name;
},
/**
Serialize this component into a JSON string.<br>
The implementation should take care of the serialization in a way that will ensure it will stick to the {@link ComponentWrapper} description.
@virtual
@return {string} - A stringified JSON from this component
*/
serialize : function() {},
/**
Deserializes given JSON string to this component.<br>
The implementation should take care of the deserialization in a way that will ensure it will stick to the {@link ComponentWrapper} description.
@param {string} jsonObject The JSON string
@virtual
*/
deserialize : function(jsonObject) {},
/**
Returns if the component is dynamic, i.e. its attributes can be added / removed on demand.<br>
@return {boolean} - true if dynamic component, false otherwise
@virtual
*/
isDynamic : function() {},
/**
Mark this component a temporary. A temporary component will not be saved when saving the whole scene into a file
@param {boolean} temporary true if this component should be temporary, false othewise
@virtual
*/
setTemporary : function(temporary) {},
/**
Returns all attributes of this component
@return {AttributeWrapper[]}
@virtual
*/
attributes : function() {},
/**
If this component is dynamic, an attribute can be created by calling this function
@param {number} typeId The type ID of the attribute that should be created
@param {string} name A unique name for the new attribute
@return {boolean} - true if the attribute was successfully created, false if not or if component is not dynamic
@virtual
*/
createAttribute : function(typeId, name) {},
/**
Gets an attribute by name
@param {string} name The name for the attribute
@return {?AttributeWrapper} - The attribute, or null if not found
@virtual
*/
attributeByName : function(name) {},
/**
Gets an attribute by index
@param {number} index The index for the attribute
@return {?AttributeWrapper} - The attribute, or null if not found
@virtual
*/
getAttributeByIndex : function(index) {},
/**
Removes an attribute by index
@param {number} index The index for the attribute to be removed
@return {boolean} - true if the attribute was successfully removed, false if not or if component is not dynamic
@virtual
*/
removeAttribute : function(index) {},
/**
Registers a callback for an 'attribute added' event.<br>
The implementation of this method should internally subscribe to the 'attribute added' event internally to this component, using the {@link IWrapper} methods for callbacks, and execute the callback when the underlying system fires the event.
@param {object} context The object as context.
@param {function} callback The callback to be called.
@virtual
@return {?object} - A subscription object if available.
*/
onAttributeAdded : function(context, callback) {},
/**
Registers a callback for an 'attribute removed' event.<br>
The implementation of this method should internally subscribe to the 'attribute removed' event internally to this component, using the {@link IWrapper} methods for callbacks, and execute the callback when the underlying system fires the event.
@param {object} context The object as context.
@param {function} callback The callback to be called.
@virtual
@return {?object} - A subscription object if available.
*/
onAttributeAboutToBeRemoved : function(context, callback) {}
});
var AttributeWrapper = IWrapper.$extend(
/** @lends AttributeWrapper.prototype */
{
/**
Wrapper interface for an attribute object.
The attribute object should provide access to manipulating values of attributes.
@param {number} index The index of this attribute. Index is the position where this attribute resides in the component
@param {number} typeId The type ID of the attribute
@param {string} name The name of the attribute
@param {ComponentWrapper} parent The parent component of this attribute
@constructs
@extends IWrapper
*/
__init__ : function(index, typeId, name, parent)
{
this.$super();
/**
Type ID of the attribute
@type {number}
*/
this.typeId = typeId;
/**
Name of the attribute
@type {string}
@default ""
*/
this.name = isNull(name) ? "" : name;
/**
Attribute index
@type {number}
*/
this.index = index;
/**
The component that owns the attribute
@type {ComponentWrapper}
*/
this.owner = parent;
},
/**
Returns the valid values that this attribute can accept. The default implementation returns null<br>
The implementation of this method should check with the underlying system the allowed values for this attribute, and return them in an array.
@return {*} - values array of valid values. Can be any type
*/
validValues : function()
{
return null;
},
/**
Get the raw value of this attribute
@return {*} - The value of this attribute
*/
get : function() {},
/**
Sets the raw value of this attribute
@param {*} value The value to be set
*/
set : function(value) {}
});
var IEvent = Class.$extend(
/** @lends IEvent.prototype */
{
/**
A wrapper for events. Any input event wrapper should inherit this class.
@param {number} eventType The event type, see the static members
@param {number} [id] Unique ID for this event
@constructs
*/
__init__ : function(eventType, id)
{
this.eventType = eventType;
this.id = id;
this.targetId = "";
this.targetNodeName = "";
this.originalEvent = null;
this.suppressed = false
},
__classvars__ :
{
/**
Mouse event
@static
@type {number}
@default 0
*/
MouseEvent : 0,
/**
Key event
@static
@type {number}
@default 1
*/
KeyEvent : 1,
/**
Resize event
@static
@type {number}
@default 2
*/
ResizeEvent : 2
}
});
var KeyEventWrapper = IEvent.$extend(
/** @lends KeyEventWrapper.prototype */
{
/**
A wrapper for key events. Any key event wrapper should inherit this class.
@param {number} [id] Unique ID for this event
@constructs
@extends IEvent
*/
__init__ : function(id)
{
this.$super(IEvent.KeyEvent, id);
this.type = "";
this.keyCode = 0;
this.key = "";
this.repeat = false;
this.pressed = {};
},
/**
Returns if the given keyboard `key` is pressed
@param {string} key The key to be checked
@return {boolean} - true if the key is pressed
*/
isPressed : function(key)
{
if (isNotNull(this.pressed[key]))
return this.pressed[key];
return false;
}
});
var MouseEventWrapper = IEvent.$extend(
/** @lends MouseEventWrapper.prototype */
{
/**
A wrapper for mouse events. Any mouse event wrapper should inherit this class.
@param {number} [id] Unique ID for this event
@constructs
@extends IEvent
*/
__init__ : function(id)
{
this.$super(IEvent.MouseEvent, id);
this.type == "";
this.x = null;
this.y = null;
this.relativeX = 0;
this.relativeY = 0;
this.relativeZ = 0;
this.leftDown = false;
this.middleDown = false;
this.rightDown = false;
}
});
var RaycastResultWrapper = Class.$extend(
/** @lends RaycastResultWrapper.prototype */
{
/**
A raycast result object.
@constructs
*/
__init__ : function()
{
/**
A pointer to the entity wrapper object that has been hit. Can be null
@var {?EntityWrapper}
*/
this.entity = null;
/**
A pointer to the component wrapper object (for example a mesh, billboard etc) that has been hit. Can be null
@var {?ComponentWrapper}
*/
this.component = null;
/**
A 3-tuple that represents the position of the location where it hit the entity.
@var {*}
*/
this.pos = null;
/**
Distance from screen coordinates to the entity that has been hit by the raycasting.
@var {number}
*/
this.distance = -1;
/**
Index of the submesh that has been hit by the raycasting.
@var {number}
*/
this.submesh = -1;
/**
Face index that has been hit by the raycasting.
@var {number}
*/
this.faceIndex = -1;
/**
Pointer to the original ray used in the casting.