diff --git a/unpublishedScripts/parent-ator/parentator.js b/unpublishedScripts/parent-ator/parentator.js index ad38f524e6..546ac38ba1 100644 --- a/unpublishedScripts/parent-ator/parentator.js +++ b/unpublishedScripts/parent-ator/parentator.js @@ -16,6 +16,7 @@ (function() { + var MESSAGE_0_TEXTURE_URL = Script.resolvePath( 'resources/message-0-off.png' ); var MESSAGE_1_TEXTURE_URL = Script.resolvePath( 'resources/message-1-start.png' ); var MESSAGE_2_TEXTURE_URL = Script.resolvePath( 'resources/message-2-noperms.png' ); var MESSAGE_3_TEXTURE_URL = Script.resolvePath( 'resources/message-3-tryagain.png' ); @@ -28,6 +29,8 @@ var SOUND_SUCCESS_URL = Script.resolvePath( 'resources/parent-tool-sound-success.wav' ); var SOUND_1, SOUND_2, SOUND_ERROR, SOUND_SUCCESS; var childEntityID, parentEntityID; + var active = false; + @@ -35,9 +38,17 @@ return; } - Parentator.prototype.reset = function() { + Parentator.prototype.turnOff = function() { childEntityID = 0; parentEntityID = 0; + this.active = false; + Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_0_TEXTURE_URL }) }); + } + + Parentator.prototype.turnOn = function() { + childEntityID = 0; + parentEntityID = 0; + this.active = true; if (Entities.canRez()) { Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_1_TEXTURE_URL }) }); this.playSoundAtCurrentPosition( SOUND_1 ); @@ -47,6 +58,7 @@ } } + Parentator.prototype.preload = function( entityID ) { this.entityID = entityID; SOUND_1 = SoundCache.getSound( SOUND_1_URL ); @@ -54,73 +66,79 @@ SOUND_ERROR = SoundCache.getSound( SOUND_ERROR_URL ); SOUND_SUCCESS = SoundCache.getSound( SOUND_SUCCESS_URL ); - // The following is in case a user has been in a domain where they didn't have permission to rez - // (and that is displayed on the parent-tor screen) and then they move to a domain where they can rez - Window.domainChanged.connect( function() { - this.reset(); - }); + // Makue sure it's off + this.turnOff(); } Parentator.prototype.startEquip = function( args ) { this.hand = args[0]; - this.reset(); + this.turnOn(); + } + + + Parentator.prototype.releaseEquip = function( args ) { + this.hand = undefined; + this.turnOff(); } Parentator.prototype.collisionWithEntity = function( parentatorID, collidedID, collisionInfo ) { - // We don't want to be able to select Lights, Zone, and Particles but they are not collidable anyway so we don't have to worry about them - var collidedEntityProperties = Entities.getEntityProperties( collidedID ); + if ( this.active ) { + // We don't want to be able to select Lights, Zone, and Particles but they are not collidable anyway so we don't have to worry about them + var collidedEntityProperties = Entities.getEntityProperties( collidedID ); - if ( !Entities.canRez() ) { - Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_2_TEXTURE_URL }) }); - this.playSoundAtCurrentPosition( SOUND_ERROR ); - } - - // User has just reclicked the first entity (or it's 'bounced') - if ( childEntityID == collidedID ) { - return; - } - - if ( collidedEntityProperties.locked ) { - Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_3_TEXTURE_URL }) }); - this.playSoundAtCurrentPosition( SOUND_ERROR ); - return; - } - - // If no entity has been chosen - if ( childEntityID == 0 ) { - childEntityID = collidedID; - - // if there is a parentID, remove it - if ( collidedEntityProperties.parentID != "{00000000-0000-0000-0000-000000000000}" ) { - Entities.editEntity( collidedID, { parentID: "{00000000-0000-0000-0000-000000000000}" }); + if ( !Entities.canRez() ) { + Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_2_TEXTURE_URL }) }); + this.playSoundAtCurrentPosition( SOUND_ERROR ); } - if ( collidedEntityProperties.dynamic ) { - Entities.editEntity( collidedID, { dynamic: false }); + // User has just reclicked the first entity (or it's 'bounced') + if ( childEntityID == collidedID ) { + return; } - Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_4_TEXTURE_URL }) }); - this.playSoundAtCurrentPosition( SOUND_2 ); - } else { - parentEntityID = collidedID; - this.setParent(); + if ( collidedEntityProperties.locked ) { + Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_3_TEXTURE_URL }) }); + this.playSoundAtCurrentPosition( SOUND_ERROR ); + return; + } + + // If no entity has been chosen + if ( childEntityID == 0 ) { + childEntityID = collidedID; + + // if there is a parentID, remove it + if ( collidedEntityProperties.parentID != "{00000000-0000-0000-0000-000000000000}" ) { + Entities.editEntity( collidedID, { parentID: "{00000000-0000-0000-0000-000000000000}" }); + } + + if ( collidedEntityProperties.dynamic ) { + Entities.editEntity( collidedID, { dynamic: false }); + } + + Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_4_TEXTURE_URL }) }); + this.playSoundAtCurrentPosition( SOUND_2 ); + } else { + parentEntityID = collidedID; + this.setParent(); + } } } Parentator.prototype.setParent = function() { + var _this = this; Entities.editEntity( childEntityID, { parentID: parentEntityID }); Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_5_TEXTURE_URL }) }); this.playSoundAtCurrentPosition( SOUND_SUCCESS ); - Script.setTimeout( function() { - this.reset() - }.bind( this ), 5000 ); + _this.turnOn(); // reset + }, 5000 ); } Parentator.prototype.playSoundAtCurrentPosition = function( sound ) { var audioProperties = { volume: 0.3, - position: Entities.getEntityProperties( this.entityID ).position + position: Entities.getEntityProperties( this.entityID ).position, + localOnly: true } Audio.playSound( sound, audioProperties ); } diff --git a/unpublishedScripts/parent-ator/resources/message-0-off.png b/unpublishedScripts/parent-ator/resources/message-0-off.png new file mode 100644 index 0000000000..4985c8fda7 Binary files /dev/null and b/unpublishedScripts/parent-ator/resources/message-0-off.png differ