-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathlogicpack.js
2272 lines (1835 loc) · 67.7 KB
/
logicpack.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
/* Goo Engine UNOFFICIAL
* Copyright 2016 Goo Technologies AB
*/
webpackJsonp([11],{
/***/ 0:
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(377);
/***/ },
/***/ 377:
/***/ function(module, exports, __webpack_require__) {
module.exports = {
LogicInterface: __webpack_require__(378),
LogicLayer: __webpack_require__(379),
LogicNode: __webpack_require__(380),
LogicNodeAdd: __webpack_require__(381),
LogicNodeApplyMatrix: __webpack_require__(383),
LogicNodeConstVec3: __webpack_require__(384),
LogicNodeDebug: __webpack_require__(385),
LogicNodeEntityProxy: __webpack_require__(386),
LogicNodeFloat: __webpack_require__(387),
LogicNodeInput: __webpack_require__(388),
LogicNodeInt: __webpack_require__(389),
LogicNodeLightComponent: __webpack_require__(390),
LogicNodeMax: __webpack_require__(391),
LogicNodeMeshRendererComponent: __webpack_require__(392),
LogicNodeMouse: __webpack_require__(393),
LogicNodeMultiply: __webpack_require__(394),
LogicNodeMultiplyFloat: __webpack_require__(395),
LogicNodeOutput: __webpack_require__(396),
LogicNodeRandom: __webpack_require__(397),
LogicNodeRotationMatrix: __webpack_require__(398),
LogicNodes: __webpack_require__(382),
LogicNodeSine: __webpack_require__(399),
LogicNodeSub: __webpack_require__(400),
LogicNodeTime: __webpack_require__(401),
LogicNodeTransformComponent: __webpack_require__(402),
LogicNodeVec3: __webpack_require__(403),
LogicNodeVec3Add: __webpack_require__(404),
LogicNodeWASD: __webpack_require__(405),
LogicNodeWASD2: __webpack_require__(406),
LogicComponent: __webpack_require__(407),
LogicComponentHandler: __webpack_require__(408),
LogicSystem: __webpack_require__(409)
};
if (typeof(window) !== 'undefined') {
for (var key in module.exports) {
window.goo[key] = module.exports[key];
}
}
/***/ },
/***/ 378:
/***/ function(module, exports) {
/**
* @private
* Describes all the inputs / outputs for this logic interface. Typically one instance of this class exists for every class that
* implements logic.
*/
function LogicInterface(name) {
this.ports = [];
this.configOpts = [];
// Name builds the data name prefix
if (name === undefined) {
this.dn_pfx = '';
} else {
this.dn_pfx = name + '-';
}
}
LogicInterface.prototype.addInputProperty = function (name_, valueType, defaultValue) {
this.ports.push({
id: ++LogicInterface._portID,
input: true,
property: true,
event: false,
name: (this.dn_pfx + name_),
type: valueType,
def: defaultValue
});
return LogicInterface._portID;
};
LogicInterface.prototype.addOutputProperty = function (name_, valueType) {
this.ports.push({
id: ++LogicInterface._portID,
input: false,
property: true,
event: false,
name: (this.dn_pfx + name_),
type: valueType
});
return LogicInterface._portID;
};
LogicInterface.prototype.addInputEvent = function (name_) {
this.ports.push({
id: ++LogicInterface._portID,
input: true,
property: false,
event: true,
name: (this.dn_pfx + name_)
});
return LogicInterface._portID;
};
LogicInterface.prototype.addOutputEvent = function (name_) {
this.ports.push({
id: ++LogicInterface._portID,
input: false,
property: false,
event: true,
name: (this.dn_pfx + name_)
});
return LogicInterface._portID;
};
LogicInterface.createDynamicInput = function (name_) {
return {
id: LogicInterface.makeDynamicId(),
input: true,
property: true,
event: true,
dynamic: true,
name: name_
};
};
LogicInterface.createDynamicOutput = function (name_) {
return {
id: LogicInterface.makeDynamicId(),
input: false,
property: true,
event: true,
dynamic: true,
name: name_
};
};
/*
* The config entry here is an object containing all the parameters that go into the automatically
* generated goo-property-edit when editing the schematics
*/
LogicInterface.prototype.addConfigEntry = function (conf) {
this.configOpts.push(conf);
};
LogicInterface.prototype.getConfigEntries = function () {
return this.configOpts;
};
LogicInterface.prototype.getPorts = function () {
return this.ports;
};
LogicInterface.isDynamicPortName = function (name) {
return name[0] === '$';
};
LogicInterface.makeDynamicId = function () {
return ++LogicInterface._portID;
};
/**
* Computes a name for the port that can be saved in the data model without having it confused when (other) ports are added/removed
* @param port Port description object as returned by createDynamicInput/Output or from the getPorts() array.
*/
LogicInterface.makePortDataName = function (port) {
if (port.dataname !== undefined) {
return port.dataname;
} else {
var prefix = port.input ? 'in-' : 'out-';
if (port.property) {
prefix += 'prop-';
}
if (port.event) {
prefix += 'event-';
}
// tag dynamic ports with $ at the start so they can be routed
// properly.
var dyn = (port.dynamic === true) ? '$' : '';
return dyn + prefix + port.name;
}
};
LogicInterface.assignPortDataName = function (port, dataname) {
port.dataname = dataname;
};
/**
* Globally unique port id counter
*/
LogicInterface._portID = 0;
module.exports = LogicInterface;
/***/ },
/***/ 379:
/***/ function(module, exports, __webpack_require__) {
var LogicInterface = __webpack_require__(378);
/**
* Handles a logic layer, which is a container for Logic Nodes and connections. It handles resolving and executing
* connections, as well as cross-layer connections (through LogicSystem). Each LogicLayer has an entity owner.
* @private
*/
function LogicLayer(ownerEntity) {
this._logicInterfaces = {};
this._connectionsBySource = {}; // REVIEW: unused?
this._instanceID = 0;
this._updateRound = 0;
this._nextFrameNotifications = [];
this.ownerEntity = ownerEntity;
// Hax to get LogicSystem
this.logicSystem = ownerEntity._world.getSystem('LogicSystem');
}
LogicLayer.prototype.clear = function () {
this._logicInterfaces = {};
this._connectionsBySource = {};
this._instanceID = 0;
this._nextFrameNotifications = [];
};
/**
* Creates an active instance (node) of logic described by iface parameter, tied to an instance of some other object.
* The instance is expected to implement onPropertyWrite and onEvent but can be of any class. The instance descriptor
* returned can then be used to make connections through connectEndPoints
*
* @param iface The interface descriptor (LogicInterface) for the object 'instance'
* @param instance The object that exposes the logic interface defined by iface.
* @param name The name (ref) for adding connections by name. Supply null for automatically generated name.
* @param wantsProcessCall If the instance passed wants processLogic per-frame calls
* @returns An instance descriptor
*/
LogicLayer.prototype.addInterfaceInstance = function (iface, instance, name, wantsProcessCall) {
// if wished, autogenerate name.
if (name === null) {
name = '_auto-' + this._instanceID;
}
// create the instance description
var instDesc = {
id: this._instanceID,
name: name,
obj: instance,
iface: iface,
layer: this,
wantsProcess: wantsProcessCall
};
this._instanceID++;
// also supply self-destructing code
var _this = this;
instDesc.remove = function () {
delete this.outConnections;
delete _this._logicInterfaces[name];
// nice n^2 algo here to remove all instances.
_this.unresolveAllConnections();
};
instDesc.getPorts = function () {
return iface.getPorts();
};
// HACK: Pick up LogicNodeEntityProxy entityRef and store it in the description too.
if (instance.entityRef !== undefined) {
instDesc.proxyRef = instance.entityRef;
}
this._logicInterfaces[name] = instDesc;
return instDesc;
};
LogicLayer.prototype.unresolveAllConnections = function () {
// Un-do all connection resolving. Processes all instances, all ports and all connections
for (var n in this._logicInterfaces) {
var ports = this._logicInterfaces[n].outConnections;
if (ports === undefined) { // REVIEW: not really needed, the for loop below would not blow up or execute anything if ports were undefined
continue;
}
for (var p in ports) {
var cx = ports[p]; // REVIEW: why is an element of 'ports' called 'cx'? what is a cx?
for (var i = 0; i < cx.length; i++) {
if (cx[i].length > 2) {
cx[i] = [cx[i][0], cx[i][1]];
}
}
}
}
};
LogicLayer.resolvePortID = function (instDesc, portName) {
if (typeof portName === 'number') {
return portName;
}
if (LogicInterface.isDynamicPortName(portName)) {
return portName;
}
// could be good to actually figure out if we need to do this.
// if realPortid is a number, no need to do all this
var ports = instDesc.getPorts();
for (var j = 0; j < ports.length; j++) {
if (LogicInterface.makePortDataName(ports[j]) === portName) {
return ports[j].id;
}
}
console.warn('Unable to resolve port [' + portName + ']!');
return null;
};
LogicLayer.prototype.resolveTargetAndPortID = function (targetRef, portName) {
var tgt = this._logicInterfaces[targetRef];
// can't be resolved right away, not added yet.
if (tgt === undefined) {
return;
}
// First check the proxy cases.
if (tgt.obj.entityRef !== undefined && LogicInterface.isDynamicPortName(portName)) {
var logicLayer2 = this.logicSystem.getLayerByEntity(tgt.obj.entityRef);
for (var n in logicLayer2._logicInterfaces) {
var l = logicLayer2._logicInterfaces[n];
// if (l.obj.type === "LogicNodeInput") {
// console.log(l);
// }
if (l.obj.type === 'LogicNodeInput' && l.obj.dummyInport !== null && LogicInterface.makePortDataName(l.obj.dummyInport)) {
return {
target: l,
portID: portName
};
}
}
}
// See if the port exists directly at that node.
var directAttempt = LogicLayer.resolvePortID(tgt, portName);
if (directAttempt !== null) {
// direct connection.
return {
target: tgt,
portID: directAttempt
};
}
console.warn('Failed resolving target&portid to ' + targetRef + ':' + portName);
return null;
};
LogicLayer.prototype.addConnectionByName = function (instDesc, sourcePort, targetName, targetPort) {
//
// Adding connection here which will be in unresolved state
// [targetName, targetPort]
//
// when resolved they will have 4 columns
if (instDesc.outConnections === undefined) {
instDesc.outConnections = {};
}
// resolve from name
var sourcePortID = LogicLayer.resolvePortID(instDesc, sourcePort);
if (instDesc.outConnections[sourcePortID] === undefined) {
instDesc.outConnections[sourcePortID] = [];
}
instDesc.outConnections[sourcePortID].push([targetName, targetPort]); // REVIEW: so this is a 'cx'
};
/**
* Resolve all outgoing connections from the logic instance instDesc and
* call the provided callback function on each connected target.
*/
LogicLayer.doConnections = function (instDesc, portID, func) {
if (instDesc.outConnections === undefined) {
return;
}
var cArr = instDesc.outConnections[portID];
if (cArr === undefined) {
return;
}
if (cArr.length === 0) {
delete instDesc.outConnections;
}
// Connections can be encountered as unresolved [x, y] or resolved [x, y, z, w].
// Resolved connections contain pointers to the actual objects.
for (var i = 0; i < cArr.length; i++) {
var tconn = cArr[i];
// unresolved
if (tconn.length === 2) {
var out = instDesc.layer.resolveTargetAndPortID(tconn[0], tconn[1]);
if (out === null) {
console.log('Target unresolved ' + tconn[0] + ' and ' + tconn[1]);
// TODO: Queue write.
continue;
}
tconn.push(out.target);
tconn.push(out.portID);
}
// now resolved.
func(tconn[2], tconn[3]);
}
};
/**
* Writes a value using an instance descriptor and a portID (which must be registered through the interface the instance
* was created with). All connected objects get the onPropertyWrite call.
*/
LogicLayer.writeValue = function (instDesc, outPortID, value) {
//
LogicLayer.doConnections(instDesc, outPortID, function (targetDesc, portID) {
// write
if (targetDesc._portValues === undefined) {
targetDesc._portValues = {};
}
if (targetDesc._lastNotification === undefined) {
targetDesc._lastNotification = {};
}
var old = targetDesc._portValues[portID];
targetDesc._portValues[portID] = value;
if (old !== value) {
var tlayer = targetDesc.layer;
if (targetDesc._lastNotification[portID] !== tlayer._updateRound) {
targetDesc._lastNotification[portID] = tlayer._updateRound;
targetDesc.obj.onInputChanged(targetDesc, portID, value);
} else {
tlayer._nextFrameNotifications.push([targetDesc, portID, value]);
}
}
});
};
/**
* Use this to write a layer to an output node, they need to be treated specially.
* @param outNodeDesc instDesc of the output node
* @param outPortDesc Port id of the output port
* @param value Value to write
*/
LogicLayer.writeValueToLayerOutput = function (outNodeDesc, outPortDesc, value) {
// TODO: Cache writeFn
var writeFn = outNodeDesc.layer.logicSystem.makeOutputWriteFn(outNodeDesc.layer.ownerEntity, outPortDesc);
writeFn(value);
};
/**
* Read a (possibly cached) value from an input port on a particular node.
* @param instDesc instDesc of the node to read from
* @param portID portID of interest
* @returns Returns the value at the port
*/
LogicLayer.readPort = function (instDesc, portID) {
// 2-step lookup. note that value will first be
// _portValue if it exists.
var value = instDesc._portValues;
if (value !== undefined) {
value = value[portID];
} else {
instDesc._portValues = {};
}
if (value !== undefined) {
return value;
}
// default value - here we could look up editable. Unfortunately
// if the default specifies 'undefined' value, reading from it will
// repeatedly end up in this loop.
var ports = instDesc.iface.getPorts();
for (var n in ports) {
if (ports[n].id === portID) {
return instDesc._portValues[portID] = ports[n].def;
}
}
console.log('Could not find the port [' + portID + ']!');
return undefined; // REVIEW: returns undefined anyway
};
/**
* Fire an event.
* @param portId The port connecting the event. (Returned when registering the event port)
*/
LogicLayer.fireEvent = function (instDesc, outPortID) {
LogicLayer.doConnections(instDesc, outPortID, function (targetDesc, portID) {
targetDesc.obj.onEvent(targetDesc, portID);
});
};
LogicLayer.resolveEntityRef = function (instDesc, entityRef) {
if (entityRef === '[self]') {
return instDesc.layer.ownerEntity;
} else {
return instDesc.layer.logicSystem.resolveEntityRef(entityRef);
}
};
LogicLayer.prototype.process = function (tpf) {
// First of all process queued property update notifications from last frame.
// These are limited to one per frame and queued up if more should happen.
// Reason for this being avoiding cyclic and infinite update loops.
var not = this._nextFrameNotifications;
this._nextFrameNotifications = [];
for (var i = 0; i < not.length; i++) {
var ne = not[i];
ne[0]._lastNotification[ne[1]] = this._updateRound;
ne[0].obj.onInputChanged(ne[0], ne[1], ne[2]);
}
// ...then update all logic objects
for (var i in this._logicInterfaces) {
if (this._logicInterfaces[i].wantsProcess && this._logicInterfaces[i].obj.processLogic) {
this._logicInterfaces[i].obj.processLogic(tpf);
}
}
this._updateRound++;
};
/**
* For all logic objects (i.e. those who added logicInstances and passed themselves along)
* @param f Function to call for every object.
*/
LogicLayer.prototype.forEachLogicObject = function (f) {
for (var i in this._logicInterfaces) {
var o = this._logicInterfaces[i].obj;
if (o !== undefined) {
f(o);
}
}
};
/**
* For all objects that follow the convention of having an logicInstance property for their connections
* (components, logic nodes), this is useful for less verbose connection code. It looks up the logicInstance
* in the objects passed in and connects their endpoints.
*/
LogicLayer.prototype.connectObjectsWithLogic = function (sourceObj, sourcePort, destObj, destPort) {
this.connectEndpoints(sourceObj.logicInstance, sourcePort, destObj.logicInstance, destPort);
};
/**
* Connects two objects through their instance descriptors and port names.
*/
LogicLayer.prototype.connectEndpoints = function (sourceInst, sourcePort, destInst, destPort) {
this.addConnectionByName(sourceInst, sourcePort, destInst.name, destPort);
};
module.exports = LogicLayer;
/***/ },
/***/ 380:
/***/ function(module, exports) {
/**
* Base class/module for all logic boxes
* @private
*/
function LogicNode() {
// Generated the same way as entities are, except different naming.
Object.defineProperty(this, 'id', {
value: LogicNode._instanceCount++,
writable: false
});
// create default configuration.
this.config = {
ref: 'unconf-' + this.id
};
this.name = name !== undefined ? name : 'Logic_' + this.id;
// If instantiated in a logic layer.
this.logicInstance = null;
// For now this needs to be set to true in the constructor of those who wants it, or
// at least before addToWorldLogic is called.
this.wantsProcessCall = false;
}
/**
* Add the logic node to the world's logic layer. This is a necessary step for allowing
* connections. This should be called by logic node implementations.
*
* @param {world} World to add it to
*/
LogicNode.prototype.addToLogicLayer = function (logicLayer, withId) {
// Cleanup of previous; this will also remove connections so we always need to (re-) add them.
if (this.logicInstance !== null) {
this.logicInstance.remove();
}
this.logicInstance = logicLayer.addInterfaceInstance(this.logicInterface, this, withId, this.wantsProcessCall);
if (this.connections !== undefined) {
// data comes from configure call.
for (var i = 0; i < this.connections.length; i++) {
var conn = this.connections[i];
logicLayer.addConnectionByName(this.logicInstance, conn.sourcePort, conn.targetRef, conn.targetPort);
}
// this prevents duplicate adding.
delete this.connections;
}
};
LogicNode.prototype.configure = function (nodeData) {
var c = (nodeData.config !== undefined) ? nodeData.config : {};
this.onConfigure(c);
this.config = c;
this.connections = nodeData.connections;
};
/**
* Called after getting new configuration data; before getting added to world. Override
* this function and not configure.
* @param newConfig The new configuration data.
*/
LogicNode.prototype.onConfigure = function () {};
/**
* When logic system is started.
*/
LogicNode.prototype.onSystemStarted = function () {};
/**
* Called when system is stopped.
* @param stopForPause If true, world has been paused. Otherwise stopped & reset.
*/
LogicNode.prototype.onSystemStopped = function () {};
/**
* Called when node receives an input value.
* @param instDesc Instance description
* @param port Port ID
* @param nv New value on that particular port.
*/
LogicNode.prototype.onInputChanged = function () {};
LogicNode._instanceCount = 0;
module.exports = LogicNode;
/***/ },
/***/ 381:
/***/ function(module, exports, __webpack_require__) {
var LogicLayer = __webpack_require__(379);
var LogicNode = __webpack_require__(380);
var LogicNodes = __webpack_require__(382);
var LogicInterface = __webpack_require__(378);
/**
* Logic node to add values.
* @private
*/
function LogicNodeAdd() {
LogicNode.call(this);
this.logicInterface = LogicNodeAdd.logicInterface;
this.type = 'LogicNodeAdd';
}
LogicNodeAdd.prototype = Object.create(LogicNode.prototype);
LogicNodeAdd.editorName = 'Add';
LogicNodeAdd.prototype.onInputChanged = function (instDesc) {
var out = LogicLayer.readPort(instDesc, LogicNodeAdd.inportX) +
LogicLayer.readPort(instDesc, LogicNodeAdd.inportY);
LogicLayer.writeValue(this.logicInstance, LogicNodeAdd.outportSum, out);
};
LogicNodeAdd.logicInterface = new LogicInterface();
LogicNodeAdd.outportSum = LogicNodeAdd.logicInterface.addOutputProperty('sum', 'float');
LogicNodeAdd.inportX = LogicNodeAdd.logicInterface.addInputProperty('x', 'float', 0);
LogicNodeAdd.inportY = LogicNodeAdd.logicInterface.addInputProperty('y', 'float', 0);
LogicNodes.registerType('LogicNodeAdd', LogicNodeAdd);
module.exports = LogicNodeAdd;
/***/ },
/***/ 382:
/***/ function(module, exports) {
/**
* Base class/module for all logic boxes
* @private
*/
function LogicNodes() {}
LogicNodes.types = {};
/**
* Register a new logic node. All logic nodes must call this to register themselves.
* @private
*/
LogicNodes.registerType = function (name, fn) {
LogicNodes.types[name] = {
fn: fn,
name: name,
editorName: fn.editorName
};
};
LogicNodes.getInterfaceByName = function (name) {
if (LogicNodes.types[name] !== undefined) {
return LogicNodes.types[name].fn.logicInterface;
}
return null;
};
LogicNodes.getClass = function (name) {
if (LogicNodes.types[name] === undefined) {
return function () {
console.error('LogicNode type [' + name + '] does not exist.');
return null;
};
}
return LogicNodes.types[name].fn;
};
LogicNodes.getAllTypes = function () {
var out = [];
for (var n in LogicNodes.types) {
out.push(LogicNodes.types[n]);
}
return out;
};
module.exports = LogicNodes;
/***/ },
/***/ 383:
/***/ function(module, exports, __webpack_require__) {
var LogicLayer = __webpack_require__(379);
var LogicNode = __webpack_require__(380);
var LogicNodes = __webpack_require__(382);
var LogicInterface = __webpack_require__(378);
var Vector3 = __webpack_require__(8);
var Matrix3 = __webpack_require__(24);
/**
* Logic node for vector < matrix computation
* @private
*/
function LogicNodeApplyMatrix() {
LogicNode.call(this);
this.logicInterface = LogicNodeApplyMatrix.logicInterface;
this.type = 'LogicNodeApplyMatrix';
this.vec = new Vector3();
}
LogicNodeApplyMatrix.prototype = Object.create(LogicNode.prototype);
LogicNodeApplyMatrix.editorName = 'ApplyMatrix';
LogicNodeApplyMatrix.prototype.onInputChanged = function (instDesc) {
var vec = LogicLayer.readPort(instDesc, LogicNodeApplyMatrix.inportX);
var mat = LogicLayer.readPort(instDesc, LogicNodeApplyMatrix.inportY);
this.vec.copy(vec);
mat.applyPost(this.vec);
LogicLayer.writeValue(this.logicInstance, LogicNodeApplyMatrix.outportProduct, this.vec);
};
LogicNodeApplyMatrix.logicInterface = new LogicInterface();
LogicNodeApplyMatrix.outportProduct = LogicNodeApplyMatrix.logicInterface.addOutputProperty('product', 'Vector3');
LogicNodeApplyMatrix.inportX = LogicNodeApplyMatrix.logicInterface.addInputProperty('vec', 'Vector3', new Vector3());
LogicNodeApplyMatrix.inportY = LogicNodeApplyMatrix.logicInterface.addInputProperty('mat', 'Matrix3', new Matrix3());
LogicNodes.registerType('LogicNodeApplyMatrix', LogicNodeApplyMatrix);
module.exports = LogicNodeApplyMatrix;
/***/ },
/***/ 384:
/***/ function(module, exports, __webpack_require__) {
var LogicLayer = __webpack_require__(379);
var LogicNode = __webpack_require__(380);
var LogicNodes = __webpack_require__(382);
var LogicInterface = __webpack_require__(378);
var Vector3 = __webpack_require__(8);
/**
* Logic node to provide a const Vec3
* @private
*/
function LogicNodeConstVec3() {
LogicNode.call(this);
this.logicInterface = LogicNodeConstVec3.logicInterface;
this.type = 'LogicNodeConstVec3';
}
LogicNodeConstVec3.prototype = Object.create(LogicNode.prototype);
LogicNodeConstVec3.editorName = 'ConstVec3';
LogicNodeConstVec3.prototype.onConfigure = function (newConfig) {
if (newConfig.value !== undefined) {
this.value = newConfig.value;
LogicLayer.writeValue(this.logicInstance, LogicNodeConstVec3.outportVec, new Vector3(this.x, this.y, this.z));
}
};
LogicNodeConstVec3.prototype.onSystemStarted = function () {
LogicLayer.writeValue(this.logicInstance, LogicNodeConstVec3.outportVec, new Vector3(this.x, this.y, this.z));
};
LogicNodes.registerType('LogicNodeConstVec3', LogicNodeConstVec3);
LogicNodeConstVec3.logicInterface = new LogicInterface();
LogicNodeConstVec3.outportVec = LogicNodeConstVec3.logicInterface.addOutputProperty('xyz', 'Vector3');
LogicNodeConstVec3.logicInterface.addConfigEntry({
name: 'x',
type: 'float',
label: 'X'
});
LogicNodeConstVec3.logicInterface.addConfigEntry({
name: 'y',
type: 'float',
label: 'Y'
});
LogicNodeConstVec3.logicInterface.addConfigEntry({
name: 'z',
type: 'float',
label: 'Z'
});
module.exports = LogicNodeConstVec3;
/***/ },
/***/ 385:
/***/ function(module, exports, __webpack_require__) {
var LogicNode = __webpack_require__(380);
var LogicNodes = __webpack_require__(382);
var LogicInterface = __webpack_require__(378);
/**
* Logic node that writes output to the console.
* @private
*/
function LogicNodeDebug() {
LogicNode.call(this);
this.logicInterface = LogicNodeDebug.logicInterface;
this.type = 'LogicNodeDebug';
this._time = 0;
}
LogicNodeDebug.prototype = Object.create(LogicNode.prototype);
LogicNodeDebug.editorName = 'Debug';
LogicNodeDebug.prototype.onInputChanged = function (instDesc, portID, value) {
console.log('LogicNodeDebug (' + this.logicInstance.name + ') value port ' + portID + ' = [' + value + ']');
};
LogicNodeDebug.prototype.onEvent = function (instDesc, portID) {
console.log('LogicNodeDebug (' + this.logicInstance.name + ') event on port ' + portID);
};
LogicNodeDebug.logicInterface = new LogicInterface();
LogicNodeDebug.inportEvent = LogicNodeDebug.logicInterface.addInputEvent('Event');
LogicNodeDebug.inportFloat = LogicNodeDebug.logicInterface.addInputProperty('FloatValue', 'float', 0);
LogicNodes.registerType('LogicNodeDebug', LogicNodeDebug);
module.exports = LogicNodeDebug;
/***/ },
/***/ 386:
/***/ function(module, exports, __webpack_require__) {
var LogicNode = __webpack_require__(380);
var LogicNodes = __webpack_require__(382);
var LogicInterface = __webpack_require__(378);
/**
* Logic node that lets you access the logic layer of a different entity.
* @private
*/
function LogicNodeEntityProxy() {
LogicNode.call(this);
this.logicInterface = LogicNodeEntityProxy.logicInterface;
this.type = 'LogicNodeEntityProxy';
}
LogicNodeEntityProxy.prototype = Object.create(LogicNode.prototype);
LogicNodeEntityProxy.editorName = 'EntityProxy';
LogicNodeEntityProxy.prototype.onConfigure = function (config) {
this.entityRef = config.entityRef;
};
// Empty.
LogicNodeEntityProxy.logicInterface = new LogicInterface('Component Proxy');
LogicNodeEntityProxy.logicInterface.addConfigEntry({
name: 'entityRef',
type: 'entityRef',
label: 'Entity'
});
LogicNodes.registerType('LogicNodeEntityProxy', LogicNodeEntityProxy);
module.exports = LogicNodeEntityProxy;
/***/ },
/***/ 387:
/***/ function(module, exports, __webpack_require__) {
var LogicLayer = __webpack_require__(379);
var LogicNode = __webpack_require__(380);
var LogicNodes = __webpack_require__(382);
var LogicInterface = __webpack_require__(378);
/**
* Logic node that provides a float value.
* @private
*/
function LogicNodeFloat() {
LogicNode.call(this);
this.logicInterface = LogicNodeFloat.logicInterface;
this.type = 'LogicNodeFloat';
}
LogicNodeFloat.prototype = Object.create(LogicNode.prototype);
LogicNodeFloat.editorName = 'Float';
LogicNodeFloat.prototype.onConfigure = function (newConfig) {
if (newConfig.value !== undefined) {
this.value = newConfig.value;
LogicLayer.writeValue(this.logicInstance, LogicNodeFloat.outportFloat, this.value);
}
};
LogicNodeFloat.prototype.onSystemStarted = function () {
LogicLayer.writeValue(this.logicInstance, LogicNodeFloat.outportFloat, this.value);
};
LogicNodes.registerType('LogicNodeFloat', LogicNodeFloat);
LogicNodeFloat.logicInterface = new LogicInterface();
LogicNodeFloat.outportFloat = LogicNodeFloat.logicInterface.addOutputProperty('value', 'float');
LogicNodeFloat.logicInterface.addConfigEntry({
name: 'value',
type: 'float',
label: 'Value'
});
module.exports = LogicNodeFloat;
/***/ },
/***/ 388:
/***/ function(module, exports, __webpack_require__) {