From cd1f7699a9c49d0a019c60258be15774dbbfffe0 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Fri, 5 Dec 2014 15:39:31 -0500 Subject: [PATCH 001/129] Create event manager driver and component behavior --- support/client/lib/vwf.js | 2 + support/client/lib/vwf/model/eventManager.js | 221 ++++++++++++++++++ support/proxy/vwf.example.com/eventManager.js | 9 + .../vwf.example.com/eventManager.vwf.yaml | 24 ++ 4 files changed, 256 insertions(+) create mode 100644 support/client/lib/vwf/model/eventManager.js create mode 100644 support/proxy/vwf.example.com/eventManager.js create mode 100644 support/proxy/vwf.example.com/eventManager.vwf.yaml diff --git a/support/client/lib/vwf.js b/support/client/lib/vwf.js index 36e3e758a..76dcc8815 100644 --- a/support/client/lib/vwf.js +++ b/support/client/lib/vwf.js @@ -363,6 +363,7 @@ active: false }, { library: "vwf/model/graphtool", active: false }, + { library: "vwf/model/eventManager", active: false }, { library: "vwf/model/sound", active: false }, { library: "vwf/model/object", active: true }, { library: "vwf/model/stage/log", active: true }, @@ -439,6 +440,7 @@ { library: "vwf/model/cesium", active: false }, { library: "vwf/model/blockly", active: false }, { library: "vwf/model/graphtool", active: false }, + { library: "vwf/model/eventManager", active: false }, { library: "vwf/model/sound", active: false }, { library: "vwf/model/kineticjs", active: false }, { library: "vwf/model/mil-sym", active: false }, diff --git a/support/client/lib/vwf/model/eventManager.js b/support/client/lib/vwf/model/eventManager.js new file mode 100644 index 000000000..e9770fbfd --- /dev/null +++ b/support/client/lib/vwf/model/eventManager.js @@ -0,0 +1,221 @@ +"use strict"; + +define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utility ) { + + + return model.load( module, { + + // == Module Definition ==================================================================== + + // -- initialize --------------------------------------------------------------------------- + + initialize: function() { + this.state.nodes = {}; + this.state.kernel = this.kernel.kernel.kernel; + }, + + // == Model API ============================================================================ + + // -- creatingNode ------------------------------------------------------------------------- + + creatingNode: function( nodeID, childID, childExtendsID, childImplementsIDs, + childSource, childType, childIndex, childName, callback /* ( ready ) */ ) { + + if ( isEventManager( childImplementsIDs ) ) { + this.state.nodes[ childID ] = { + "isBroadcasting": true, + "isListening": true, + "eventMap": {} + }; + } + + }, + + // -- initializingNode --------------------------------------------------------------------- + + initializingNode: function( nodeID, childID, childExtendsID, childImplementsIDs, + childSource, childType, childIndex, childName ) { + }, + + // -- deletingNode ------------------------------------------------------------------------- + + deletingNode: function( nodeID ) { + + if ( nodeID ) { + var childNode = this.state.nodes[ nodeID ]; + if ( childNode ) { + var threeObject = childNode.threeObject; + if ( threeObject && threeObject.parent ) { + threeObject.parent.remove( threeObject ); + } + delete this.state.nodes[ childNode ]; + } + } + + }, + + // -- addingChild -------------------------------------------------------------------------- + + addingChild: function( nodeID, childID, childName ) { + }, + + // -- removingChild ------------------------------------------------------------------------ + + removingChild: function( nodeID, childID ) { + }, + + // -- creatingProperty --------------------------------------------------------------------- + + creatingProperty: function( nodeID, propertyName, propertyValue ) { + + return this.initializingProperty( nodeID, propertyName, propertyValue ); + + }, + + // -- initializingProperty ----------------------------------------------------------------- + + initializingProperty: function( nodeID, propertyName, propertyValue ) { + + var value = undefined; + if ( propertyValue !== undefined ) { + var node = this.state.nodes[ nodeID ]; + if ( node !== undefined && propertyName ) { + value = this.settingProperty( nodeID, propertyName, propertyValue ); + } + } + return value; + + }, + + // TODO: deletingProperty + + // -- settingProperty ---------------------------------------------------------------------- + + settingProperty: function( nodeID, propertyName, propertyValue ) { + + var node, value; + if ( this.state.nodes[ nodeID ] ) { + node = this.state.nodes[ nodeID ]; + switch ( propertyName ) { + case "isBroadcasting": + value = propertyValue; + node.isBroadcasting = value; + break; + case "isListening": + value = propertyValue; + node.isListening = value; + break; + case "eventMap": + value = propertyValue; + node.eventMap = value; + break; + } + } + return value; + + }, + + // -- gettingProperty ---------------------------------------------------------------------- + + gettingProperty: function( nodeID, propertyName, propertyValue ) { + + var node = this.state.nodes[ nodeID ]; + var value; + if ( node ) { + switch ( propertyName ) { + case "isBroadcasting": + value = node.isBroadcasting; + break; + case "isListening": + value = node.isListening; + break; + case "eventMap": + value = node.eventMap; + break; + } + } + return value; + + }, + + // -- creatingMethod ----------------------------------------------------------------------- + + creatingMethod: function( nodeID, methodName, methodParameters, methodBody ) { + }, + + // TODO: deletingMethod + + // -- callingMethod ------------------------------------------------------------------------ + + callingMethod: function( nodeID, methodName, methodParameters, methodValue ) { + var node = this.state.nodes[ nodeID ]; + var eventName, callbackName; + + if ( node ) { + switch ( methodName ) { + case "addListener": + eventName = methodParameters[ 0 ]; + callbackName = methodParameters[ 1 ]; + node.eventMap[ eventName ] = callbackName; + break; + case "removeListener": + eventName = methodParameters[ 0 ]; + delete node.eventMap[ eventName ]; + break; + } + } + + }, + + // -- creatingEvent ------------------------------------------------------------------------ + + creatingEvent: function( nodeID, eventName, eventParameters ) { + }, + + // TODO: deletingEvent + + // -- firingEvent -------------------------------------------------------------------------- + + firingEvent: function( nodeID, eventName, eventParameters ) { + + var node = this.state.nodes[ nodeID ]; + var listeners, listenerNode; + if ( node && node.isBroadcasting ) { + listeners = findListeners( this.state.nodes, eventName ); + for ( var i = 0; i < listeners.length; i++ ) { + listenerNode = this.state.nodes[ listeners[ i ] ]; + this.kernel.callMethod( + listeners[ i ], + listenerNode.eventMap[ eventName ], + eventParameters + ); + } + } + + }, + + // -- executing ---------------------------------------------------------------------------- + + executing: function( nodeID, scriptText, scriptType ) { + }, + + } ); + + function isEventManager( implementsIDs ) { + return implementsIDs && implementsIDs.indexOf( "http-vwf-example-com-eventManager-vwf" ) !== -1; + } + + function findListeners( nodes, eventName ) { + var listeners = new Array(); + var keys = Object.keys( nodes ); + var node; + for ( var i = 0; i < keys.length; i++ ) { + node = nodes[ keys[ i ] ] + if ( node.isListening && node.eventMap.hasOwnProperty( eventName ) ) { + listeners.push( keys[ i ] ); + } + } + return listeners; + } + +} ); \ No newline at end of file diff --git a/support/proxy/vwf.example.com/eventManager.js b/support/proxy/vwf.example.com/eventManager.js new file mode 100644 index 000000000..3d1ce989e --- /dev/null +++ b/support/proxy/vwf.example.com/eventManager.js @@ -0,0 +1,9 @@ +this.addListener = function( eventName, callbackMethodName ) { + this.eventMap[ eventName ] = callbackMethodName; +} + +this.removeListener = function( eventName ) { + delete this[ eventName ]; +} + +//@ sourceURL=http://vwf.example.com/eventManager.js \ No newline at end of file diff --git a/support/proxy/vwf.example.com/eventManager.vwf.yaml b/support/proxy/vwf.example.com/eventManager.vwf.yaml new file mode 100644 index 000000000..f66115a74 --- /dev/null +++ b/support/proxy/vwf.example.com/eventManager.vwf.yaml @@ -0,0 +1,24 @@ +# Copyright 2014 Lockheed Martin Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +properties: + isBroadcasting: true + isListening: true + eventMap: {} +methods: + addListener: + removeListener: +scripts: +- source: "http://vwf.example.com/eventManager.js" \ No newline at end of file From 84449f337d6951293af4a85661b0001f8fbc3951 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Sun, 7 Dec 2014 13:55:18 -0500 Subject: [PATCH 002/129] Addressed PR comments --- support/client/lib/vwf/model/eventManager.js | 75 ++++--------------- support/proxy/vwf.example.com/eventManager.js | 9 --- .../vwf.example.com/eventManager.vwf.yaml | 2 - 3 files changed, 16 insertions(+), 70 deletions(-) delete mode 100644 support/proxy/vwf.example.com/eventManager.js diff --git a/support/client/lib/vwf/model/eventManager.js b/support/client/lib/vwf/model/eventManager.js index e9770fbfd..f795463b3 100644 --- a/support/client/lib/vwf/model/eventManager.js +++ b/support/client/lib/vwf/model/eventManager.js @@ -11,7 +11,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili initialize: function() { this.state.nodes = {}; - this.state.kernel = this.kernel.kernel.kernel; }, // == Model API ============================================================================ @@ -54,48 +53,25 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili }, - // -- addingChild -------------------------------------------------------------------------- - - addingChild: function( nodeID, childID, childName ) { - }, - - // -- removingChild ------------------------------------------------------------------------ - - removingChild: function( nodeID, childID ) { - }, - // -- creatingProperty --------------------------------------------------------------------- creatingProperty: function( nodeID, propertyName, propertyValue ) { - return this.initializingProperty( nodeID, propertyName, propertyValue ); - }, // -- initializingProperty ----------------------------------------------------------------- initializingProperty: function( nodeID, propertyName, propertyValue ) { - - var value = undefined; - if ( propertyValue !== undefined ) { - var node = this.state.nodes[ nodeID ]; - if ( node !== undefined && propertyName ) { - value = this.settingProperty( nodeID, propertyName, propertyValue ); - } - } - return value; - + return this.settingProperty( nodeID, propertyName, propertyValue ); }, - // TODO: deletingProperty - // -- settingProperty ---------------------------------------------------------------------- settingProperty: function( nodeID, propertyName, propertyValue ) { - var node, value; - if ( this.state.nodes[ nodeID ] ) { - node = this.state.nodes[ nodeID ]; + var node = this.state.nodes[ nodeID ]; + var value; + if ( node ) { switch ( propertyName ) { case "isBroadcasting": value = propertyValue; @@ -138,25 +114,18 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili }, - // -- creatingMethod ----------------------------------------------------------------------- - - creatingMethod: function( nodeID, methodName, methodParameters, methodBody ) { - }, - - // TODO: deletingMethod - // -- callingMethod ------------------------------------------------------------------------ callingMethod: function( nodeID, methodName, methodParameters, methodValue ) { var node = this.state.nodes[ nodeID ]; - var eventName, callbackName; + var eventName, eventHandlerName; if ( node ) { switch ( methodName ) { case "addListener": eventName = methodParameters[ 0 ]; - callbackName = methodParameters[ 1 ]; - node.eventMap[ eventName ] = callbackName; + eventHandlerName = methodParameters[ 1 ]; + node.eventMap[ eventName ] = eventHandlerName; break; case "removeListener": eventName = methodParameters[ 0 ]; @@ -167,25 +136,18 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili }, - // -- creatingEvent ------------------------------------------------------------------------ - - creatingEvent: function( nodeID, eventName, eventParameters ) { - }, - - // TODO: deletingEvent - // -- firingEvent -------------------------------------------------------------------------- firingEvent: function( nodeID, eventName, eventParameters ) { var node = this.state.nodes[ nodeID ]; - var listeners, listenerNode; + var listenerIDs, listenerNode; if ( node && node.isBroadcasting ) { - listeners = findListeners( this.state.nodes, eventName ); - for ( var i = 0; i < listeners.length; i++ ) { - listenerNode = this.state.nodes[ listeners[ i ] ]; + listenerIDs = findListenerIDs( this.state.nodes, eventName ); + for ( var i = 0; i < listenerIDs.length; i++ ) { + listenerNode = this.state.nodes[ listenerIDs[ i ] ]; this.kernel.callMethod( - listeners[ i ], + listenerIDs[ i ], listenerNode.eventMap[ eventName ], eventParameters ); @@ -194,28 +156,23 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili }, - // -- executing ---------------------------------------------------------------------------- - - executing: function( nodeID, scriptText, scriptType ) { - }, - } ); function isEventManager( implementsIDs ) { return implementsIDs && implementsIDs.indexOf( "http-vwf-example-com-eventManager-vwf" ) !== -1; } - function findListeners( nodes, eventName ) { - var listeners = new Array(); + function findListenerIDs( nodes, eventName ) { + var listenerIDs = []; var keys = Object.keys( nodes ); var node; for ( var i = 0; i < keys.length; i++ ) { node = nodes[ keys[ i ] ] if ( node.isListening && node.eventMap.hasOwnProperty( eventName ) ) { - listeners.push( keys[ i ] ); + listenerIDs.push( keys[ i ] ); } } - return listeners; + return listenerIDs; } } ); \ No newline at end of file diff --git a/support/proxy/vwf.example.com/eventManager.js b/support/proxy/vwf.example.com/eventManager.js deleted file mode 100644 index 3d1ce989e..000000000 --- a/support/proxy/vwf.example.com/eventManager.js +++ /dev/null @@ -1,9 +0,0 @@ -this.addListener = function( eventName, callbackMethodName ) { - this.eventMap[ eventName ] = callbackMethodName; -} - -this.removeListener = function( eventName ) { - delete this[ eventName ]; -} - -//@ sourceURL=http://vwf.example.com/eventManager.js \ No newline at end of file diff --git a/support/proxy/vwf.example.com/eventManager.vwf.yaml b/support/proxy/vwf.example.com/eventManager.vwf.yaml index f66115a74..61438fcd0 100644 --- a/support/proxy/vwf.example.com/eventManager.vwf.yaml +++ b/support/proxy/vwf.example.com/eventManager.vwf.yaml @@ -20,5 +20,3 @@ properties: methods: addListener: removeListener: -scripts: -- source: "http://vwf.example.com/eventManager.js" \ No newline at end of file From c08be94090a2315d271741e8429e1893b7c6a0a9 Mon Sep 17 00:00:00 2001 From: Kevin Dill Date: Fri, 5 Dec 2014 17:13:42 -0500 Subject: [PATCH 003/129] Added findInScene and findTypeInScene --- support/proxy/vwf.example.com/sceneGetter.js | 55 +++++++++++++++++++ .../vwf.example.com/sceneGetter.vwf.yaml | 16 ++++++ 2 files changed, 71 insertions(+) create mode 100644 support/proxy/vwf.example.com/sceneGetter.js diff --git a/support/proxy/vwf.example.com/sceneGetter.js b/support/proxy/vwf.example.com/sceneGetter.js new file mode 100644 index 000000000..c1d2cc604 --- /dev/null +++ b/support/proxy/vwf.example.com/sceneGetter.js @@ -0,0 +1,55 @@ +// Copyright 2014 Lockheed Martin Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +this.findInScene = function( objName ) { + if ( !this.scene ) { + this.logger.errorx( "findInScene", "Scene is undefined!" ); + return undefined; + } + + var results = this.scene.find( "//" + objName ); + + if ( results.length < 1 ) { + this.logger.errorx( "findInScene", "Object '" + objName + + "' not found" ); + } else if ( results.length > 1 ) { + this.logger.warnx( "findInScene", "Multiple objects named '" + + objName + "' found. Names should really " + + "be unique... but we'll return the first one." ); + } + + return results[ 0 ]; +} + +this.findTypeInScene = function( typeName ) { + if (!this.scene) { + this.logger.errorx( "findTypeInScene", "Scene is undefined!" ); + return undefined; + } + + var results = this.scene.find( ".//element(*,'" + typeName + "')" ); + + if ( results.length < 1 ) { + this.logger.errorx( "findTypeInScene", "Nothing found with type '" + + typeName + "'." ); + } else if ( results.length > 1 ) { + this.logger.warnx( "findTypeInScene", "Multiple objects of type '" + + typeName + "' found. We'll return the first " + + "one." ); + } + + return results[ 0 ]; +} + +//@ sourceURL=http://vwf.example.com/sceneGetter.js diff --git a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml index 109f9bd2c..396b9f9c8 100644 --- a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml +++ b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml @@ -31,3 +31,19 @@ properties: // Nullify the current scene so that next time it is gotten, it will find it from the new path this.scene = null; //@ sourceURL=sceneGetter.scenePath.set + +methods: + + # A helper that does basically what Find does, except that it handles some of + # the busywork (and assumes that we'll be looking in the scene). + # Arguments: + # objectName - the string to search for + findInScene: + + # Same as findInScene, except that this looks by type rather than by name. + # Arguments: + # typeName - the type to search for + findTypeInScene: + +scripts: +- source: "http://vwf.example.com/sceneGetter.js" From 378597770b412d4b086adf8bcd637ad99a6e211f Mon Sep 17 00:00:00 2001 From: Kevin Dill Date: Fri, 12 Dec 2014 10:30:02 -0500 Subject: [PATCH 004/129] Added asserts. --- support/proxy/vwf.example.com/assert.js | 29 +++++++++++++++++++ support/proxy/vwf.example.com/assert.vwf.yaml | 28 ++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 support/proxy/vwf.example.com/assert.js create mode 100644 support/proxy/vwf.example.com/assert.vwf.yaml diff --git a/support/proxy/vwf.example.com/assert.js b/support/proxy/vwf.example.com/assert.js new file mode 100644 index 000000000..572d77717 --- /dev/null +++ b/support/proxy/vwf.example.com/assert.js @@ -0,0 +1,29 @@ +// Copyright 2014 Lockheed Martin Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +this.assert = function( value, message, dontHalt ) { + if ( !value ) { + if ( message ) { + this.logger.errorx( "assert", message ); + } else { + this.logger.errorx( "assert", "Assert failed!" ); + } + + if ( !dontHalt ) { + debugger; + } + } +} + +//@ sourceURL=http://vwf.example.com/assert.js diff --git a/support/proxy/vwf.example.com/assert.vwf.yaml b/support/proxy/vwf.example.com/assert.vwf.yaml new file mode 100644 index 000000000..d29cb91b1 --- /dev/null +++ b/support/proxy/vwf.example.com/assert.vwf.yaml @@ -0,0 +1,28 @@ +# Copyright 2014 Lockheed Martin Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- + +methods: + + # A C++ style assert + # NOTE: these only fire if you have the console open. + # Arguments: + # value - the value we're checking. If true, we log and halt. + # message - the message to log if the assert fails. Optional. + # dontHalt - if true, we just log the message. Optional. + assert: + +scripts: +- source: "http://vwf.example.com/assert.js" \ No newline at end of file From 38336af5dfcbeae522fd3f4c4faf1d2bceba4ff8 Mon Sep 17 00:00:00 2001 From: Kevin Dill Date: Wed, 17 Dec 2014 13:07:44 -0500 Subject: [PATCH 005/129] Improved documentation, made warnings and errors optional. --- support/proxy/vwf.example.com/sceneGetter.js | 29 +++++++++++++++---- .../vwf.example.com/sceneGetter.vwf.yaml | 17 +++++++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/support/proxy/vwf.example.com/sceneGetter.js b/support/proxy/vwf.example.com/sceneGetter.js index c1d2cc604..575232fad 100644 --- a/support/proxy/vwf.example.com/sceneGetter.js +++ b/support/proxy/vwf.example.com/sceneGetter.js @@ -12,7 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -this.findInScene = function( objName ) { +this.findInScene = function( objName, errorOnNotFound, warnOnTooMany ) { + if ( errorOnNotFound === undefined ) { + errorOnNotFound = true; + } + + if ( warnOnTooMany === undefined ) { + warnOnTooMany = true; + } + if ( !this.scene ) { this.logger.errorx( "findInScene", "Scene is undefined!" ); return undefined; @@ -20,10 +28,10 @@ this.findInScene = function( objName ) { var results = this.scene.find( "//" + objName ); - if ( results.length < 1 ) { + if ( errorOnNotFound && ( results.length < 1 ) ) { this.logger.errorx( "findInScene", "Object '" + objName + "' not found" ); - } else if ( results.length > 1 ) { + } else if ( warnOnTooMany && ( results.length > 1 ) ) { this.logger.warnx( "findInScene", "Multiple objects named '" + objName + "' found. Names should really " + "be unique... but we'll return the first one." ); @@ -32,7 +40,16 @@ this.findInScene = function( objName ) { return results[ 0 ]; } -this.findTypeInScene = function( typeName ) { +this.findTypeInScene = function( typeName, errorOnNotFound, + warnOnTooMany ) { + if ( errorOnNotFound === undefined ) { + errorOnNotFound = true; + } + + if ( warnOnTooMany === undefined ) { + warnOnTooMany = true; + } + if (!this.scene) { this.logger.errorx( "findTypeInScene", "Scene is undefined!" ); return undefined; @@ -40,10 +57,10 @@ this.findTypeInScene = function( typeName ) { var results = this.scene.find( ".//element(*,'" + typeName + "')" ); - if ( results.length < 1 ) { + if ( errorOnNotFound && ( results.length < 1 ) ) { this.logger.errorx( "findTypeInScene", "Nothing found with type '" + typeName + "'." ); - } else if ( results.length > 1 ) { + } else if ( warnOnTooMany && ( results.length > 1 ) ) { this.logger.warnx( "findTypeInScene", "Multiple objects of type '" + typeName + "' found. We'll return the first " + "one." ); diff --git a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml index 396b9f9c8..ff625de79 100644 --- a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml +++ b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml @@ -36,13 +36,26 @@ methods: # A helper that does basically what Find does, except that it handles some of # the busywork (and assumes that we'll be looking in the scene). + # NOTE: THIS ONLY GETS THE FIRST OBJECT FOUND. If you want the whole array, + # you'll need to extend this function (or write another). # Arguments: - # objectName - the string to search for + # objectName - the name of the object to search for + # errorOnNotFound - if true (the default) we log an error if the object is + # not found. + # warnOnTooMany - if true (the default) we log a warning if more than one + # object is found. findInScene: # Same as findInScene, except that this looks by type rather than by name. + # NOTE: THIS ONLY GETS THE FIRST OBJECT FOUND. If you want the whole array, + # you'll need to extend this function (or write another). # Arguments: - # typeName - the type to search for + # typeName - the type to search for (where the "type" is the filename + # that the object extends). + # errorOnNotFound - if true (the default) we log an error if the object is + # not found. + # warnOnTooMany - if true (the default) we log a warning if more than one + # object is found. findTypeInScene: scripts: From 2607a09d58b6d5a5e6e19c33bbfa19d257ed5f11 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Tue, 27 Jan 2015 11:31:00 -0500 Subject: [PATCH 006/129] Now, if there's an error parsing the YAML file, we print some details on the error. --- lib/nodejs/serve.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/nodejs/serve.js b/lib/nodejs/serve.js index 5413ac069..9a1b56767 100755 --- a/lib/nodejs/serve.js +++ b/lib/nodejs/serve.js @@ -98,7 +98,8 @@ function ServeYAML( filename, response, URL ) { try { var deYAML = JSON.stringify( YAML.load( file ) ); } catch ( e ) { - global.log( "error parsing YAML " + filename ); + global.log( "error parsing YAML " + filename); + global.log("" + e); _404( response ); return; } From 1a9602ab757f5c0124ee993ffb9ef30bbae04b08 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Tue, 20 Jan 2015 13:35:42 -0500 Subject: [PATCH 007/129] Modify raycast results to remove circular references --- support/client/lib/vwf/model/threejs.js | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/support/client/lib/vwf/model/threejs.js b/support/client/lib/vwf/model/threejs.js index 2c16019b8..4af5929da 100644 --- a/support/client/lib/vwf/model/threejs.js +++ b/support/client/lib/vwf/model/threejs.js @@ -2699,7 +2699,34 @@ define( [ "module", var raycaster = new THREE.Raycaster( origin, direction, near, far ); var intersects = raycaster.intersectObjects( objects, recursive ); - return intersects; + + // clean up results before passing back to applications + var results = []; + var result, intersectedNode; + for ( var i = 0; i < intersects.length; i++ ) { + result = {}; + result[ "distance" ] = intersects[ i ].distance; + result[ "point" ] = [ + intersects[ i ].point.x, + intersects[ i ].point.y, + intersects[ i ].point.z ]; + intersectedNode = intersects[ i ].object; + while ( !intersectedNode.vwfID ) { + intersectedNode = intersectedNode.parent; + } + result[ "node" ] = this.state.kernel.kutility.nodeReference( intersectedNode.vwfID ); + result[ "normal" ] = [ + intersects[ i ].face.normal.x, + intersects[ i ].face.normal.y, + intersects[ i ].face.normal.z ]; + result[ "centroid" ] = [ + intersects[ i ].face.centroid.x, + intersects[ i ].face.centroid.y, + intersects[ i ].face.centroid.z ]; + results[ i ] = result; + } + + return results; } From c5912fd4a710a5fa5394588e72d27c756ff85c60 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 21 Jan 2015 13:05:04 -0500 Subject: [PATCH 008/129] Return sound instance id rather than instance object --- support/client/lib/vwf/model/sound.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/support/client/lib/vwf/model/sound.js b/support/client/lib/vwf/model/sound.js index f824ad00a..46582f4db 100644 --- a/support/client/lib/vwf/model/sound.js +++ b/support/client/lib/vwf/model/sound.js @@ -356,8 +356,9 @@ define( [ "module", "vwf/model" ], function( module, model ) { } if ( !this.allowMultiplay && this.isPlaying() ) { + var instance = Object.keys( this.playingInstances )[ 0 ]; return { soundName: this.name, - instanceID: this.playingInstances[ 0 ] }; + instanceID: this.playingInstances[ instance ].id }; } var id = this.instanceIDCounter; From e7116c9fe7e102d48c157eda63a255defe930238 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 21 Jan 2015 13:05:29 -0500 Subject: [PATCH 009/129] Remove blockly xml log statement --- support/client/lib/vwf/view/blockly.js | 1 - 1 file changed, 1 deletion(-) diff --git a/support/client/lib/vwf/view/blockly.js b/support/client/lib/vwf/view/blockly.js index f5262ce7f..e0f343739 100644 --- a/support/client/lib/vwf/view/blockly.js +++ b/support/client/lib/vwf/view/blockly.js @@ -156,7 +156,6 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor // Set the appropriate model properties based on this change var xmlDom = Blockly.Xml.workspaceToDom( Blockly.getMainWorkspace() ); - console.log (xmlDom); if ( xmlDom ) { var newXmlText = Blockly.Xml.domToText( xmlDom ); self.kernel.setProperty( self.state.blockly.node.ID, "blockly_xml", From 3abae6df6e7e261e86038b7a88b36aa0d2add79f Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 21 Jan 2015 13:15:22 -0500 Subject: [PATCH 010/129] Remove console.log in blockly driver --- support/client/lib/vwf/view/blockly.js | 1 - 1 file changed, 1 deletion(-) diff --git a/support/client/lib/vwf/view/blockly.js b/support/client/lib/vwf/view/blockly.js index e0f343739..d79f2f292 100644 --- a/support/client/lib/vwf/view/blockly.js +++ b/support/client/lib/vwf/view/blockly.js @@ -500,7 +500,6 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor } } if ( xmlDom ) { - console.log (xmlDom); clearBeforeSet && Blockly.mainWorkspace.clear(); domCopyToWorkspace( Blockly.mainWorkspace, xmlDom ); } From b081bf685ec9618f7090eded48e6c6866d09c5fb Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Thu, 22 Jan 2015 13:15:31 -0500 Subject: [PATCH 011/129] Comment out line generating errors with repeat blocks --- support/client/lib/vwf/model/blockly.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/support/client/lib/vwf/model/blockly.js b/support/client/lib/vwf/model/blockly.js index 5bdea9eac..237c9d231 100644 --- a/support/client/lib/vwf/model/blockly.js +++ b/support/client/lib/vwf/model/blockly.js @@ -389,7 +389,9 @@ define( [ "module", "vwf/model", "vwf/utility", nextStep( blocklyNode ); - this.kernel.fireEvent( nodeID, "blocklyExecuted", [ blocklyNode.interpreter.value ] ); + // Does this serve any real purpose? It's not handled in any application. + // Certain blocks, such as repeat blocks, break with the recursive node reference changes. + // this.kernel.fireEvent( nodeID, "blocklyExecuted", [ blocklyNode.interpreter.value ] ); } } } From c9f060754322fc5710122354cc4da354c42401d1 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Mon, 26 Jan 2015 12:13:55 -0500 Subject: [PATCH 012/129] Remove centroid from raycast --- support/client/lib/vwf/model/threejs.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/support/client/lib/vwf/model/threejs.js b/support/client/lib/vwf/model/threejs.js index 4af5929da..6ec6a7646 100644 --- a/support/client/lib/vwf/model/threejs.js +++ b/support/client/lib/vwf/model/threejs.js @@ -2719,10 +2719,6 @@ define( [ "module", intersects[ i ].face.normal.x, intersects[ i ].face.normal.y, intersects[ i ].face.normal.z ]; - result[ "centroid" ] = [ - intersects[ i ].face.centroid.x, - intersects[ i ].face.centroid.y, - intersects[ i ].face.centroid.z ]; results[ i ] = result; } From e7a3695e5d43f214dc0c41a856153e06ad7c5873 Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Thu, 29 Jan 2015 10:35:35 -0500 Subject: [PATCH 013/129] More verbose/correct sceneGetter warning --- support/proxy/vwf.example.com/sceneGetter.vwf.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml index ff625de79..af7a594e1 100644 --- a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml +++ b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml @@ -18,7 +18,11 @@ properties: scene: get: | if ( !this.scene ) { - this.scene = this.find( this.scenePath || "/" )[ 0 ]; + var sp = this.scenePath || "/"; + this.scene = this.find( sp )[ 0 ]; + if ( !this.scene ) { + this.logger.errorx( "scene.get", "Could not find scene node: '", sp, "'" ); + } } return this.scene; //@ sourceURL=sceneGetter.scene.get From d969ed26e855a3e472f19b6fca3fcce3446950cc Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Thu, 29 Jan 2015 15:37:56 -0500 Subject: [PATCH 014/129] Update light target matrix when target property is set. --- support/client/lib/vwf/model/threejs.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/support/client/lib/vwf/model/threejs.js b/support/client/lib/vwf/model/threejs.js index 6ec6a7646..9166bc9c5 100644 --- a/support/client/lib/vwf/model/threejs.js +++ b/support/client/lib/vwf/model/threejs.js @@ -2012,7 +2012,8 @@ define( [ "module", if ( propertyValue instanceof Array ) { value = propertyValue; if ( threeObject.target ) { - threeObject.target.position.set( value[ 0 ], value[ 1 ], value[ 2 ] ); + threeObject.target.position.set( value[ 0 ], value[ 1 ], value[ 2 ] ); + threeObject.target.updateMatrixWorld(); } } else if ( this.state.nodes[ propertyValue ] ) { value = propertyValue; From 84a74b8063efcfe4fc56210186517973636c099d Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 4 Feb 2015 13:17:31 -0500 Subject: [PATCH 015/129] Change graph visibility to a property --- support/client/lib/vwf/model/graphtool.js | 31 +++++++++---------- .../vwf.example.com/graphtool/graph.vwf.yaml | 9 +----- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/support/client/lib/vwf/model/graphtool.js b/support/client/lib/vwf/model/graphtool.js index 791c6348d..69a19418e 100644 --- a/support/client/lib/vwf/model/graphtool.js +++ b/support/client/lib/vwf/model/graphtool.js @@ -47,6 +47,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili "yAxisVisible": undefined, "zAxisVisible": undefined, "gridVisible": undefined, + "graphVisible": undefined, "axisOpacity": undefined, "gridOpacity": undefined, "renderTop": undefined @@ -209,7 +210,12 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili case "yAxisVisible": case "zAxisVisible": case "gridVisible": - setGraphVisibility( node, true ); + if ( propertyValue ) { + this.kernel.setProperty( nodeID, "graphVisible", true ); + } + break; + case "graphVisible": + setGraphVisibility( node, propertyValue ); break; case "graphScale": redrawGraph( node ); @@ -264,15 +270,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili callingMethod: function( nodeID, methodName, methodParameters, methodValue ) { var node; - if ( this.state.graphs[ nodeID ] ) { - node = this.state.graphs[ nodeID ]; - - if ( methodName === "setGraphVisibility" ) { - var visible = methodParameters[0]; - setGraphVisibility( node, visible ); - } - - } else if ( this.state.objects[ nodeID ] ) { + if ( this.state.objects[ nodeID ] ) { node = this.state.objects[ nodeID ]; if ( methodName === "setGroupItemProperty" ) { @@ -391,6 +389,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili props.yAxisVisible, props.zAxisVisible, props.gridVisible, + props.graphVisible, props.axisOpacity, props.gridOpacity, props.renderTop @@ -541,7 +540,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } function generateGraph( graphScale, gridInterval, gridLineInterval, gridLength, xAxisVisible, - yAxisVisible, zAxisVisible, gridVisible, axisOpacity, gridOpacity, renderTop ) { + yAxisVisible, zAxisVisible, gridVisible, graphVisible, axisOpacity, gridOpacity, renderTop ) { var xAxis, yAxis, zAxis, gridX, gridY, axisLine; var thickness = 0.1; @@ -552,15 +551,15 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili xAxis = generateLine( graphScale, [ 1, 0, 0 ], -gridLength, gridLength, [ 255, 0, 0 ], axisOpacity, thickness, renderTop ); xAxis.name = "xAxis"; - xAxis.visible = xAxisVisible; + xAxis.visible = xAxisVisible && graphVisible; yAxis = generateLine( graphScale, [ 0, 1, 0 ], -gridLength, gridLength, [ 0, 0, 255 ], axisOpacity, thickness, renderTop ); yAxis.name = "yAxis"; - yAxis.visible = yAxisVisible; + yAxis.visible = yAxisVisible && graphVisible; zAxis = generateLine( graphScale, [ 0, 0, 1 ], -gridLength, gridLength, [ 0, 255, 0 ], axisOpacity, thickness, renderTop ); zAxis.name = "zAxis"; - zAxis.visible = zAxisVisible; + zAxis.visible = zAxisVisible && graphVisible; if ( renderTop ) { xAxis.renderDepth = yAxis.renderDepth = zAxis.renderDepth = DEPTH_AXES; @@ -583,11 +582,11 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili gridX = generateLine( graphScale, [ 1, 0, 0 ], -gridLength, gridLength, [ 255, 255, 255 ], gridOpacity, thickness, renderTop ); gridX.position.set( 0, i, 0 ); - gridX.visible = gridVisible; + gridX.visible = gridVisible && graphVisible; gridY = generateLine( graphScale, [ 0, 1, 0 ], -gridLength, gridLength, [ 255, 255, 255 ], gridOpacity, thickness, renderTop ); gridY.position.set( i, 0, 0 ); - gridY.visible = gridVisible; + gridY.visible = gridVisible && graphVisible; if ( renderTop ) { gridX.renderDepth = gridY.renderDepth = DEPTH_GRID; diff --git a/support/proxy/vwf.example.com/graphtool/graph.vwf.yaml b/support/proxy/vwf.example.com/graphtool/graph.vwf.yaml index 2ba83d0b6..7612e91f5 100644 --- a/support/proxy/vwf.example.com/graphtool/graph.vwf.yaml +++ b/support/proxy/vwf.example.com/graphtool/graph.vwf.yaml @@ -9,18 +9,11 @@ properties: yAxisVisible: undefined zAxisVisible: undefined gridVisible: undefined + graphVisible: undefined axisOpacity: undefined gridOpacity: undefined renderTop: undefined - graphIsVisible$: true methods: - setGraphVisibility: - parameters: - - visible - body: | - this.graphIsVisible$ = visible; - toggleGraphVisibility: | - this.setGraphVisibility( !this.graphIsVisible$ ); graphLine: parameters: - axis From 7e77816cd9ce2339d1194aa8b15096264c1e220f Mon Sep 17 00:00:00 2001 From: Kevin Dill Date: Thu, 12 Feb 2015 12:24:46 -0500 Subject: [PATCH 016/129] Fixed the sceneGetter so that it doesn't set this.scene incorrectly when called on the prototype. --- support/proxy/vwf.example.com/sceneGetter.vwf.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml index af7a594e1..54cec5179 100644 --- a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml +++ b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml @@ -20,8 +20,16 @@ properties: if ( !this.scene ) { var sp = this.scenePath || "/"; this.scene = this.find( sp )[ 0 ]; + // If this is the prototype object then it will think that it is the + // scene (because it is directly attached to the root) - in that case, + // we want to make sure that we don't incorrectly set this.scene, so + // just short-circuit and return undefined. + if ( this.scene === this ) { + return undefined; + } if ( !this.scene ) { - this.logger.errorx( "scene.get", "Could not find scene node: '", sp, "'" ); + this.logger.errorx( "scene.get", "Could not find scene node: '" + sp + + "'" ); } } return this.scene; From 862d9afbd8b84024526e2eb1b0011ed19898f11b Mon Sep 17 00:00:00 2001 From: Kevin Dill Date: Thu, 12 Feb 2015 12:59:09 -0500 Subject: [PATCH 017/129] Really fix the sceneGetter this time. --- support/proxy/vwf.example.com/sceneGetter.vwf.yaml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml index 54cec5179..3f48065e0 100644 --- a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml +++ b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml @@ -25,11 +25,10 @@ properties: // we want to make sure that we don't incorrectly set this.scene, so // just short-circuit and return undefined. if ( this.scene === this ) { - return undefined; - } - if ( !this.scene ) { - this.logger.errorx( "scene.get", "Could not find scene node: '" + sp + - "'" ); + this.scene = undefined; + } else if ( !this.scene ) { + this.logger.errorx( "scene.get", + "Could not find scene node: '" + sp + "'" ); } } return this.scene; From 28d89256135caf4d1e224bc0418521f3abac9a79 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Thu, 12 Feb 2015 17:57:28 -0500 Subject: [PATCH 018/129] Start writing HUD driver and components --- support/client/lib/vwf/model/hud.js | 217 +++++++++ support/client/lib/vwf/view/hud.js | 451 ++++++++++++++++++ .../vwf.example.com/HUD/element.vwf.yaml | 18 + .../vwf.example.com/HUD/overlay.vwf.yaml | 7 + 4 files changed, 693 insertions(+) create mode 100644 support/client/lib/vwf/model/hud.js create mode 100644 support/client/lib/vwf/view/hud.js create mode 100644 support/proxy/vwf.example.com/HUD/element.vwf.yaml create mode 100644 support/proxy/vwf.example.com/HUD/overlay.vwf.yaml diff --git a/support/client/lib/vwf/model/hud.js b/support/client/lib/vwf/model/hud.js new file mode 100644 index 000000000..f5d4a12f7 --- /dev/null +++ b/support/client/lib/vwf/model/hud.js @@ -0,0 +1,217 @@ +"use strict"; + +define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utility ) { + + var logger; + + return model.load( module, { + + // == Module Definition ==================================================================== + + // -- initialize --------------------------------------------------------------------------- + + initialize: function() { + var lastKernel; + this.state.overlays = {}; + this.state.elements = {}; + lastKernel = this.kernel; + while ( lastKernel.kernel ) { + lastKernel = lastKernel.kernel; + } + this.state.kernel = lastKernel; + logger = this.logger; + }, + + // == Model API ============================================================================ + + // -- creatingNode ------------------------------------------------------------------------- + + creatingNode: function( nodeID, childID, childExtendsID, childImplementsIDs, + childSource, childType, childIndex, childName, callback /* ( ready ) */ ) { + + var node = undefined; + var protos = getPrototypes.call( this, kernel, childExtendsID ); + + if ( protos && isOverlay( protos ) ) { + + node = this.state.overlays[ childID ] = { + "elements": {}, + "properties": {}, + "initialized": false + }; + + } else if ( protos && isElement( protos ) ) { + + node = this.state.elements[ childID ] = { + "overlay": this.state.overlays[ node.parentID ], + "properties": {}, + "drawProperties": {}, + "initialized": false + }; + node.overlay.elements[ childID ] = node; + node.initialized = false; + + } + }, + + // -- initializingNode --------------------------------------------------------------------- + + initializingNode: function( nodeID, childID, childExtendsID, childImplementsIDs, + childSource, childType, childIndex, childName ) { + + var node; + + if ( this.state.overlays[ childID ] ) { + + node = this.state.overlays[ childID ]; + node.properties = { + "drawRate": undefined, + "visible": undefined + }; + + } else if ( this.state.elements[ childID ] ) { + + node = this.state.elements[ childID ]; + node.properties = { + "images": undefined, + "width": undefined, + "height": undefined, + "visible": undefined, + "enabled": undefined, + "alignH": undefined, + "alignV": undefined, + "offsetH": undefined, + "offsetV": undefined + }; + node.drawProperties = {}; + + } + + }, + + // -- creatingProperty --------------------------------------------------------------------- + + creatingProperty: function( nodeID, propertyName, propertyValue ) { + return this.initializingProperty( nodeID, propertyName, propertyValue ); + }, + + // -- initializingProperty ----------------------------------------------------------------- + + initializingProperty: function( nodeID, propertyName, propertyValue ) { + var value = undefined; + + if ( propertyValue !== undefined ) { + var node = this.state.overlays[ nodeID ] || this.state.elements[ nodeID ] ; + if ( node !== undefined ) { + switch ( propertyName ) { + default: + value = this.settingProperty( nodeID, propertyName, propertyValue ); + break; + } + } + } + + return value; + }, + + // TODO: deletingProperty + + // -- settingProperty ---------------------------------------------------------------------- + + settingProperty: function( nodeID, propertyName, propertyValue ) { + var node, value; + + if ( this.state.overlays[ childID ] ) { + + node = this.state.overlays[ childID ]; + if ( node.properties.hasOwnProperty( propertyName ) ) { + node.properties[ propertyName ] = propertyValue; + value = propertyValue; + } + + } else if ( this.state.elements[ childID ] ) { + + node = this.state.elements[ childID ]; + if ( node.properties.hasOwnProperty( propertyName ) ) { + if ( node.initialized ) { + switch ( propertyName ) { + case "images": + node.properties.images = loadImages( node, propertyValue ); + break; + } + } else { + node.properties[ propertyName ] = propertyValue; + } + } else { + node.drawProperties[ propertyName ] = propertyValue; + } + value = propertyValue; + + } + + return value; + }, + + // -- gettingProperty ---------------------------------------------------------------------- + + gettingProperty: function( nodeID, propertyName, propertyValue ) { + }, + + // -- creatingMethod ------------------------------------------------------------------------ + + creatingMethod: function( nodeID, methodName, methodParameters, methodBody ) { + if ( this.state.elements[ nodeID ] ) { + var node = this.state.elements[ nodeID ]; + if ( methodName === "draw" ) { + node.draw = methodBody; + } + } + } + + // -- callingMethod ------------------------------------------------------------------------ + + callingMethod: function( nodeID, methodName, methodParameters, methodValue ) { + if ( this.state.elements[ nodeID ] ) { + var node = this.state.elements[ nodeID ]; + if ( methodName === "draw" ) { + this.logger.errorx( "callingMethod", "The draw method should not be called " + + "from outside the HUD driver!" ); + return undefined; + } + } + }, + + // -- firingEvent -------------------------------------------------------------------------- + + firingEvent: function( nodeID, eventName, eventParameters ) { + }, + + } ); + + function loadImages( node, images ) { + var keys = Object.keys( images ); + var newImage, oldImage; + for ( var i = 0; i < keys.length; i++ ) { + newImage = images[ keys[ i ] ]; + if ( !newImage.hasOwnProperty( "src" ) ) { + logger.errorx( "loadImages", "Image \"" + keys[ i ] + "\" is malformed! It " + + "does not contain a \"src\" property! Skipping image load!" ); + continue; + } else if ( !newImage.hasOwnProperty( "value" ) ) { + logger.warnx( "loadImages", "Image \"" + keys[ i ] + "\" does not contain a " + + "\"value\" property! One will be generated automatically." ); + } + oldImage = node.properties.images[ keys[ i ] ]; + // If the image property doesn't exist or the image hasn't been loaded or the image src + // has changed, then we need to load the image. Otherwise, just copy the old image data + if ( !oldImage || !( oldImage.value instanceof Image ) || oldImage.src !== newImage.src ) { + newImage.value = new Image(); + newImage.value.src = newImage.src; + } else { + newImage = oldImage; + } + } + return images; + } + +} ); \ No newline at end of file diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js new file mode 100644 index 000000000..af9d776ed --- /dev/null +++ b/support/client/lib/vwf/view/hud.js @@ -0,0 +1,451 @@ +"use strict"; + +define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utility ) { + + return model.load( module, { + + // == Module Definition ==================================================================== + + // -- initialize --------------------------------------------------------------------------- + + initialize: function() { + }, + + // == Model API ============================================================================ + + // -- createdNode ------------------------------------------------------------------------- + + createdNode: function( nodeID, childID, childExtendsID, childImplementsIDs, + childSource, childType, childIndex, childName, callback /* ( ready ) */ ) { + }, + + // -- initializedNode --------------------------------------------------------------------- + + initializedNode: function( nodeID, childID, childExtendsID, childImplementsIDs, + childSource, childType, childIndex, childName ) { + + var node; + + if ( this.state.overlays[ childID ] ) { + + node = this.state.overlays[ childID ]; + node.viewObject = createOverlay( node ); + node.initialized = true; + + } else if ( this.state.elements[ childID ] ) { + + node = this.state.elements[ childID ]; + node.viewObject = createElement( node ); + node.initialized = true; + + } + }, + + // -- deletedNode ------------------------------------------------------------------------- + + deletedNode: function( nodeID ) { + + if ( this.state.overlays[ nodeID ] ) { + var node, keys, i; + node = this.state.overlays[ nodeID ]; + delete this.state.overlays[ nodeID ]; + } else if ( this.state.elements[ nodeID ] ) { + var node, parent; + node = this.state.elements[ nodeID ]; + delete this.state.elements[ nodeID ]; + } + + }, + + // -- createdProperty --------------------------------------------------------------------- + + createdProperty: function( nodeID, propertyName, propertyValue ) { + return this.initializedProperty( nodeID, propertyName, propertyValue ); + }, + + // -- initializedProperty ----------------------------------------------------------------- + + initializedProperty: function( nodeID, propertyName, propertyValue ) { + var value = undefined; + + if ( propertyValue !== undefined ) { + var node = this.state.overlays[ nodeID ] || this.state.elements[ nodeID ] ; + if ( node !== undefined ) { + switch ( propertyName ) { + default: + value = this.satProperty( nodeID, propertyName, propertyValue ); + break; + } + } + } + + return value; + }, + + // -- satProperty ------------------------------------------------------------------------- + + satProperty: function( nodeID, propertyName, propertyValue ) { + var value = undefined; + + if ( this.state.elements[ nodeID ] ) { + var node = this.state.elements[ nodeID ]; + if ( node.drawProperties.hasOwnProperty( propertyName ) ) { + node.viewObject[ propertyName ] = propertyValue; + } + } + } + + } ); + + function createOverlay( node ) { + return new HUD(); + } + + function createElement( node ) { + // id, drawFunc, width, height, visible + var props = node.properties; + var drawProps = node.drawProperties; + var drawFunction = function( context, position ) { eval( node.draw ) }; + var element = new Element( node.id, drawFunction, props.width, props.height, props.visible ); + var i, keys; + keys = Object.keys( drawProps ); + for ( i = 0; i < keys.length; i++ ) { + element[ keys[ i ] ] = drawProps[ keys[ i ] ]; + } + keys = Object.keys( props.images ); + for ( i = 0; i < keys.length; i++ ) { + element[ keys[ i ] ] = props.images[ keys[ i ] ].value; + } + node.overlay.viewObject.add( element, props.alignH, props.alignV, props.offsetH, props.offsetV ); + return element; + } + + HUD = function() { + this.initialize(); + return this; + } + + HUD.prototype = { + constructor: HUD, + elements: undefined, + elementCount: undefined, + sortedElements: undefined, + picks: undefined, + canvas: undefined, + visible: undefined, + defaultHandlers: undefined, + + initialize: function() { + var gameCanvas = document.getElementById( vwf_view.kernel.application() ); + this.elements = {}; + this.elementCount = 0; + this.sortedElements = []; + this.picks = []; + this.canvas = document.createElement( "CANVAS" ); + this.canvas.id = "HUDCanvas"; + gameCanvas.parentElement.appendChild( this.canvas ); + this.visible = true; + this.update(); + this.defaultHandlers = {}; + this.registerEventListeners( gameCanvas ); + }, + + update: function() { + this.canvas.width = window.innerWidth; + this.canvas.height = window.innerHeight; + if ( this.visible ) { + this.draw(); + } + }, + + draw: function() { + var context = this.canvas.getContext( '2d' ); + this.sortedElements.length = 0; + + for ( var el in this.elements ) { + var element = this.elements[ el ]; + element.position.x = 0; + element.position.y = 0; + + switch ( element.alignH ) { + case "left": + element.position.x = 0; + break; + case "center": + element.position.x = -element.width / 2; + element.position.x += this.canvas.width / 2; + break; + case "right": + element.position.x = -element.width; + element.position.x += this.canvas.width; + break; + } + + switch ( element.alignV ) { + case "top": + element.position.y = 0; + break; + case "middle": + element.position.y = -element.height / 2; + element.position.y += this.canvas.height / 2; + break; + case "bottom": + element.position.y = -element.height; + element.position.y += this.canvas.height; + break; + } + + element.position.x += element.offsetH; + element.position.y += element.offsetV; + + if ( element.visible ) { + this.sortedElements.push( element ); + } + } + + this.globalPreDraw( context ); + this.sortedElements.sort( this.sortFunction ); + for ( var i = 0; i < this.sortedElements.length; i++ ) { + this.elementPreDraw( context, this.sortedElements[ i ] ); + this.sortedElements[ i ].preDraw( context, this.sortedElements[ i ].position ); + this.sortedElements[ i ].draw( context, this.sortedElements[ i ].position ); + this.sortedElements[ i ].postDraw( context, this.sortedElements[ i ].position ); + this.elementPostDraw( context, this.sortedElements[ i ] ); + } + this.globalPostDraw( context ); + + }, + + add: function( element, alignH, alignV, offsetH, offsetV ) { + + // Add the element to the HUD's elements list + // Initialize the offset position + this.elements[ element.id ] = element; + var newElement = this.elements[ element.id ]; + + newElement[ "offsetH" ] = isNaN( offsetH ) ? 0 : offsetH; + newElement[ "offsetV" ] = isNaN( offsetV ) ? 0 : offsetV; + + newElement[ "position" ] = { + "x": 0, + "y": 0 + } + + switch ( alignH ) { + case "left": + case "center": + case "right": + newElement[ "alignH" ] = alignH; + break; + default: + newElement[ "alignH" ] = "left"; + break; + } + + switch ( alignV ) { + case "top": + case "middle": + case "bottom": + newElement[ "alignV" ] = alignV; + break; + default: + newElement[ "alignV" ] = "top"; + break; + } + + this.countElements(); + newElement[ "drawOrder" ] = this.elementCount; + }, + + sortFunction: function( a, b ) { + return a.drawOrder - b.drawOrder; + }, + + remove: function( element ) { + var index = this.elements[ element.id ].drawOrder; + delete this.elements[ element.id ]; + + for ( var el in this.elements ) { + if ( this.elements[ el ].drawOrder > index ) { + this.elements[ el ].drawOrder--; + } + } + + this.countElements(); + }, + + countElements: function() { + var count = 0; + + for ( var el in this.elements ) { + count++; + } + + this.elementCount = count; + }, + + pick: function( event ) { + // Use sortedElements since they are all visible + var elements = this.sortedElements; + this.picks.length = 0; + // Loop backward to order picks from nearest to furthest + for ( var i = elements.length - 1; i >= 0; i-- ) { + var pos = elements[ i ].position; + var width = pos.x + elements[ i ].width; + var height = pos.y + elements[ i ].height; + + if ( event.clientX > pos.x && event.clientX < width && + event.clientY > pos.y && event.clientY < height ) { + + if ( elements[ i ].isMouseOver !== true ) { + elements[ i ].isMouseOver = true; + elements[ i ].onMouseOver( event ); + } + this.picks.push( elements[ i ] ); + + } else if ( elements[ i ].isMouseOver === true ) { + elements[ i ].isMouseOver = false; + elements[ i ].onMouseOut( event ); + } + } + }, + + registerEventListeners: function( gameCanvas ) { + var emptyEvent = function( event ) {}; + this.defaultHandlers.onClick = gameCanvas.onclick; + gameCanvas.onclick = emptyEvent; + gameCanvas.addEventListener( "click", this.handleEvent.bind( this ) ); + + this.defaultHandlers.onMouseUp = gameCanvas.onmouseup; + gameCanvas.onmouseup = emptyEvent; + gameCanvas.addEventListener( "mouseup", this.handleEvent.bind( this ) ); + + this.defaultHandlers.onMouseDown = gameCanvas.onmousedown; + gameCanvas.onmousedown = emptyEvent; + gameCanvas.addEventListener( "mousedown", this.handleEvent.bind( this ) ); + + this.defaultHandlers.onMouseMove = gameCanvas.onmousemove; + gameCanvas.onmousemove = emptyEvent; + gameCanvas.addEventListener( "mousemove", this.handleEvent.bind( this ) ); + }, + + handleEvent: function( event ) { + this.pick( event ); + var topPick = this.picks[ 0 ]; + var type; + + switch ( event.type ) { + case "click": + type = "onClick"; + break; + case "mouseup": + type = "onMouseUp"; + break; + case "mousedown": + type = "onMouseDown"; + break; + case "mousemove": + type = "onMouseMove"; + break; + default: + console.log( "HUD.handleEvent - Unhandled event type: " + event.type ); + return; + } + + if ( topPick ) { + if ( topPick.enabled ) { + this.elements[ topPick.id ][ type ]( event ); + } + } else if ( this.defaultHandlers[ type ] instanceof Function ) { + this.defaultHandlers[ type ]( event ); + } + }, + + moveToTop: function( id ) { + var index = this.elements[ id ].drawOrder; + for ( var el in this.elements ) { + if ( this.elements[ el ].drawOrder > index ) { + this.elements[ el ].drawOrder--; + } + } + this.elements[ id ].drawOrder = this.elementCount; + }, + + // Draw instructions that occur prior to the element's preDraw + // and draw functions. Executes on each element in the HUD. + elementPreDraw: function( context, element ) { }, + + // Draw instructions that occur after the element's draw and + // postDraw functions. Executes on each element in the HUD. + elementPostDraw: function( context, element ) { }, + + // Draw instructions that occur before anything is drawn to + // the HUD. + globalPreDraw: function( context ) { }, + + // Draw instructions that occur after everything is drawn to + // the HUD. + globalPostDraw: function( context ) { } + + } + + Element = function( id, drawFunc, width, height, visible ) { + this.initialize( id, drawFunc, width, height ); + return this; + } + + Element.prototype = { + constructor: HUD.Element, + id: undefined, + width: undefined, + height: undefined, + isMouseOver: undefined, + visible: undefined, + enabled: undefined, + + initialize: function( id, drawFunc, width, height, visible ) { + this.id = id; + + if ( drawFunc instanceof Function ) { + this.draw = drawFunc; + } + + this.width = isNaN( width ) ? 0 : width; + this.height = isNaN( height ) ? 0 : height; + + if ( visible === true || visible === undefined ) { + this.visible = true; + } else { + this.visible = false; + } + + this.enabled = true; + }, + + // Draw instructions for the element. Executes after the HUD's + // elementPreDraw funtion and the element's preDraw function. + draw: function( context, position ) { }, + + // Draw instructions that execute just befor the element's + // draw function. + preDraw: function( context, position ) { }, + + // Draw instructions that execute immediately after the element's + // draw function. + postDraw: function( context, position ) { }, + + onClick: function( event ) { }, + + onMouseDown: function( event ) { }, + + onMouseUp: function( event ) { }, + + onMouseMove: function( event ) { }, + + onMouseOver: function( event ) { }, + + onMouseOut: function( event ) { } + + } + +} ); \ No newline at end of file diff --git a/support/proxy/vwf.example.com/HUD/element.vwf.yaml b/support/proxy/vwf.example.com/HUD/element.vwf.yaml new file mode 100644 index 000000000..ddfd0c7a5 --- /dev/null +++ b/support/proxy/vwf.example.com/HUD/element.vwf.yaml @@ -0,0 +1,18 @@ +extends: http://vwf.example.com/node.vwf +properties: + images: + # image: + # src: + # value: + width: + height: + visible: + enabled: + alignH: + alignV: + offsetH: + offsetV: +methods: + draw: +events: +scripts: \ No newline at end of file diff --git a/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml b/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml new file mode 100644 index 000000000..785ba03d5 --- /dev/null +++ b/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml @@ -0,0 +1,7 @@ +extends: http://vwf.example.com/node.vwf +properties: + drawRate: 30 + visible: true +methods: +events: +scripts: \ No newline at end of file From f942ef648b4ebd0f8acf9945ea0e78b450e73d67 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Tue, 17 Feb 2015 03:03:05 -0500 Subject: [PATCH 019/129] Finish HUD creation --- support/client/lib/vwf.js | 7 + support/client/lib/vwf/model/hud.js | 158 +++---- support/client/lib/vwf/model/hud/HUD.js | 327 ++++++++++++++ support/client/lib/vwf/view/hud.js | 408 +++--------------- .../vwf.example.com/HUD/element.vwf.yaml | 2 +- .../vwf.example.com/HUD/overlay.vwf.yaml | 3 +- 6 files changed, 437 insertions(+), 468 deletions(-) create mode 100644 support/client/lib/vwf/model/hud/HUD.js diff --git a/support/client/lib/vwf.js b/support/client/lib/vwf.js index 76dcc8815..8c13bb75e 100644 --- a/support/client/lib/vwf.js +++ b/support/client/lib/vwf.js @@ -323,6 +323,9 @@ "vwf/model/blockly/msg/js/en": { deps: [ "vwf/model/blockly/blockly_compressed" ] }, + "vwf/model/hud/hud": { + exports: "HUD2" + } } }; @@ -363,6 +366,7 @@ active: false }, { library: "vwf/model/graphtool", active: false }, + { library: "vwf/model/hud", active: false }, { library: "vwf/model/eventManager", active: false }, { library: "vwf/model/sound", active: false }, { library: "vwf/model/object", active: true }, @@ -401,6 +405,7 @@ active: false }, { library: "vwf/view/blockly", active: false }, + { library: "vwf/view/hud", active: false }, { library: "vwf/view/sound", active: false }, { library: "vwf/view/touch", active: false }, { library: "vwf/view/cesium", active: false }, @@ -440,6 +445,7 @@ { library: "vwf/model/cesium", active: false }, { library: "vwf/model/blockly", active: false }, { library: "vwf/model/graphtool", active: false }, + { library: "vwf/model/hud", active: false }, { library: "vwf/model/eventManager", active: false }, { library: "vwf/model/sound", active: false }, { library: "vwf/model/kineticjs", active: false }, @@ -458,6 +464,7 @@ { library: "vwf/view/google-earth", active: false }, { library: "vwf/view/cesium", active: false }, { library: "vwf/view/blockly", active: false }, + { library: "vwf/view/hud", active: false }, { library: "vwf/view/sound", active: false }, { library: "vwf/view/touch", active: false }, { library: "vwf/view/kineticjs", active: false }, diff --git a/support/client/lib/vwf/model/hud.js b/support/client/lib/vwf/model/hud.js index f5d4a12f7..d26a86c9c 100644 --- a/support/client/lib/vwf/model/hud.js +++ b/support/client/lib/vwf/model/hud.js @@ -6,10 +6,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili return model.load( module, { - // == Module Definition ==================================================================== - - // -- initialize --------------------------------------------------------------------------- - initialize: function() { var lastKernel; this.state.overlays = {}; @@ -22,29 +18,40 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili logger = this.logger; }, - // == Model API ============================================================================ - - // -- creatingNode ------------------------------------------------------------------------- - creatingNode: function( nodeID, childID, childExtendsID, childImplementsIDs, childSource, childType, childIndex, childName, callback /* ( ready ) */ ) { var node = undefined; - var protos = getPrototypes.call( this, kernel, childExtendsID ); + var protos = getPrototypes.call( this, this.state.kernel, childExtendsID ); if ( protos && isOverlay( protos ) ) { node = this.state.overlays[ childID ] = { + "id": childID, + "name": childName, "elements": {}, - "properties": {}, + "properties": { + "visible": undefined + }, "initialized": false }; } else if ( protos && isElement( protos ) ) { - node = this.state.elements[ childID ] = { - "overlay": this.state.overlays[ node.parentID ], - "properties": {}, + "id": childID, + "name": childName, + "overlay": this.state.overlays[ nodeID ], + "properties": { + "images": undefined, + "width": undefined, + "height": undefined, + "visible": undefined, + "enabled": undefined, + "alignH": undefined, + "alignV": undefined, + "offsetH": undefined, + "offsetV": undefined + }, "drawProperties": {}, "initialized": false }; @@ -54,49 +61,10 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } }, - // -- initializingNode --------------------------------------------------------------------- - - initializingNode: function( nodeID, childID, childExtendsID, childImplementsIDs, - childSource, childType, childIndex, childName ) { - - var node; - - if ( this.state.overlays[ childID ] ) { - - node = this.state.overlays[ childID ]; - node.properties = { - "drawRate": undefined, - "visible": undefined - }; - - } else if ( this.state.elements[ childID ] ) { - - node = this.state.elements[ childID ]; - node.properties = { - "images": undefined, - "width": undefined, - "height": undefined, - "visible": undefined, - "enabled": undefined, - "alignH": undefined, - "alignV": undefined, - "offsetH": undefined, - "offsetV": undefined - }; - node.drawProperties = {}; - - } - - }, - - // -- creatingProperty --------------------------------------------------------------------- - creatingProperty: function( nodeID, propertyName, propertyValue ) { return this.initializingProperty( nodeID, propertyName, propertyValue ); }, - // -- initializingProperty ----------------------------------------------------------------- - initializingProperty: function( nodeID, propertyName, propertyValue ) { var value = undefined; @@ -114,34 +82,22 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili return value; }, - // TODO: deletingProperty - - // -- settingProperty ---------------------------------------------------------------------- - settingProperty: function( nodeID, propertyName, propertyValue ) { var node, value; - if ( this.state.overlays[ childID ] ) { + if ( this.state.overlays[ nodeID ] ) { - node = this.state.overlays[ childID ]; + node = this.state.overlays[ nodeID ]; if ( node.properties.hasOwnProperty( propertyName ) ) { node.properties[ propertyName ] = propertyValue; value = propertyValue; } - } else if ( this.state.elements[ childID ] ) { + } else if ( this.state.elements[ nodeID ] ) { - node = this.state.elements[ childID ]; + node = this.state.elements[ nodeID ]; if ( node.properties.hasOwnProperty( propertyName ) ) { - if ( node.initialized ) { - switch ( propertyName ) { - case "images": - node.properties.images = loadImages( node, propertyValue ); - break; - } - } else { - node.properties[ propertyName ] = propertyValue; - } + node.properties[ propertyName ] = propertyValue; } else { node.drawProperties[ propertyName ] = propertyValue; } @@ -152,13 +108,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili return value; }, - // -- gettingProperty ---------------------------------------------------------------------- - - gettingProperty: function( nodeID, propertyName, propertyValue ) { - }, - - // -- creatingMethod ------------------------------------------------------------------------ - creatingMethod: function( nodeID, methodName, methodParameters, methodBody ) { if ( this.state.elements[ nodeID ] ) { var node = this.state.elements[ nodeID ]; @@ -166,9 +115,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili node.draw = methodBody; } } - } - - // -- callingMethod ------------------------------------------------------------------------ + }, callingMethod: function( nodeID, methodName, methodParameters, methodValue ) { if ( this.state.elements[ nodeID ] ) { @@ -181,37 +128,38 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } }, - // -- firingEvent -------------------------------------------------------------------------- - - firingEvent: function( nodeID, eventName, eventParameters ) { - }, - } ); - function loadImages( node, images ) { - var keys = Object.keys( images ); - var newImage, oldImage; - for ( var i = 0; i < keys.length; i++ ) { - newImage = images[ keys[ i ] ]; - if ( !newImage.hasOwnProperty( "src" ) ) { - logger.errorx( "loadImages", "Image \"" + keys[ i ] + "\" is malformed! It " + - "does not contain a \"src\" property! Skipping image load!" ); - continue; - } else if ( !newImage.hasOwnProperty( "value" ) ) { - logger.warnx( "loadImages", "Image \"" + keys[ i ] + "\" does not contain a " + - "\"value\" property! One will be generated automatically." ); + function getPrototypes( kernel, extendsID ) { + var prototypes = []; + var id = extendsID; + while ( id !== undefined ) { + prototypes.push( id ); + id = kernel.prototype( id ); + } + return prototypes; + } + + function isOverlay( prototypes ) { + var foundOverlay = false; + if ( prototypes ) { + for ( var i = 0; i < prototypes.length && !foundOverlay; i++ ) { + foundOverlay = ( prototypes[i] == "http-vwf-example-com-hud-overlay-vwf" ); } - oldImage = node.properties.images[ keys[ i ] ]; - // If the image property doesn't exist or the image hasn't been loaded or the image src - // has changed, then we need to load the image. Otherwise, just copy the old image data - if ( !oldImage || !( oldImage.value instanceof Image ) || oldImage.src !== newImage.src ) { - newImage.value = new Image(); - newImage.value.src = newImage.src; - } else { - newImage = oldImage; + } + + return foundOverlay; + } + + function isElement( prototypes ) { + var foundElement = false; + if ( prototypes ) { + for ( var i = 0; i < prototypes.length && !foundElement; i++ ) { + foundElement = ( prototypes[i] == "http-vwf-example-com-hud-element-vwf" ); } } - return images; + + return foundElement; } } ); \ No newline at end of file diff --git a/support/client/lib/vwf/model/hud/HUD.js b/support/client/lib/vwf/model/hud/HUD.js new file mode 100644 index 000000000..74064310d --- /dev/null +++ b/support/client/lib/vwf/model/hud/HUD.js @@ -0,0 +1,327 @@ +HUD = function() { + this.initialize(); + return this; +} + +HUD.prototype = { + constructor: HUD, + elements: undefined, + elementCount: undefined, + sortedElements: undefined, + picks: undefined, + canvas: undefined, + visible: undefined, + defaultHandlers: undefined, + + initialize: function() { + var gameCanvas = document.getElementById( vwf_view.kernel.application() ); + this.elements = {}; + this.elementCount = 0; + this.sortedElements = []; + this.picks = []; + this.canvas = document.createElement( "CANVAS" ); + this.canvas.id = "HUDCanvas2"; + gameCanvas.parentElement.appendChild( this.canvas ); + this.visible = true; + this.update(); + this.defaultHandlers = {}; + this.registerEventListeners( gameCanvas ); + }, + + update: function() { + this.canvas.width = window.innerWidth; + this.canvas.height = window.innerHeight; + if ( this.visible ) { + this.draw(); + } + }, + + draw: function() { + var context = this.canvas.getContext( '2d' ); + this.sortedElements.length = 0; + + for ( var el in this.elements ) { + var element = this.elements[ el ]; + element.position.x = 0; + element.position.y = 0; + + switch ( element.alignH ) { + case "left": + element.position.x = 0; + break; + case "center": + element.position.x = -element.width / 2; + element.position.x += this.canvas.width / 2; + break; + case "right": + element.position.x = -element.width; + element.position.x += this.canvas.width; + break; + } + + switch ( element.alignV ) { + case "top": + element.position.y = 0; + break; + case "middle": + element.position.y = -element.height / 2; + element.position.y += this.canvas.height / 2; + break; + case "bottom": + element.position.y = -element.height; + element.position.y += this.canvas.height; + break; + } + + element.position.x += element.offsetH; + element.position.y += element.offsetV; + + if ( element.visible ) { + this.sortedElements.push( element ); + } + } + + this.globalPreDraw( context ); + this.sortedElements.sort( this.sortFunction ); + for ( var i = 0; i < this.sortedElements.length; i++ ) { + this.elementPreDraw( context, this.sortedElements[ i ] ); + this.sortedElements[ i ].preDraw( context, this.sortedElements[ i ].position ); + this.sortedElements[ i ].draw( context, this.sortedElements[ i ].position ); + this.sortedElements[ i ].postDraw( context, this.sortedElements[ i ].position ); + this.elementPostDraw( context, this.sortedElements[ i ] ); + } + this.globalPostDraw( context ); + + }, + + add: function( element, alignH, alignV, offsetH, offsetV ) { + + // Add the element to the HUD's elements list + // Initialize the offset position + this.elements[ element.id ] = element; + var newElement = this.elements[ element.id ]; + + newElement[ "offsetH" ] = isNaN( offsetH ) ? 0 : offsetH; + newElement[ "offsetV" ] = isNaN( offsetV ) ? 0 : offsetV; + + newElement[ "position" ] = { + "x": 0, + "y": 0 + } + + switch ( alignH ) { + case "left": + case "center": + case "right": + newElement[ "alignH" ] = alignH; + break; + default: + newElement[ "alignH" ] = "left"; + break; + } + + switch ( alignV ) { + case "top": + case "middle": + case "bottom": + newElement[ "alignV" ] = alignV; + break; + default: + newElement[ "alignV" ] = "top"; + break; + } + + this.countElements(); + newElement[ "drawOrder" ] = this.elementCount; + }, + + sortFunction: function( a, b ) { + return a.drawOrder - b.drawOrder; + }, + + remove: function( element ) { + var index = this.elements[ element.id ].drawOrder; + delete this.elements[ element.id ]; + + for ( var el in this.elements ) { + if ( this.elements[ el ].drawOrder > index ) { + this.elements[ el ].drawOrder--; + } + } + + this.countElements(); + }, + + countElements: function() { + var count = 0; + + for ( var el in this.elements ) { + count++; + } + + this.elementCount = count; + }, + + pick: function( event ) { + // Use sortedElements since they are all visible + var elements = this.sortedElements; + this.picks.length = 0; + // Loop backward to order picks from nearest to furthest + for ( var i = elements.length - 1; i >= 0; i-- ) { + var pos = elements[ i ].position; + var width = pos.x + elements[ i ].width; + var height = pos.y + elements[ i ].height; + + if ( event.clientX > pos.x && event.clientX < width && + event.clientY > pos.y && event.clientY < height ) { + + if ( elements[ i ].isMouseOver !== true ) { + elements[ i ].isMouseOver = true; + elements[ i ].onMouseOver( event ); + } + this.picks.push( elements[ i ] ); + + } else if ( elements[ i ].isMouseOver === true ) { + elements[ i ].isMouseOver = false; + elements[ i ].onMouseOut( event ); + } + } + }, + + registerEventListeners: function( gameCanvas ) { + var emptyEvent = function( event ) {}; + this.defaultHandlers.onClick = gameCanvas.onclick; + gameCanvas.onclick = emptyEvent; + gameCanvas.addEventListener( "click", this.handleEvent.bind( this ) ); + + this.defaultHandlers.onMouseUp = gameCanvas.onmouseup; + gameCanvas.onmouseup = emptyEvent; + gameCanvas.addEventListener( "mouseup", this.handleEvent.bind( this ) ); + + this.defaultHandlers.onMouseDown = gameCanvas.onmousedown; + gameCanvas.onmousedown = emptyEvent; + gameCanvas.addEventListener( "mousedown", this.handleEvent.bind( this ) ); + + this.defaultHandlers.onMouseMove = gameCanvas.onmousemove; + gameCanvas.onmousemove = emptyEvent; + gameCanvas.addEventListener( "mousemove", this.handleEvent.bind( this ) ); + }, + + handleEvent: function( event ) { + this.pick( event ); + var topPick = this.picks[ 0 ]; + var type; + + switch ( event.type ) { + case "click": + type = "onClick"; + break; + case "mouseup": + type = "onMouseUp"; + break; + case "mousedown": + type = "onMouseDown"; + break; + case "mousemove": + type = "onMouseMove"; + break; + default: + console.log( "HUD.handleEvent - Unhandled event type: " + event.type ); + return; + } + + if ( topPick ) { + if ( topPick.enabled ) { + this.elements[ topPick.id ][ type ]( event ); + } + } else if ( this.defaultHandlers[ type ] instanceof Function ) { + this.defaultHandlers[ type ]( event ); + } + }, + + moveToTop: function( id ) { + var index = this.elements[ id ].drawOrder; + for ( var el in this.elements ) { + if ( this.elements[ el ].drawOrder > index ) { + this.elements[ el ].drawOrder--; + } + } + this.elements[ id ].drawOrder = this.elementCount; + }, + + // Draw instructions that occur prior to the element's preDraw + // and draw functions. Executes on each element in the HUD. + elementPreDraw: function( context, element ) { }, + + // Draw instructions that occur after the element's draw and + // postDraw functions. Executes on each element in the HUD. + elementPostDraw: function( context, element ) { }, + + // Draw instructions that occur before anything is drawn to + // the HUD. + globalPreDraw: function( context ) { }, + + // Draw instructions that occur after everything is drawn to + // the HUD. + globalPostDraw: function( context ) { } + +} + +HUD.Element = function( id, drawFunc, width, height, visible ) { + this.initialize( id, drawFunc, width, height ); + return this; +} + +HUD.Element.prototype = { + constructor: HUD.Element, + id: undefined, + width: undefined, + height: undefined, + isMouseOver: undefined, + visible: undefined, + enabled: undefined, + + initialize: function( id, drawFunc, width, height, visible ) { + this.id = id; + + if ( drawFunc instanceof Function ) { + this.draw = drawFunc; + } + + this.width = isNaN( width ) ? 0 : width; + this.height = isNaN( height ) ? 0 : height; + + if ( visible === true || visible === undefined ) { + this.visible = true; + } else { + this.visible = false; + } + + this.enabled = true; + }, + + // Draw instructions for the element. Executes after the HUD's + // elementPreDraw funtion and the element's preDraw function. + draw: function( context, position ) { }, + + // Draw instructions that execute just befor the element's + // draw function. + preDraw: function( context, position ) { }, + + // Draw instructions that execute immediately after the element's + // draw function. + postDraw: function( context, position ) { }, + + onClick: function( event ) { }, + + onMouseDown: function( event ) { }, + + onMouseUp: function( event ) { }, + + onMouseMove: function( event ) { }, + + onMouseOver: function( event ) { }, + + onMouseOut: function( event ) { } + +} \ No newline at end of file diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js index af9d776ed..3a8033338 100644 --- a/support/client/lib/vwf/view/hud.js +++ b/support/client/lib/vwf/view/hud.js @@ -1,53 +1,37 @@ "use strict"; -define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utility ) { +var debugHUD; - return model.load( module, { - - // == Module Definition ==================================================================== +define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( module, model, utility, HUD ) { - // -- initialize --------------------------------------------------------------------------- + return model.load( module, { initialize: function() { + this.runningOverlays = {}; }, - // == Model API ============================================================================ - - // -- createdNode ------------------------------------------------------------------------- - - createdNode: function( nodeID, childID, childExtendsID, childImplementsIDs, - childSource, childType, childIndex, childName, callback /* ( ready ) */ ) { - }, - - // -- initializedNode --------------------------------------------------------------------- - initializedNode: function( nodeID, childID, childExtendsID, childImplementsIDs, childSource, childType, childIndex, childName ) { var node; - if ( this.state.overlays[ childID ] ) { - node = this.state.overlays[ childID ]; node.viewObject = createOverlay( node ); + node.rafID = requestAnimationFrame( animateHUD.bind( node ) ); node.initialized = true; - } else if ( this.state.elements[ childID ] ) { - node = this.state.elements[ childID ]; node.viewObject = createElement( node ); node.initialized = true; - } }, - // -- deletedNode ------------------------------------------------------------------------- - deletedNode: function( nodeID ) { if ( this.state.overlays[ nodeID ] ) { var node, keys, i; node = this.state.overlays[ nodeID ]; + cancelAnimationFrame( node.rafID ); delete this.state.overlays[ nodeID ]; } else if ( this.state.elements[ nodeID ] ) { var node, parent; @@ -57,14 +41,10 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili }, - // -- createdProperty --------------------------------------------------------------------- - createdProperty: function( nodeID, propertyName, propertyValue ) { return this.initializedProperty( nodeID, propertyName, propertyValue ); }, - // -- initializedProperty ----------------------------------------------------------------- - initializedProperty: function( nodeID, propertyName, propertyValue ) { var value = undefined; @@ -82,14 +62,13 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili return value; }, - // -- satProperty ------------------------------------------------------------------------- - satProperty: function( nodeID, propertyName, propertyValue ) { - var value = undefined; - + var value, node; if ( this.state.elements[ nodeID ] ) { - var node = this.state.elements[ nodeID ]; - if ( node.drawProperties.hasOwnProperty( propertyName ) ) { + node = this.state.elements[ nodeID ]; + if ( propertyName === "images" ) { + node.properties.images = loadImages( node, propertyValue ); + } else if ( node.drawProperties.hasOwnProperty( propertyName ) ) { node.viewObject[ propertyName ] = propertyValue; } } @@ -97,16 +76,28 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } ); + function animateHUD() { + this.viewObject.update(); + requestAnimationFrame( animateHUD.bind( this ) ); + } + function createOverlay( node ) { - return new HUD(); + var overlay = new HUD(); + var keys = Object.keys( node.elements ); + var element, props; + for ( var i = 0; i < keys.length; i++ ) { + element = node.elements[ keys[ i ] ]; + props = element.properties; + overlay.add( element.viewObject, props.alignH, props.alignV, props.offsetH, props.offsetV ); + } + return overlay; } function createElement( node ) { - // id, drawFunc, width, height, visible var props = node.properties; var drawProps = node.drawProperties; var drawFunction = function( context, position ) { eval( node.draw ) }; - var element = new Element( node.id, drawFunction, props.width, props.height, props.visible ); + var element = new HUD.Element( node.name, drawFunction, props.width, props.height, props.visible ); var i, keys; keys = Object.keys( drawProps ); for ( i = 0; i < keys.length; i++ ) { @@ -116,336 +107,33 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili for ( i = 0; i < keys.length; i++ ) { element[ keys[ i ] ] = props.images[ keys[ i ] ].value; } - node.overlay.viewObject.add( element, props.alignH, props.alignV, props.offsetH, props.offsetV ); return element; } - HUD = function() { - this.initialize(); - return this; - } - - HUD.prototype = { - constructor: HUD, - elements: undefined, - elementCount: undefined, - sortedElements: undefined, - picks: undefined, - canvas: undefined, - visible: undefined, - defaultHandlers: undefined, - - initialize: function() { - var gameCanvas = document.getElementById( vwf_view.kernel.application() ); - this.elements = {}; - this.elementCount = 0; - this.sortedElements = []; - this.picks = []; - this.canvas = document.createElement( "CANVAS" ); - this.canvas.id = "HUDCanvas"; - gameCanvas.parentElement.appendChild( this.canvas ); - this.visible = true; - this.update(); - this.defaultHandlers = {}; - this.registerEventListeners( gameCanvas ); - }, - - update: function() { - this.canvas.width = window.innerWidth; - this.canvas.height = window.innerHeight; - if ( this.visible ) { - this.draw(); - } - }, - - draw: function() { - var context = this.canvas.getContext( '2d' ); - this.sortedElements.length = 0; - - for ( var el in this.elements ) { - var element = this.elements[ el ]; - element.position.x = 0; - element.position.y = 0; - - switch ( element.alignH ) { - case "left": - element.position.x = 0; - break; - case "center": - element.position.x = -element.width / 2; - element.position.x += this.canvas.width / 2; - break; - case "right": - element.position.x = -element.width; - element.position.x += this.canvas.width; - break; - } - - switch ( element.alignV ) { - case "top": - element.position.y = 0; - break; - case "middle": - element.position.y = -element.height / 2; - element.position.y += this.canvas.height / 2; - break; - case "bottom": - element.position.y = -element.height; - element.position.y += this.canvas.height; - break; - } - - element.position.x += element.offsetH; - element.position.y += element.offsetV; - - if ( element.visible ) { - this.sortedElements.push( element ); - } - } - - this.globalPreDraw( context ); - this.sortedElements.sort( this.sortFunction ); - for ( var i = 0; i < this.sortedElements.length; i++ ) { - this.elementPreDraw( context, this.sortedElements[ i ] ); - this.sortedElements[ i ].preDraw( context, this.sortedElements[ i ].position ); - this.sortedElements[ i ].draw( context, this.sortedElements[ i ].position ); - this.sortedElements[ i ].postDraw( context, this.sortedElements[ i ].position ); - this.elementPostDraw( context, this.sortedElements[ i ] ); - } - this.globalPostDraw( context ); - - }, - - add: function( element, alignH, alignV, offsetH, offsetV ) { - - // Add the element to the HUD's elements list - // Initialize the offset position - this.elements[ element.id ] = element; - var newElement = this.elements[ element.id ]; - - newElement[ "offsetH" ] = isNaN( offsetH ) ? 0 : offsetH; - newElement[ "offsetV" ] = isNaN( offsetV ) ? 0 : offsetV; - - newElement[ "position" ] = { - "x": 0, - "y": 0 - } - - switch ( alignH ) { - case "left": - case "center": - case "right": - newElement[ "alignH" ] = alignH; - break; - default: - newElement[ "alignH" ] = "left"; - break; - } - - switch ( alignV ) { - case "top": - case "middle": - case "bottom": - newElement[ "alignV" ] = alignV; - break; - default: - newElement[ "alignV" ] = "top"; - break; - } - - this.countElements(); - newElement[ "drawOrder" ] = this.elementCount; - }, - - sortFunction: function( a, b ) { - return a.drawOrder - b.drawOrder; - }, - - remove: function( element ) { - var index = this.elements[ element.id ].drawOrder; - delete this.elements[ element.id ]; - - for ( var el in this.elements ) { - if ( this.elements[ el ].drawOrder > index ) { - this.elements[ el ].drawOrder--; - } - } - - this.countElements(); - }, - - countElements: function() { - var count = 0; - - for ( var el in this.elements ) { - count++; - } - - this.elementCount = count; - }, - - pick: function( event ) { - // Use sortedElements since they are all visible - var elements = this.sortedElements; - this.picks.length = 0; - // Loop backward to order picks from nearest to furthest - for ( var i = elements.length - 1; i >= 0; i-- ) { - var pos = elements[ i ].position; - var width = pos.x + elements[ i ].width; - var height = pos.y + elements[ i ].height; - - if ( event.clientX > pos.x && event.clientX < width && - event.clientY > pos.y && event.clientY < height ) { - - if ( elements[ i ].isMouseOver !== true ) { - elements[ i ].isMouseOver = true; - elements[ i ].onMouseOver( event ); - } - this.picks.push( elements[ i ] ); - - } else if ( elements[ i ].isMouseOver === true ) { - elements[ i ].isMouseOver = false; - elements[ i ].onMouseOut( event ); - } - } - }, - - registerEventListeners: function( gameCanvas ) { - var emptyEvent = function( event ) {}; - this.defaultHandlers.onClick = gameCanvas.onclick; - gameCanvas.onclick = emptyEvent; - gameCanvas.addEventListener( "click", this.handleEvent.bind( this ) ); - - this.defaultHandlers.onMouseUp = gameCanvas.onmouseup; - gameCanvas.onmouseup = emptyEvent; - gameCanvas.addEventListener( "mouseup", this.handleEvent.bind( this ) ); - - this.defaultHandlers.onMouseDown = gameCanvas.onmousedown; - gameCanvas.onmousedown = emptyEvent; - gameCanvas.addEventListener( "mousedown", this.handleEvent.bind( this ) ); - - this.defaultHandlers.onMouseMove = gameCanvas.onmousemove; - gameCanvas.onmousemove = emptyEvent; - gameCanvas.addEventListener( "mousemove", this.handleEvent.bind( this ) ); - }, - - handleEvent: function( event ) { - this.pick( event ); - var topPick = this.picks[ 0 ]; - var type; - - switch ( event.type ) { - case "click": - type = "onClick"; - break; - case "mouseup": - type = "onMouseUp"; - break; - case "mousedown": - type = "onMouseDown"; - break; - case "mousemove": - type = "onMouseMove"; - break; - default: - console.log( "HUD.handleEvent - Unhandled event type: " + event.type ); - return; - } - - if ( topPick ) { - if ( topPick.enabled ) { - this.elements[ topPick.id ][ type ]( event ); - } - } else if ( this.defaultHandlers[ type ] instanceof Function ) { - this.defaultHandlers[ type ]( event ); - } - }, - - moveToTop: function( id ) { - var index = this.elements[ id ].drawOrder; - for ( var el in this.elements ) { - if ( this.elements[ el ].drawOrder > index ) { - this.elements[ el ].drawOrder--; - } - } - this.elements[ id ].drawOrder = this.elementCount; - }, - - // Draw instructions that occur prior to the element's preDraw - // and draw functions. Executes on each element in the HUD. - elementPreDraw: function( context, element ) { }, - - // Draw instructions that occur after the element's draw and - // postDraw functions. Executes on each element in the HUD. - elementPostDraw: function( context, element ) { }, - - // Draw instructions that occur before anything is drawn to - // the HUD. - globalPreDraw: function( context ) { }, - - // Draw instructions that occur after everything is drawn to - // the HUD. - globalPostDraw: function( context ) { } - - } - - Element = function( id, drawFunc, width, height, visible ) { - this.initialize( id, drawFunc, width, height ); - return this; - } - - Element.prototype = { - constructor: HUD.Element, - id: undefined, - width: undefined, - height: undefined, - isMouseOver: undefined, - visible: undefined, - enabled: undefined, - - initialize: function( id, drawFunc, width, height, visible ) { - this.id = id; - - if ( drawFunc instanceof Function ) { - this.draw = drawFunc; - } - - this.width = isNaN( width ) ? 0 : width; - this.height = isNaN( height ) ? 0 : height; - - if ( visible === true || visible === undefined ) { - this.visible = true; + function loadImages( node, images ) { + var keys = Object.keys( images ); + var newImage, oldImage; + for ( var i = 0; i < keys.length; i++ ) { + newImage = images[ keys[ i ] ]; + if ( !newImage.hasOwnProperty( "src" ) ) { + logger.errorx( "loadImages", "Image \"" + keys[ i ] + "\" is malformed! It " + + "does not contain a \"src\" property! Skipping image load!" ); + continue; + } else if ( !newImage.hasOwnProperty( "value" ) ) { + logger.warnx( "loadImages", "Image \"" + keys[ i ] + "\" does not contain a " + + "\"value\" property! One will be generated automatically." ); + } + oldImage = node.properties.images[ keys[ i ] ]; + // If the image property doesn't exist or the image hasn't been loaded or the image src + // has changed, then we need to load the image. Otherwise, just copy the old image data + if ( !oldImage || !( oldImage.value instanceof Image ) || oldImage.src !== newImage.src ) { + newImage.value = new Image(); + newImage.value.src = newImage.src; } else { - this.visible = false; + newImage = oldImage; } - - this.enabled = true; - }, - - // Draw instructions for the element. Executes after the HUD's - // elementPreDraw funtion and the element's preDraw function. - draw: function( context, position ) { }, - - // Draw instructions that execute just befor the element's - // draw function. - preDraw: function( context, position ) { }, - - // Draw instructions that execute immediately after the element's - // draw function. - postDraw: function( context, position ) { }, - - onClick: function( event ) { }, - - onMouseDown: function( event ) { }, - - onMouseUp: function( event ) { }, - - onMouseMove: function( event ) { }, - - onMouseOver: function( event ) { }, - - onMouseOut: function( event ) { } - + } + return images; } } ); \ No newline at end of file diff --git a/support/proxy/vwf.example.com/HUD/element.vwf.yaml b/support/proxy/vwf.example.com/HUD/element.vwf.yaml index ddfd0c7a5..9b4441dad 100644 --- a/support/proxy/vwf.example.com/HUD/element.vwf.yaml +++ b/support/proxy/vwf.example.com/HUD/element.vwf.yaml @@ -15,4 +15,4 @@ properties: methods: draw: events: -scripts: \ No newline at end of file +scripts: diff --git a/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml b/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml index 785ba03d5..84e0dbd32 100644 --- a/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml +++ b/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml @@ -1,7 +1,6 @@ extends: http://vwf.example.com/node.vwf properties: - drawRate: 30 visible: true methods: events: -scripts: \ No newline at end of file +scripts: From 6153341ac48f9643883ac5fa17a56a473f2796c5 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Tue, 17 Feb 2015 14:57:15 -0500 Subject: [PATCH 020/129] Delete HUD.js for renaming --- support/client/lib/vwf/model/hud/HUD.js | 327 ------------------------ 1 file changed, 327 deletions(-) delete mode 100644 support/client/lib/vwf/model/hud/HUD.js diff --git a/support/client/lib/vwf/model/hud/HUD.js b/support/client/lib/vwf/model/hud/HUD.js deleted file mode 100644 index 74064310d..000000000 --- a/support/client/lib/vwf/model/hud/HUD.js +++ /dev/null @@ -1,327 +0,0 @@ -HUD = function() { - this.initialize(); - return this; -} - -HUD.prototype = { - constructor: HUD, - elements: undefined, - elementCount: undefined, - sortedElements: undefined, - picks: undefined, - canvas: undefined, - visible: undefined, - defaultHandlers: undefined, - - initialize: function() { - var gameCanvas = document.getElementById( vwf_view.kernel.application() ); - this.elements = {}; - this.elementCount = 0; - this.sortedElements = []; - this.picks = []; - this.canvas = document.createElement( "CANVAS" ); - this.canvas.id = "HUDCanvas2"; - gameCanvas.parentElement.appendChild( this.canvas ); - this.visible = true; - this.update(); - this.defaultHandlers = {}; - this.registerEventListeners( gameCanvas ); - }, - - update: function() { - this.canvas.width = window.innerWidth; - this.canvas.height = window.innerHeight; - if ( this.visible ) { - this.draw(); - } - }, - - draw: function() { - var context = this.canvas.getContext( '2d' ); - this.sortedElements.length = 0; - - for ( var el in this.elements ) { - var element = this.elements[ el ]; - element.position.x = 0; - element.position.y = 0; - - switch ( element.alignH ) { - case "left": - element.position.x = 0; - break; - case "center": - element.position.x = -element.width / 2; - element.position.x += this.canvas.width / 2; - break; - case "right": - element.position.x = -element.width; - element.position.x += this.canvas.width; - break; - } - - switch ( element.alignV ) { - case "top": - element.position.y = 0; - break; - case "middle": - element.position.y = -element.height / 2; - element.position.y += this.canvas.height / 2; - break; - case "bottom": - element.position.y = -element.height; - element.position.y += this.canvas.height; - break; - } - - element.position.x += element.offsetH; - element.position.y += element.offsetV; - - if ( element.visible ) { - this.sortedElements.push( element ); - } - } - - this.globalPreDraw( context ); - this.sortedElements.sort( this.sortFunction ); - for ( var i = 0; i < this.sortedElements.length; i++ ) { - this.elementPreDraw( context, this.sortedElements[ i ] ); - this.sortedElements[ i ].preDraw( context, this.sortedElements[ i ].position ); - this.sortedElements[ i ].draw( context, this.sortedElements[ i ].position ); - this.sortedElements[ i ].postDraw( context, this.sortedElements[ i ].position ); - this.elementPostDraw( context, this.sortedElements[ i ] ); - } - this.globalPostDraw( context ); - - }, - - add: function( element, alignH, alignV, offsetH, offsetV ) { - - // Add the element to the HUD's elements list - // Initialize the offset position - this.elements[ element.id ] = element; - var newElement = this.elements[ element.id ]; - - newElement[ "offsetH" ] = isNaN( offsetH ) ? 0 : offsetH; - newElement[ "offsetV" ] = isNaN( offsetV ) ? 0 : offsetV; - - newElement[ "position" ] = { - "x": 0, - "y": 0 - } - - switch ( alignH ) { - case "left": - case "center": - case "right": - newElement[ "alignH" ] = alignH; - break; - default: - newElement[ "alignH" ] = "left"; - break; - } - - switch ( alignV ) { - case "top": - case "middle": - case "bottom": - newElement[ "alignV" ] = alignV; - break; - default: - newElement[ "alignV" ] = "top"; - break; - } - - this.countElements(); - newElement[ "drawOrder" ] = this.elementCount; - }, - - sortFunction: function( a, b ) { - return a.drawOrder - b.drawOrder; - }, - - remove: function( element ) { - var index = this.elements[ element.id ].drawOrder; - delete this.elements[ element.id ]; - - for ( var el in this.elements ) { - if ( this.elements[ el ].drawOrder > index ) { - this.elements[ el ].drawOrder--; - } - } - - this.countElements(); - }, - - countElements: function() { - var count = 0; - - for ( var el in this.elements ) { - count++; - } - - this.elementCount = count; - }, - - pick: function( event ) { - // Use sortedElements since they are all visible - var elements = this.sortedElements; - this.picks.length = 0; - // Loop backward to order picks from nearest to furthest - for ( var i = elements.length - 1; i >= 0; i-- ) { - var pos = elements[ i ].position; - var width = pos.x + elements[ i ].width; - var height = pos.y + elements[ i ].height; - - if ( event.clientX > pos.x && event.clientX < width && - event.clientY > pos.y && event.clientY < height ) { - - if ( elements[ i ].isMouseOver !== true ) { - elements[ i ].isMouseOver = true; - elements[ i ].onMouseOver( event ); - } - this.picks.push( elements[ i ] ); - - } else if ( elements[ i ].isMouseOver === true ) { - elements[ i ].isMouseOver = false; - elements[ i ].onMouseOut( event ); - } - } - }, - - registerEventListeners: function( gameCanvas ) { - var emptyEvent = function( event ) {}; - this.defaultHandlers.onClick = gameCanvas.onclick; - gameCanvas.onclick = emptyEvent; - gameCanvas.addEventListener( "click", this.handleEvent.bind( this ) ); - - this.defaultHandlers.onMouseUp = gameCanvas.onmouseup; - gameCanvas.onmouseup = emptyEvent; - gameCanvas.addEventListener( "mouseup", this.handleEvent.bind( this ) ); - - this.defaultHandlers.onMouseDown = gameCanvas.onmousedown; - gameCanvas.onmousedown = emptyEvent; - gameCanvas.addEventListener( "mousedown", this.handleEvent.bind( this ) ); - - this.defaultHandlers.onMouseMove = gameCanvas.onmousemove; - gameCanvas.onmousemove = emptyEvent; - gameCanvas.addEventListener( "mousemove", this.handleEvent.bind( this ) ); - }, - - handleEvent: function( event ) { - this.pick( event ); - var topPick = this.picks[ 0 ]; - var type; - - switch ( event.type ) { - case "click": - type = "onClick"; - break; - case "mouseup": - type = "onMouseUp"; - break; - case "mousedown": - type = "onMouseDown"; - break; - case "mousemove": - type = "onMouseMove"; - break; - default: - console.log( "HUD.handleEvent - Unhandled event type: " + event.type ); - return; - } - - if ( topPick ) { - if ( topPick.enabled ) { - this.elements[ topPick.id ][ type ]( event ); - } - } else if ( this.defaultHandlers[ type ] instanceof Function ) { - this.defaultHandlers[ type ]( event ); - } - }, - - moveToTop: function( id ) { - var index = this.elements[ id ].drawOrder; - for ( var el in this.elements ) { - if ( this.elements[ el ].drawOrder > index ) { - this.elements[ el ].drawOrder--; - } - } - this.elements[ id ].drawOrder = this.elementCount; - }, - - // Draw instructions that occur prior to the element's preDraw - // and draw functions. Executes on each element in the HUD. - elementPreDraw: function( context, element ) { }, - - // Draw instructions that occur after the element's draw and - // postDraw functions. Executes on each element in the HUD. - elementPostDraw: function( context, element ) { }, - - // Draw instructions that occur before anything is drawn to - // the HUD. - globalPreDraw: function( context ) { }, - - // Draw instructions that occur after everything is drawn to - // the HUD. - globalPostDraw: function( context ) { } - -} - -HUD.Element = function( id, drawFunc, width, height, visible ) { - this.initialize( id, drawFunc, width, height ); - return this; -} - -HUD.Element.prototype = { - constructor: HUD.Element, - id: undefined, - width: undefined, - height: undefined, - isMouseOver: undefined, - visible: undefined, - enabled: undefined, - - initialize: function( id, drawFunc, width, height, visible ) { - this.id = id; - - if ( drawFunc instanceof Function ) { - this.draw = drawFunc; - } - - this.width = isNaN( width ) ? 0 : width; - this.height = isNaN( height ) ? 0 : height; - - if ( visible === true || visible === undefined ) { - this.visible = true; - } else { - this.visible = false; - } - - this.enabled = true; - }, - - // Draw instructions for the element. Executes after the HUD's - // elementPreDraw funtion and the element's preDraw function. - draw: function( context, position ) { }, - - // Draw instructions that execute just befor the element's - // draw function. - preDraw: function( context, position ) { }, - - // Draw instructions that execute immediately after the element's - // draw function. - postDraw: function( context, position ) { }, - - onClick: function( event ) { }, - - onMouseDown: function( event ) { }, - - onMouseUp: function( event ) { }, - - onMouseMove: function( event ) { }, - - onMouseOver: function( event ) { }, - - onMouseOut: function( event ) { } - -} \ No newline at end of file From 44ec0a64528857ea1cdf5d4fb893485e5510b68a Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Tue, 17 Feb 2015 14:57:31 -0500 Subject: [PATCH 021/129] Re-add hud.js for renaming --- support/client/lib/vwf/model/hud/hud.js | 327 ++++++++++++++++++++++++ 1 file changed, 327 insertions(+) create mode 100644 support/client/lib/vwf/model/hud/hud.js diff --git a/support/client/lib/vwf/model/hud/hud.js b/support/client/lib/vwf/model/hud/hud.js new file mode 100644 index 000000000..92ab30681 --- /dev/null +++ b/support/client/lib/vwf/model/hud/hud.js @@ -0,0 +1,327 @@ +HUD = function() { + this.initialize(); + return this; +} + +HUD.prototype = { + constructor: HUD, + elements: undefined, + elementCount: undefined, + sortedElements: undefined, + picks: undefined, + canvas: undefined, + visible: undefined, + defaultHandlers: undefined, + + initialize: function() { + var gameCanvas = document.getElementById( vwf_view.kernel.application() ); + this.elements = {}; + this.elementCount = 0; + this.sortedElements = []; + this.picks = []; + this.canvas = document.createElement( "CANVAS" ); + this.canvas.id = "HUDCanvas"; + gameCanvas.parentElement.appendChild( this.canvas ); + this.visible = true; + this.update(); + this.defaultHandlers = {}; + this.registerEventListeners( gameCanvas ); + }, + + update: function() { + this.canvas.width = window.innerWidth; + this.canvas.height = window.innerHeight; + if ( this.visible ) { + this.draw(); + } + }, + + draw: function() { + var context = this.canvas.getContext( '2d' ); + this.sortedElements.length = 0; + + for ( var el in this.elements ) { + var element = this.elements[ el ]; + element.position.x = 0; + element.position.y = 0; + + switch ( element.alignH ) { + case "left": + element.position.x = 0; + break; + case "center": + element.position.x = -element.width / 2; + element.position.x += this.canvas.width / 2; + break; + case "right": + element.position.x = -element.width; + element.position.x += this.canvas.width; + break; + } + + switch ( element.alignV ) { + case "top": + element.position.y = 0; + break; + case "middle": + element.position.y = -element.height / 2; + element.position.y += this.canvas.height / 2; + break; + case "bottom": + element.position.y = -element.height; + element.position.y += this.canvas.height; + break; + } + + element.position.x += element.offsetH; + element.position.y += element.offsetV; + + if ( element.visible ) { + this.sortedElements.push( element ); + } + } + + this.globalPreDraw( context ); + this.sortedElements.sort( this.sortFunction ); + for ( var i = 0; i < this.sortedElements.length; i++ ) { + this.elementPreDraw( context, this.sortedElements[ i ] ); + this.sortedElements[ i ].preDraw( context, this.sortedElements[ i ].position ); + this.sortedElements[ i ].draw( context, this.sortedElements[ i ].position ); + this.sortedElements[ i ].postDraw( context, this.sortedElements[ i ].position ); + this.elementPostDraw( context, this.sortedElements[ i ] ); + } + this.globalPostDraw( context ); + + }, + + add: function( element, alignH, alignV, offsetH, offsetV ) { + + // Add the element to the HUD's elements list + // Initialize the offset position + this.elements[ element.id ] = element; + var newElement = this.elements[ element.id ]; + + newElement[ "offsetH" ] = isNaN( offsetH ) ? 0 : offsetH; + newElement[ "offsetV" ] = isNaN( offsetV ) ? 0 : offsetV; + + newElement[ "position" ] = { + "x": 0, + "y": 0 + } + + switch ( alignH ) { + case "left": + case "center": + case "right": + newElement[ "alignH" ] = alignH; + break; + default: + newElement[ "alignH" ] = "left"; + break; + } + + switch ( alignV ) { + case "top": + case "middle": + case "bottom": + newElement[ "alignV" ] = alignV; + break; + default: + newElement[ "alignV" ] = "top"; + break; + } + + this.countElements(); + newElement[ "drawOrder" ] = this.elementCount; + }, + + sortFunction: function( a, b ) { + return a.drawOrder - b.drawOrder; + }, + + remove: function( element ) { + var index = this.elements[ element.id ].drawOrder; + delete this.elements[ element.id ]; + + for ( var el in this.elements ) { + if ( this.elements[ el ].drawOrder > index ) { + this.elements[ el ].drawOrder--; + } + } + + this.countElements(); + }, + + countElements: function() { + var count = 0; + + for ( var el in this.elements ) { + count++; + } + + this.elementCount = count; + }, + + pick: function( event ) { + // Use sortedElements since they are all visible + var elements = this.sortedElements; + this.picks.length = 0; + // Loop backward to order picks from nearest to furthest + for ( var i = elements.length - 1; i >= 0; i-- ) { + var pos = elements[ i ].position; + var width = pos.x + elements[ i ].width; + var height = pos.y + elements[ i ].height; + + if ( event.clientX > pos.x && event.clientX < width && + event.clientY > pos.y && event.clientY < height ) { + + if ( elements[ i ].isMouseOver !== true ) { + elements[ i ].isMouseOver = true; + elements[ i ].onMouseOver( event ); + } + this.picks.push( elements[ i ] ); + + } else if ( elements[ i ].isMouseOver === true ) { + elements[ i ].isMouseOver = false; + elements[ i ].onMouseOut( event ); + } + } + }, + + registerEventListeners: function( gameCanvas ) { + var emptyEvent = function( event ) {}; + this.defaultHandlers.onClick = gameCanvas.onclick; + gameCanvas.onclick = emptyEvent; + gameCanvas.addEventListener( "click", this.handleEvent.bind( this ) ); + + this.defaultHandlers.onMouseUp = gameCanvas.onmouseup; + gameCanvas.onmouseup = emptyEvent; + gameCanvas.addEventListener( "mouseup", this.handleEvent.bind( this ) ); + + this.defaultHandlers.onMouseDown = gameCanvas.onmousedown; + gameCanvas.onmousedown = emptyEvent; + gameCanvas.addEventListener( "mousedown", this.handleEvent.bind( this ) ); + + this.defaultHandlers.onMouseMove = gameCanvas.onmousemove; + gameCanvas.onmousemove = emptyEvent; + gameCanvas.addEventListener( "mousemove", this.handleEvent.bind( this ) ); + }, + + handleEvent: function( event ) { + this.pick( event ); + var topPick = this.picks[ 0 ]; + var type; + + switch ( event.type ) { + case "click": + type = "onClick"; + break; + case "mouseup": + type = "onMouseUp"; + break; + case "mousedown": + type = "onMouseDown"; + break; + case "mousemove": + type = "onMouseMove"; + break; + default: + console.log( "HUD.handleEvent - Unhandled event type: " + event.type ); + return; + } + + if ( topPick ) { + if ( topPick.enabled ) { + this.elements[ topPick.id ][ type ]( event ); + } + } else if ( this.defaultHandlers[ type ] instanceof Function ) { + this.defaultHandlers[ type ]( event ); + } + }, + + moveToTop: function( id ) { + var index = this.elements[ id ].drawOrder; + for ( var el in this.elements ) { + if ( this.elements[ el ].drawOrder > index ) { + this.elements[ el ].drawOrder--; + } + } + this.elements[ id ].drawOrder = this.elementCount; + }, + + // Draw instructions that occur prior to the element's preDraw + // and draw functions. Executes on each element in the HUD. + elementPreDraw: function( context, element ) { }, + + // Draw instructions that occur after the element's draw and + // postDraw functions. Executes on each element in the HUD. + elementPostDraw: function( context, element ) { }, + + // Draw instructions that occur before anything is drawn to + // the HUD. + globalPreDraw: function( context ) { }, + + // Draw instructions that occur after everything is drawn to + // the HUD. + globalPostDraw: function( context ) { } + +} + +HUD.Element = function( id, drawFunc, width, height, visible ) { + this.initialize( id, drawFunc, width, height ); + return this; +} + +HUD.Element.prototype = { + constructor: HUD.Element, + id: undefined, + width: undefined, + height: undefined, + isMouseOver: undefined, + visible: undefined, + enabled: undefined, + + initialize: function( id, drawFunc, width, height, visible ) { + this.id = id; + + if ( drawFunc instanceof Function ) { + this.draw = drawFunc; + } + + this.width = isNaN( width ) ? 0 : width; + this.height = isNaN( height ) ? 0 : height; + + if ( visible === true || visible === undefined ) { + this.visible = true; + } else { + this.visible = false; + } + + this.enabled = true; + }, + + // Draw instructions for the element. Executes after the HUD's + // elementPreDraw funtion and the element's preDraw function. + draw: function( context, position ) { }, + + // Draw instructions that execute just befor the element's + // draw function. + preDraw: function( context, position ) { }, + + // Draw instructions that execute immediately after the element's + // draw function. + postDraw: function( context, position ) { }, + + onClick: function( event ) { }, + + onMouseDown: function( event ) { }, + + onMouseUp: function( event ) { }, + + onMouseMove: function( event ) { }, + + onMouseOver: function( event ) { }, + + onMouseOut: function( event ) { } + +} \ No newline at end of file From 56cef00ecd736fcb7eedacd1d5098370333c56bf Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Tue, 17 Feb 2015 15:11:09 -0500 Subject: [PATCH 022/129] Fix HUD export --- support/client/lib/vwf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/client/lib/vwf.js b/support/client/lib/vwf.js index 8c13bb75e..b024a6abd 100644 --- a/support/client/lib/vwf.js +++ b/support/client/lib/vwf.js @@ -324,7 +324,7 @@ deps: [ "vwf/model/blockly/blockly_compressed" ] }, "vwf/model/hud/hud": { - exports: "HUD2" + exports: "HUD" } } }; From 1a816da529cb3977abb77630b4cf3379f3ec1538 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Tue, 17 Feb 2015 16:33:47 -0500 Subject: [PATCH 023/129] Handle events --- support/client/lib/vwf/model/hud.js | 2 +- support/client/lib/vwf/view/hud.js | 21 +++++++++++++++++++ .../vwf.example.com/HUD/element.vwf.yaml | 6 ++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/support/client/lib/vwf/model/hud.js b/support/client/lib/vwf/model/hud.js index d26a86c9c..4f1de6d2f 100644 --- a/support/client/lib/vwf/model/hud.js +++ b/support/client/lib/vwf/model/hud.js @@ -126,7 +126,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili return undefined; } } - }, + } } ); diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js index 3a8033338..83c3a391e 100644 --- a/support/client/lib/vwf/view/hud.js +++ b/support/client/lib/vwf/view/hud.js @@ -99,14 +99,35 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( var drawFunction = function( context, position ) { eval( node.draw ) }; var element = new HUD.Element( node.name, drawFunction, props.width, props.height, props.visible ); var i, keys; + // Add custom properties to the element keys = Object.keys( drawProps ); for ( i = 0; i < keys.length; i++ ) { element[ keys[ i ] ] = drawProps[ keys[ i ] ]; } + // Add images to the element as properties keys = Object.keys( props.images ); for ( i = 0; i < keys.length; i++ ) { element[ keys[ i ] ] = props.images[ keys[ i ] ].value; } + // Add event listeners to the element + element.onClick = function( event ) { + vwf_view.kernel.fireEvent( node.id, "onClick" ); + }; + element.onMouseDown = function( event ) { + vwf_view.kernel.fireEvent( node.id, "onMouseDown" ); + }; + element.onMouseUp = function( event ) { + vwf_view.kernel.fireEvent( node.id, "onMouseUp" ); + }; + element.onMouseMove = function( event ) { + vwf_view.kernel.fireEvent( node.id, "onMouseMove" ); + }; + element.onMouseOver = function( event ) { + vwf_view.kernel.fireEvent( node.id, "onMouseOver" ); + }; + element.onMouseOut = function( event ) { + vwf_view.kernel.fireEvent( node.id, "onMouseOut" ); + }; return element; } diff --git a/support/proxy/vwf.example.com/HUD/element.vwf.yaml b/support/proxy/vwf.example.com/HUD/element.vwf.yaml index 9b4441dad..1dedcd70a 100644 --- a/support/proxy/vwf.example.com/HUD/element.vwf.yaml +++ b/support/proxy/vwf.example.com/HUD/element.vwf.yaml @@ -15,4 +15,10 @@ properties: methods: draw: events: + onClick: + onMouseDown: + onMouseUp: + onMouseMove: + onMouseOver: + onMouseOut: scripts: From 82933d87a78d69557d764ec23f26a879d8a7736b Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Tue, 17 Feb 2015 17:58:41 -0500 Subject: [PATCH 024/129] Properly handle empty image placeholders and extra properties --- support/client/lib/vwf/view/hud.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js index 83c3a391e..88e2f4bad 100644 --- a/support/client/lib/vwf/view/hud.js +++ b/support/client/lib/vwf/view/hud.js @@ -68,7 +68,7 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( node = this.state.elements[ nodeID ]; if ( propertyName === "images" ) { node.properties.images = loadImages( node, propertyValue ); - } else if ( node.drawProperties.hasOwnProperty( propertyName ) ) { + } else if ( node.initialized && node.drawProperties.hasOwnProperty( propertyName ) ) { node.viewObject[ propertyName ] = propertyValue; } } @@ -148,8 +148,14 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( // If the image property doesn't exist or the image hasn't been loaded or the image src // has changed, then we need to load the image. Otherwise, just copy the old image data if ( !oldImage || !( oldImage.value instanceof Image ) || oldImage.src !== newImage.src ) { - newImage.value = new Image(); - newImage.value.src = newImage.src; + if ( oldImage.value instanceof Image ) { + newImage.value = oldImage.value; + } else { + newImage.value = new Image(); + } + if ( newImage.src ) { + newImage.value.src = newImage.src; + } } else { newImage = oldImage; } From 816eb46fb062b7b48defdce4aadc6d4edab676ec Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 18 Feb 2015 10:39:52 -0500 Subject: [PATCH 025/129] Code cleanup --- support/client/lib/vwf/model/hud.js | 20 +++----------------- support/client/lib/vwf/view/hud.js | 22 ++++------------------ 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/support/client/lib/vwf/model/hud.js b/support/client/lib/vwf/model/hud.js index 4f1de6d2f..adf1b79c9 100644 --- a/support/client/lib/vwf/model/hud.js +++ b/support/client/lib/vwf/model/hud.js @@ -21,11 +21,9 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili creatingNode: function( nodeID, childID, childExtendsID, childImplementsIDs, childSource, childType, childIndex, childName, callback /* ( ready ) */ ) { - var node = undefined; + var node; var protos = getPrototypes.call( this, this.state.kernel, childExtendsID ); - if ( protos && isOverlay( protos ) ) { - node = this.state.overlays[ childID ] = { "id": childID, "name": childName, @@ -35,7 +33,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili }, "initialized": false }; - } else if ( protos && isElement( protos ) ) { node = this.state.elements[ childID ] = { "id": childID, @@ -56,8 +53,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili "initialized": false }; node.overlay.elements[ childID ] = node; - node.initialized = false; - } }, @@ -66,8 +61,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili }, initializingProperty: function( nodeID, propertyName, propertyValue ) { - var value = undefined; - + var value; if ( propertyValue !== undefined ) { var node = this.state.overlays[ nodeID ] || this.state.elements[ nodeID ] ; if ( node !== undefined ) { @@ -78,23 +72,18 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } } } - return value; }, settingProperty: function( nodeID, propertyName, propertyValue ) { var node, value; - if ( this.state.overlays[ nodeID ] ) { - node = this.state.overlays[ nodeID ]; if ( node.properties.hasOwnProperty( propertyName ) ) { node.properties[ propertyName ] = propertyValue; value = propertyValue; } - } else if ( this.state.elements[ nodeID ] ) { - node = this.state.elements[ nodeID ]; if ( node.properties.hasOwnProperty( propertyName ) ) { node.properties[ propertyName ] = propertyValue; @@ -102,7 +91,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili node.drawProperties[ propertyName ] = propertyValue; } value = propertyValue; - } return value; @@ -123,7 +111,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili if ( methodName === "draw" ) { this.logger.errorx( "callingMethod", "The draw method should not be called " + "from outside the HUD driver!" ); - return undefined; + return; } } } @@ -147,7 +135,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili foundOverlay = ( prototypes[i] == "http-vwf-example-com-hud-overlay-vwf" ); } } - return foundOverlay; } @@ -158,7 +145,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili foundElement = ( prototypes[i] == "http-vwf-example-com-hud-element-vwf" ); } } - return foundElement; } diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js index 88e2f4bad..6c2ea1d2e 100644 --- a/support/client/lib/vwf/view/hud.js +++ b/support/client/lib/vwf/view/hud.js @@ -1,14 +1,10 @@ "use strict"; -var debugHUD; - define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( module, model, utility, HUD ) { return model.load( module, { - initialize: function() { - this.runningOverlays = {}; - }, + initialize: function() {}, initializedNode: function( nodeID, childID, childExtendsID, childImplementsIDs, childSource, childType, childIndex, childName ) { @@ -27,7 +23,6 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( }, deletedNode: function( nodeID ) { - if ( this.state.overlays[ nodeID ] ) { var node, keys, i; node = this.state.overlays[ nodeID ]; @@ -38,7 +33,6 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( node = this.state.elements[ nodeID ]; delete this.state.elements[ nodeID ]; } - }, createdProperty: function( nodeID, propertyName, propertyValue ) { @@ -46,8 +40,7 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( }, initializedProperty: function( nodeID, propertyName, propertyValue ) { - var value = undefined; - + var value; if ( propertyValue !== undefined ) { var node = this.state.overlays[ nodeID ] || this.state.elements[ nodeID ] ; if ( node !== undefined ) { @@ -58,7 +51,6 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( } } } - return value; }, @@ -136,14 +128,6 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( var newImage, oldImage; for ( var i = 0; i < keys.length; i++ ) { newImage = images[ keys[ i ] ]; - if ( !newImage.hasOwnProperty( "src" ) ) { - logger.errorx( "loadImages", "Image \"" + keys[ i ] + "\" is malformed! It " + - "does not contain a \"src\" property! Skipping image load!" ); - continue; - } else if ( !newImage.hasOwnProperty( "value" ) ) { - logger.warnx( "loadImages", "Image \"" + keys[ i ] + "\" does not contain a " + - "\"value\" property! One will be generated automatically." ); - } oldImage = node.properties.images[ keys[ i ] ]; // If the image property doesn't exist or the image hasn't been loaded or the image src // has changed, then we need to load the image. Otherwise, just copy the old image data @@ -155,6 +139,8 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( } if ( newImage.src ) { newImage.value.src = newImage.src; + } else { + newImage.src = ""; } } else { newImage = oldImage; From c47478ed1854d3c4fb95ef72e748b0531fd66e8f Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 18 Feb 2015 16:57:03 -0500 Subject: [PATCH 026/129] Initialize empty image objects --- support/client/lib/vwf/view/hud.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js index 6c2ea1d2e..07bcc995b 100644 --- a/support/client/lib/vwf/view/hud.js +++ b/support/client/lib/vwf/view/hud.js @@ -127,7 +127,7 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( var keys = Object.keys( images ); var newImage, oldImage; for ( var i = 0; i < keys.length; i++ ) { - newImage = images[ keys[ i ] ]; + newImage = images[ keys[ i ] ] || {}; oldImage = node.properties.images[ keys[ i ] ]; // If the image property doesn't exist or the image hasn't been loaded or the image src // has changed, then we need to load the image. Otherwise, just copy the old image data From 6325240cb8300c0f743800053793532a5f05238b Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 18 Feb 2015 18:26:08 -0500 Subject: [PATCH 027/129] Added support for pre/post draw functions --- support/client/lib/vwf/model/hud.js | 42 +++++++++++++++++-- support/client/lib/vwf/model/hud/hud.js | 20 --------- support/client/lib/vwf/view/hud.js | 20 +++++++++ .../vwf.example.com/HUD/overlay.vwf.yaml | 4 ++ 4 files changed, 62 insertions(+), 24 deletions(-) diff --git a/support/client/lib/vwf/model/hud.js b/support/client/lib/vwf/model/hud.js index adf1b79c9..a665ab5f8 100644 --- a/support/client/lib/vwf/model/hud.js +++ b/support/client/lib/vwf/model/hud.js @@ -31,6 +31,10 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili "properties": { "visible": undefined }, + "elementPreDraw": undefined, + "elementPostDraw": undefined, + "globalPreDraw": undefined, + "globalPostDraw": undefined, "initialized": false }; } else if ( protos && isElement( protos ) ) { @@ -76,7 +80,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili }, settingProperty: function( nodeID, propertyName, propertyValue ) { - var node, value; + var node, value, images, keys, i, image; if ( this.state.overlays[ nodeID ] ) { node = this.state.overlays[ nodeID ]; if ( node.properties.hasOwnProperty( propertyName ) ) { @@ -86,7 +90,26 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } else if ( this.state.elements[ nodeID ] ) { node = this.state.elements[ nodeID ]; if ( node.properties.hasOwnProperty( propertyName ) ) { - node.properties[ propertyName ] = propertyValue; + if ( propertyName === "images" ) { + images = propertyValue; + keys = Object.keys( images ); + for ( i = 0; i < keys.length; i++ ) { + image = images[ keys[ i ] ]; + if ( !image ) { + image = {}; + } + if ( !image.hasOwnProperty( "src" ) ) { + image.src = undefined; + } + if ( !image.hasOwnProperty( "value" ) ) { + image.value = undefined; + } + images[ keys[ i ] ] = image; + } + node.properties.images = images; + } else { + node.properties[ propertyName ] = propertyValue; + } } else { node.drawProperties[ propertyName ] = propertyValue; } @@ -97,8 +120,19 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili }, creatingMethod: function( nodeID, methodName, methodParameters, methodBody ) { - if ( this.state.elements[ nodeID ] ) { - var node = this.state.elements[ nodeID ]; + var node; + if ( this.state.overlays[ nodeID ] ) { + node = this.state.overlays[ nodeID ]; + switch ( methodName ) { + case "elementPreDraw": + case "elementPostDraw": + case "globalPreDraw": + case "globalPostDraw": + node[ methodName ] = methodBody; + break; + } + } else if ( this.state.elements[ nodeID ] ) { + node = this.state.elements[ nodeID ]; if ( methodName === "draw" ) { node.draw = methodBody; } diff --git a/support/client/lib/vwf/model/hud/hud.js b/support/client/lib/vwf/model/hud/hud.js index 92ab30681..0e533f7ec 100644 --- a/support/client/lib/vwf/model/hud/hud.js +++ b/support/client/lib/vwf/model/hud/hud.js @@ -85,9 +85,7 @@ HUD.prototype = { this.sortedElements.sort( this.sortFunction ); for ( var i = 0; i < this.sortedElements.length; i++ ) { this.elementPreDraw( context, this.sortedElements[ i ] ); - this.sortedElements[ i ].preDraw( context, this.sortedElements[ i ].position ); this.sortedElements[ i ].draw( context, this.sortedElements[ i ].position ); - this.sortedElements[ i ].postDraw( context, this.sortedElements[ i ].position ); this.elementPostDraw( context, this.sortedElements[ i ] ); } this.globalPostDraw( context ); @@ -249,20 +247,12 @@ HUD.prototype = { this.elements[ id ].drawOrder = this.elementCount; }, - // Draw instructions that occur prior to the element's preDraw - // and draw functions. Executes on each element in the HUD. elementPreDraw: function( context, element ) { }, - // Draw instructions that occur after the element's draw and - // postDraw functions. Executes on each element in the HUD. elementPostDraw: function( context, element ) { }, - // Draw instructions that occur before anything is drawn to - // the HUD. globalPreDraw: function( context ) { }, - // Draw instructions that occur after everything is drawn to - // the HUD. globalPostDraw: function( context ) { } } @@ -300,18 +290,8 @@ HUD.Element.prototype = { this.enabled = true; }, - // Draw instructions for the element. Executes after the HUD's - // elementPreDraw funtion and the element's preDraw function. draw: function( context, position ) { }, - // Draw instructions that execute just befor the element's - // draw function. - preDraw: function( context, position ) { }, - - // Draw instructions that execute immediately after the element's - // draw function. - postDraw: function( context, position ) { }, - onClick: function( event ) { }, onMouseDown: function( event ) { }, diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js index 07bcc995b..6af5cb826 100644 --- a/support/client/lib/vwf/view/hud.js +++ b/support/client/lib/vwf/view/hud.js @@ -82,6 +82,26 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( props = element.properties; overlay.add( element.viewObject, props.alignH, props.alignV, props.offsetH, props.offsetV ); } + if ( node.elementPreDraw ) { + overlay.elementPreDraw = function( context, element ) { + eval( node.elementPreDraw ) + } + } + if ( node.elementPostDraw ) { + overlay.elementPostDraw = function( context, element ) { + eval( node.elementPostDraw ) + } + } + if ( node.globalPreDraw ) { + overlay.globalPreDraw = function( context ) { + eval( node.globalPreDraw ) + } + } + if ( node.globalPostDraw ) { + overlay.globalPostDraw = function( context ) { + eval( node.globalPostDraw ) + } + } return overlay; } diff --git a/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml b/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml index 84e0dbd32..182fd4ca5 100644 --- a/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml +++ b/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml @@ -2,5 +2,9 @@ extends: http://vwf.example.com/node.vwf properties: visible: true methods: + elementPreDraw: + elementPostDraw: + globalPreDraw: + globalPostDraw: events: scripts: From 24c184276bb0b3cc7c6e438007fafae59f51431a Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Thu, 19 Feb 2015 16:55:22 -0500 Subject: [PATCH 028/129] Fixed bugs with images --- support/client/lib/vwf/model/hud.js | 52 +++++++++------ support/client/lib/vwf/view/hud.js | 64 +++++++++++-------- .../vwf.example.com/HUD/element.vwf.yaml | 4 -- .../vwf.example.com/HUD/overlay.vwf.yaml | 2 - 4 files changed, 73 insertions(+), 49 deletions(-) diff --git a/support/client/lib/vwf/model/hud.js b/support/client/lib/vwf/model/hud.js index a665ab5f8..0511569f7 100644 --- a/support/client/lib/vwf/model/hud.js +++ b/support/client/lib/vwf/model/hud.js @@ -91,22 +91,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili node = this.state.elements[ nodeID ]; if ( node.properties.hasOwnProperty( propertyName ) ) { if ( propertyName === "images" ) { - images = propertyValue; - keys = Object.keys( images ); - for ( i = 0; i < keys.length; i++ ) { - image = images[ keys[ i ] ]; - if ( !image ) { - image = {}; - } - if ( !image.hasOwnProperty( "src" ) ) { - image.src = undefined; - } - if ( !image.hasOwnProperty( "value" ) ) { - image.value = undefined; - } - images[ keys[ i ] ] = image; - } - node.properties.images = images; + node.properties.images = propertyValue; } else { node.properties[ propertyName ] = propertyValue; } @@ -119,6 +104,24 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili return value; }, + gettingProperty: function( nodeID, propertyName ) { + var node, value; + if ( this.state.overlays[ nodeID ] ) { + node = this.state.overlays[ nodeID ]; + if ( node.properties.hasOwnProperty( propertyName ) ) { + value = node.properties[ propertyName ]; + } + } else if ( this.state.elements[ nodeID ] ) { + node = this.state.elements[ nodeID ]; + if ( node.properties.hasOwnProperty( propertyName ) ) { + value = node.properties[ propertyName ]; + } else if ( node.drawProperties.hasOwnProperty( propertyName ) ) { + value = node.drawProperties[ propertyName ]; + } + } + return value; + }, + creatingMethod: function( nodeID, methodName, methodParameters, methodBody ) { var node; if ( this.state.overlays[ nodeID ] ) { @@ -140,8 +143,21 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili }, callingMethod: function( nodeID, methodName, methodParameters, methodValue ) { - if ( this.state.elements[ nodeID ] ) { - var node = this.state.elements[ nodeID ]; + var node; + if ( this.state.overlays[ nodeID ] ) { + node = this.state.overlays[ nodeID ]; + switch ( methodName ) { + case "elementPreDraw": + case "elementPostDraw": + case "globalPreDraw": + case "globalPostDraw": + this.logger.errorx( "callingMethod", "The " + methodName + " method should not " + + "be called from outside the HUD driver!" ); + return; + break; + } + } else if ( this.state.elements[ nodeID ] ) { + node = this.state.elements[ nodeID ]; if ( methodName === "draw" ) { this.logger.errorx( "callingMethod", "The draw method should not be called " + "from outside the HUD driver!" ); diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js index 6af5cb826..ba8041e1c 100644 --- a/support/client/lib/vwf/view/hud.js +++ b/support/client/lib/vwf/view/hud.js @@ -56,14 +56,25 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( satProperty: function( nodeID, propertyName, propertyValue ) { var value, node; - if ( this.state.elements[ nodeID ] ) { + if ( this.state.overlays[ nodeID ] ) { + node = this.state.overlays[ nodeID ]; + if ( node.initialized && node.properties.hasOwnProperty( propertyName ) ) { + node.viewObject[ propertyName ] = propertyValue; + } + value = propertyValue; + } else if ( this.state.elements[ nodeID ] ) { node = this.state.elements[ nodeID ]; if ( propertyName === "images" ) { - node.properties.images = loadImages( node, propertyValue ); + value = propertyValue; + if ( node.initialized ) { + updateImages( node, propertyValue ); + } } else if ( node.initialized && node.drawProperties.hasOwnProperty( propertyName ) ) { node.viewObject[ propertyName ] = propertyValue; + value = propertyValue; } } + return value; } } ); @@ -110,16 +121,17 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( var drawProps = node.drawProperties; var drawFunction = function( context, position ) { eval( node.draw ) }; var element = new HUD.Element( node.name, drawFunction, props.width, props.height, props.visible ); - var i, keys; + var i, keys, images; // Add custom properties to the element keys = Object.keys( drawProps ); for ( i = 0; i < keys.length; i++ ) { element[ keys[ i ] ] = drawProps[ keys[ i ] ]; } // Add images to the element as properties - keys = Object.keys( props.images ); + images = loadImages( node ); + keys = Object.keys( images ); for ( i = 0; i < keys.length; i++ ) { - element[ keys[ i ] ] = props.images[ keys[ i ] ].value; + element[ keys[ i ] ] = images[ keys[ i ] ]; } // Add event listeners to the element element.onClick = function( event ) { @@ -143,30 +155,32 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( return element; } - function loadImages( node, images ) { + function loadImages( node ) { + var images = node.properties.images; var keys = Object.keys( images ); - var newImage, oldImage; + var image, src; + var results = {}; for ( var i = 0; i < keys.length; i++ ) { - newImage = images[ keys[ i ] ] || {}; - oldImage = node.properties.images[ keys[ i ] ]; - // If the image property doesn't exist or the image hasn't been loaded or the image src - // has changed, then we need to load the image. Otherwise, just copy the old image data - if ( !oldImage || !( oldImage.value instanceof Image ) || oldImage.src !== newImage.src ) { - if ( oldImage.value instanceof Image ) { - newImage.value = oldImage.value; - } else { - newImage.value = new Image(); - } - if ( newImage.src ) { - newImage.value.src = newImage.src; - } else { - newImage.src = ""; - } - } else { - newImage = oldImage; + image = new Image(); + src = images[ keys[ i ] ]; + if ( src ) { + image.src = src; + } + results[ keys[ i ] ] = image; + } + return results; + } + + function updateImages( node, images ) { + var keys = Object.keys( images ); + var newImageSrc, oldImage; + for ( var i = 0; i < keys.length; i++ ) { + newImageSrc = images[ keys[ i ] ]; + oldImage = node.viewObject[ keys[ i ] ]; + if ( newImageSrc && oldImage instanceof Image && newImageSrc !== oldImage.src ) { + oldImage.src = newImageSrc; } } - return images; } } ); \ No newline at end of file diff --git a/support/proxy/vwf.example.com/HUD/element.vwf.yaml b/support/proxy/vwf.example.com/HUD/element.vwf.yaml index 1dedcd70a..992d2d9dd 100644 --- a/support/proxy/vwf.example.com/HUD/element.vwf.yaml +++ b/support/proxy/vwf.example.com/HUD/element.vwf.yaml @@ -1,9 +1,6 @@ extends: http://vwf.example.com/node.vwf properties: images: - # image: - # src: - # value: width: height: visible: @@ -21,4 +18,3 @@ events: onMouseMove: onMouseOver: onMouseOut: -scripts: diff --git a/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml b/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml index 182fd4ca5..6394ba501 100644 --- a/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml +++ b/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml @@ -6,5 +6,3 @@ methods: elementPostDraw: globalPreDraw: globalPostDraw: -events: -scripts: From 3848f5e50a57b338afd087ff04ef28775cfcbb80 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Thu, 19 Feb 2015 17:16:13 -0500 Subject: [PATCH 029/129] Moved hud.js to view folder and removed global reference --- support/client/lib/vwf/model/hud/hud.js | 307 ----------------------- support/client/lib/vwf/view/hud.js | 2 +- support/client/lib/vwf/view/hud/hud.js | 313 ++++++++++++++++++++++++ 3 files changed, 314 insertions(+), 308 deletions(-) delete mode 100644 support/client/lib/vwf/model/hud/hud.js create mode 100644 support/client/lib/vwf/view/hud/hud.js diff --git a/support/client/lib/vwf/model/hud/hud.js b/support/client/lib/vwf/model/hud/hud.js deleted file mode 100644 index 0e533f7ec..000000000 --- a/support/client/lib/vwf/model/hud/hud.js +++ /dev/null @@ -1,307 +0,0 @@ -HUD = function() { - this.initialize(); - return this; -} - -HUD.prototype = { - constructor: HUD, - elements: undefined, - elementCount: undefined, - sortedElements: undefined, - picks: undefined, - canvas: undefined, - visible: undefined, - defaultHandlers: undefined, - - initialize: function() { - var gameCanvas = document.getElementById( vwf_view.kernel.application() ); - this.elements = {}; - this.elementCount = 0; - this.sortedElements = []; - this.picks = []; - this.canvas = document.createElement( "CANVAS" ); - this.canvas.id = "HUDCanvas"; - gameCanvas.parentElement.appendChild( this.canvas ); - this.visible = true; - this.update(); - this.defaultHandlers = {}; - this.registerEventListeners( gameCanvas ); - }, - - update: function() { - this.canvas.width = window.innerWidth; - this.canvas.height = window.innerHeight; - if ( this.visible ) { - this.draw(); - } - }, - - draw: function() { - var context = this.canvas.getContext( '2d' ); - this.sortedElements.length = 0; - - for ( var el in this.elements ) { - var element = this.elements[ el ]; - element.position.x = 0; - element.position.y = 0; - - switch ( element.alignH ) { - case "left": - element.position.x = 0; - break; - case "center": - element.position.x = -element.width / 2; - element.position.x += this.canvas.width / 2; - break; - case "right": - element.position.x = -element.width; - element.position.x += this.canvas.width; - break; - } - - switch ( element.alignV ) { - case "top": - element.position.y = 0; - break; - case "middle": - element.position.y = -element.height / 2; - element.position.y += this.canvas.height / 2; - break; - case "bottom": - element.position.y = -element.height; - element.position.y += this.canvas.height; - break; - } - - element.position.x += element.offsetH; - element.position.y += element.offsetV; - - if ( element.visible ) { - this.sortedElements.push( element ); - } - } - - this.globalPreDraw( context ); - this.sortedElements.sort( this.sortFunction ); - for ( var i = 0; i < this.sortedElements.length; i++ ) { - this.elementPreDraw( context, this.sortedElements[ i ] ); - this.sortedElements[ i ].draw( context, this.sortedElements[ i ].position ); - this.elementPostDraw( context, this.sortedElements[ i ] ); - } - this.globalPostDraw( context ); - - }, - - add: function( element, alignH, alignV, offsetH, offsetV ) { - - // Add the element to the HUD's elements list - // Initialize the offset position - this.elements[ element.id ] = element; - var newElement = this.elements[ element.id ]; - - newElement[ "offsetH" ] = isNaN( offsetH ) ? 0 : offsetH; - newElement[ "offsetV" ] = isNaN( offsetV ) ? 0 : offsetV; - - newElement[ "position" ] = { - "x": 0, - "y": 0 - } - - switch ( alignH ) { - case "left": - case "center": - case "right": - newElement[ "alignH" ] = alignH; - break; - default: - newElement[ "alignH" ] = "left"; - break; - } - - switch ( alignV ) { - case "top": - case "middle": - case "bottom": - newElement[ "alignV" ] = alignV; - break; - default: - newElement[ "alignV" ] = "top"; - break; - } - - this.countElements(); - newElement[ "drawOrder" ] = this.elementCount; - }, - - sortFunction: function( a, b ) { - return a.drawOrder - b.drawOrder; - }, - - remove: function( element ) { - var index = this.elements[ element.id ].drawOrder; - delete this.elements[ element.id ]; - - for ( var el in this.elements ) { - if ( this.elements[ el ].drawOrder > index ) { - this.elements[ el ].drawOrder--; - } - } - - this.countElements(); - }, - - countElements: function() { - var count = 0; - - for ( var el in this.elements ) { - count++; - } - - this.elementCount = count; - }, - - pick: function( event ) { - // Use sortedElements since they are all visible - var elements = this.sortedElements; - this.picks.length = 0; - // Loop backward to order picks from nearest to furthest - for ( var i = elements.length - 1; i >= 0; i-- ) { - var pos = elements[ i ].position; - var width = pos.x + elements[ i ].width; - var height = pos.y + elements[ i ].height; - - if ( event.clientX > pos.x && event.clientX < width && - event.clientY > pos.y && event.clientY < height ) { - - if ( elements[ i ].isMouseOver !== true ) { - elements[ i ].isMouseOver = true; - elements[ i ].onMouseOver( event ); - } - this.picks.push( elements[ i ] ); - - } else if ( elements[ i ].isMouseOver === true ) { - elements[ i ].isMouseOver = false; - elements[ i ].onMouseOut( event ); - } - } - }, - - registerEventListeners: function( gameCanvas ) { - var emptyEvent = function( event ) {}; - this.defaultHandlers.onClick = gameCanvas.onclick; - gameCanvas.onclick = emptyEvent; - gameCanvas.addEventListener( "click", this.handleEvent.bind( this ) ); - - this.defaultHandlers.onMouseUp = gameCanvas.onmouseup; - gameCanvas.onmouseup = emptyEvent; - gameCanvas.addEventListener( "mouseup", this.handleEvent.bind( this ) ); - - this.defaultHandlers.onMouseDown = gameCanvas.onmousedown; - gameCanvas.onmousedown = emptyEvent; - gameCanvas.addEventListener( "mousedown", this.handleEvent.bind( this ) ); - - this.defaultHandlers.onMouseMove = gameCanvas.onmousemove; - gameCanvas.onmousemove = emptyEvent; - gameCanvas.addEventListener( "mousemove", this.handleEvent.bind( this ) ); - }, - - handleEvent: function( event ) { - this.pick( event ); - var topPick = this.picks[ 0 ]; - var type; - - switch ( event.type ) { - case "click": - type = "onClick"; - break; - case "mouseup": - type = "onMouseUp"; - break; - case "mousedown": - type = "onMouseDown"; - break; - case "mousemove": - type = "onMouseMove"; - break; - default: - console.log( "HUD.handleEvent - Unhandled event type: " + event.type ); - return; - } - - if ( topPick ) { - if ( topPick.enabled ) { - this.elements[ topPick.id ][ type ]( event ); - } - } else if ( this.defaultHandlers[ type ] instanceof Function ) { - this.defaultHandlers[ type ]( event ); - } - }, - - moveToTop: function( id ) { - var index = this.elements[ id ].drawOrder; - for ( var el in this.elements ) { - if ( this.elements[ el ].drawOrder > index ) { - this.elements[ el ].drawOrder--; - } - } - this.elements[ id ].drawOrder = this.elementCount; - }, - - elementPreDraw: function( context, element ) { }, - - elementPostDraw: function( context, element ) { }, - - globalPreDraw: function( context ) { }, - - globalPostDraw: function( context ) { } - -} - -HUD.Element = function( id, drawFunc, width, height, visible ) { - this.initialize( id, drawFunc, width, height ); - return this; -} - -HUD.Element.prototype = { - constructor: HUD.Element, - id: undefined, - width: undefined, - height: undefined, - isMouseOver: undefined, - visible: undefined, - enabled: undefined, - - initialize: function( id, drawFunc, width, height, visible ) { - this.id = id; - - if ( drawFunc instanceof Function ) { - this.draw = drawFunc; - } - - this.width = isNaN( width ) ? 0 : width; - this.height = isNaN( height ) ? 0 : height; - - if ( visible === true || visible === undefined ) { - this.visible = true; - } else { - this.visible = false; - } - - this.enabled = true; - }, - - draw: function( context, position ) { }, - - onClick: function( event ) { }, - - onMouseDown: function( event ) { }, - - onMouseUp: function( event ) { }, - - onMouseMove: function( event ) { }, - - onMouseOver: function( event ) { }, - - onMouseOut: function( event ) { } - -} \ No newline at end of file diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js index ba8041e1c..e1e9f1f51 100644 --- a/support/client/lib/vwf/view/hud.js +++ b/support/client/lib/vwf/view/hud.js @@ -1,6 +1,6 @@ "use strict"; -define( [ "module", "vwf/model", "vwf/utility", "vwf/model/hud/hud" ], function( module, model, utility, HUD ) { +define( [ "module", "vwf/model", "vwf/utility", "vwf/view/hud/hud" ], function( module, model, utility, HUD ) { return model.load( module, { diff --git a/support/client/lib/vwf/view/hud/hud.js b/support/client/lib/vwf/view/hud/hud.js new file mode 100644 index 000000000..fa9bb232a --- /dev/null +++ b/support/client/lib/vwf/view/hud/hud.js @@ -0,0 +1,313 @@ +define( function() { + + var HUD = function() { + this.initialize(); + return this; + } + + HUD.prototype = { + constructor: HUD, + elements: undefined, + elementCount: undefined, + sortedElements: undefined, + picks: undefined, + canvas: undefined, + visible: undefined, + defaultHandlers: undefined, + + initialize: function() { + var gameCanvas = document.getElementById( vwf_view.kernel.application() ); + this.elements = {}; + this.elementCount = 0; + this.sortedElements = []; + this.picks = []; + this.canvas = document.createElement( "CANVAS" ); + this.canvas.id = "HUDCanvas"; + gameCanvas.parentElement.appendChild( this.canvas ); + this.visible = true; + this.update(); + this.defaultHandlers = {}; + this.registerEventListeners( gameCanvas ); + }, + + update: function() { + this.canvas.width = window.innerWidth; + this.canvas.height = window.innerHeight; + if ( this.visible ) { + this.draw(); + } + }, + + draw: function() { + var context = this.canvas.getContext( '2d' ); + this.sortedElements.length = 0; + + for ( var el in this.elements ) { + var element = this.elements[ el ]; + element.position.x = 0; + element.position.y = 0; + + switch ( element.alignH ) { + case "left": + element.position.x = 0; + break; + case "center": + element.position.x = -element.width / 2; + element.position.x += this.canvas.width / 2; + break; + case "right": + element.position.x = -element.width; + element.position.x += this.canvas.width; + break; + } + + switch ( element.alignV ) { + case "top": + element.position.y = 0; + break; + case "middle": + element.position.y = -element.height / 2; + element.position.y += this.canvas.height / 2; + break; + case "bottom": + element.position.y = -element.height; + element.position.y += this.canvas.height; + break; + } + + element.position.x += element.offsetH; + element.position.y += element.offsetV; + + if ( element.visible ) { + this.sortedElements.push( element ); + } + } + + this.globalPreDraw( context ); + this.sortedElements.sort( this.sortFunction ); + for ( var i = 0; i < this.sortedElements.length; i++ ) { + this.elementPreDraw( context, this.sortedElements[ i ] ); + this.sortedElements[ i ].draw( context, this.sortedElements[ i ].position ); + this.elementPostDraw( context, this.sortedElements[ i ] ); + } + this.globalPostDraw( context ); + + }, + + add: function( element, alignH, alignV, offsetH, offsetV ) { + + // Add the element to the HUD's elements list + // Initialize the offset position + this.elements[ element.id ] = element; + var newElement = this.elements[ element.id ]; + + newElement[ "offsetH" ] = isNaN( offsetH ) ? 0 : offsetH; + newElement[ "offsetV" ] = isNaN( offsetV ) ? 0 : offsetV; + + newElement[ "position" ] = { + "x": 0, + "y": 0 + } + + switch ( alignH ) { + case "left": + case "center": + case "right": + newElement[ "alignH" ] = alignH; + break; + default: + newElement[ "alignH" ] = "left"; + break; + } + + switch ( alignV ) { + case "top": + case "middle": + case "bottom": + newElement[ "alignV" ] = alignV; + break; + default: + newElement[ "alignV" ] = "top"; + break; + } + + this.countElements(); + newElement[ "drawOrder" ] = this.elementCount; + }, + + sortFunction: function( a, b ) { + return a.drawOrder - b.drawOrder; + }, + + remove: function( element ) { + var index = this.elements[ element.id ].drawOrder; + delete this.elements[ element.id ]; + + for ( var el in this.elements ) { + if ( this.elements[ el ].drawOrder > index ) { + this.elements[ el ].drawOrder--; + } + } + + this.countElements(); + }, + + countElements: function() { + var count = 0; + + for ( var el in this.elements ) { + count++; + } + + this.elementCount = count; + }, + + pick: function( event ) { + // Use sortedElements since they are all visible + var elements = this.sortedElements; + this.picks.length = 0; + // Loop backward to order picks from nearest to furthest + for ( var i = elements.length - 1; i >= 0; i-- ) { + var pos = elements[ i ].position; + var width = pos.x + elements[ i ].width; + var height = pos.y + elements[ i ].height; + + if ( event.clientX > pos.x && event.clientX < width && + event.clientY > pos.y && event.clientY < height ) { + + if ( elements[ i ].isMouseOver !== true ) { + elements[ i ].isMouseOver = true; + elements[ i ].onMouseOver( event ); + } + this.picks.push( elements[ i ] ); + + } else if ( elements[ i ].isMouseOver === true ) { + elements[ i ].isMouseOver = false; + elements[ i ].onMouseOut( event ); + } + } + }, + + registerEventListeners: function( gameCanvas ) { + var emptyEvent = function( event ) {}; + this.defaultHandlers.onClick = gameCanvas.onclick; + gameCanvas.onclick = emptyEvent; + gameCanvas.addEventListener( "click", this.handleEvent.bind( this ) ); + + this.defaultHandlers.onMouseUp = gameCanvas.onmouseup; + gameCanvas.onmouseup = emptyEvent; + gameCanvas.addEventListener( "mouseup", this.handleEvent.bind( this ) ); + + this.defaultHandlers.onMouseDown = gameCanvas.onmousedown; + gameCanvas.onmousedown = emptyEvent; + gameCanvas.addEventListener( "mousedown", this.handleEvent.bind( this ) ); + + this.defaultHandlers.onMouseMove = gameCanvas.onmousemove; + gameCanvas.onmousemove = emptyEvent; + gameCanvas.addEventListener( "mousemove", this.handleEvent.bind( this ) ); + }, + + handleEvent: function( event ) { + this.pick( event ); + var topPick = this.picks[ 0 ]; + var type; + + switch ( event.type ) { + case "click": + type = "onClick"; + break; + case "mouseup": + type = "onMouseUp"; + break; + case "mousedown": + type = "onMouseDown"; + break; + case "mousemove": + type = "onMouseMove"; + break; + default: + console.log( "HUD.handleEvent - Unhandled event type: " + event.type ); + return; + } + + if ( topPick ) { + if ( topPick.enabled ) { + this.elements[ topPick.id ][ type ]( event ); + } + } else if ( this.defaultHandlers[ type ] instanceof Function ) { + this.defaultHandlers[ type ]( event ); + } + }, + + moveToTop: function( id ) { + var index = this.elements[ id ].drawOrder; + for ( var el in this.elements ) { + if ( this.elements[ el ].drawOrder > index ) { + this.elements[ el ].drawOrder--; + } + } + this.elements[ id ].drawOrder = this.elementCount; + }, + + elementPreDraw: function( context, element ) { }, + + elementPostDraw: function( context, element ) { }, + + globalPreDraw: function( context ) { }, + + globalPostDraw: function( context ) { } + + } + + HUD.Element = function( id, drawFunc, width, height, visible ) { + this.initialize( id, drawFunc, width, height ); + return this; + } + + HUD.Element.prototype = { + constructor: HUD.Element, + id: undefined, + width: undefined, + height: undefined, + isMouseOver: undefined, + visible: undefined, + enabled: undefined, + + initialize: function( id, drawFunc, width, height, visible ) { + this.id = id; + + if ( drawFunc instanceof Function ) { + this.draw = drawFunc; + } + + this.width = isNaN( width ) ? 0 : width; + this.height = isNaN( height ) ? 0 : height; + + if ( visible === true || visible === undefined ) { + this.visible = true; + } else { + this.visible = false; + } + + this.enabled = true; + }, + + draw: function( context, position ) { }, + + onClick: function( event ) { }, + + onMouseDown: function( event ) { }, + + onMouseUp: function( event ) { }, + + onMouseMove: function( event ) { }, + + onMouseOver: function( event ) { }, + + onMouseOut: function( event ) { } + + } + + return HUD; + +} ); \ No newline at end of file From 9a21ae0545fa5007d956ee4378e6bc84e31fd05a Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Fri, 20 Feb 2015 13:29:00 -0500 Subject: [PATCH 030/129] Allow an element to have no images --- support/client/lib/vwf/view/hud.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js index e1e9f1f51..ee776fbed 100644 --- a/support/client/lib/vwf/view/hud.js +++ b/support/client/lib/vwf/view/hud.js @@ -128,10 +128,12 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/view/hud/hud" ], function( element[ keys[ i ] ] = drawProps[ keys[ i ] ]; } // Add images to the element as properties - images = loadImages( node ); - keys = Object.keys( images ); - for ( i = 0; i < keys.length; i++ ) { - element[ keys[ i ] ] = images[ keys[ i ] ]; + if ( props.images ) { + images = loadImages( node ); + keys = Object.keys( images ); + for ( i = 0; i < keys.length; i++ ) { + element[ keys[ i ] ] = images[ keys[ i ] ]; + } } // Add event listeners to the element element.onClick = function( event ) { From d1e3782862688f306b0d7d9b404a4a37edc766e8 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Fri, 20 Feb 2015 13:53:47 -0500 Subject: [PATCH 031/129] Fix setting properties on elements --- support/client/lib/vwf/view/hud.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js index ee776fbed..e7e2e6b10 100644 --- a/support/client/lib/vwf/view/hud.js +++ b/support/client/lib/vwf/view/hud.js @@ -64,15 +64,15 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/view/hud/hud" ], function( value = propertyValue; } else if ( this.state.elements[ nodeID ] ) { node = this.state.elements[ nodeID ]; - if ( propertyName === "images" ) { - value = propertyValue; - if ( node.initialized ) { + if ( node.initialized ) { + if ( propertyName === "images" ) { updateImages( node, propertyValue ); + } else if ( node.properties.hasOwnProperty( propertyName ) || + node.drawProperties.hasOwnProperty( propertyName ) ) { + node.viewObject[ propertyName ] = propertyValue; } - } else if ( node.initialized && node.drawProperties.hasOwnProperty( propertyName ) ) { - node.viewObject[ propertyName ] = propertyValue; - value = propertyValue; } + value = propertyValue; } return value; } From 8762eb20247015c9814787a517d91bc148ac86dd Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Fri, 20 Feb 2015 18:40:26 -0500 Subject: [PATCH 032/129] Set draw functions after initialize to allow them to be defined in external scripts --- support/client/lib/vwf/model/hud.js | 20 -------- support/client/lib/vwf/view/hud.js | 71 ++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 42 deletions(-) diff --git a/support/client/lib/vwf/model/hud.js b/support/client/lib/vwf/model/hud.js index 0511569f7..d57f62a6b 100644 --- a/support/client/lib/vwf/model/hud.js +++ b/support/client/lib/vwf/model/hud.js @@ -122,26 +122,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili return value; }, - creatingMethod: function( nodeID, methodName, methodParameters, methodBody ) { - var node; - if ( this.state.overlays[ nodeID ] ) { - node = this.state.overlays[ nodeID ]; - switch ( methodName ) { - case "elementPreDraw": - case "elementPostDraw": - case "globalPreDraw": - case "globalPostDraw": - node[ methodName ] = methodBody; - break; - } - } else if ( this.state.elements[ nodeID ] ) { - node = this.state.elements[ nodeID ]; - if ( methodName === "draw" ) { - node.draw = methodBody; - } - } - }, - callingMethod: function( nodeID, methodName, methodParameters, methodValue ) { var node; if ( this.state.overlays[ nodeID ] ) { diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js index e7e2e6b10..272b6d089 100644 --- a/support/client/lib/vwf/view/hud.js +++ b/support/client/lib/vwf/view/hud.js @@ -75,6 +75,54 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/view/hud/hud" ], function( value = propertyValue; } return value; + }, + + createdMethod: function( nodeID, methodName, methodParameters, methodBody ) { + var node; + if ( this.state.overlays[ nodeID ] ) { + node = this.state.overlays[ nodeID ]; + switch ( methodName ) { + case "elementPreDraw": + case "elementPostDraw": + case "globalPreDraw": + case "globalPostDraw": + this.kernel.getMethod( nodeID, methodName ); + break; + } + } else if ( this.state.elements[ nodeID ] ) { + node = this.state.elements[ nodeID ]; + if ( methodName === "draw" ) { + this.kernel.getMethod( nodeID, "draw" ); + } + } + }, + + gotMethod: function( nodeID, methodName, methodHandler ) { + var node; + if ( this.state.overlays[ nodeID ] ) { + node = this.state.overlays[ nodeID ]; + switch ( methodName ) { + case "elementPreDraw": + case "elementPostDraw": + node.viewObject[ methodName ] = function( context, element ) { + eval( methodHandler.body ); + }; + break; + case "globalPreDraw": + case "globalPostDraw": + node.viewObject[ methodName ] = function( context ) { + eval( methodHandler.body ); + }; + break; + } + } else if ( this.state.elements[ nodeID ] ) { + node = this.state.elements[ nodeID ]; + if ( methodName === "draw" ) { + node.viewObject[ methodName ] = function( context, position ) { + eval( methodHandler.body ); + }; + } + } } } ); @@ -93,34 +141,13 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/view/hud/hud" ], function( props = element.properties; overlay.add( element.viewObject, props.alignH, props.alignV, props.offsetH, props.offsetV ); } - if ( node.elementPreDraw ) { - overlay.elementPreDraw = function( context, element ) { - eval( node.elementPreDraw ) - } - } - if ( node.elementPostDraw ) { - overlay.elementPostDraw = function( context, element ) { - eval( node.elementPostDraw ) - } - } - if ( node.globalPreDraw ) { - overlay.globalPreDraw = function( context ) { - eval( node.globalPreDraw ) - } - } - if ( node.globalPostDraw ) { - overlay.globalPostDraw = function( context ) { - eval( node.globalPostDraw ) - } - } return overlay; } function createElement( node ) { var props = node.properties; var drawProps = node.drawProperties; - var drawFunction = function( context, position ) { eval( node.draw ) }; - var element = new HUD.Element( node.name, drawFunction, props.width, props.height, props.visible ); + var element = new HUD.Element( node.name, undefined, props.width, props.height, props.visible ); var i, keys, images; // Add custom properties to the element keys = Object.keys( drawProps ); From 8efddd9e830bfe6f770e55b418a41d28df56b66d Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Sun, 15 Feb 2015 21:13:54 -0500 Subject: [PATCH 033/129] Got the jPlayer driver to load... --- support/client/lib/vwf.js | 2 + support/client/lib/vwf/view/jPlayer.js | 71 ++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100755 support/client/lib/vwf/view/jPlayer.js diff --git a/support/client/lib/vwf.js b/support/client/lib/vwf.js index b024a6abd..03f998ab1 100644 --- a/support/client/lib/vwf.js +++ b/support/client/lib/vwf.js @@ -411,6 +411,7 @@ { library: "vwf/view/cesium", active: false }, { library: "vwf/view/kineticjs", active: false }, { library: "vwf/view/mil-sym", active: false }, + { library: "vwf/view/jPlayer", linkedLibraries: ["vwf/model/jPlayer.2.7.1/jquery.jplayer.min"], active: false }, { library: "vwf/view/audio", active: false }, { library: "vwf/kernel/utility", active: true }, { library: "vwf/utility", active: true }, @@ -469,6 +470,7 @@ { library: "vwf/view/touch", active: false }, { library: "vwf/view/kineticjs", active: false }, { library: "vwf/view/mil-sym", active: false }, + { library: "vwf/view/jPlayer", active: false }, { library: "vwf/view/audio", active: false }, { library: "vwf/view/webrtc", active: false} ] diff --git a/support/client/lib/vwf/view/jPlayer.js b/support/client/lib/vwf/view/jPlayer.js new file mode 100755 index 000000000..8144e518c --- /dev/null +++ b/support/client/lib/vwf/view/jPlayer.js @@ -0,0 +1,71 @@ +/// vwf/view/jPlayer.js is a sound/video driver +/// +/// @module vwf/model/jPlayer +/// @requires vwf/model + +define( [ + "module", + "vwf/view", + "jquery" + ], function( module, view, $ ) { + return view.load( module, { + createdProperty: function (nodeID, propertyName, propertyValue) { + this.satProperty(nodeID, propertyName, propertyValue); + }, + + initializedProperty: function ( nodeID, propertyName, propertyValue ) { + this.satProperty(nodeID, propertyName, propertyValue); + }, + + calledMethod: function( nodeID, methodName, methodParameters, methodValue ) { + var node = this.state.nodes[nodeID]; + + if( node ){ + var containerSelector = "#" + node.containerDivId; + var playerSelector = "#" + node.playerDivId; + + switch ( methodName ){ + //We cannot safely call .show() or .hide() on the jPlayer div + //See http://jplayer.org/latest/developer-guide/#jPlayer-disable-by-css + case "show": + var contX = node.containerSize[0]; + var contY = node.containerSize[1]; + var playerX = node.playerSize[0]; + var playerY = node.playerSize[1]; + + $( containerSelector ).css('width', contX); + $( containerSelector ).css('height', contY); + $( playerSelector ).css('width', playerX); + $( playerSelector ).css('height', playerY); + break; + + case "hide": + $( containerSelector ).css('width', 0); + $( containerSelector ).css('height', 0); + $( playerSelector ).css('width', 0); + $( playerSelector ).css('height', 0); + break; + } + } + }, + + satProperty: function ( nodeID, propertyName, propertyValue ) { + var node = this.state.nodes[nodeID]; + if( node && propertyValue ){ + switch( propertyName ){ + case "z_index": + var containerSelector = "#" + node.containerDivId; + $(containerSelector).css('z-index', propertyValue); + break; + case "containerDivSize": + node.containerDivSize = propertyValue; + break; + case "playerDivSize": + node.playerDivSize = propertyValue; + break; + } + } + } + }); + } +); \ No newline at end of file From c2d1e24d19a0972a6b6ea24563e8e533f27cd2b9 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Sun, 15 Feb 2015 21:18:58 -0500 Subject: [PATCH 034/129] Got the new videoManager dropped in. Doesn't break TDG. --- .../vwf.example.com/jplayer/videoManager.vwf.yaml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml index dd8c6dd7c..a688233d2 100644 --- a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml +++ b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml @@ -6,8 +6,14 @@ properties: loop: false containerDivId: "videoContainer" playerDivId: "videoScreen" + containerSize: [ 1024, 768 ] + playerSize: [1024, 768] methods: - play: + play: pause: - stop: - \ No newline at end of file + stop: + show: + hide: + clearMedia: +events: + videoEnded: \ No newline at end of file From 577d6e74564c429c4a531c2979efde5a04100d3b Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Sun, 15 Feb 2015 22:04:39 -0500 Subject: [PATCH 035/129] Got the changes to the jPlayer model driver merged in. It loads and nothing breaks horifically. --- support/client/lib/vwf/model/jPlayer.js | 41 +++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 6debc886e..7aa082296 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -1,4 +1,4 @@ -/// vwf/model/jPlayer.js is a sound driver +/// vwf/model/jPlayer.js is a sound/video driver /// /// @module vwf/model/jPlayer /// @requires vwf/model @@ -203,6 +203,7 @@ define( [ setLoop( node, propertyValue ); value = node.loop; break; + case "playerDivId": if ( propertyValue === node.playerDivId ) { break; @@ -233,8 +234,14 @@ define( [ setControlDivId( node, node.containerDivId ); } }, - supplied: fileTypes + supplied: fileTypes, + // size: { width: node.playmoderDivSize[0], height: node.playerDivSize[1] } } ); + + if ( node.playerDivId ) { + $( "#" + node.playerDivId ).bind($.jPlayer.event.ended, videoEndedCallback ); + } + value = node.playerDivId; break; case "containerDivId": @@ -245,6 +252,14 @@ define( [ setPosterImageUrl( node, propertyValue ); value = node.posterImageUrl; break; + case "playerSize": + setPlayerSize( node, propertyValue ); + value = node.playerSize; + break; + case "containerSize": + setContainerSize( node, propertyValue ); + value = node.containerSize; + break; default: break; } @@ -334,6 +349,9 @@ define( [ node.jPlayerElement.jPlayer( "stop" ); break; + case "clearMedia": + node.jPlayerElement.jPlayer( "clearMedia" ); + break; } } @@ -342,6 +360,13 @@ define( [ } ); + function videoEndedCallback(){ + var mediaManagerID = vwf.find( undefined, "/mediaManager" )[ 0 ]; + var videoManagerID = vwf.find( mediaManagerID, "videoManager" ) [ 0 ]; + console.log("Video ended callback in driver fired!"); + vwf.fireEvent(videoManagerID, "videoEnded"); + } + function getPrototypes( kernel, extendsID ) { var prototypes = []; var id = extendsID; @@ -403,7 +428,7 @@ define( [ } break; case "video": - if ( url.search( "data:video/mp4" ) === 0 ) { + if ( url.search( "data:video/mp4" ) === 0 || url.search( ".mp4$" ) > -1 ) { mediaObject = { m4v: url, poster: node.posterImageUrl @@ -454,4 +479,14 @@ define( [ } ); } } + + function setPlayerSize( node, playerSize ){ + node.playerSize = playerSize; + node.jPlayerElement.jPlayer( "option", "size", {width: playerSize[0], height: playerSize[1]}); + } + + function setContainerSize( node, containerSize ){ + node.containerSize = containerSize; + } + } ); From 72dd773dffe067440899e325e7838e7fc8dad456 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Tue, 17 Feb 2015 12:08:32 -0500 Subject: [PATCH 036/129] Removed unnecessary method which sets z-index. --- support/client/lib/vwf/view/jPlayer.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/support/client/lib/vwf/view/jPlayer.js b/support/client/lib/vwf/view/jPlayer.js index 8144e518c..834b78b3c 100755 --- a/support/client/lib/vwf/view/jPlayer.js +++ b/support/client/lib/vwf/view/jPlayer.js @@ -53,10 +53,6 @@ define( [ var node = this.state.nodes[nodeID]; if( node && propertyValue ){ switch( propertyName ){ - case "z_index": - var containerSelector = "#" + node.containerDivId; - $(containerSelector).css('z-index', propertyValue); - break; case "containerDivSize": node.containerDivSize = propertyValue; break; From 47fb8fbe7eaae4aa60e8e112074b9f700bd0ffd8 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Tue, 17 Feb 2015 12:42:20 -0500 Subject: [PATCH 037/129] Debugged calling "play" along with passing in the URL. --- support/client/lib/vwf/model/jPlayer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 7aa082296..ba956ea3c 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -338,6 +338,10 @@ define( [ switch( methodName ) { case "play": + + if( methodParameters ){ + vwf.setProperty( node.ID, "url", methodParameters ); + } node.jPlayerElement.jPlayer( "play" ); break; From a46f39a01a431fd7f908f09deda6e1abe98c029d Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Thu, 19 Feb 2015 13:35:14 -0500 Subject: [PATCH 038/129] Got more stuff using "vwf." rather than this.kernel. --- support/client/lib/vwf/model/jPlayer.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index ba956ea3c..ddc164a47 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -67,7 +67,13 @@ define( [ } } return found; - } + }, + "videoEndedCallback" : function() { + var mediaManagerID = modelDriver.kernel.find( undefined, "/mediaManager" )[ 0 ]; + var videoManagerID = modelDriver.kernel.find( mediaManagerID, "videoManager" ) [ 0 ]; + console.log("Video ended callback in driver fired!"); + modelDriver.kernel.fireEvent(videoManagerID, "videoEnded"); + }, }; // turns on logger debugger console messages @@ -239,7 +245,7 @@ define( [ } ); if ( node.playerDivId ) { - $( "#" + node.playerDivId ).bind($.jPlayer.event.ended, videoEndedCallback ); + $( "#" + node.playerDivId ).bind($.jPlayer.event.ended, this.state.videoEndedCallback ); } value = node.playerDivId; @@ -316,7 +322,6 @@ define( [ return node && node[ propertyName ]; }, - // TODO: deletingMethod // -- callingMethod -------------------------------------------------------------------------- @@ -340,7 +345,7 @@ define( [ case "play": if( methodParameters ){ - vwf.setProperty( node.ID, "url", methodParameters ); + this.kernel.setProperty( node.ID, "url", methodParameters ); } node.jPlayerElement.jPlayer( "play" ); break; @@ -364,12 +369,12 @@ define( [ } ); - function videoEndedCallback(){ - var mediaManagerID = vwf.find( undefined, "/mediaManager" )[ 0 ]; - var videoManagerID = vwf.find( mediaManagerID, "videoManager" ) [ 0 ]; - console.log("Video ended callback in driver fired!"); - vwf.fireEvent(videoManagerID, "videoEnded"); - } + // function videoEndedCallback(){ + // var mediaManagerID = this.kernel.kernel.find( undefined, "/mediaManager" )[ 0 ]; + // var videoManagerID = this.kernel.kernel.find( mediaManagerID, "videoManager" ) [ 0 ]; + // console.log("Video ended callback in driver fired!"); + // this.kernel.fireEvent(videoManagerID, "videoEnded"); + // } function getPrototypes( kernel, extendsID ) { var prototypes = []; From 79c42a1821dee6b637f6abc5c1e89d3fd845b705 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Thu, 19 Feb 2015 13:51:23 -0500 Subject: [PATCH 039/129] Now it appears that we can inject divs dynamically? --- support/client/lib/vwf/model/jPlayer.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index ddc164a47..4fc2e4ede 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -22,6 +22,15 @@ define( [ // -- initialize --------------------------------------------------------------------------- initialize: function( options ) { + + var containerDiv = document.createElement( 'div' ); + containerDiv.id = "jp_container_1"; + containerDiv.className = "jp-video jp-video-360p"; + var playerDiv = document.createElement( 'div' ); + playerDiv.id = "jquery_jplayer_1"; + playerDiv.className = "jp-jplayer"; + containerDiv.appendChild( playerDiv ); + $( "body" ).append(containerDiv); modelDriver = this; From ad8fdbdcac4b6e7a843ff92952c9e4422f346790 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Thu, 19 Feb 2015 19:29:32 -0500 Subject: [PATCH 040/129] Div injection now works (I think?) --- support/client/lib/vwf/model/jPlayer.js | 37 ++++++++++++++----- .../jplayer/videoManager.vwf.yaml | 4 +- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 4fc2e4ede..fad17b353 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -12,8 +12,9 @@ define( [ var modelDriver; var jPlayerInstanceCreated = false; - var audioManagerProtoId = "http://vwf.example.com/jplayer/audioManager.vwf"; - var videoManagerProtoId = "http://vwf.example.com/jplayer/videoManager.vwf"; + var audioManagerProtoId = "http-vwf-example-com-jplayer-audioManager-vwf"; + var videoManagerProtoId = "http-vwf-example-com-jplayer-videoManager-vwf"; + var jplayerContainerId = "jp_container_1"; return model.load( module, { @@ -24,7 +25,7 @@ define( [ initialize: function( options ) { var containerDiv = document.createElement( 'div' ); - containerDiv.id = "jp_container_1"; + containerDiv.id = jplayerContainerId; containerDiv.className = "jp-video jp-video-360p"; var playerDiv = document.createElement( 'div' ); playerDiv.id = "jquery_jplayer_1"; @@ -231,10 +232,26 @@ define( [ if ( $existingElement.length ) { node.jPlayerElement = $existingElement; } else { - node.jPlayerElement = $( "
", { - id: node.playerDivId - } ); - $( "body" ).append( node.jPlayerElement ); + //Change the existing element to match the new name + var playerDiv = document.createElement( 'div' ); + playerDiv.id = node.playerDivId; + if( node.containerDivId ){ + // playerDiv.className = "jp-jplayer"; + $( "#" + node.containerDivId ).append( playerDiv ); + } else { + $("#jp_container_1").append( playerDiv ); + } + node.jPlayerElement = $( "#" + node.playerDivId ); + + // $( "#" + jplayerContainerId ).jPlayer("option", "cssSelectorAncestor", "#" + node.playerDivId); + // $( "#" + jplayerContainerId ).attr( "id", node.playerDivId ); + // jplayerContainerId = node.playerDivId; + + // node.jPlayerElement = $( "#" + node.playerDivId ); + // node.jPlayerElement = $( "
", { + // id: node.playerDivId + // } ); + // $( "body" ).append( node.jPlayerElement ); } var fileTypes = ( node.managerType === "audio" ) ? "mp3,wav" : "m4v"; node.jPlayerElement.jPlayer( { @@ -483,9 +500,9 @@ define( [ function setControlDivId( node, containerDivId ) { node.containerDivId = containerDivId; - if ( node.jPlayerElement ) { - node.jPlayerElement.jPlayer( "option", { cssSelectorAncestor: "#" + containerDivId } ); - } + // if ( node.jPlayerElement ) { + // node.jPlayerElement.jPlayer( "option", { cssSelectorAncestor: "#" + containerDivId } ); + // } } function setPosterImageUrl( node, posterImageUrl ) { diff --git a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml index a688233d2..a8b203c63 100644 --- a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml +++ b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml @@ -4,8 +4,10 @@ properties: url: posterImageUrl: loop: false - containerDivId: "videoContainer" + containerDivId: "jp_container_1" playerDivId: "videoScreen" + # containerDivId: "videoContainer" + # playerDivId: "videoScreen" containerSize: [ 1024, 768 ] playerSize: [1024, 768] methods: From d8af39b564a8ef20d6b3a076db46ada569ade6db Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Thu, 19 Feb 2015 19:34:43 -0500 Subject: [PATCH 041/129] Changed default names of jPlayer div container and player container BACK so that TDG doesn't break! --- support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml index a8b203c63..a688233d2 100644 --- a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml +++ b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml @@ -4,10 +4,8 @@ properties: url: posterImageUrl: loop: false - containerDivId: "jp_container_1" + containerDivId: "videoContainer" playerDivId: "videoScreen" - # containerDivId: "videoContainer" - # playerDivId: "videoScreen" containerSize: [ 1024, 768 ] playerSize: [1024, 768] methods: From 26751b4e613ecd237656239ffa871c600a24d96e Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Fri, 20 Feb 2015 12:15:19 -0500 Subject: [PATCH 042/129] Corrected tabs vs spaces in the view driver. --- support/client/lib/vwf/view/jPlayer.js | 10 +++++----- .../vwf.example.com/jplayer/videoManager.vwf.yaml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/support/client/lib/vwf/view/jPlayer.js b/support/client/lib/vwf/view/jPlayer.js index 834b78b3c..389b3f590 100755 --- a/support/client/lib/vwf/view/jPlayer.js +++ b/support/client/lib/vwf/view/jPlayer.js @@ -8,7 +8,7 @@ define( [ "vwf/view", "jquery" ], function( module, view, $ ) { - return view.load( module, { + return view.load( module, { createdProperty: function (nodeID, propertyName, propertyValue) { this.satProperty(nodeID, propertyName, propertyValue); }, @@ -49,7 +49,7 @@ define( [ } }, - satProperty: function ( nodeID, propertyName, propertyValue ) { + satProperty: function ( nodeID, propertyName, propertyValue ) { var node = this.state.nodes[nodeID]; if( node && propertyValue ){ switch( propertyName ){ @@ -61,7 +61,7 @@ define( [ break; } } - } - }); + } + }); } -); \ No newline at end of file +); diff --git a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml index a688233d2..d22358976 100644 --- a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml +++ b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml @@ -7,7 +7,7 @@ properties: containerDivId: "videoContainer" playerDivId: "videoScreen" containerSize: [ 1024, 768 ] - playerSize: [1024, 768] + playerSize: [ 1024, 768 ] methods: play: pause: From a055a030403129c0d854d4bd59c8920cd6cedf5e Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Tue, 24 Feb 2015 15:18:27 -0500 Subject: [PATCH 043/129] Fixed HUD prototype test --- support/client/lib/vwf/model/hud.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/support/client/lib/vwf/model/hud.js b/support/client/lib/vwf/model/hud.js index d57f62a6b..f41dd4590 100644 --- a/support/client/lib/vwf/model/hud.js +++ b/support/client/lib/vwf/model/hud.js @@ -162,7 +162,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili var foundOverlay = false; if ( prototypes ) { for ( var i = 0; i < prototypes.length && !foundOverlay; i++ ) { - foundOverlay = ( prototypes[i] == "http-vwf-example-com-hud-overlay-vwf" ); + foundOverlay = ( prototypes[i] == "http://vwf.example.com/hud/overlay.vwf" ); } } return foundOverlay; @@ -172,7 +172,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili var foundElement = false; if ( prototypes ) { for ( var i = 0; i < prototypes.length && !foundElement; i++ ) { - foundElement = ( prototypes[i] == "http-vwf-example-com-hud-element-vwf" ); + foundElement = ( prototypes[i] == "http://vwf.example.com/hud/element.vwf" ); } } return foundElement; From f7dc38d1aa97598d9dd9bc77bcc89b5d0b9a4ce8 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 25 Feb 2015 16:08:27 -0500 Subject: [PATCH 044/129] Fix prototype ids for jPlayer --- support/client/lib/vwf/model/jPlayer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index fad17b353..857e5d044 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -12,8 +12,8 @@ define( [ var modelDriver; var jPlayerInstanceCreated = false; - var audioManagerProtoId = "http-vwf-example-com-jplayer-audioManager-vwf"; - var videoManagerProtoId = "http-vwf-example-com-jplayer-videoManager-vwf"; + var audioManagerProtoId = "http://vwf.example.com/jplayer/audioManager.vwf"; + var videoManagerProtoId = "http://vwf.example.com/jplayer/videoManager.vwf"; var jplayerContainerId = "jp_container_1"; return model.load( module, { From d9b22f3a5b7508909c2ec0883e6011db61547c2e Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 25 Feb 2015 16:17:19 -0500 Subject: [PATCH 045/129] Delete HUD components for renaming --- .../vwf.example.com/HUD/element.vwf.yaml | 20 ------------------- .../vwf.example.com/HUD/overlay.vwf.yaml | 8 -------- 2 files changed, 28 deletions(-) delete mode 100644 support/proxy/vwf.example.com/HUD/element.vwf.yaml delete mode 100644 support/proxy/vwf.example.com/HUD/overlay.vwf.yaml diff --git a/support/proxy/vwf.example.com/HUD/element.vwf.yaml b/support/proxy/vwf.example.com/HUD/element.vwf.yaml deleted file mode 100644 index 992d2d9dd..000000000 --- a/support/proxy/vwf.example.com/HUD/element.vwf.yaml +++ /dev/null @@ -1,20 +0,0 @@ -extends: http://vwf.example.com/node.vwf -properties: - images: - width: - height: - visible: - enabled: - alignH: - alignV: - offsetH: - offsetV: -methods: - draw: -events: - onClick: - onMouseDown: - onMouseUp: - onMouseMove: - onMouseOver: - onMouseOut: diff --git a/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml b/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml deleted file mode 100644 index 6394ba501..000000000 --- a/support/proxy/vwf.example.com/HUD/overlay.vwf.yaml +++ /dev/null @@ -1,8 +0,0 @@ -extends: http://vwf.example.com/node.vwf -properties: - visible: true -methods: - elementPreDraw: - elementPostDraw: - globalPreDraw: - globalPostDraw: From 09eff1463076a6c4ed201c8a9161121f25d1fe18 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 25 Feb 2015 16:17:39 -0500 Subject: [PATCH 046/129] Add hud components with renamed directory --- .../vwf.example.com/hud/element.vwf.yaml | 20 +++++++++++++++++++ .../vwf.example.com/hud/overlay.vwf.yaml | 8 ++++++++ 2 files changed, 28 insertions(+) create mode 100644 support/proxy/vwf.example.com/hud/element.vwf.yaml create mode 100644 support/proxy/vwf.example.com/hud/overlay.vwf.yaml diff --git a/support/proxy/vwf.example.com/hud/element.vwf.yaml b/support/proxy/vwf.example.com/hud/element.vwf.yaml new file mode 100644 index 000000000..992d2d9dd --- /dev/null +++ b/support/proxy/vwf.example.com/hud/element.vwf.yaml @@ -0,0 +1,20 @@ +extends: http://vwf.example.com/node.vwf +properties: + images: + width: + height: + visible: + enabled: + alignH: + alignV: + offsetH: + offsetV: +methods: + draw: +events: + onClick: + onMouseDown: + onMouseUp: + onMouseMove: + onMouseOver: + onMouseOut: diff --git a/support/proxy/vwf.example.com/hud/overlay.vwf.yaml b/support/proxy/vwf.example.com/hud/overlay.vwf.yaml new file mode 100644 index 000000000..6394ba501 --- /dev/null +++ b/support/proxy/vwf.example.com/hud/overlay.vwf.yaml @@ -0,0 +1,8 @@ +extends: http://vwf.example.com/node.vwf +properties: + visible: true +methods: + elementPreDraw: + elementPostDraw: + globalPreDraw: + globalPostDraw: From e2335a65ce74e0148eabd322c2f5aec916f6ef2e Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Fri, 27 Feb 2015 16:25:34 -0500 Subject: [PATCH 047/129] Add information to element events --- support/client/lib/vwf/view/hud.js | 36 +++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js index 272b6d089..6d79b4870 100644 --- a/support/client/lib/vwf/view/hud.js +++ b/support/client/lib/vwf/view/hud.js @@ -164,22 +164,46 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/view/hud/hud" ], function( } // Add event listeners to the element element.onClick = function( event ) { - vwf_view.kernel.fireEvent( node.id, "onClick" ); + var elementMousePosition = { + "x": event.clientX - this.position.x, + "y": event.clientY - this.position.y + }; + vwf_view.kernel.fireEvent( node.id, "onClick", [ elementMousePosition ] ); }; element.onMouseDown = function( event ) { - vwf_view.kernel.fireEvent( node.id, "onMouseDown" ); + var elementMousePosition = { + "x": event.clientX - this.position.x, + "y": event.clientY - this.position.y + }; + vwf_view.kernel.fireEvent( node.id, "onMouseDown", [ elementMousePosition ] ); }; element.onMouseUp = function( event ) { - vwf_view.kernel.fireEvent( node.id, "onMouseUp" ); + var elementMousePosition = { + "x": event.clientX - this.position.x, + "y": event.clientY - this.position.y + }; + vwf_view.kernel.fireEvent( node.id, "onMouseUp", [ elementMousePosition ] ); }; element.onMouseMove = function( event ) { - vwf_view.kernel.fireEvent( node.id, "onMouseMove" ); + var elementMousePosition = { + "x": event.clientX - this.position.x, + "y": event.clientY - this.position.y + }; + vwf_view.kernel.fireEvent( node.id, "onMouseMove", [ elementMousePosition ] ); }; element.onMouseOver = function( event ) { - vwf_view.kernel.fireEvent( node.id, "onMouseOver" ); + var elementMousePosition = { + "x": event.clientX - this.position.x, + "y": event.clientY - this.position.y + }; + vwf_view.kernel.fireEvent( node.id, "onMouseOver", [ elementMousePosition ] ); }; element.onMouseOut = function( event ) { - vwf_view.kernel.fireEvent( node.id, "onMouseOut" ); + var elementMousePosition = { + "x": event.clientX - this.position.x, + "y": event.clientY - this.position.y + }; + vwf_view.kernel.fireEvent( node.id, "onMouseOut", [ elementMousePosition ] ); }; return element; } From 1a46caa10b2d7c5f67d4e047e485e1cb71d6227e Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Thu, 19 Feb 2015 19:29:32 -0500 Subject: [PATCH 048/129] Div injection now works (I think?) --- support/client/lib/vwf/model/jPlayer.js | 4 ++-- support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 857e5d044..fad17b353 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -12,8 +12,8 @@ define( [ var modelDriver; var jPlayerInstanceCreated = false; - var audioManagerProtoId = "http://vwf.example.com/jplayer/audioManager.vwf"; - var videoManagerProtoId = "http://vwf.example.com/jplayer/videoManager.vwf"; + var audioManagerProtoId = "http-vwf-example-com-jplayer-audioManager-vwf"; + var videoManagerProtoId = "http-vwf-example-com-jplayer-videoManager-vwf"; var jplayerContainerId = "jp_container_1"; return model.load( module, { diff --git a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml index d22358976..2f6c0cc2c 100644 --- a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml +++ b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml @@ -4,8 +4,10 @@ properties: url: posterImageUrl: loop: false - containerDivId: "videoContainer" + containerDivId: "jp_container_1" playerDivId: "videoScreen" + # containerDivId: "videoContainer" + # playerDivId: "videoScreen" containerSize: [ 1024, 768 ] playerSize: [ 1024, 768 ] methods: From 96efc5448da87276e1de7d0cd4868a767ca8860d Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Thu, 26 Feb 2015 18:18:13 -0500 Subject: [PATCH 049/129] Instead of creating a new mediaObject for every case of file format, we now create a single mediaObject and augment as necessary. --- support/client/lib/vwf/model/jPlayer.js | 26 ++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index fad17b353..ba1ae4ec2 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -446,17 +446,19 @@ define( [ if ( url ) { // Construct the media object based on the type of file being passed in - var mediaObject; + var mediaObject = {}; switch ( node.managerType ) { case "audio": if ( url.search( "data:audio/mp3" ) === 0 ) { - mediaObject = { - mp3: url - }; + medaObject.mp3 = url; + // mediaObject = { + // mp3: url + // }; } else if ( url.search( "data:audio/wav" ) === 0 ) { - mediaObject = { - wav: url - }; + mediaObject.wav = url; + // mediaObject = { + // wav: url + // }; } else { modelDriver.logger.errorx( "setUrl", "Unsupported sound type for '", url, "'" ); @@ -464,10 +466,12 @@ define( [ break; case "video": if ( url.search( "data:video/mp4" ) === 0 || url.search( ".mp4$" ) > -1 ) { - mediaObject = { - m4v: url, - poster: node.posterImageUrl - }; + mediaObject.poster = node.posterImageUrl; + mediaObject.m4v = url; + // mediaObject = { + // m4v: url, + // poster: node.posterImageUrl + // }; } else { modelDriver.logger.errorx( "setUrl", "Unsupported video type for '", url, "'" ); From 654f7eb5b296e12079fc4db29640dab02f3b57b2 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Fri, 27 Feb 2015 00:39:39 -0500 Subject: [PATCH 050/129] Beginnings of consuming an array of video input URLs is there... --- support/client/lib/vwf/model/jPlayer.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index ba1ae4ec2..06f9e011d 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -257,7 +257,7 @@ define( [ node.jPlayerElement.jPlayer( { ready: function() { if ( node.url !== undefined ) { - setUrl( node, node.url ); + setUrl( node, [ node.url ] ); } if ( node.loop !== undefined ) { setLoop( node, node.loop ); @@ -432,7 +432,8 @@ define( [ } } - function setUrl( node, url ) { + function setUrl( node, urlArray ) { + var url = urlArray[ 0 ]; node.url = url; // If there is no jPlayerElement, there is nothing to do yet so we return. @@ -449,16 +450,11 @@ define( [ var mediaObject = {}; switch ( node.managerType ) { case "audio": + //TODO: Support multiple URLs for audio. if ( url.search( "data:audio/mp3" ) === 0 ) { medaObject.mp3 = url; - // mediaObject = { - // mp3: url - // }; } else if ( url.search( "data:audio/wav" ) === 0 ) { mediaObject.wav = url; - // mediaObject = { - // wav: url - // }; } else { modelDriver.logger.errorx( "setUrl", "Unsupported sound type for '", url, "'" ); @@ -468,10 +464,6 @@ define( [ if ( url.search( "data:video/mp4" ) === 0 || url.search( ".mp4$" ) > -1 ) { mediaObject.poster = node.posterImageUrl; mediaObject.m4v = url; - // mediaObject = { - // m4v: url, - // poster: node.posterImageUrl - // }; } else { modelDriver.logger.errorx( "setUrl", "Unsupported video type for '", url, "'" ); From 5768c4122f8dcafb4c0c733c14dab8f5b8c3163f Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Fri, 27 Feb 2015 01:05:19 -0500 Subject: [PATCH 051/129] Adding multi-format support appears to work! --- support/client/lib/vwf/model/jPlayer.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 06f9e011d..39baa179e 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -253,11 +253,11 @@ define( [ // } ); // $( "body" ).append( node.jPlayerElement ); } - var fileTypes = ( node.managerType === "audio" ) ? "mp3,wav" : "m4v"; + var fileTypes = ( node.managerType === "audio" ) ? "mp3,wav" : "m4v,webmv"; node.jPlayerElement.jPlayer( { ready: function() { if ( node.url !== undefined ) { - setUrl( node, [ node.url ] ); + setUrl( node, node.url ); } if ( node.loop !== undefined ) { setLoop( node, node.loop ); @@ -461,12 +461,16 @@ define( [ } break; case "video": - if ( url.search( "data:video/mp4" ) === 0 || url.search( ".mp4$" ) > -1 ) { - mediaObject.poster = node.posterImageUrl; - mediaObject.m4v = url; - } else { - modelDriver.logger.errorx( "setUrl", - "Unsupported video type for '", url, "'" ); + mediaObject.poster = node.posterImageUrl; + for( var i = 0; i < urlArray.length; i++ ){ + if ( url.search( "data:video/mp4" ) === 0 || url.search( ".mp4$" ) > -1 ) { + mediaObject.m4v = urlArray[ i ]; + }else if( url.search( ".webm$" ) > -1 ){ + mediaObject.webmv = urlArray[ i ]; + } else { + modelDriver.logger.errorx( "setUrl", + "Unsupported video type for '", url, "'" ); + } } break; default: From d3437e240ea0cb5de70c6c0be7d3d1d23b8075f0 Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Fri, 27 Feb 2015 15:51:53 -0500 Subject: [PATCH 052/129] Now, mars-game appears to pass both test cases: playing on a browser without h.264 support, but with webM support (Chromium) and vice versa (Safari) --- support/client/lib/vwf/model/jPlayer.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 39baa179e..52a77a73b 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -463,9 +463,9 @@ define( [ case "video": mediaObject.poster = node.posterImageUrl; for( var i = 0; i < urlArray.length; i++ ){ - if ( url.search( "data:video/mp4" ) === 0 || url.search( ".mp4$" ) > -1 ) { + if ( urlArray[ i ].search( "data:video/mp4" ) === 0 || urlArray[ i ].search( ".mp4$" ) > -1 ) { mediaObject.m4v = urlArray[ i ]; - }else if( url.search( ".webm$" ) > -1 ){ + }else if( urlArray[ i ].search( ".webm$" ) > -1 ){ mediaObject.webmv = urlArray[ i ]; } else { modelDriver.logger.errorx( "setUrl", @@ -479,6 +479,9 @@ define( [ break; } + console.log("Setting media object!"); + console.log("Media object is: " + mediaObject) + // If we succeeded in creating a media object, set it on the jPlayer object // Otherwise, clear the current media if ( mediaObject ) { From df3db105bc1c92e17d87e74a52077f50c8a6e6d6 Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Mon, 2 Mar 2015 14:49:33 -0500 Subject: [PATCH 053/129] Adding some comments to explain what I commented out. --- support/client/lib/vwf/model/jPlayer.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 52a77a73b..8dbdb1236 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -12,8 +12,13 @@ define( [ var modelDriver; var jPlayerInstanceCreated = false; - var audioManagerProtoId = "http-vwf-example-com-jplayer-audioManager-vwf"; - var videoManagerProtoId = "http-vwf-example-com-jplayer-videoManager-vwf"; + // NXM: For some reason, using the format below breaks video! + // var audioManagerProtoId = "http-vwf-example-com-jplayer-audioManager-vwf"; + // var videoManagerProtoId = "http-vwf-example-com-jplayer-videoManager-vwf"; + + var audioManagerProtoId = "http://vwf.example.com/jplayer/audioManager.vwf"; + var videoManagerProtoId = "http://vwf.example.com/jplayer/videoManager.vwf"; + var jplayerContainerId = "jp_container_1"; return model.load( module, { @@ -129,8 +134,10 @@ define( [ if ( prototypeID.indexOf( audioManagerProtoId ) !== -1 ) { this.state.audioManagerProto = this.state.prototypes[ prototypeID ]; + this.logger.infox( "Got audio manager prototype!" ); } else if ( prototypeID.indexOf( videoManagerProtoId ) !== -1 ) { this.state.videoManagerProto = this.state.prototypes[ prototypeID ]; + this.logger.infox( "Got video manager prototype!" ); } return; @@ -361,6 +368,10 @@ define( [ var node = this.state.nodes[ nodeID ]; if ( !node ) { + //NATHAN: Remove the below... IF block... it's for debugging only + if( methodName === "play" ){ + this.logger.infox( "Node is NULL when calling: " + methodName + " on " + nodeID); + } return; } From 72c415c307258dfec2c8b805970f463a5ba98c11 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Mon, 2 Mar 2015 14:54:10 -0500 Subject: [PATCH 054/129] Removed two unnecessary lines of code. --- support/client/lib/vwf/model/jPlayer.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 8dbdb1236..42841cd33 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -490,9 +490,6 @@ define( [ break; } - console.log("Setting media object!"); - console.log("Media object is: " + mediaObject) - // If we succeeded in creating a media object, set it on the jPlayer object // Otherwise, clear the current media if ( mediaObject ) { From 3c96ab099474a94a3103cb57fbd2e05481bf0470 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Mon, 2 Mar 2015 16:14:15 -0500 Subject: [PATCH 055/129] Cleaned up the video URL. Now we are ready to test if it's a string or a list. --- support/client/lib/vwf/model/jPlayer.js | 21 ++++++++++++------- .../jplayer/videoManager.vwf.yaml | 3 +-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 42841cd33..e97b9149d 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -459,6 +459,18 @@ define( [ // Construct the media object based on the type of file being passed in var mediaObject = {}; + + function setVideoURL( mediaObj, url ){ + if ( url.search( "data:video/mp4" ) === 0 || url.search( ".mp4$" ) > -1 ) { + mediaObj.m4v = url; + }else if( url.search( ".webm$" ) > -1 ){ + mediaObj.webmv = url; + } else { + modelDriver.logger.errorx( "setUrl", + "Unsupported video type for '", url, "'" ); + } + } + switch ( node.managerType ) { case "audio": //TODO: Support multiple URLs for audio. @@ -474,14 +486,7 @@ define( [ case "video": mediaObject.poster = node.posterImageUrl; for( var i = 0; i < urlArray.length; i++ ){ - if ( urlArray[ i ].search( "data:video/mp4" ) === 0 || urlArray[ i ].search( ".mp4$" ) > -1 ) { - mediaObject.m4v = urlArray[ i ]; - }else if( urlArray[ i ].search( ".webm$" ) > -1 ){ - mediaObject.webmv = urlArray[ i ]; - } else { - modelDriver.logger.errorx( "setUrl", - "Unsupported video type for '", url, "'" ); - } + setVideoURL( mediaObject, urlArray[i] ); } break; default: diff --git a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml index 2f6c0cc2c..124c640de 100644 --- a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml +++ b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml @@ -2,12 +2,11 @@ extends: http://vwf.example.com/node.vwf properties: url: + altUrls: posterImageUrl: loop: false containerDivId: "jp_container_1" playerDivId: "videoScreen" - # containerDivId: "videoContainer" - # playerDivId: "videoScreen" containerSize: [ 1024, 768 ] playerSize: [ 1024, 768 ] methods: From 177569de4ef37c6306c47e627979e9aa87e3dc0d Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Mon, 2 Mar 2015 22:17:40 -0500 Subject: [PATCH 056/129] Added check to see if we're parsing a string or an array. --- support/client/lib/vwf/model/jPlayer.js | 65 ++++++++++--------------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index e97b9149d..879c3c8b4 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -243,22 +243,11 @@ define( [ var playerDiv = document.createElement( 'div' ); playerDiv.id = node.playerDivId; if( node.containerDivId ){ - // playerDiv.className = "jp-jplayer"; $( "#" + node.containerDivId ).append( playerDiv ); } else { $("#jp_container_1").append( playerDiv ); } node.jPlayerElement = $( "#" + node.playerDivId ); - - // $( "#" + jplayerContainerId ).jPlayer("option", "cssSelectorAncestor", "#" + node.playerDivId); - // $( "#" + jplayerContainerId ).attr( "id", node.playerDivId ); - // jplayerContainerId = node.playerDivId; - - // node.jPlayerElement = $( "#" + node.playerDivId ); - // node.jPlayerElement = $( "
", { - // id: node.playerDivId - // } ); - // $( "body" ).append( node.jPlayerElement ); } var fileTypes = ( node.managerType === "audio" ) ? "mp3,wav" : "m4v,webmv"; node.jPlayerElement.jPlayer( { @@ -274,11 +263,10 @@ define( [ } }, supplied: fileTypes, - // size: { width: node.playmoderDivSize[0], height: node.playerDivSize[1] } } ); if ( node.playerDivId ) { - $( "#" + node.playerDivId ).bind($.jPlayer.event.ended, this.state.videoEndedCallback ); + $( "#" + node.playerDivId ).bind( $.jPlayer.event.ended, this.state.videoEndedCallback ); } value = node.playerDivId; @@ -406,13 +394,6 @@ define( [ } ); - // function videoEndedCallback(){ - // var mediaManagerID = this.kernel.kernel.find( undefined, "/mediaManager" )[ 0 ]; - // var videoManagerID = this.kernel.kernel.find( mediaManagerID, "videoManager" ) [ 0 ]; - // console.log("Video ended callback in driver fired!"); - // this.kernel.fireEvent(videoManagerID, "videoEnded"); - // } - function getPrototypes( kernel, extendsID ) { var prototypes = []; var id = extendsID; @@ -443,7 +424,29 @@ define( [ } } - function setUrl( node, urlArray ) { + function setVideoURL( mediaObj, url ) { + if ( url.search( "data:video/mp4" ) === 0 || url.search( ".mp4$" ) > -1 ) { + mediaObj.m4v = url; + }else if( url.search( ".webm$" ) > -1 ){ + mediaObj.webmv = url; + } else { + modelDriver.logger.errorx( "setUrl", + "Unsupported video type for '", url, "'" ); + } + } + + function setUrl( node, url ) { + + var usingMultiUrls; + if( url.constructor === Array ){ + usingMultiUrls = true; + } else if( typeof url === 'string' ) { + usingMultiUrls = false; + } else { + modelDriver.logger.errorx( "setUrl", + "URL is not a string or an array" ); + } + var url = urlArray[ 0 ]; node.url = url; @@ -460,17 +463,6 @@ define( [ // Construct the media object based on the type of file being passed in var mediaObject = {}; - function setVideoURL( mediaObj, url ){ - if ( url.search( "data:video/mp4" ) === 0 || url.search( ".mp4$" ) > -1 ) { - mediaObj.m4v = url; - }else if( url.search( ".webm$" ) > -1 ){ - mediaObj.webmv = url; - } else { - modelDriver.logger.errorx( "setUrl", - "Unsupported video type for '", url, "'" ); - } - } - switch ( node.managerType ) { case "audio": //TODO: Support multiple URLs for audio. @@ -485,9 +477,9 @@ define( [ break; case "video": mediaObject.poster = node.posterImageUrl; - for( var i = 0; i < urlArray.length; i++ ){ - setVideoURL( mediaObject, urlArray[i] ); - } + // for( var i = 0; i < urlArray.length; i++ ){ + setVideoURL( mediaObject, urlArray[i] ); + // } break; default: modelDriver.logger.errorx( "setUrl", @@ -516,9 +508,6 @@ define( [ function setControlDivId( node, containerDivId ) { node.containerDivId = containerDivId; - // if ( node.jPlayerElement ) { - // node.jPlayerElement.jPlayer( "option", { cssSelectorAncestor: "#" + containerDivId } ); - // } } function setPosterImageUrl( node, posterImageUrl ) { From 9b3697b53280173239803db7823a1dfa470cf2b3 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Tue, 3 Mar 2015 10:31:40 -0500 Subject: [PATCH 057/129] Cleand up the code a little bit - in setURL, we now determine if we're feeding it an array or a single string. --- support/client/lib/vwf/model/jPlayer.js | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 879c3c8b4..da9b16abc 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -134,10 +134,8 @@ define( [ if ( prototypeID.indexOf( audioManagerProtoId ) !== -1 ) { this.state.audioManagerProto = this.state.prototypes[ prototypeID ]; - this.logger.infox( "Got audio manager prototype!" ); } else if ( prototypeID.indexOf( videoManagerProtoId ) !== -1 ) { this.state.videoManagerProto = this.state.prototypes[ prototypeID ]; - this.logger.infox( "Got video manager prototype!" ); } return; @@ -435,19 +433,17 @@ define( [ } } - function setUrl( node, url ) { + function setUrl( node, inputUrl ) { var usingMultiUrls; - if( url.constructor === Array ){ + var url; + if( inputUrl && ( inputUrl.constructor === Array ) ){ usingMultiUrls = true; - } else if( typeof url === 'string' ) { + url = inputUrl[ 0 ]; + } else{ usingMultiUrls = false; - } else { - modelDriver.logger.errorx( "setUrl", - "URL is not a string or an array" ); - } - - var url = urlArray[ 0 ]; + url = inputUrl; + } node.url = url; // If there is no jPlayerElement, there is nothing to do yet so we return. @@ -477,9 +473,13 @@ define( [ break; case "video": mediaObject.poster = node.posterImageUrl; - // for( var i = 0; i < urlArray.length; i++ ){ - setVideoURL( mediaObject, urlArray[i] ); - // } + if( usingMultiUrls ) { + for( var i = 0; i < inputUrl.length; i++ ) { + setVideoURL( mediaObject, inputUrl[ i ] ); + } + } else { + setVideoURL( mediaObject, url ); + } break; default: modelDriver.logger.errorx( "setUrl", From 22f6a62f3d7cb6089b9361da47fe8bebee86cae5 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Wed, 4 Mar 2015 10:52:13 -0500 Subject: [PATCH 058/129] Fixed spacing and removed some debug code. --- support/client/lib/vwf/model/jPlayer.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index da9b16abc..37dc6ae75 100644 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -354,10 +354,6 @@ define( [ var node = this.state.nodes[ nodeID ]; if ( !node ) { - //NATHAN: Remove the below... IF block... it's for debugging only - if( methodName === "play" ){ - this.logger.infox( "Node is NULL when calling: " + methodName + " on " + nodeID); - } return; } @@ -425,7 +421,7 @@ define( [ function setVideoURL( mediaObj, url ) { if ( url.search( "data:video/mp4" ) === 0 || url.search( ".mp4$" ) > -1 ) { mediaObj.m4v = url; - }else if( url.search( ".webm$" ) > -1 ){ + } else if( url.search( ".webm$" ) > -1 ){ mediaObj.webmv = url; } else { modelDriver.logger.errorx( "setUrl", @@ -440,7 +436,7 @@ define( [ if( inputUrl && ( inputUrl.constructor === Array ) ){ usingMultiUrls = true; url = inputUrl[ 0 ]; - } else{ + } else { usingMultiUrls = false; url = inputUrl; } From f58860c3a609e60db54638992a140d6233f562d6 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Wed, 11 Mar 2015 14:50:18 -0400 Subject: [PATCH 059/129] we can now stop execution on a particular Blockly node,as opposed to just one of them. --- support/client/lib/vwf/model/blockly.js | 19 ++++++++++++++++++- support/client/lib/vwf/view/blockly.js | 4 ++-- .../vwf.example.com/blockly/manager.vwf.yaml | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/support/client/lib/vwf/model/blockly.js b/support/client/lib/vwf/model/blockly.js index 237c9d231..0fb8c8c7e 100644 --- a/support/client/lib/vwf/model/blockly.js +++ b/support/client/lib/vwf/model/blockly.js @@ -307,7 +307,7 @@ define( [ "module", "vwf/model", "vwf/utility", // -- callingMethod -------------------------------------------------------------------------- - callingMethod: function( nodeID, methodName /* [, parameter1, parameter2, ... ] */ ) { // TODO: parameters + callingMethod: function( nodeID, methodName, methodParameters ) { var node = this.state.nodes[ nodeID ]; if ( this.debug.methods ) { @@ -318,6 +318,23 @@ define( [ "module", "vwf/model", "vwf/utility", switch ( methodName ) { + case "stopExecutionForNode": + if ( methodParameters ) { + var id = methodParameters; + var currBlockly3Node= this.state.executingBlocks[ id ]; + if ( currBlockly3Node ) { + currBlockly3Node.interpreterStatus = "completed"; + this.kernel.setProperty( id, 'blockly_executing', false ); + this.kernel.fireEvent( id, "blocklyStopped", [ true ] ); + } else { + this.logger.errorx("stopExecutionForNode", "Node with", id, + "is not currently executing Blockly!"); + } + } else { + this.logger.errorx("stopExecutionForNode", "No node specified!"); + } + break; + case "stopAllExecution": for ( var id in this.state.executingBlocks ) { this.state.executingBlocks[ id ].interpreterStatus = "completed"; diff --git a/support/client/lib/vwf/view/blockly.js b/support/client/lib/vwf/view/blockly.js index d79f2f292..b27df8b2f 100644 --- a/support/client/lib/vwf/view/blockly.js +++ b/support/client/lib/vwf/view/blockly.js @@ -245,7 +245,7 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor getBlockXML( previousActiveNode ); setBlocklyUIVisibility( previousActiveNode, false ); show = ( previousActiveNode.ID !== newActiveNodeId ); - this.state.blockly.node = undefined; + this.state.blockly.node = undefined; } // If the new active node is different than the old, @@ -269,7 +269,7 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor if ( previousActiveNode !== undefined ) { getBlockXML( previousActiveNode ); setBlocklyUIVisibility( previousActiveNode, false ); - this.state.blockly.node = undefined; + this.state.blockly.node = undefined; } } break; diff --git a/support/proxy/vwf.example.com/blockly/manager.vwf.yaml b/support/proxy/vwf.example.com/blockly/manager.vwf.yaml index 2cae95f56..1ea052bc6 100644 --- a/support/proxy/vwf.example.com/blockly/manager.vwf.yaml +++ b/support/proxy/vwf.example.com/blockly/manager.vwf.yaml @@ -27,6 +27,6 @@ properties: methods: startAllExecution: stopAllExecution: + stopExecutionForNode: events: blocklyContentChanged: - \ No newline at end of file From bc7c3694c662d9c10dd3afb87a3910549659d245 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Fri, 13 Mar 2015 03:22:37 -0400 Subject: [PATCH 060/129] Now, per Brett's suggestion, we changed stopExecutingForNode in manager.vwf.yaml to stopExecuting in controller.vwf.yaml. This way we don't have to pass the node ID as an argument. --- support/client/lib/vwf/model/blockly.js | 30 +++++++------------ .../blockly/controller.vwf.yaml | 1 + .../vwf.example.com/blockly/manager.vwf.yaml | 1 - 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/support/client/lib/vwf/model/blockly.js b/support/client/lib/vwf/model/blockly.js index 0fb8c8c7e..5948c6f12 100644 --- a/support/client/lib/vwf/model/blockly.js +++ b/support/client/lib/vwf/model/blockly.js @@ -317,23 +317,6 @@ define( [ "module", "vwf/model", "vwf/utility", if ( nodeID == this.kernel.application() ) { switch ( methodName ) { - - case "stopExecutionForNode": - if ( methodParameters ) { - var id = methodParameters; - var currBlockly3Node= this.state.executingBlocks[ id ]; - if ( currBlockly3Node ) { - currBlockly3Node.interpreterStatus = "completed"; - this.kernel.setProperty( id, 'blockly_executing', false ); - this.kernel.fireEvent( id, "blocklyStopped", [ true ] ); - } else { - this.logger.errorx("stopExecutionForNode", "Node with", id, - "is not currently executing Blockly!"); - } - } else { - this.logger.errorx("stopExecutionForNode", "No node specified!"); - } - break; case "stopAllExecution": for ( var id in this.state.executingBlocks ) { @@ -349,8 +332,6 @@ define( [ "module", "vwf/model", "vwf/utility", this.kernel.fireEvent( id, "blocklyStarted", [ true ] ); } break; - - } } else if ( node !== undefined ) { switch ( methodName ) { @@ -361,6 +342,17 @@ define( [ "module", "vwf/model", "vwf/utility", this.kernel.setProperty( nodeID, "blockly_xml", '' ); } break; + case "stopExecution": + var currBlockly3Node = this.state.executingBlocks[ nodeID ]; + if ( currBlockly3Node ) { + currBlockly3Node.interpreterStatus = "completed"; + this.kernel.setProperty( nodeID, 'blockly_executing', false ); + this.kernel.fireEvent( nodeID, "blocklyStopped", [ true ] ); + } else { + this.logger.errorx("stopExecutionForNode", "Node with", nodeID, + "is not currently executing Blockly!"); + } + break; } } }, diff --git a/support/proxy/vwf.example.com/blockly/controller.vwf.yaml b/support/proxy/vwf.example.com/blockly/controller.vwf.yaml index bc120d91b..fe9c506be 100644 --- a/support/proxy/vwf.example.com/blockly/controller.vwf.yaml +++ b/support/proxy/vwf.example.com/blockly/controller.vwf.yaml @@ -55,6 +55,7 @@ properties: methods: getWorldXYVector: blocklyClear: + stopExecution: events: blocklyStarted: blocklyExecuted: diff --git a/support/proxy/vwf.example.com/blockly/manager.vwf.yaml b/support/proxy/vwf.example.com/blockly/manager.vwf.yaml index 1ea052bc6..a5143b347 100644 --- a/support/proxy/vwf.example.com/blockly/manager.vwf.yaml +++ b/support/proxy/vwf.example.com/blockly/manager.vwf.yaml @@ -27,6 +27,5 @@ properties: methods: startAllExecution: stopAllExecution: - stopExecutionForNode: events: blocklyContentChanged: From f36355f8803351b65e2fea0b4aacc6f117e6703c Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Mon, 9 Mar 2015 14:48:46 -0400 Subject: [PATCH 061/129] Allow images to be inserted at run time --- support/client/lib/vwf/view/hud.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/support/client/lib/vwf/view/hud.js b/support/client/lib/vwf/view/hud.js index 6d79b4870..fc1c42dd9 100644 --- a/support/client/lib/vwf/view/hud.js +++ b/support/client/lib/vwf/view/hud.js @@ -232,6 +232,9 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/view/hud/hud" ], function( oldImage = node.viewObject[ keys[ i ] ]; if ( newImageSrc && oldImage instanceof Image && newImageSrc !== oldImage.src ) { oldImage.src = newImageSrc; + } else if ( !oldImage ) { + var newImage = node.viewObject[ keys[ i ] ] = new Image(); + newImage.src = newImageSrc; } } } From a563a6c229d401aeb68ef5a4d8872e6003964f95 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Thu, 12 Mar 2015 13:28:23 -0400 Subject: [PATCH 062/129] Remove UI visibility code from blockly_activeNodeID handler --- support/client/lib/vwf/view/blockly.js | 51 +++++++++----------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/support/client/lib/vwf/view/blockly.js b/support/client/lib/vwf/view/blockly.js index b27df8b2f..8ef5a4ced 100644 --- a/support/client/lib/vwf/view/blockly.js +++ b/support/client/lib/vwf/view/blockly.js @@ -232,45 +232,30 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor // If the new node is the same as the old - exit early to prevent // breaking synchronization. - if ( previousActiveNode === newActiveNodeId ) { + if ( previousActiveNode === blocklyNode ) { break; } - if ( blocklyNode !== undefined ) { - var show = true; - - //If there was already an active blockly node, deal with it before - //activating the new one - if ( previousActiveNode !== undefined ) { - getBlockXML( previousActiveNode ); - setBlocklyUIVisibility( previousActiveNode, false ); - show = ( previousActiveNode.ID !== newActiveNodeId ); - this.state.blockly.node = undefined; - } + if ( previousActiveNode !== undefined ) { + getBlockXML( previousActiveNode ); + this.state.blockly.node = undefined; + } + if ( blocklyNode !== undefined ) { // If the new active node is different than the old, // then we need to load its program into the toolbox - if ( show ) { - if ( blocklyNode.toolbox !== undefined ) { - loadToolbox( blocklyNode.toolbox ); - } else if ( app.toolbox !== undefined ) { - loadToolbox( app.toolbox ); - } - if ( blocklyNode.defaultXml !== undefined ) { - loadDefaultXml( blocklyNode.defaultXml ); - } else if ( app.defaultXml !== undefined ) { - loadDefaultXml( app.defaultXml ); - } - this.state.blockly.node = blocklyNode; - setBlockXML( blocklyNode ); - setBlocklyUIVisibility( blocklyNode, true ); - } - } else { - if ( previousActiveNode !== undefined ) { - getBlockXML( previousActiveNode ); - setBlocklyUIVisibility( previousActiveNode, false ); - this.state.blockly.node = undefined; - } + if ( blocklyNode.toolbox !== undefined ) { + loadToolbox( blocklyNode.toolbox ); + } else if ( app.toolbox !== undefined ) { + loadToolbox( app.toolbox ); + } + if ( blocklyNode.defaultXml !== undefined ) { + loadDefaultXml( blocklyNode.defaultXml ); + } else if ( app.defaultXml !== undefined ) { + loadDefaultXml( app.defaultXml ); + } + this.state.blockly.node = blocklyNode; + setBlockXML( blocklyNode ); } break; From 56b69a5bf29494da5cc72dcf2726a71829fa0834 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Thu, 12 Mar 2015 13:46:56 -0400 Subject: [PATCH 063/129] Add blockly_interfaceVisible property --- support/client/lib/vwf/view/blockly.js | 4 ++++ support/proxy/vwf.example.com/blockly/manager.vwf.yaml | 1 + 2 files changed, 5 insertions(+) diff --git a/support/client/lib/vwf/view/blockly.js b/support/client/lib/vwf/view/blockly.js index 8ef5a4ced..46e8e3187 100644 --- a/support/client/lib/vwf/view/blockly.js +++ b/support/client/lib/vwf/view/blockly.js @@ -276,6 +276,10 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor this.delayedProperties.blockly_autoClose = Boolean( propertyValue ); } break; + + case "blockly_interfaceVisible": + setBlocklyUIVisibility( this.state.blockly.node, propertyValue ); + break; } } else if ( this.state.blockly.node && ( nodeID === this.state.blockly.node.ID ) ) { diff --git a/support/proxy/vwf.example.com/blockly/manager.vwf.yaml b/support/proxy/vwf.example.com/blockly/manager.vwf.yaml index a5143b347..3716ff9b7 100644 --- a/support/proxy/vwf.example.com/blockly/manager.vwf.yaml +++ b/support/proxy/vwf.example.com/blockly/manager.vwf.yaml @@ -24,6 +24,7 @@ properties: blockly_toolbox: blockly_defaultXml: blockly_autoClose: + blockly_interfaceVisible: methods: startAllExecution: stopAllExecution: From f70cf77216e02b6e58f4cedd0e9e4062fbab4eba Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Thu, 12 Mar 2015 14:40:25 -0400 Subject: [PATCH 064/129] Only fire blocklyVisibleChanged if active node is defined --- support/client/lib/vwf/view/blockly.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/support/client/lib/vwf/view/blockly.js b/support/client/lib/vwf/view/blockly.js index 46e8e3187..17ddf5ff3 100644 --- a/support/client/lib/vwf/view/blockly.js +++ b/support/client/lib/vwf/view/blockly.js @@ -388,7 +388,9 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor self.delayedProperties = undefined; } - self.kernel.fireEvent( node.ID, "blocklyVisibleChanged", [ show ] ); + if ( node && node.ID ) { + self.kernel.fireEvent( node.ID, "blocklyVisibleChanged", [ show ] ); + } } function loadToolbox( toolboxDef ) { From 5a8ba67e325cd498bf49e83d15ad5e292403e76c Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Thu, 12 Mar 2015 16:25:49 -0400 Subject: [PATCH 065/129] Fire blocklyVisibleChanged when active node changes --- support/client/lib/vwf/view/blockly.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/support/client/lib/vwf/view/blockly.js b/support/client/lib/vwf/view/blockly.js index 17ddf5ff3..d9bb766d1 100644 --- a/support/client/lib/vwf/view/blockly.js +++ b/support/client/lib/vwf/view/blockly.js @@ -256,6 +256,7 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor } this.state.blockly.node = blocklyNode; setBlockXML( blocklyNode ); + this.kernel.fireEvent( blocklyNode.ID, "blocklyVisibleChanged", [ getBlocklyUIVisibility() ] ); } break; @@ -393,6 +394,12 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor } } + function getBlocklyUIVisibility() { + var div = document.getElementById( self.options.divParent ); + var result = div.style.visibility === "visible" ? true : false; + return result; + } + function loadToolbox( toolboxDef ) { // check the 'Changing the Toolbox' section at // https://code.google.com/p/blockly/wiki/Toolbox From bccb8bcdf1f03ef9d044b69ebccdbb691bf15682 Mon Sep 17 00:00:00 2001 From: David Easter Date: Mon, 2 Mar 2015 01:06:22 -0500 Subject: [PATCH 066/129] Treat properties with names ending in `$` as private record values only. --- support/client/lib/vwf.js | 205 ++++++++++++++++++++++---------------- 1 file changed, 117 insertions(+), 88 deletions(-) diff --git a/support/client/lib/vwf.js b/support/client/lib/vwf.js index 03f998ab1..675dc9a53 100644 --- a/support/client/lib/vwf.js +++ b/support/client/lib/vwf.js @@ -3188,73 +3188,87 @@ if ( ! childComponent.source ) { var delegated = false, assigned = false; - // Call settingProperty() on each model. The first model to return a non-undefined value - // has performed the set and dictates the return value. The property is considered set - // after all models have run. + if ( propertyName[ propertyName.length - 1 ] !== "$" ) { - this.models.some( function( model, index ) { + // Call settingProperty() on each model. The first model to return a non-undefined value + // has performed the set and dictates the return value. The property is considered set + // after all models have run. - // Skip initial models that an outer call has already invoked for this node and - // property (if any). If an inner call completed for this node and property, skip - // the remaining models. + this.models.some( function( model, index ) { - if ( ( ! reentered || index > entry.index ) && ! reentry.completed ) { + // Skip initial models that an outer call has already invoked for this node and + // property (if any). If an inner call completed for this node and property, skip + // the remaining models. - // Record the active model number. - - reentry.index = index; + if ( ( ! reentered || index > entry.index ) && ! reentry.completed ) { - // Record the number of assignments made since the outermost call. When - // `entrants.assignments` increases, a driver has called `setProperty` to make - // an assignment elsewhere. + // Record the active model number. - var assignments = entrants.assignments; + reentry.index = index; - // Make the call. + // Record the number of assignments made since the outermost call. When + // `entrants.assignments` increases, a driver has called `setProperty` to make + // an assignment elsewhere. - if ( ! delegated && ! assigned ) { - var value = model[settingPropertyEtc] && model[settingPropertyEtc]( nodeID, propertyName, propertyValue ); - } else { - model[settingPropertyEtc] && model[settingPropertyEtc]( nodeID, propertyName, undefined ); - } + var assignments = entrants.assignments; - // Ignore the result if reentry is disabled and the driver attempted to call - // back into the kernel. Kernel reentry is disabled during replication to - // prevent coloring from accessor scripts. + // Make the call. - if ( this.models.kernel.blocked() ) { // TODO: this might be better handled wholly in vwf/kernel/model by converting to a stage and clearing blocked results on the return - value = undefined; - } + if ( ! delegated && ! assigned ) { + var value = model[settingPropertyEtc] && model[settingPropertyEtc]( nodeID, propertyName, propertyValue ); + } else { + model[settingPropertyEtc] && model[settingPropertyEtc]( nodeID, propertyName, undefined ); + } - // The property was delegated if the call made any assignments. + // Ignore the result if reentry is disabled and the driver attempted to call + // back into the kernel. Kernel reentry is disabled during replication to + // prevent coloring from accessor scripts. - if ( entrants.assignments !== assignments ) { - delegated = true; - } + if ( this.models.kernel.blocked() ) { // TODO: this might be better handled wholly in vwf/kernel/model by converting to a stage and clearing blocked results on the return + value = undefined; + } - // Otherwise if the call returned a value, the property was assigned here. + // The property was delegated if the call made any assignments. - else if ( value !== undefined ) { - entrants.assignments++; - assigned = true; - } + if ( entrants.assignments !== assignments ) { + delegated = true; + } + + // Otherwise if the call returned a value, the property was assigned here. - // Record the value actually assigned. This may differ from the incoming value - // if it was range limited, quantized, etc. by the model. This is the value - // passed to the views. + else if ( value !== undefined ) { + entrants.assignments++; + assigned = true; + } + + // Record the value actually assigned. This may differ from the incoming value + // if it was range limited, quantized, etc. by the model. This is the value + // passed to the views. + + if ( value !== undefined ) { + propertyValue = value; + } + + // If we are setting, exit from the this.models.some() iterator once the value + // has been set. Don't exit early if we are creating or initializing since every + // model needs the opportunity to register the property. - if ( value !== undefined ) { - propertyValue = value; + return settingPropertyEtc == "settingProperty" && ( delegated || assigned ); } - // If we are setting, exit from the this.models.some() iterator once the value - // has been set. Don't exit early if we are creating or initializing since every - // model needs the opportunity to register the property. + }, this ); + + } else { + + var value = this.models.object[settingPropertyEtc]( nodeID, propertyName, propertyValue ); - return settingPropertyEtc == "settingProperty" && ( delegated || assigned ); + if ( value !== undefined ) { + entrants.assignments++; + assigned = true; + propertyValue = value; } - }, this ); + } // Record the change if the property was assigned here. @@ -3269,7 +3283,7 @@ if ( ! childComponent.source ) { // ephemeral, and views on late-joining clients would never see it, it's best to never // send those notifications. - if ( assigned ) { + if ( assigned && propertyName[ propertyName.length - 1 ] !== "$" ) { this.views.forEach( function( view ) { view[satPropertyEtc] && view[satPropertyEtc]( nodeID, propertyName, propertyValue ); } ); @@ -3361,65 +3375,78 @@ if ( ! childComponent.source ) { var delegated = false, retrieved = false; - // Call gettingProperty() on each model. The first model to return a non-undefined value - // dictates the return value. + if ( propertyName[ propertyName.length - 1 ] !== "$" ) { - this.models.some( function( model, index ) { + // Call gettingProperty() on each model. The first model to return a non-undefined value + // dictates the return value. - // Skip initial models that an outer call has already invoked for this node and - // property (if any). If an inner call completed for this node and property, skip - // the remaining models. + this.models.some( function( model, index ) { - if ( ( ! reentered || index > entry.index ) && ! reentry.completed ) { + // Skip initial models that an outer call has already invoked for this node and + // property (if any). If an inner call completed for this node and property, skip + // the remaining models. - // Record the active model number. - - reentry.index = index; + if ( ( ! reentered || index > entry.index ) && ! reentry.completed ) { - // Record the number of retrievals made since the outermost call. When - // `entrants.retrievals` increases, a driver has called `getProperty` to make - // a retrieval elsewhere. + // Record the active model number. - var retrievals = entrants.retrievals; + reentry.index = index; - // Make the call. + // Record the number of retrievals made since the outermost call. When + // `entrants.retrievals` increases, a driver has called `getProperty` to make + // a retrieval elsewhere. - var value = model.gettingProperty && - model.gettingProperty( nodeID, propertyName, propertyValue ); // TODO: probably don't need propertyValue here + var retrievals = entrants.retrievals; - // Ignore the result if reentry is disabled and the driver attempted to call - // back into the kernel. Kernel reentry is disabled during replication to - // prevent coloring from accessor scripts. + // Make the call. - if ( this.models.kernel.blocked() ) { // TODO: this might be better handled wholly in vwf/kernel/model by converting to a stage and clearing blocked results on the return - value = undefined; - } + var value = model.gettingProperty && + model.gettingProperty( nodeID, propertyName, propertyValue ); // TODO: probably don't need propertyValue here - // The property was delegated if the call made any retrievals. + // Ignore the result if reentry is disabled and the driver attempted to call + // back into the kernel. Kernel reentry is disabled during replication to + // prevent coloring from accessor scripts. - if ( entrants.retrievals !== retrievals ) { - delegated = true; - } + if ( this.models.kernel.blocked() ) { // TODO: this might be better handled wholly in vwf/kernel/model by converting to a stage and clearing blocked results on the return + value = undefined; + } - // Otherwise if the call returned a value, the property was retrieved here. + // The property was delegated if the call made any retrievals. - else if ( value !== undefined ) { - entrants.retrievals++; - retrieved = true; - } + if ( entrants.retrievals !== retrievals ) { + delegated = true; + } + + // Otherwise if the call returned a value, the property was retrieved here. + + else if ( value !== undefined ) { + entrants.retrievals++; + retrieved = true; + } + + // Record the value retrieved. - // Record the value retrieved. + if ( value !== undefined ) { + propertyValue = value; + } - if ( value !== undefined ) { - propertyValue = value; + // Exit from the this.models.some() iterator once we have a return value. + + return delegated || retrieved; } - // Exit from the this.models.some() iterator once we have a return value. + }, this ); + + } else { + + var value = this.models.object.gettingProperty( nodeID, propertyName, propertyValue ); // TODO: probably don't need propertyValue here - return delegated || retrieved; + if ( value !== undefined ) { + entrants.retrievals++; + propertyValue = value; } - }, this ); + } if ( reentered ) { @@ -3458,9 +3485,11 @@ if ( ! childComponent.source ) { // Call gotProperty() on each view. - this.views.forEach( function( view ) { - view.gotProperty && view.gotProperty( nodeID, propertyName, propertyValue ); // TODO: be sure this is the value actually gotten and not an intermediate value from above - } ); + if ( propertyName[ propertyName.length - 1 ] !== "$" ) { + this.views.forEach( function( view ) { + view.gotProperty && view.gotProperty( nodeID, propertyName, propertyValue ); // TODO: be sure this is the value actually gotten and not an intermediate value from above + } ); + } } From 81e8f3294963c5d3d8c7dc71213fd6d471e9d7eb Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Wed, 18 Mar 2015 12:51:12 -0400 Subject: [PATCH 067/129] Optimized kernel.application calls in view/threejs --- support/client/lib/vwf/view/threejs.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/support/client/lib/vwf/view/threejs.js b/support/client/lib/vwf/view/threejs.js index ff60f2c51..2b0c0c0b1 100644 --- a/support/client/lib/vwf/view/threejs.js +++ b/support/client/lib/vwf/view/threejs.js @@ -86,6 +86,8 @@ define( [ "module", var enableStereo = false; + var sceneRootID = undefined; + return view.load( module, { initialize: function( options ) { @@ -95,7 +97,7 @@ define( [ "module", checkCompatibility.call(this); this.state.appInitialized = false; - + sceneRootID = this.kernel.application(); this.pickInterval = 10; this.enableInputs = true; this.applicationWantsPointerEvents = false; @@ -159,17 +161,18 @@ define( [ "module", createdNode: function( nodeID, childID, childExtendsID, childImplementsIDs, childSource, childType, childIndex, childName, callback /* ( ready ) */) { + sceneRootID = this.kernel.application(); //the created node is a scene, and has already been added to the state by the model. //how/when does the model set the state object? if ( this.state.scenes[ childID ] ) { - this.canvasQuery = $(this.rootSelector).append("" + this.canvasQuery = $(this.rootSelector).append("" ).children(":last"); initScene.call(this,this.state.scenes[childID]); } - else if ( this.state.scenes[ this.kernel.application() ] ) { - var sceneNode = this.state.scenes[ this.kernel.application() ]; + else if ( this.state.scenes[ sceneRootID ] ) { + var sceneNode = this.state.scenes[ sceneRootID ]; if ( sceneNode.camera.ID == childID ) { setActiveCamera.call( this, sceneNode.camera.ID ); } @@ -183,7 +186,8 @@ define( [ "module", initializedNode: function( nodeID, childID ) { // If the node that was initialized is the application node, find the user's navigation object - var appID = this.kernel.application(); + var appID = sceneRootID; + if ( childID == appID ) { if ( enableStereo ) { @@ -207,6 +211,7 @@ define( [ "module", } this.state.appInitialized = true; + } else { //TODO: This is a temporary workaround until the callback functionality is implemented for @@ -289,7 +294,7 @@ define( [ "module", } else if ( propertyName == "boundingBox" ) { boundingBox = propertyValue; } else if ( propertyName == "activeCamera" ) { - setActiveCamera.call( this, this.state.scenes[ this.kernel.application() ].camera.ID ); + setActiveCamera.call( this, this.state.scenes[ sceneRootID ].camera.ID ); } else if ( propertyName == "usersShareView" ) { usersShareView = propertyValue; } @@ -315,7 +320,7 @@ define( [ "module", gotProperty: function ( nodeID, propertyName, propertyValue ) { var clientThatGotProperty = this.kernel.client(); var me = this.kernel.moniker(); - var sceneRootID = this.kernel.application(); + if ( clientThatGotProperty == me ) { if ( propertyName == "owner") { @@ -358,7 +363,7 @@ define( [ "module", // Retrieve the userObject property so we may create a navigation object from // it for this user (the rest of the logic is in the gotProperty call for // userObject) - this.kernel.getProperty( this.kernel.application(), "userObject" ); + this.kernel.getProperty( sceneRootID, "userObject" ); userObjectRequested = true; } } @@ -388,7 +393,7 @@ define( [ "module", // TODO: The callback function is commented out because callbacks have not yet been // implemented for createChild - see workaround in initializedNode - this.kernel.createChild( this.kernel.application(), navObjectName, userObject, undefined, undefined /*, + this.kernel.createChild( sceneRootID, navObjectName, userObject, undefined, undefined /*, function( nodeID ) { controlNavObject( this.state.nodes[ nodeID ] ); } */ ); From 7b7159fea2f357620f76f9409055a44cc5ec3b8b Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Mon, 23 Mar 2015 11:06:47 -0400 Subject: [PATCH 068/129] Re-apply transparency fix to collada loader --- .../model/threejs/js/loaders/ColladaLoader.js | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/support/client/lib/vwf/model/threejs/js/loaders/ColladaLoader.js b/support/client/lib/vwf/model/threejs/js/loaders/ColladaLoader.js index 33f0b5745..f7436ca0b 100644 --- a/support/client/lib/vwf/model/threejs/js/loaders/ColladaLoader.js +++ b/support/client/lib/vwf/model/threejs/js/loaders/ColladaLoader.js @@ -1153,7 +1153,7 @@ THREE.ColladaLoader = function () { } - material3js.opacity = !material3js.opacity ? 1 : material3js.opacity; + material3js.opacity = material3js.opacity === undefined ? 1 : material3js.opacity; used_materials[ instance_material.symbol ] = num_materials; used_materials_array.push( material3js ); first_material = material3js; @@ -3633,20 +3633,33 @@ THREE.ColladaLoader = function () { var props = {}; - var transparent = false; - - if (this['transparency'] !== undefined && this['transparent'] !== undefined) { + if ( this[ 'transparency' ] !== undefined && this[ 'transparent' ] !== undefined ) { // convert transparent color RBG to average value - var transparentColor = this['transparent']; - var transparencyLevel = (this.transparent.color.r + this.transparent.color.g + this.transparent.color.b) / 3 * this.transparency; - - if (transparencyLevel > 0) { - transparent = true; + var transparentColor = this[ 'transparent' ]; + var transparencyLevel = 0; + // Determine transparency level based on opaque mode + if ( transparentColor.opaque == "RGB_ONE" ) { + transparencyLevel = ( 3 - this.transparent.color.r - + this.transparent.color.g - + this.transparent.color.b ) / + 3 * this.transparency; + } else if ( transparentColor.opaque == "RGB_ZERO" ) { + transparencyLevel = ( this.transparent.color.r + + this.transparent.color.g + + this.transparent.color.b ) / + 3 * this.transparency; + } else if ( transparentColor.opaque == "A_ONE" ) { + transparencyLevel = ( 1 - this.transparent.color.a ) * this.transparency; + } else { // A_ZERO (default in collada 1.5.0) - http://www.khronos.org/files/collada_1_5_release_notes.pdf (pg 16) + transparencyLevel = this.transparent.color.a * this.transparency; + } + // Assumes all texures in the 'transparent' field will have an alpha channel + if ( transparentColor.isTexture() || transparencyLevel > 0 ) { props[ 'transparent' ] = true; - props[ 'opacity' ] = 1 - transparencyLevel; - + } else { + props[ 'transparent' ] = false; } - + props[ 'opacity' ] = 1 - transparencyLevel; } var keys = { @@ -3722,7 +3735,7 @@ THREE.ColladaLoader = function () { } - } else if ( prop === 'diffuse' || !transparent ) { + } else { if ( prop === 'emission' ) { From 9b9040a49a3e3388ba8619b25c317e3164ee1eef Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Mon, 23 Mar 2015 11:28:05 -0400 Subject: [PATCH 069/129] Enable specular map from specularLevel node --- .../client/lib/vwf/model/threejs/js/loaders/ColladaLoader.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/support/client/lib/vwf/model/threejs/js/loaders/ColladaLoader.js b/support/client/lib/vwf/model/threejs/js/loaders/ColladaLoader.js index f7436ca0b..f57dcca25 100644 --- a/support/client/lib/vwf/model/threejs/js/loaders/ColladaLoader.js +++ b/support/client/lib/vwf/model/threejs/js/loaders/ColladaLoader.js @@ -3577,6 +3577,7 @@ THREE.ColladaLoader = function () { case 'emission': case 'diffuse': case 'specular': + case 'specularLevel': case 'transparent': this[ child.nodeName ] = ( new ColorOrTexture() ).parse( child ); @@ -3666,6 +3667,7 @@ THREE.ColladaLoader = function () { 'diffuse':'map', 'ambient':'lightMap' , 'specular':'specularMap', + 'specularLevel':'specularMap', 'emission':'emissionMap', 'bump':'bumpMap', 'normal':'normalMap' @@ -3679,6 +3681,7 @@ THREE.ColladaLoader = function () { case 'emission': case 'diffuse': case 'specular': + case 'specularLevel': case 'bump': case 'normal': From 147b793af0ebf391fe954f2da4506c35766e1267 Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Tue, 7 Apr 2015 13:59:08 -0400 Subject: [PATCH 070/129] Brings back the trashcan and removes an offset that isn't needed (which should fix tooltips and mutator callout origins for Blockly). --- support/client/lib/vwf/view/blockly.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/support/client/lib/vwf/view/blockly.js b/support/client/lib/vwf/view/blockly.js index d9bb766d1..f5c4d024c 100644 --- a/support/client/lib/vwf/view/blockly.js +++ b/support/client/lib/vwf/view/blockly.js @@ -101,7 +101,6 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor Blockly.inject( document.getElementById( self.options.divName ), { path: this.options.blocklyPath, toolbox: document.getElementById( self.options.toolbox ), - trashcan: false, } ); // HACK: Fix Blockly's hijacking of the backspace and delete keys in password fields @@ -451,10 +450,12 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor function cleanUpdateToolbox( xml ) { // negateOverlap is being use to negate some of the effect of the MARGIN variable // in Blockly.createDom_ when deleting blocks over the flyout - var negateOverlap = 35; + // SJF: Overlap not present in Blockly with categories enabled + + //var negateOverlap = 35; Blockly.updateToolbox( xml ); - Blockly.mainWorkspace.scrollX = Blockly.mainWorkspace.flyout_.width_ + negateOverlap; - var translation = 'translate(' + Blockly.mainWorkspace.scrollX + ', 0)'; + //Blockly.mainWorkspace.scrollX = Blockly.mainWorkspace.flyout_.width_ + negateOverlap; + var translation = 'translate( 0, 0)'; Blockly.mainWorkspace.getCanvas().setAttribute('transform', translation); } From d70e9de94c49bc488ef6c04a19af950cc6b68f1a Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Tue, 7 Apr 2015 14:08:21 -0400 Subject: [PATCH 071/129] Clean up changes --- support/client/lib/vwf/view/blockly.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/support/client/lib/vwf/view/blockly.js b/support/client/lib/vwf/view/blockly.js index f5c4d024c..30943b858 100644 --- a/support/client/lib/vwf/view/blockly.js +++ b/support/client/lib/vwf/view/blockly.js @@ -100,7 +100,7 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor self.kernel.setProperty( childID, "toolbox", self.options.toolbox ); Blockly.inject( document.getElementById( self.options.divName ), { path: this.options.blocklyPath, - toolbox: document.getElementById( self.options.toolbox ), + toolbox: document.getElementById( self.options.toolbox ) } ); // HACK: Fix Blockly's hijacking of the backspace and delete keys in password fields @@ -452,11 +452,11 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor // in Blockly.createDom_ when deleting blocks over the flyout // SJF: Overlap not present in Blockly with categories enabled - //var negateOverlap = 35; + // var negateOverlap = 35; Blockly.updateToolbox( xml ); - //Blockly.mainWorkspace.scrollX = Blockly.mainWorkspace.flyout_.width_ + negateOverlap; - var translation = 'translate( 0, 0)'; - Blockly.mainWorkspace.getCanvas().setAttribute('transform', translation); + // Blockly.mainWorkspace.scrollX = Blockly.mainWorkspace.flyout_.width_ + negateOverlap; + // var translation = 'translate( ' + Blockly.mainWorkspace.scrollX + ', 0 )'; + // Blockly.mainWorkspace.getCanvas().setAttribute('transform', translation); } // domCopyToWorkspace copies the saved blocks to the workspace exactly From 9fda43c7699c44963d42037d947a586615236c65 Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Thu, 9 Apr 2015 12:37:56 -0400 Subject: [PATCH 072/129] Adds support to change the execution time of Blockly depending on the length of the task to be completed in the Blockly block. --- support/client/lib/vwf/model/blockly.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/support/client/lib/vwf/model/blockly.js b/support/client/lib/vwf/model/blockly.js index 5948c6f12..ce2af3f05 100644 --- a/support/client/lib/vwf/model/blockly.js +++ b/support/client/lib/vwf/model/blockly.js @@ -231,6 +231,10 @@ define( [ "module", "vwf/model", "vwf/utility", value = node.blocks = propertyValue; break; + case "blockly_timeBetweenLines": + this.state.blockly.node.timeBetweenLines = propertyValue; + break; + case "blockly_executing": var exe = Boolean( propertyValue ); if ( exe ) { @@ -376,6 +380,7 @@ define( [ "module", "vwf/model", "vwf/utility", for ( var nodeID in this.state.executingBlocks ) { blocklyNode = this.state.executingBlocks[ nodeID ]; + var executeNextLine = false; if ( blocklyNode.interpreter === undefined || @@ -387,6 +392,7 @@ define( [ "module", "vwf/model", "vwf/utility", } else { var elaspedTime = vwfTime - blocklyNode.lastLineExeTime; if ( elaspedTime >= blocklyNode.timeBetweenLines ) { + console.log( 'm'+ blocklyNode.timeBetweenLines ); executeNextLine = true; blocklyNode.lastLineExeTime = vwfTime; } From dcfa9c24a4e2e1e4c970f4f126a28677b359ac9c Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Fri, 10 Apr 2015 11:51:32 -0400 Subject: [PATCH 073/129] Remove log messages --- support/client/lib/vwf/model/blockly.js | 1 - 1 file changed, 1 deletion(-) diff --git a/support/client/lib/vwf/model/blockly.js b/support/client/lib/vwf/model/blockly.js index ce2af3f05..01bafb704 100644 --- a/support/client/lib/vwf/model/blockly.js +++ b/support/client/lib/vwf/model/blockly.js @@ -392,7 +392,6 @@ define( [ "module", "vwf/model", "vwf/utility", } else { var elaspedTime = vwfTime - blocklyNode.lastLineExeTime; if ( elaspedTime >= blocklyNode.timeBetweenLines ) { - console.log( 'm'+ blocklyNode.timeBetweenLines ); executeNextLine = true; blocklyNode.lastLineExeTime = vwfTime; } From 242deb790cda6dacf1b6615221ce22803f31b727 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Mon, 20 Apr 2015 17:21:29 -0400 Subject: [PATCH 074/129] Now we are checking if the URL exists. --- support/client/lib/vwf/model/jPlayer.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) mode change 100644 => 100755 support/client/lib/vwf/model/jPlayer.js diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js old mode 100644 new mode 100755 index 37dc6ae75..ebbe4dfde --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -220,6 +220,7 @@ define( [ setUrl( node, propertyValue ); value = node.url; break; + case "loop": setLoop( node, propertyValue ); value = node.loop; @@ -362,11 +363,17 @@ define( [ switch( methodName ) { case "play": - - if( methodParameters ){ - this.kernel.setProperty( node.ID, "url", methodParameters ); + //TODO: Check if URL exists. If it doesn't, print out an error. + //ALSO, node.url should be instantiated to null. Or something. + //Basically, if the URL is never set, we have to catch that. + //if( methodParameters ){ + //this.kernel.setProperty( node.ID, "url", methodParameters ); + //} + if( node.url ) { + node.jPlayerElement.jPlayer( "play" ); + } else { + } - node.jPlayerElement.jPlayer( "play" ); break; case "pause": From f183bd973607fe40977e67480f32e83022aaf37d Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Mon, 20 Apr 2015 18:21:51 -0400 Subject: [PATCH 075/129] Separated setting the URL from playing the video. This should allow us to preload. --- support/client/lib/vwf/model/jPlayer.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index ebbe4dfde..874b91f07 100755 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -363,16 +363,10 @@ define( [ switch( methodName ) { case "play": - //TODO: Check if URL exists. If it doesn't, print out an error. - //ALSO, node.url should be instantiated to null. Or something. - //Basically, if the URL is never set, we have to catch that. - //if( methodParameters ){ - //this.kernel.setProperty( node.ID, "url", methodParameters ); - //} if( node.url ) { node.jPlayerElement.jPlayer( "play" ); } else { - + this.logger.errorx( "No URL given!" ); } break; From 18ca8f49a24dccdd08384387a2f0d3e848ad4baf Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Tue, 21 Apr 2015 09:26:58 -0400 Subject: [PATCH 076/129] "load" now works in the jPlayer model. --- support/client/lib/vwf/model/jPlayer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 874b91f07..87a55cde8 100755 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -362,6 +362,10 @@ define( [ switch( methodName ) { + case "load": + node.jPlayerElement.jPlayer( "load" ); + break; + case "play": if( node.url ) { node.jPlayerElement.jPlayer( "play" ); From 4463792e1680230411732af5db5ffc753a3774b4 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Tue, 21 Apr 2015 12:37:13 -0400 Subject: [PATCH 077/129] Got the load functionality into the jPlayer driver... --- support/client/lib/vwf/model/jPlayer.js | 7 ++++++- .../proxy/vwf.example.com/jplayer/videoManager.vwf.yaml | 3 ++- support/proxy/vwf.example.com/sceneGetter.js | 0 3 files changed, 8 insertions(+), 2 deletions(-) mode change 100644 => 100755 support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml mode change 100644 => 100755 support/proxy/vwf.example.com/sceneGetter.js diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 87a55cde8..31a9fb7fe 100755 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -363,7 +363,12 @@ define( [ switch( methodName ) { case "load": - node.jPlayerElement.jPlayer( "load" ); + if( node.url ) { + node.jPlayerElement.jPlayer( "load" ); + this.logger.infox( "Loading!" ); + } else { + this.logger.errorx( "No URL given!" ); + } break; case "play": diff --git a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml old mode 100644 new mode 100755 index 124c640de..751c6fb03 --- a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml +++ b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml @@ -10,6 +10,7 @@ properties: containerSize: [ 1024, 768 ] playerSize: [ 1024, 768 ] methods: + load: play: pause: stop: @@ -17,4 +18,4 @@ methods: hide: clearMedia: events: - videoEnded: \ No newline at end of file + videoEnded: diff --git a/support/proxy/vwf.example.com/sceneGetter.js b/support/proxy/vwf.example.com/sceneGetter.js old mode 100644 new mode 100755 From 53be4d13a20620fa4dbeb01477ca556ecbfcc552 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Wed, 22 Apr 2015 16:49:17 -0400 Subject: [PATCH 078/129] Now we can pre-load the correct cutscenes in the scenario1* series of scenarios. --- support/client/lib/vwf/model/jPlayer.js | 66 ++++++++++++++++--- .../jplayer/videoManager.vwf.yaml | 2 +- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 31a9fb7fe..721d0b3ac 100755 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -221,6 +221,11 @@ define( [ value = node.url; break; + case "preload": + setPreload( node, propertyValue ); + value = node.preload; + break; + case "loop": setLoop( node, propertyValue ); value = node.loop; @@ -257,6 +262,9 @@ define( [ if ( node.loop !== undefined ) { setLoop( node, node.loop ); } + if ( node.preload !== undefined ) { + setPreload( node, node.preload ); + } if ( node.containerDivId !== undefined ) { setControlDivId( node, node.containerDivId ); } @@ -362,14 +370,19 @@ define( [ switch( methodName ) { - case "load": - if( node.url ) { - node.jPlayerElement.jPlayer( "load" ); - this.logger.infox( "Loading!" ); - } else { - this.logger.errorx( "No URL given!" ); - } - break; + //case "load": + //if( node.url ) { + //if( !node.loadedUrl || node.url !== node.loadedUrl ){ + //node.jPlayerElement.jPlayer( "load" ); + //node.loadedUrl = node.url; + //console.log("Loading!"); + //} else { + //console.log("Not loading, becuase node.url matches node.loadedURL"); + //} + //} else { + //this.logger.errorx( "No URL given!" ); + //} + //break; case "play": if( node.url ) { @@ -439,6 +452,30 @@ define( [ } } + Array.prototype.equals = function (array) { + // if the other array is a falsy value, return + if (!array) + return false; + + // compare lengths - can save a lot of time + if (this.length != array.length) + return false; + + for (var i = 0, l=this.length; i < l; i++) { + // Check if we have nested arrays + if (this[i] instanceof Array && array[i] instanceof Array) { + // recurse into the nested arrays + if (!this[i].equals(array[i])) + return false; + } + else if (this[i] != array[i]) { + // Warning - two different object instances will never be equal: {x:20} != {x:20} + return false; + } + } + return true; + } + function setUrl( node, inputUrl ) { var usingMultiUrls; @@ -450,6 +487,10 @@ define( [ usingMultiUrls = false; url = inputUrl; } + if( node.url && url && (node.url).equals( url ) ){ + console.log("Setting redudant URL! Quitting!"); + return; + } node.url = url; // If there is no jPlayerElement, there is nothing to do yet so we return. @@ -497,6 +538,7 @@ define( [ // Otherwise, clear the current media if ( mediaObject ) { node.jPlayerElement.jPlayer( "setMedia", mediaObject ); + node.jPlayerElement.jPlayer( "load" ); } else { node.jPlayerElement.jPlayer( "clearMedia" ); } @@ -505,6 +547,14 @@ define( [ } } + function setPreload( node, preload ) { + node.preload = preload; + if ( node.jPlayerElement ) { + node.jPlayerElement.jPlayer( "option", { preload: preload } ); + console.log("Setting preload to: " + preload); + } + } + function setLoop( node, loop ) { node.loop = loop; if ( node.jPlayerElement ) { diff --git a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml index 751c6fb03..bf0930b36 100755 --- a/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml +++ b/support/proxy/vwf.example.com/jplayer/videoManager.vwf.yaml @@ -9,8 +9,8 @@ properties: playerDivId: "videoScreen" containerSize: [ 1024, 768 ] playerSize: [ 1024, 768 ] + preload: "auto" methods: - load: play: pause: stop: From f321e9eaec2716e7fd9f5096922f0abf8aa94329 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Wed, 22 Apr 2015 19:01:31 -0400 Subject: [PATCH 079/129] Now the jPlayer driver doesn't set the URL (which may cause a load to trigger) if its being set to the same URL as before. --- support/client/lib/vwf/model/jPlayer.js | 52 +++++++++++++------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 721d0b3ac..1a1cf91ab 100755 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -452,29 +452,31 @@ define( [ } } - Array.prototype.equals = function (array) { - // if the other array is a falsy value, return - if (!array) - return false; - - // compare lengths - can save a lot of time - if (this.length != array.length) - return false; - - for (var i = 0, l=this.length; i < l; i++) { - // Check if we have nested arrays - if (this[i] instanceof Array && array[i] instanceof Array) { - // recurse into the nested arrays - if (!this[i].equals(array[i])) - return false; - } - else if (this[i] != array[i]) { - // Warning - two different object instances will never be equal: {x:20} != {x:20} - return false; - } - } - return true; - } +/* + * Array.prototype.equals = function (array) { + * // if the other array is a falsy value, return + * if (!array) + * return false; + * + * // compare lengths - can save a lot of time + * if (this.length != array.length) + * return false; + * + * for (var i = 0, l=this.length; i < l; i++) { + * // Check if we have nested arrays + * if (this[i] instanceof Array && array[i] instanceof Array) { + * // recurse into the nested arrays + * if (!this[i].equals(array[i])) + * return false; + * } + * else if (this[i] != array[i]) { + * // Warning - two different object instances will never be equal: {x:20} != {x:20} + * return false; + * } + * } + * return true; + * } + */ function setUrl( node, inputUrl ) { @@ -487,10 +489,12 @@ define( [ usingMultiUrls = false; url = inputUrl; } - if( node.url && url && (node.url).equals( url ) ){ + + if( node.url && url && ( node.url === url ) ){ console.log("Setting redudant URL! Quitting!"); return; } + node.url = url; // If there is no jPlayerElement, there is nothing to do yet so we return. From f9f7b39f5672bfad08ed0fdb99d6728a0bcbfe40 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Thu, 23 Apr 2015 12:39:08 -0400 Subject: [PATCH 080/129] Update jPlayer.js Got rid of unnecessary, commented-out code. --- support/client/lib/vwf/model/jPlayer.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index 1a1cf91ab..fa1573a0a 100755 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -370,20 +370,6 @@ define( [ switch( methodName ) { - //case "load": - //if( node.url ) { - //if( !node.loadedUrl || node.url !== node.loadedUrl ){ - //node.jPlayerElement.jPlayer( "load" ); - //node.loadedUrl = node.url; - //console.log("Loading!"); - //} else { - //console.log("Not loading, becuase node.url matches node.loadedURL"); - //} - //} else { - //this.logger.errorx( "No URL given!" ); - //} - //break; - case "play": if( node.url ) { node.jPlayerElement.jPlayer( "play" ); From ad3366743e6e326b2901926c52dadea397984bc0 Mon Sep 17 00:00:00 2001 From: Nathan Marshak Date: Thu, 23 Apr 2015 12:39:39 -0400 Subject: [PATCH 081/129] Update jPlayer.js Got rid of another commented-out block that has no relevance. --- support/client/lib/vwf/model/jPlayer.js | 26 ------------------------- 1 file changed, 26 deletions(-) diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index fa1573a0a..f0cf70674 100755 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -438,32 +438,6 @@ define( [ } } -/* - * Array.prototype.equals = function (array) { - * // if the other array is a falsy value, return - * if (!array) - * return false; - * - * // compare lengths - can save a lot of time - * if (this.length != array.length) - * return false; - * - * for (var i = 0, l=this.length; i < l; i++) { - * // Check if we have nested arrays - * if (this[i] instanceof Array && array[i] instanceof Array) { - * // recurse into the nested arrays - * if (!this[i].equals(array[i])) - * return false; - * } - * else if (this[i] != array[i]) { - * // Warning - two different object instances will never be equal: {x:20} != {x:20} - * return false; - * } - * } - * return true; - * } - */ - function setUrl( node, inputUrl ) { var usingMultiUrls; From 36214c5e607c5c07aab06b7ca3e938fb2e3cf06e Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Thu, 16 Apr 2015 14:32:16 -0400 Subject: [PATCH 082/129] Add lights property to shader material --- support/client/lib/vwf/model/threejs.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/support/client/lib/vwf/model/threejs.js b/support/client/lib/vwf/model/threejs.js index 9166bc9c5..2471b59ea 100644 --- a/support/client/lib/vwf/model/threejs.js +++ b/support/client/lib/vwf/model/threejs.js @@ -1655,6 +1655,10 @@ define( [ "module", eval( this.updateFunction ); } } + if ( propertyName === "lights" ) { + value = propertyValue; + threeObject.lights = value; + } } } if ( node.isUniformObject ) { From a015f89328a2d50faa81285694d92c694a416d3a Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Tue, 21 Apr 2015 15:04:21 -0400 Subject: [PATCH 083/129] Allow properties to be stored on material for use in updateFunction --- support/client/lib/vwf/model/threejs.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/support/client/lib/vwf/model/threejs.js b/support/client/lib/vwf/model/threejs.js index 2471b59ea..ef6902590 100644 --- a/support/client/lib/vwf/model/threejs.js +++ b/support/client/lib/vwf/model/threejs.js @@ -1608,7 +1608,7 @@ define( [ "module", } } } - if ( threeObject instanceof THREE.Material ) { + if ( threeObject instanceof THREE.Material && !( threeObject instanceof THREE.ShaderMaterial ) ) { value = setMaterialProperty( threeObject, propertyName, propertyValue ); @@ -1639,25 +1639,23 @@ define( [ "module", if ( propertyName === "uniforms" ) { value = propertyValue; threeObject.uniforms = value; - } - if ( propertyName === "vertexShader" ) { + } else if ( propertyName === "vertexShader" ) { value = propertyValue; threeObject.vertexShader = value; - } - if ( propertyName === "fragmentShader" ) { + } else if ( propertyName === "fragmentShader" ) { value = propertyValue; threeObject.fragmentShader = value; - } - if ( propertyName === "updateFunction" ) { + } else if ( propertyName === "updateFunction" ) { value = propertyValue; threeObject.updateFunction = value; threeObject.update = function() { eval( this.updateFunction ); } - } - if ( propertyName === "lights" ) { + } else if ( propertyName === "lights" ) { value = propertyValue; threeObject.lights = value; + } else if ( !threeObject.hasOwnProperty( propertyName ) ) { + threeObject[ propertyName ] = propertyValue; } } } From 5692c50727e3c4435b7c7e43f175efe0a2a92ad0 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 22 Apr 2015 15:34:13 -0400 Subject: [PATCH 084/129] Store custom properties on material object --- support/client/lib/vwf/model/threejs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/client/lib/vwf/model/threejs.js b/support/client/lib/vwf/model/threejs.js index ef6902590..972c3388e 100644 --- a/support/client/lib/vwf/model/threejs.js +++ b/support/client/lib/vwf/model/threejs.js @@ -1654,7 +1654,7 @@ define( [ "module", } else if ( propertyName === "lights" ) { value = propertyValue; threeObject.lights = value; - } else if ( !threeObject.hasOwnProperty( propertyName ) ) { + } else { threeObject[ propertyName ] = propertyValue; } } From 8db9cbf2c6d988543a368507b7e281b8dc9d2d3c Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Thu, 23 Apr 2015 20:02:36 -0400 Subject: [PATCH 085/129] Fix uniform generation with shader material components --- support/client/lib/vwf/model/threejs.js | 49 +++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/support/client/lib/vwf/model/threejs.js b/support/client/lib/vwf/model/threejs.js index 972c3388e..77797a95e 100644 --- a/support/client/lib/vwf/model/threejs.js +++ b/support/client/lib/vwf/model/threejs.js @@ -1635,9 +1635,20 @@ define( [ "module", if ( threeObject instanceof THREE.ShaderMaterial ) { if ( utility.validObject( propertyValue ) ) { - if ( propertyName === "uniforms" ) { - value = propertyValue; + // Copy uniforms to prevent uniforms being shared across shaders + var names = Object.keys( propertyValue ); + var uniforms = {}; + for ( var i = 0; i < names.length; i++ ) { + var type, value; + type = propertyValue[ names[ i ] ].type; + value = propertyValue[ names[ i ] ].value; + uniforms[ names[ i ] ] = { + "type": type, + "value": getUniformValueByType( type, value ) + } + } + value = uniforms; threeObject.uniforms = value; } else if ( propertyName === "vertexShader" ) { value = propertyValue; @@ -1654,7 +1665,10 @@ define( [ "module", } else if ( propertyName === "lights" ) { value = propertyValue; threeObject.lights = value; - } else { + } else if ( threeObject.uniforms.hasOwnProperty( propertyName ) ) { + var type = threeObject.uniforms[ propertyName ].type; + setUniformProperty( threeObject.uniforms, propertyName, type, propertyValue ); + } else if ( propertyName.indexOf("_") === 0 ) { threeObject[ propertyName ] = propertyValue; } } @@ -5576,6 +5590,35 @@ define( [ "module", } } + function getUniformValueByType( type, value ) { + var result = value; + switch ( type ) { + case 'i': + result = Number( value ); + break + case 'f': + result = parseFloat( value ); + break; + case 'c': + result = new THREE.Color( value ); + break; + case 'v2': + result = new THREE.Vector2( value[0], value[1] ); + break; + case 'v3': + result = new THREE.Vector3( value[0], value[1], value[2] ); + break; + case 'v4': + result = new THREE.Vector4( value[0], value[1], value[2], value[3] ); + break; + case 't': + if ( value ) { + result = loadTexture( undefined, value ); + } + break; + } + return result; + } function decompress(dataencoded) { blobsfound = 0; From 60327858873435493c2219cc27d336cfb36b03e8 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Mon, 27 Apr 2015 14:01:52 -0400 Subject: [PATCH 086/129] Texture arrays and texture wrapping to shader materials --- support/client/lib/vwf/model/threejs.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/support/client/lib/vwf/model/threejs.js b/support/client/lib/vwf/model/threejs.js index 77797a95e..112f45df8 100644 --- a/support/client/lib/vwf/model/threejs.js +++ b/support/client/lib/vwf/model/threejs.js @@ -5587,6 +5587,13 @@ define( [ "module", obj[ prop ].src = value; obj[ prop ].value = loadTexture( undefined, value ); break; + case 'tv': + var textureArray = []; + for ( var i = 0; i < value.length; i++ ) { + textureArray.push( loadTexture( undefined, value[ i ] ) ); + } + obj[ prop ].value = textureArray; + break; } } @@ -5616,6 +5623,12 @@ define( [ "module", result = loadTexture( undefined, value ); } break; + case 'tv': + result = []; + for ( var i = 0; i < value.length; i++ ) { + result.push( loadTexture( undefined, value[ i ] ) ); + } + break; } return result; } @@ -5635,6 +5648,7 @@ define( [ "module", var txt = undefined; var url = undefined; var mapping = undefined; + var wrapTexture = false; var onLoad = function( texture ) { if ( mat ) { mat.map = texture; @@ -5653,6 +5667,7 @@ define( [ "module", } else { url = def.url; mapping = def.mapping; + wrapTexture = Boolean( def.wrapTexture ); } if ( mat === undefined ) { @@ -5665,6 +5680,10 @@ define( [ "module", txt = THREE.ImageUtils.loadTexture( url, mapping, onLoad, onError ); } + if ( wrapTexture ) { + txt.wrapS = txt.wrapT = THREE.RepeatWrapping; + } + return txt; } From 847fbcc174679dbcab11399148f4701ccfb26829 Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Tue, 28 Apr 2015 10:03:35 -0400 Subject: [PATCH 087/129] Refinements in progress... --- support/client/lib/vwf/model/blockly.js | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/support/client/lib/vwf/model/blockly.js b/support/client/lib/vwf/model/blockly.js index 01bafb704..d03284b64 100644 --- a/support/client/lib/vwf/model/blockly.js +++ b/support/client/lib/vwf/model/blockly.js @@ -64,6 +64,7 @@ define( [ "module", "vwf/model", "vwf/utility", "code": undefined, "lastLineExeTime": undefined, "timeBetweenLines": 1, + "baseExecutionSpeed": 1, "interpreter": undefined, "interpreterStatus": "" }; @@ -235,6 +236,17 @@ define( [ "module", "vwf/model", "vwf/utility", this.state.blockly.node.timeBetweenLines = propertyValue; break; + case "blockly_baseExecutionSpeed": + + if ( propertyValue > 0 && propertyValue <= 10 ) { + this.state.blockly.node.baseExecutionSpeed = propertyValue; + } else { + this.logger.errorx("baseExecutionSpeed", "Blockly node with", nodeID, + "must have base execution greater than 0 and less than 10."); + } + + break; + case "blockly_executing": var exe = Boolean( propertyValue ); if ( exe ) { @@ -357,6 +369,22 @@ define( [ "module", "vwf/model", "vwf/utility", "is not currently executing Blockly!"); } break; + case "changeBaseExecutionSpeed": + if ( !methodParameters || methodParameters.length !== 1 ) { + this.logger.errorx("changeBaseExecutionSpeed", "Node with", nodeID, + "takes one argument to change the Blockly base execution speed!"); + break; + } + + var newValue = methodParameters[ 0 ]; + + if ( newValue > 0 && newValue <= 10 ) { + this.kernel.setProperty( nodeID, 'blockly_baseExecutionSpeed',newValue ); + } else { + this.logger.errorx("changeBaseExecutionSpeed", "Blockly node with", + nodeID, "must have base execution greater than 0 and less than 10."); + } + break; } } }, @@ -391,7 +419,7 @@ define( [ "module", "vwf/model", "vwf/utility", executeNextLine = true; } else { var elaspedTime = vwfTime - blocklyNode.lastLineExeTime; - if ( elaspedTime >= blocklyNode.timeBetweenLines ) { + if ( elaspedTime >= blocklyNode.timeBetweenLines * blocklyNode.baseExecutionSpeed ) { executeNextLine = true; blocklyNode.lastLineExeTime = vwfTime; } From 1c084a591a63cb9a0103088da3c9d2de94e0b9ad Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Tue, 28 Apr 2015 12:30:59 -0400 Subject: [PATCH 088/129] Speed up working. --- support/client/lib/vwf/model/blockly.js | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/support/client/lib/vwf/model/blockly.js b/support/client/lib/vwf/model/blockly.js index d03284b64..9a5e77134 100644 --- a/support/client/lib/vwf/model/blockly.js +++ b/support/client/lib/vwf/model/blockly.js @@ -240,6 +240,7 @@ define( [ "module", "vwf/model", "vwf/utility", if ( propertyValue > 0 && propertyValue <= 10 ) { this.state.blockly.node.baseExecutionSpeed = propertyValue; + console.log('speed set'); } else { this.logger.errorx("baseExecutionSpeed", "Blockly node with", nodeID, "must have base execution greater than 0 and less than 10."); @@ -369,22 +370,6 @@ define( [ "module", "vwf/model", "vwf/utility", "is not currently executing Blockly!"); } break; - case "changeBaseExecutionSpeed": - if ( !methodParameters || methodParameters.length !== 1 ) { - this.logger.errorx("changeBaseExecutionSpeed", "Node with", nodeID, - "takes one argument to change the Blockly base execution speed!"); - break; - } - - var newValue = methodParameters[ 0 ]; - - if ( newValue > 0 && newValue <= 10 ) { - this.kernel.setProperty( nodeID, 'blockly_baseExecutionSpeed',newValue ); - } else { - this.logger.errorx("changeBaseExecutionSpeed", "Blockly node with", - nodeID, "must have base execution greater than 0 and less than 10."); - } - break; } } }, @@ -410,7 +395,7 @@ define( [ "module", "vwf/model", "vwf/utility", blocklyNode = this.state.executingBlocks[ nodeID ]; var executeNextLine = false; - + if ( blocklyNode.interpreter === undefined || blocklyNode.interpreterStatus === "completed" ) { blocklyNode.interpreter = createInterpreter( acorn, blocklyNode.code ); @@ -419,7 +404,7 @@ define( [ "module", "vwf/model", "vwf/utility", executeNextLine = true; } else { var elaspedTime = vwfTime - blocklyNode.lastLineExeTime; - if ( elaspedTime >= blocklyNode.timeBetweenLines * blocklyNode.baseExecutionSpeed ) { + if ( elaspedTime >= ( blocklyNode.timeBetweenLines * blocklyNode.baseExecutionSpeed ) ) { executeNextLine = true; blocklyNode.lastLineExeTime = vwfTime; } From e619348ebc1edce41c5fc1ab1a15444632c7c74f Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Thu, 30 Apr 2015 16:23:31 -0400 Subject: [PATCH 089/129] Remove a log message --- support/client/lib/vwf/model/blockly.js | 1 - 1 file changed, 1 deletion(-) diff --git a/support/client/lib/vwf/model/blockly.js b/support/client/lib/vwf/model/blockly.js index 9a5e77134..74100e6be 100644 --- a/support/client/lib/vwf/model/blockly.js +++ b/support/client/lib/vwf/model/blockly.js @@ -240,7 +240,6 @@ define( [ "module", "vwf/model", "vwf/utility", if ( propertyValue > 0 && propertyValue <= 10 ) { this.state.blockly.node.baseExecutionSpeed = propertyValue; - console.log('speed set'); } else { this.logger.errorx("baseExecutionSpeed", "Blockly node with", nodeID, "must have base execution greater than 0 and less than 10."); From 01a6f618966a40b04381cf50bbd72957d2535c12 Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Tue, 5 May 2015 09:14:31 -0400 Subject: [PATCH 090/129] Fix error message --- support/client/lib/vwf/model/blockly.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/client/lib/vwf/model/blockly.js b/support/client/lib/vwf/model/blockly.js index 74100e6be..1f76830e7 100644 --- a/support/client/lib/vwf/model/blockly.js +++ b/support/client/lib/vwf/model/blockly.js @@ -242,7 +242,7 @@ define( [ "module", "vwf/model", "vwf/utility", this.state.blockly.node.baseExecutionSpeed = propertyValue; } else { this.logger.errorx("baseExecutionSpeed", "Blockly node with", nodeID, - "must have base execution greater than 0 and less than 10."); + "must be in the range (0,10)."); } break; From e62fc4f7b2ad404dbf01bf3f329e9aac2bab377f Mon Sep 17 00:00:00 2001 From: David Easter Date: Sat, 9 May 2015 17:12:53 -0400 Subject: [PATCH 091/129] Use `kernel.prototypes` instead of `getPrototypes` in each driver. --- support/client/lib/vwf/model/blockly.js | 12 ------------ support/client/lib/vwf/model/buzz.js | 14 +------------- support/client/lib/vwf/model/cesium.js | 18 +++--------------- support/client/lib/vwf/model/glge.js | 22 ++++------------------ support/client/lib/vwf/model/graphtool.js | 14 +------------- support/client/lib/vwf/model/heightmap.js | 14 +------------- support/client/lib/vwf/model/hud.js | 12 +----------- support/client/lib/vwf/model/jPlayer.js | 14 +------------- support/client/lib/vwf/model/kineticjs.js | 14 +------------- support/client/lib/vwf/model/mil-sym.js | 14 +------------- support/client/lib/vwf/model/threejs.js | 16 ++-------------- support/client/lib/vwf/view/cesium.js | 14 +------------- support/client/lib/vwf/view/webrtc.js | 14 +------------- 13 files changed, 18 insertions(+), 174 deletions(-) diff --git a/support/client/lib/vwf/model/blockly.js b/support/client/lib/vwf/model/blockly.js index 1f76830e7..5443d9cac 100644 --- a/support/client/lib/vwf/model/blockly.js +++ b/support/client/lib/vwf/model/blockly.js @@ -426,18 +426,6 @@ define( [ "module", "vwf/model", "vwf/utility", } ); - function getPrototypes( extendsID ) { - var prototypes = []; - var id = extendsID; - - while ( id !== undefined ) { - prototypes.push( id ); - id = self.kernel.prototype( id ); - } - - return prototypes; - } - function isBlockly3Node( nodeID ) { return self.kernel.test( nodeID, "self::element(*,'http://vwf.example.com/blockly/controller.vwf')", diff --git a/support/client/lib/vwf/model/buzz.js b/support/client/lib/vwf/model/buzz.js index c0c010feb..b5559311f 100644 --- a/support/client/lib/vwf/model/buzz.js +++ b/support/client/lib/vwf/model/buzz.js @@ -112,7 +112,7 @@ define( [ return; } - var protos = getPrototypes( this.kernel, childExtendsID ); + var protos = this.kernel.prototypes( childID ); var node; if ( this.state.isSoundComponent( protos ) ) { @@ -415,18 +415,6 @@ define( [ } ); - function getPrototypes( kernel, extendsID ) { - var prototypes = []; - var id = extendsID; - - while ( id !== undefined ) { - prototypes.push( id ); - id = kernel.prototype( id ); - } - - return prototypes; - } - function createSound( node, url ) { var soundProps; diff --git a/support/client/lib/vwf/model/cesium.js b/support/client/lib/vwf/model/cesium.js index d47a142dd..72ede50c9 100644 --- a/support/client/lib/vwf/model/cesium.js +++ b/support/client/lib/vwf/model/cesium.js @@ -306,7 +306,7 @@ define( [ "module", } var node = undefined, parentNode, sceneNode; - var protos = getPrototypes.call( this, childExtendsID ); + var protos = this.kernel.prototypes( childID ); var createNode = function() { return { @@ -626,7 +626,7 @@ define( [ "module", // there, too function notifyDriverOfPrototypeAndBehaviorProps() { var ptPropValue; - var protos = getPrototypes.call( self, childExtendsID ); + var protos = self.kernel.prototypes( childID ); protos.forEach( function( prototypeID ) { for ( var propertyName in kernel.getProperties( prototypeID ) ) { //console.info( " 1 getting "+propertyName+" of: " + childExtendsID ); @@ -2011,18 +2011,6 @@ define( [ "module", } - function getPrototypes( extendsID ) { - var prototypes = []; - var id = extendsID; - - while ( id !== undefined ) { - prototypes.push( id ); - id = this.kernel.prototype( id ); - } - - return prototypes; - } - function findParent( ID ) { var retNode = this.state.nodes[ ID ]; if ( retNode === undefined ) { @@ -2037,7 +2025,7 @@ define( [ "module", var protos = undefined; var parent = findParent.call( this, parentID ); while ( parent && sceneNode === undefined ) { - protos = getPrototypes.call( this, parent.extendsID ); + protos = this.kernel.prototypes( parent.ID ); if ( protos && isCesium.call( this, protos ) ) { sceneNode = parent; } else { diff --git a/support/client/lib/vwf/model/glge.js b/support/client/lib/vwf/model/glge.js index 137175fa0..1966cdd14 100644 --- a/support/client/lib/vwf/model/glge.js +++ b/support/client/lib/vwf/model/glge.js @@ -75,7 +75,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili var node, parentNode, glgeChild, glgeParent; var kernel = this.kernel; - var prototypes = getPrototypes.call( this, kernel, childExtendsID ); + var prototypes = this.kernel.prototypes( childID ); // this.logger.enabled = true; // this.logger.infox( "creatingNode", nodeID, childID, childExtendsID, childImplementsIDs, @@ -328,7 +328,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili // there, too function notifyDriverOfPrototypeAndBehaviorProps() { var ptPropValue; - var protos = getPrototypes.call( this, kernel, childExtendsID ); + var protos = self.kernel.prototypes( childID ); protos.forEach( function( prototypeID ) { for ( var propertyName in kernel.getProperties( prototypeID ) ) { //console.info( " 1 getting "+propertyName+" of: " + childExtendsID ); @@ -620,7 +620,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili break; default: - prototypes = getPrototypes.call( this, this.kernel.kernel.kernel, node["type"] ); + prototypes = this.kernel.prototypes( node.ID ); if ( isGlgeMaterialDefinition.call( this, prototypes ) ){ value = setMaterialProperty.call( this, nodeID, propertyName, propertyValue ); } else if ( isGlgeCameraDefinition.call( this, prototypes ) ) { @@ -773,7 +773,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili default: // handle all of the other types - prototypes = getPrototypes.call( this, this.kernel.kernel.kernel, node["type"] ); + prototypes = this.kernel.prototypes( node.ID ); if ( isGlgeMaterialDefinition.call( this, prototypes ) ){ value = getMaterialProperty.call( this, nodeID, propertyName, propertyValue ); } else if ( isGlgeCameraDefinition.call( this, prototypes ) ) { @@ -2222,20 +2222,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili return vertexIndices; } - // get the list of types this ID extends - - function getPrototypes( kernel, extendsID ) { - var prototypes = []; - var id = extendsID; - - while ( id !== undefined ) { - prototypes.push( id ); - id = kernel.prototype( id ); - } - - return prototypes; - } - function isPrototype( nodeID, childID ) { var ptID; if ( ( nodeID == 0 && childID != this.kernel.application() ) || this.state.prototypes[ nodeID ] !== undefined ) { diff --git a/support/client/lib/vwf/model/graphtool.js b/support/client/lib/vwf/model/graphtool.js index 69a19418e..1a86ef44d 100644 --- a/support/client/lib/vwf/model/graphtool.js +++ b/support/client/lib/vwf/model/graphtool.js @@ -32,7 +32,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili var node = undefined; var kernel = this.state.kernel; - var protos = getPrototypes.call( this, kernel, childExtendsID ); + var protos = this.kernel.prototypes( childID ); if ( protos && isGraph( protos ) ) { @@ -316,18 +316,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili return threejs; } - - function getPrototypes( kernel, extendsID ) { - var prototypes = []; - var id = extendsID; - - while ( id !== undefined ) { - prototypes.push( id ); - id = kernel.prototype( id ); - } - - return prototypes; - } function isGraph( prototypes ) { diff --git a/support/client/lib/vwf/model/heightmap.js b/support/client/lib/vwf/model/heightmap.js index 106620309..60d0a9c84 100644 --- a/support/client/lib/vwf/model/heightmap.js +++ b/support/client/lib/vwf/model/heightmap.js @@ -18,7 +18,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili creatingNode: function( nodeID, childID, childExtendsID, childImplementsIDs, childSource, childType, childIndex, childName, callback ) { - var protos = getPrototypes( this.kernel, childExtendsID ); + var protos = this.kernel.prototypes( childID ); if ( isHeightmap( protos ) ) { @@ -86,18 +86,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } ); - function getPrototypes( kernel, extendsID ) { - var prototypes = []; - var id = extendsID; - - while ( id !== undefined ) { - prototypes.push( id ); - id = kernel.prototype( id ); - } - - return prototypes; - } - function isHeightmap( prototypes ) { var found = false; if ( prototypes ) { diff --git a/support/client/lib/vwf/model/hud.js b/support/client/lib/vwf/model/hud.js index f41dd4590..478b5d7e0 100644 --- a/support/client/lib/vwf/model/hud.js +++ b/support/client/lib/vwf/model/hud.js @@ -22,7 +22,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili childSource, childType, childIndex, childName, callback /* ( ready ) */ ) { var node; - var protos = getPrototypes.call( this, this.state.kernel, childExtendsID ); + var protos = this.kernel.prototypes( childID ); if ( protos && isOverlay( protos ) ) { node = this.state.overlays[ childID ] = { "id": childID, @@ -148,16 +148,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } ); - function getPrototypes( kernel, extendsID ) { - var prototypes = []; - var id = extendsID; - while ( id !== undefined ) { - prototypes.push( id ); - id = kernel.prototype( id ); - } - return prototypes; - } - function isOverlay( prototypes ) { var foundOverlay = false; if ( prototypes ) { diff --git a/support/client/lib/vwf/model/jPlayer.js b/support/client/lib/vwf/model/jPlayer.js index f0cf70674..95eeb8ed5 100755 --- a/support/client/lib/vwf/model/jPlayer.js +++ b/support/client/lib/vwf/model/jPlayer.js @@ -141,7 +141,7 @@ define( [ return; } - var protos = getPrototypes( this.kernel, childExtendsID ); + var protos = this.kernel.prototypes( childID ); var isAudioManager = this.state.isAudioManager( protos ); var isVideoManager = this.state.isVideoManager( protos ); @@ -397,18 +397,6 @@ define( [ } ); - function getPrototypes( kernel, extendsID ) { - var prototypes = []; - var id = extendsID; - - while ( id !== undefined ) { - prototypes.push( id ); - id = kernel.prototype( id ); - } - - return prototypes; - } - function setWithPrototypeProperties( proto ) { if ( proto.url !== null ) { vwf.setProperty( node.ID, "url", proto.url ); diff --git a/support/client/lib/vwf/model/kineticjs.js b/support/client/lib/vwf/model/kineticjs.js index dd7f3bdaf..959d2de63 100644 --- a/support/client/lib/vwf/model/kineticjs.js +++ b/support/client/lib/vwf/model/kineticjs.js @@ -116,7 +116,7 @@ define( [ "module", return; } - var protos = getPrototypes( this.kernel, childExtendsID ); + var protos = this.kernel.prototypes( childID ); var node; @@ -2087,18 +2087,6 @@ define( [ "module", } ); // == PRIVATE ======================================================================================== - function getPrototypes( kernel, extendsID ) { - var prototypes = []; - var id = extendsID; - - while ( id !== undefined ) { - prototypes.push( id ); - id = kernel.prototype( id ); - } - - return prototypes; - } - function createKineticObject( node, config ) { var protos = node.prototypes; var kineticObj = undefined; diff --git a/support/client/lib/vwf/model/mil-sym.js b/support/client/lib/vwf/model/mil-sym.js index f30941d0e..7b343159e 100644 --- a/support/client/lib/vwf/model/mil-sym.js +++ b/support/client/lib/vwf/model/mil-sym.js @@ -107,7 +107,7 @@ define( [ "module", return; } - var protos = getPrototypes( childExtendsID ); + var protos = this.kernel.prototypes( childID ); var node = this.state.nodes[ childID ]; if ( node === undefined ) { @@ -424,18 +424,6 @@ define( [ "module", } ); - function getPrototypes( extendsID ) { - var prototypes = []; - var id = extendsID; - - while ( id !== undefined ) { - prototypes.push( id ); - id = self.kernel.prototype( id ); - } - - return prototypes; - } - function isUnitNode( prototypes ) { var found = false; if ( prototypes ) { diff --git a/support/client/lib/vwf/model/threejs.js b/support/client/lib/vwf/model/threejs.js index 112f45df8..f0ad9acf6 100644 --- a/support/client/lib/vwf/model/threejs.js +++ b/support/client/lib/vwf/model/threejs.js @@ -179,7 +179,7 @@ define( [ "module", } var kernel = this.kernel.kernel.kernel; - var protos = getPrototypes.call( this, kernel, childExtendsID ); + var protos = this.kernel.prototypes( childID ); if ( isSceneDefinition.call(this, protos) && childID == this.kernel.application() ) { var sceneNode = CreateThreeJSSceneNode( nodeID, childID, childExtendsID ); @@ -511,7 +511,7 @@ define( [ "module", // there, too function notifyDriverOfPrototypeAndBehaviorProps() { var ptPropValue; - var protos = getPrototypes.call( this, kernel, childExtendsID ); + var protos = self.kernel.prototypes( childID ); protos.forEach( function( prototypeID ) { for ( var propertyName in kernel.getProperties( prototypeID ) ) { ptPropValue = kernel.getProperty( childExtendsID, propertyName ); @@ -2790,18 +2790,6 @@ define( [ "module", return false; } - function getPrototypes( kernel, extendsID ) { - var prototypes = []; - var id = extendsID; - - while ( id !== undefined ) { - prototypes.push( id ); - id = kernel.prototype( id ); - } - - return prototypes; - } - function getThreeScene( id ) { if ( id === undefined ) { id = this.kernel.application(); diff --git a/support/client/lib/vwf/view/cesium.js b/support/client/lib/vwf/view/cesium.js index f139c0a09..252f24cf8 100644 --- a/support/client/lib/vwf/view/cesium.js +++ b/support/client/lib/vwf/view/cesium.js @@ -121,7 +121,7 @@ define( [ "module", "vwf/view", "vwf/utility", "vwf/model/cesium/Cesium", "jquer }; var kernel = this.kernel; - var protos = getPrototypes.call( this, childExtendsID ) + var protos = this.kernel.prototypes( childID ); var node = undefined; if ( isCesiumDefinition.call( this, protos ) ) { @@ -362,18 +362,6 @@ define( [ "module", "vwf/view", "vwf/utility", "vwf/model/cesium/Cesium", "jquer } ); - function getPrototypes( extendsID ) { - var prototypes = []; - var id = extendsID; - - while ( id !== undefined ) { - prototypes.push( id ); - id = this.kernel.prototype( id ); - } - - return prototypes; - } - function isCesiumDefinition( prototypes ) { var foundCesium = false; if ( prototypes ) { diff --git a/support/client/lib/vwf/view/webrtc.js b/support/client/lib/vwf/view/webrtc.js index 4b6188682..068a04ae7 100644 --- a/support/client/lib/vwf/view/webrtc.js +++ b/support/client/lib/vwf/view/webrtc.js @@ -75,7 +75,7 @@ define( [ "module", "vwf/view", "vwf/utility", "vwf/utility/color", "jquery" ], var self = this, node; - var protos = getPrototypes.call( self, childExtendsID ) + var protos = this.kernel.prototypes( childID ); if ( isClientInstanceDef.call( this, protos ) && childName ) { @@ -338,18 +338,6 @@ define( [ "module", "vwf/view", "vwf/utility", "vwf/utility/color", "jquery" ], } ); - function getPrototypes( extendsID ) { - var prototypes = []; - var id = extendsID; - - while ( id !== undefined ) { - prototypes.push( id ); - id = this.kernel.prototype( id ); - } - - return prototypes; - } - function getPeer( moniker ) { var clientNode; for ( var id in this.state.clients ) { From 1feaa0edecf41ad644dddd172e93fe002477faa9 Mon Sep 17 00:00:00 2001 From: David Easter Date: Sat, 9 May 2015 17:28:36 -0400 Subject: [PATCH 092/129] Remove attempts to follow the driver chain using `kernel.kernel`. --- support/client/lib/vwf/model/graphtool.js | 2 -- support/client/lib/vwf/model/hud.js | 6 ------ support/client/lib/vwf/model/threejs.js | 23 +++++++++++------------ 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/support/client/lib/vwf/model/graphtool.js b/support/client/lib/vwf/model/graphtool.js index 1a86ef44d..b502705b9 100644 --- a/support/client/lib/vwf/model/graphtool.js +++ b/support/client/lib/vwf/model/graphtool.js @@ -20,7 +20,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili self = this; this.state.graphs = {}; this.state.objects = {}; - this.state.kernel = this.kernel.kernel.kernel; }, // == Model API ============================================================================ @@ -31,7 +30,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili childSource, childType, childIndex, childName, callback /* ( ready ) */ ) { var node = undefined; - var kernel = this.state.kernel; var protos = this.kernel.prototypes( childID ); if ( protos && isGraph( protos ) ) { diff --git a/support/client/lib/vwf/model/hud.js b/support/client/lib/vwf/model/hud.js index 478b5d7e0..5d67e6a27 100644 --- a/support/client/lib/vwf/model/hud.js +++ b/support/client/lib/vwf/model/hud.js @@ -7,14 +7,8 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili return model.load( module, { initialize: function() { - var lastKernel; this.state.overlays = {}; this.state.elements = {}; - lastKernel = this.kernel; - while ( lastKernel.kernel ) { - lastKernel = lastKernel.kernel; - } - this.state.kernel = lastKernel; logger = this.logger; }, diff --git a/support/client/lib/vwf/model/threejs.js b/support/client/lib/vwf/model/threejs.js index f0ad9acf6..677a8d81b 100644 --- a/support/client/lib/vwf/model/threejs.js +++ b/support/client/lib/vwf/model/threejs.js @@ -50,11 +50,12 @@ define( [ "module", "vwf/model", "vwf/utility", + "vwf/kernel/utility", "vwf/utility/color", "jquery" ], - function( module, model, utility, Color, $ ) { + function( module, model, utility, kutility, Color, $ ) { var self; @@ -76,7 +77,6 @@ define( [ "module", this.state.scenes = {}; // id => { glgeDocument: new GLGE.Document(), glgeRenderer: new GLGE.Renderer(), glgeScene: new GLGE.Scene() } this.state.nodes = {}; // id => { name: string, glgeObject: GLGE.Object, GLGE.Collada, GLGE.Light, or other...? } this.state.prototypes = {}; - this.state.kernel = this.kernel.kernel.kernel; this.state.lights = {}; this.state.setMeshPropertyRecursively = function( threeObject, propertyName, value ) { @@ -177,7 +177,6 @@ define( [ "module", } } } - var kernel = this.kernel.kernel.kernel; var protos = this.kernel.prototypes( childID ); if ( isSceneDefinition.call(this, protos) && childID == this.kernel.application() ) @@ -513,16 +512,16 @@ define( [ "module", var ptPropValue; var protos = self.kernel.prototypes( childID ); protos.forEach( function( prototypeID ) { - for ( var propertyName in kernel.getProperties( prototypeID ) ) { - ptPropValue = kernel.getProperty( childExtendsID, propertyName ); + for ( var propertyName in self.kernel.getProperties( prototypeID ) ) { + ptPropValue = self.kernel.getProperty( childExtendsID, propertyName ); if ( ptPropValue !== undefined && ptPropValue !== null && childID !== undefined && childID !== null) { self.settingProperty( childID, propertyName, ptPropValue ); } } } ); childImplementsIDs.forEach( function( behaviorID ) { - for ( var propertyName in kernel.getProperties( behaviorID ) ) { - ptPropValue = kernel.getProperty( behaviorID, propertyName ); + for ( var propertyName in self.kernel.getProperties( behaviorID ) ) { + ptPropValue = self.kernel.getProperty( behaviorID, propertyName ); if ( ptPropValue !== undefined && ptPropValue !== null && childID !== undefined && childID !== null) { self.settingProperty( childID, propertyName, ptPropValue ); } @@ -1282,12 +1281,12 @@ define( [ "module", // Skeletal Animations (takes precedence over Morph Target) if ( node.threeObject.bones && node.threeObject.bones.length > 0 ) { - var animRate = this.state.kernel.getProperty( nodeID, "animationRate" ) || 1; + var animRate = this.kernel.getProperty( nodeID, "animationRate" ) || 1; THREE.AnimationHandler.update(animRate); } // Morph Target Animations else if ( node.threeObject.animatedMesh && node.threeObject.animatedMesh.length && propertyValue !== undefined ) { - var fps = this.state.kernel.getProperty( nodeID, "animationFPS" ) || 30; + var fps = this.kernel.getProperty( nodeID, "animationFPS" ) || 30; for( var i = 0; i < node.threeObject.animatedMesh.length; i++ ) { if ( node.threeObject.animatedMesh[i].morphTargetInfluences ) { for( var j = 0; j < node.threeObject.animatedMesh[i].morphTargetInfluences.length; j++ ) { @@ -1740,7 +1739,7 @@ define( [ "module", } // Need to reset the viewport or you just get a blank screen - this.state.kernel.dispatchEvent( nodeID, "resetViewport" ); + this.kernel.dispatchEvent( nodeID, "resetViewport" ); } if ( propertyName == 'shadowMapCullFace') { var shadowMapCullFace; @@ -2118,7 +2117,7 @@ define( [ "module", value = animationDuration; } else if ( node.threeObject.animatedMesh && node.threeObject.animatedMesh.length ) { - var fps = this.state.kernel.getProperty( nodeID, "animationFPS") || 30; + var fps = this.kernel.getProperty( nodeID, "animationFPS") || 30; for(var i=0, il = node.threeObject.animatedMesh.length; i < il; i++) { if (node.threeObject.animatedMesh[i].bones) { @@ -2731,7 +2730,7 @@ define( [ "module", while ( !intersectedNode.vwfID ) { intersectedNode = intersectedNode.parent; } - result[ "node" ] = this.state.kernel.kutility.nodeReference( intersectedNode.vwfID ); + result[ "node" ] = kutility.nodeReference( intersectedNode.vwfID ); result[ "normal" ] = [ intersects[ i ].face.normal.x, intersects[ i ].face.normal.y, From 58b79c1796e4944185417040ceac3d67fb924231 Mon Sep 17 00:00:00 2001 From: David Easter Date: Mon, 11 May 2015 01:13:03 -0400 Subject: [PATCH 093/129] No stage/log. --- support/client/lib/vwf.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/support/client/lib/vwf.js b/support/client/lib/vwf.js index 675dc9a53..63974f946 100644 --- a/support/client/lib/vwf.js +++ b/support/client/lib/vwf.js @@ -708,7 +708,7 @@ var model = require( modelName ).create( this.models.kernel, // model's kernel access - [ require( "vwf/model/stage/log" ) ], // stages between the kernel and model + [], // stages between the kernel and model {}, // state shared with a paired view [].concat( modelArguments || [] ) // arguments for initialize() ); @@ -727,11 +727,16 @@ while ( this.models.object.model ) this.models.object = this.models.object.model; } - if(model.model.compatibilityStatus) { + if(model.model && model.model.compatibilityStatus) { if(!model.model.compatibilityStatus.compatible) { compatibilityStatus.compatible = false; jQuery.extend(compatibilityStatus.errors, model.model.compatibilityStatus.errors); } + } else if(model.compatibilityStatus) { + if(!model.compatibilityStatus.compatible) { + compatibilityStatus.compatible = false; + jQuery.extend(compatibilityStatus.errors, model.compatibilityStatus.errors); + } } } From b248459754db7be9df402b2b35d5093c0b1443b3 Mon Sep 17 00:00:00 2001 From: David Easter Date: Mon, 11 May 2015 01:13:26 -0400 Subject: [PATCH 094/129] Optimize `kernel.application`. --- support/client/lib/vwf.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/support/client/lib/vwf.js b/support/client/lib/vwf.js index 63974f946..fa239e70c 100644 --- a/support/client/lib/vwf.js +++ b/support/client/lib/vwf.js @@ -4364,8 +4364,12 @@ if ( ! childComponent.source ) { /// /// @see {@link module:vwf/api/kernel.application} +this.applicationID = undefined; + this.application = function( initializedOnly ) { +if ( this.applicationID ) return this.applicationID; + var applicationID; Object.keys( nodes.globals ).forEach( function( globalID ) { @@ -4375,6 +4379,8 @@ if ( ! childComponent.source ) { } }, this ); +this.applicationID = applicationID; + return applicationID; }; From 61de7c1891355cf738705fd4f44e5345a6b42822 Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Tue, 12 May 2015 15:02:33 -0400 Subject: [PATCH 095/129] Setting up to be merged into mars-game-dev From 8f75776c5a1de86545eccd5eed2be0e1c7b64164 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Fri, 15 May 2015 18:43:42 -0400 Subject: [PATCH 096/129] Added ability to set defines in shaders --- support/client/lib/vwf/model/threejs.js | 41 ++++++++++++++++++- .../vwf.example.com/shaderMaterial.vwf.yaml | 15 ++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/support/client/lib/vwf/model/threejs.js b/support/client/lib/vwf/model/threejs.js index 677a8d81b..1dfe31f19 100644 --- a/support/client/lib/vwf/model/threejs.js +++ b/support/client/lib/vwf/model/threejs.js @@ -676,7 +676,7 @@ define( [ "module", objectDef[ prop ] = propertyValue[ prop ]; break; } - } + } } node.threeObject = createMaterial( objectDef ); @@ -1649,6 +1649,13 @@ define( [ "module", } value = uniforms; threeObject.uniforms = value; + } else if ( propertyName === "defines" ) { + var names = Object.keys( propertyValue ); + var defines = {}; + for ( var i = 0; i < names.length; i++ ) { + defines[ names[ i ] ] = propertyValue[ names[ i ] ]; + } + threeObject.defines = defines; } else if ( propertyName === "vertexShader" ) { value = propertyValue; threeObject.vertexShader = value; @@ -1667,8 +1674,14 @@ define( [ "module", } else if ( threeObject.uniforms.hasOwnProperty( propertyName ) ) { var type = threeObject.uniforms[ propertyName ].type; setUniformProperty( threeObject.uniforms, propertyName, type, propertyValue ); + // ----------- + // TODO: Defines are constants within the shader, do they need to be set in this way? + // } else if ( threeObject.defines.hasOwnProperty( propertyName ) ) { + // value = propertyValue; + // threeObject.defines[ propertyName ] = value; } else if ( propertyName.indexOf("_") === 0 ) { - threeObject[ propertyName ] = propertyValue; + value = propertyValue; + threeObject[ propertyName ] = value; } } } @@ -2258,6 +2271,13 @@ define( [ "module", } return value; } + if ( propertyName === "defines" ) { + value = {}; + for ( var def in threeObject.defines ) { + value[ def ] = threeObject.defines[ def ]; + } + return value; + } if ( propertyName === "vertexShader" ) { value = threeObject.vertexShader; return value; @@ -5581,6 +5601,15 @@ define( [ "module", } obj[ prop ].value = textureArray; break; + case 'v2v': + var vectorArray = []; + var vector; + for ( var i = 0; i < value.length; i++ ) { + vector = value[ i ]; + vectorArray.push( new THREE.Vector2( vector[0], vector[1] ) ); + } + obj[ prop ].value = vectorArray; + break; } } @@ -5616,6 +5645,14 @@ define( [ "module", result.push( loadTexture( undefined, value[ i ] ) ); } break; + case 'v2v': + result = []; + var vector; + for ( var i = 0; i < value.length; i++ ) { + vector = value[ i ]; + result.push( new THREE.Vector2( vector[0], vector[1] ) ); + } + break; } return result; } diff --git a/support/proxy/vwf.example.com/shaderMaterial.vwf.yaml b/support/proxy/vwf.example.com/shaderMaterial.vwf.yaml index 9fbe2914f..5924817b4 100644 --- a/support/proxy/vwf.example.com/shaderMaterial.vwf.yaml +++ b/support/proxy/vwf.example.com/shaderMaterial.vwf.yaml @@ -6,6 +6,11 @@ properties: ## @name shaderMaterial.vwf#uniforms ## @property uniforms: + ## defines + ## + ## @name shaderMaterial.vwf#defines + ## @property + defines: ## Vertex Shader ## ## @name shaderMaterial.vwf#vertexShader @@ -21,4 +26,12 @@ properties: ## @name shaderMaterial.vwf#updateFunction ## @property updateFunction: - \ No newline at end of file +methods: + setDefine: + parameters: + - name + - value + body: | + var defines = this.defines; + defines[ name ] = value; + this.defines = defines; From d41d2f3fd28f6d06950d9699e0b9ee8c6eb96f72 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Sun, 17 May 2015 13:49:07 -0400 Subject: [PATCH 097/129] Update shader material when defines are modified --- support/client/lib/vwf/model/threejs.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/support/client/lib/vwf/model/threejs.js b/support/client/lib/vwf/model/threejs.js index 1dfe31f19..48a22c4c4 100644 --- a/support/client/lib/vwf/model/threejs.js +++ b/support/client/lib/vwf/model/threejs.js @@ -1656,6 +1656,7 @@ define( [ "module", defines[ names[ i ] ] = propertyValue[ names[ i ] ]; } threeObject.defines = defines; + threeObject.needsUpdate = true; } else if ( propertyName === "vertexShader" ) { value = propertyValue; threeObject.vertexShader = value; @@ -5610,6 +5611,13 @@ define( [ "module", } obj[ prop ].value = vectorArray; break; + case 'iv1': + var intArray = []; + for ( var i = 0; i < value.length; i++ ) { + intArray.push( Number( value[ i ] ) ); + } + obj[ prop ].value = intArray; + break; } } From 61e2214b44398d6e8c7db21bb3a6f24e35fb1bb3 Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Mon, 18 May 2015 12:28:44 -0400 Subject: [PATCH 098/129] Prevents invalid xml from being loaded --- support/client/lib/vwf/model/blockly.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/support/client/lib/vwf/model/blockly.js b/support/client/lib/vwf/model/blockly.js index 5443d9cac..ad34f03fe 100644 --- a/support/client/lib/vwf/model/blockly.js +++ b/support/client/lib/vwf/model/blockly.js @@ -229,7 +229,11 @@ define( [ "module", "vwf/model", "vwf/utility", break; case "blockly_xml": - value = node.blocks = propertyValue; + if ( propertyValue.indexOf('http://www.w3.org/1999/xhtml') !== -1 ) { + } else { + node.blocks = propertyValue; + value = propertyValue; + } break; case "blockly_timeBetweenLines": @@ -412,7 +416,6 @@ define( [ "module", "vwf/model", "vwf/utility", if ( executeNextLine ) { self.state.executionHalted = false; - nextStep( blocklyNode ); // Does this serve any real purpose? It's not handled in any application. From 3510aac4e04417105b13bc42c3b56a31128694c3 Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Mon, 18 May 2015 13:03:13 -0400 Subject: [PATCH 099/129] Fix handling of Blockly clear --- support/client/lib/vwf/model/blockly.js | 1 + support/client/lib/vwf/view/blockly.js | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/support/client/lib/vwf/model/blockly.js b/support/client/lib/vwf/model/blockly.js index ad34f03fe..bcff1bbf3 100644 --- a/support/client/lib/vwf/model/blockly.js +++ b/support/client/lib/vwf/model/blockly.js @@ -230,6 +230,7 @@ define( [ "module", "vwf/model", "vwf/utility", case "blockly_xml": if ( propertyValue.indexOf('http://www.w3.org/1999/xhtml') !== -1 ) { + //SJF: Invalid XML being passed in as default on Blockly clear sometimes } else { node.blocks = propertyValue; value = propertyValue; diff --git a/support/client/lib/vwf/view/blockly.js b/support/client/lib/vwf/view/blockly.js index 30943b858..d44297bc1 100644 --- a/support/client/lib/vwf/view/blockly.js +++ b/support/client/lib/vwf/view/blockly.js @@ -232,6 +232,7 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor // breaking synchronization. if ( previousActiveNode === blocklyNode ) { + setBlockXML( blocklyNode ); break; } @@ -248,11 +249,11 @@ define( [ "module", "vwf/view", "jquery", "vwf/model/blockly/JS-Interpreter/acor } else if ( app.toolbox !== undefined ) { loadToolbox( app.toolbox ); } - if ( blocklyNode.defaultXml !== undefined ) { - loadDefaultXml( blocklyNode.defaultXml ); - } else if ( app.defaultXml !== undefined ) { - loadDefaultXml( app.defaultXml ); - } + // if ( blocklyNode.defaultXml !== undefined ) { + // loadDefaultXml( blocklyNode.defaultXml ); + // } else if ( app.defaultXml !== undefined ) { + // loadDefaultXml( app.defaultXml ); + // } this.state.blockly.node = blocklyNode; setBlockXML( blocklyNode ); this.kernel.fireEvent( blocklyNode.ID, "blocklyVisibleChanged", [ getBlocklyUIVisibility() ] ); From 09305d13a44f9df923e9852702b1223aa5d913d5 Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Tue, 19 May 2015 16:01:52 -0400 Subject: [PATCH 100/129] Adds a grid and updates blockly version for new goodness. --- .../vwf/model/blockly/blockly_compressed.js | 1483 +++++++++-------- .../vwf/model/blockly/blocks_compressed.js | 212 +-- .../model/blockly/javascript_compressed.js | 39 +- support/client/lib/vwf/view/blockly.js | 3 +- 4 files changed, 951 insertions(+), 786 deletions(-) diff --git a/support/client/lib/vwf/model/blockly/blockly_compressed.js b/support/client/lib/vwf/model/blockly/blockly_compressed.js index 9a0ab7c43..babc3efba 100644 --- a/support/client/lib/vwf/model/blockly/blockly_compressed.js +++ b/support/client/lib/vwf/model/blockly/blockly_compressed.js @@ -1,199 +1,219 @@ // Do not edit this file; automatically generated by build.py. "use strict"; -var COMPILED=!0,goog=goog||{};goog.global=this;goog.exportPath_=function(a,b,c){a=a.split(".");c=c||goog.global;a[0]in c||!c.execScript||c.execScript("var "+a[0]);for(var d;a.length&&(d=a.shift());)a.length||void 0===b?c=c[d]?c[d]:c[d]={}:c[d]=b};goog.define=function(a,b){var c=b;COMPILED||goog.global.CLOSURE_DEFINES&&Object.prototype.hasOwnProperty.call(goog.global.CLOSURE_DEFINES,a)&&(c=goog.global.CLOSURE_DEFINES[a]);goog.exportPath_(a,c)};goog.DEBUG=!0;goog.LOCALE="en";goog.TRUSTED_SITE=!0; -goog.provide=function(a){if(!COMPILED){if(goog.isProvided_(a))throw Error('Namespace "'+a+'" already declared.');delete goog.implicitNamespaces_[a];for(var b=a;(b=b.substring(0,b.lastIndexOf(".")))&&!goog.getObjectByName(b);)goog.implicitNamespaces_[b]=!0}goog.exportPath_(a)};goog.setTestOnly=function(a){if(COMPILED&&!goog.DEBUG)throw a=a||"",Error("Importing test-only code into non-debug environment"+a?": "+a:".");}; -COMPILED||(goog.isProvided_=function(a){return!goog.implicitNamespaces_[a]&&!!goog.getObjectByName(a)},goog.implicitNamespaces_={});goog.getObjectByName=function(a,b){for(var c=a.split("."),d=b||goog.global,e;e=c.shift();)if(goog.isDefAndNotNull(d[e]))d=d[e];else return null;return d};goog.globalize=function(a,b){var c=b||goog.global,d;for(d in a)c[d]=a[d]}; -goog.addDependency=function(a,b,c){if(goog.DEPENDENCIES_ENABLED){var d;a=a.replace(/\\/g,"/");for(var e=goog.dependencies_,f=0;d=b[f];f++)e.nameToPath[d]=a,a in e.pathToNames||(e.pathToNames[a]={}),e.pathToNames[a][d]=!0;for(d=0;b=c[d];d++)a in e.requires||(e.requires[a]={}),e.requires[a][b]=!0}};goog.ENABLE_DEBUG_LOADER=!0; -goog.require=function(a){if(!COMPILED&&!goog.isProvided_(a)){if(goog.ENABLE_DEBUG_LOADER){var b=goog.getPathFromDeps_(a);if(b){goog.included_[b]=!0;goog.writeScripts_();return}}a="goog.require could not find: "+a;goog.global.console&&goog.global.console.error(a);throw Error(a);}};goog.basePath="";goog.nullFunction=function(){};goog.identityFunction=function(a,b){return a};goog.abstractMethod=function(){throw Error("unimplemented abstract method");}; -goog.addSingletonGetter=function(a){a.getInstance=function(){if(a.instance_)return a.instance_;goog.DEBUG&&(goog.instantiatedSingletons_[goog.instantiatedSingletons_.length]=a);return a.instance_=new a}};goog.instantiatedSingletons_=[];goog.DEPENDENCIES_ENABLED=!COMPILED&&goog.ENABLE_DEBUG_LOADER; -goog.DEPENDENCIES_ENABLED&&(goog.included_={},goog.dependencies_={pathToNames:{},nameToPath:{},requires:{},visited:{},written:{}},goog.inHtmlDocument_=function(){var a=goog.global.document;return"undefined"!=typeof a&&"write"in a},goog.findBasePath_=function(){if(goog.global.CLOSURE_BASE_PATH)goog.basePath=goog.global.CLOSURE_BASE_PATH;else if(goog.inHtmlDocument_())for(var a=goog.global.document.getElementsByTagName("script"),b=a.length-1;0<=b;--b){var c=a[b].src,d=c.lastIndexOf("?"),d=-1==d?c.length: -d;if("base.js"==c.substr(d-7,7)){goog.basePath=c.substr(0,d-7);break}}},goog.importScript_=function(a){var b=goog.global.CLOSURE_IMPORT_SCRIPT||goog.writeScriptTag_;!goog.dependencies_.written[a]&&b(a)&&(goog.dependencies_.written[a]=!0)},goog.writeScriptTag_=function(a){if(goog.inHtmlDocument_()){var b=goog.global.document;if("complete"==b.readyState){if(/\bdeps.js$/.test(a))return!1;throw Error('Cannot write "'+a+'" after document load');}b.write('