From f1e826b3050bc22e28be39f1e1f18a4bfcd49c38 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 24 May 2016 15:28:11 -0700 Subject: [PATCH] make blocky swipable --- .../Home/blocky/arrangement6B.json | 5 - .../DomainContent/Home/blocky/blocky.js | 426 ++++++++++-------- .../DomainContent/Home/blocky/wrapper.js | 11 +- .../DomainContent/Home/reset.js | 9 +- 4 files changed, 236 insertions(+), 215 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/blocky/arrangement6B.json b/unpublishedScripts/DomainContent/Home/blocky/arrangement6B.json index edced193a8..2a0510e259 100644 --- a/unpublishedScripts/DomainContent/Home/blocky/arrangement6B.json +++ b/unpublishedScripts/DomainContent/Home/blocky/arrangement6B.json @@ -200,11 +200,6 @@ }, { "angularDamping": 0, - "angularVelocity": { - "x": 0, - "y": -0.2617993950843811, - "z": 0 - }, "collisionSoundURL": "atp:/kineticObjects/blocks/ToyWoodBlock.L.wav", "created": "2016-05-09T19:30:40Z", "dimensions": { diff --git a/unpublishedScripts/DomainContent/Home/blocky/blocky.js b/unpublishedScripts/DomainContent/Home/blocky/blocky.js index 56567cc971..c7e35d15e7 100644 --- a/unpublishedScripts/DomainContent/Home/blocky/blocky.js +++ b/unpublishedScripts/DomainContent/Home/blocky/blocky.js @@ -46,213 +46,239 @@ var blocks = [ ]; var arrangements = [{ - name: 'greenhenge', - blocks: [BLOCK_GREEN, BLOCK_GREEN, BLOCK_YELLOW, BLOCK_YELLOW], - target: "atp:/blocky/newblocks1.json" - }, - { - name: 'tallstuff', - blocks: [BLOCK_RED, BLOCK_RED, BLOCK_RED], - target: "atp:/blocky/newblocks2.json" - }, - { - name: 'ostrich', - blocks: [BLOCK_RED, BLOCK_RED, BLOCK_GREEN, BLOCK_YELLOW, BLOCK_NATURAL], - target: "atp:/blocky/newblocks5.json" - }, - { - name: 'fourppl', - blocks: [BLOCK_BLUE, BLOCK_BLUE, BLOCK_BLUE, BLOCK_BLUE, BLOCK_NATURAL, BLOCK_NATURAL, BLOCK_NATURAL, BLOCK_NATURAL], - target: "atp:/blocky/newblocks3.json" - }, - { - name: 'frogguy', - blocks: [BLOCK_GREEN, BLOCK_GREEN, BLOCK_GREEN, BLOCK_YELLOW, BLOCK_RED, BLOCK_RED, BLOCK_NATURAL, BLOCK_NATURAL], - target: "atp:/blocky/newblocks4.json" - }, - { - name: 'dominoes', - blocks: [BLOCK_RED, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW], - target: "atp:/blocky/arrangement6B.json" - }] + name: 'greenhenge', + blocks: [BLOCK_GREEN, BLOCK_GREEN, BLOCK_YELLOW, BLOCK_YELLOW], + target: "atp:/blocky/newblocks1.json" +}, { + name: 'tallstuff', + blocks: [BLOCK_RED, BLOCK_RED, BLOCK_RED], + target: "atp:/blocky/newblocks2.json" +}, { + name: 'ostrich', + blocks: [BLOCK_RED, BLOCK_RED, BLOCK_GREEN, BLOCK_YELLOW, BLOCK_NATURAL], + target: "atp:/blocky/newblocks5.json" +}, { + name: 'fourppl', + blocks: [BLOCK_BLUE, BLOCK_BLUE, BLOCK_BLUE, BLOCK_BLUE, BLOCK_NATURAL, BLOCK_NATURAL, BLOCK_NATURAL, BLOCK_NATURAL], + target: "atp:/blocky/newblocks3.json" +}, { + name: 'frogguy', + blocks: [BLOCK_GREEN, BLOCK_GREEN, BLOCK_GREEN, BLOCK_YELLOW, BLOCK_RED, BLOCK_RED, BLOCK_NATURAL, BLOCK_NATURAL], + target: "atp:/blocky/newblocks4.json" +}, { + name: 'dominoes', + blocks: [BLOCK_RED, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW], + target: "atp:/blocky/arrangement6B.json" +}] - var PLAYABLE_BLOCKS_POSITION = { - x: 1097.6, - y: 460.5, - z: -66.22 - }; +var PLAYABLE_BLOCKS_POSITION = { + x: 1097.6, + y: 460.5, + z: -66.22 +}; - var TARGET_BLOCKS_POSITION = { - x: 1096.82, - y: 460.5, - z: -67.689 - }; - //#debug - (function() { +var TARGET_BLOCKS_POSITION = { + x: 1096.82, + y: 460.5, + z: -67.689 +}; +//#debug +(function() { - print('BLOCK ENTITY SCRIPT') - var _this; + print('BLOCK ENTITY SCRIPT') + var _this; - function Blocky() { - _this = this; + function Blocky() { + _this = this; + } + + Blocky.prototype = { + busy: false, + debug: false, + playableBlocks: [], + targetBlocks: [], + preload: function(entityID) { + print('BLOCKY preload') + this.entityID = entityID; + Script.update.connect(_this.update); + }, + + createTargetBlocks: function(arrangement) { + var created = []; + print('BLOCKY create target blocks') + + var created = []; + var success = Clipboard.importEntities(arrangement.target); + if (success === true) { + created = Clipboard.pasteEntities(TARGET_BLOCKS_POSITION) + print('created ' + created); } - Blocky.prototype = { - debug: false, - playableBlocks: [], - targetBlocks: [], - preload: function(entityID) { - print('BLOCKY preload') - this.entityID = entityID; - }, - createTargetBlocks: function(arrangement) { - var created = []; - print('BLOCKY create target blocks') + this.targetBlocks = created; + print('BLOCKY TARGET BLOCKS:: ' + this.targetBlocks); + }, - var created = []; - var success = Clipboard.importEntities(arrangement.target); - if (success === true) { - created = Clipboard.pasteEntities(TARGET_BLOCKS_POSITION) - print('created ' + created); - } - - this.targetBlocks = created; - print('BLOCKY TARGET BLOCKS:: ' + this.targetBlocks); - }, - createPlayableBlocks: function(arrangement) { - print('BLOCKY creating playable blocks' + arrangement.blocks.length); - arrangement.blocks.forEach(function(block) { - print('BLOCKY in a block loop') - var blockProps = { - name: "home_model_blocky_block", - type: 'Model', - collisionSoundURL: "atp:/kineticObjects/blocks/ToyWoodBlock.L.wav", - dynamic: true, - collisionless: false, - gravity: { - x: 0, - y: -9.8, - z: 0 - }, - userData: JSON.stringify({ - grabbableKey: { - grabbable: true - }, - hifiHomeKey: { - reset: true - } - }), - dimensions: block.dimensions, - modelURL: block.url, - shapeType: 'box', - velocity: { - x: 0, - y: -0.01, - z: 0, - }, - position: PLAYABLE_BLOCKS_POSITION + createPlayableBlocks: function(arrangement) { + print('BLOCKY creating playable blocks' + arrangement.blocks.length); + arrangement.blocks.forEach(function(block) { + print('BLOCKY in a block loop') + var blockProps = { + name: "home_model_blocky_block", + type: 'Model', + collisionSoundURL: "atp:/kineticObjects/blocks/ToyWoodBlock.L.wav", + dynamic: true, + collisionless: false, + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + userData: JSON.stringify({ + grabbableKey: { + grabbable: true + }, + hifiHomeKey: { + reset: true } - var newBlock = Entities.addEntity(blockProps); - print('BLOCKY made a playable block' + newBlock) - _this.playableBlocks.push(newBlock); - print('BLOCKY pushing it into playable blocks'); - }) - - print('BLOCKY after going through playable arrangement') - }, - startNearTrigger: function() { - print('BLOCKY got a near trigger'); - this.advanceRound(); - }, - advanceRound: function() { - print('BLOCKY advance round'); - this.cleanup(); - var arrangement = arrangements[Math.floor(Math.random() * arrangements.length)]; - this.createTargetBlocks(arrangement); - - if (this.debug === true) { - this.debugCreatePlayableBlocks(); - } else { - this.createPlayableBlocks(arrangement); - - } - }, - findBlocks: function() { - var found = []; - var results = Entities.findEntities(MyAvatar.position, 10); - results.forEach(function(result) { - var properties = Entities.getEntityProperties(result); - print('got result props') - if (properties.name.indexOf('blocky_block') > -1) { - found.push(result); - } - }); - return found; - }, - - cleanup: function() { - print('BLOCKY cleanup'); - var blocks = this.findBlocks(); - print('BLOCKY cleanup2' + blocks.length) - blocks.forEach(function(block) { - Entities.deleteEntity(block); - }) - print('BLOCKY after find and delete') - this.targetBlocks.forEach(function(block) { - Entities.deleteEntity(block); - }); - this.playableBlocks.forEach(function(block) { - Entities.deleteEntity(block); - }); - this.targetBlocks = []; - this.playableBlocks = []; - }, - debugCreatePlayableBlocks: function() { - print('BLOCKY debug create'); - var howMany = 10; - var i; - for (i = 0; i < howMany; i++) { - var block = blocks[Math.floor(Math.random() * blocks.length)]; - var blockProps = { - name: "home_model_blocky_block", - type: 'Model', - collisionSoundURL: "atp:/kineticObjects/blocks/ToyWoodBlock.L.wav", - dynamic: false, - collisionless: true, - // gravity: { - // x: 0, - // y: -9.8, - // z: 0 - // }, - userData: JSON.stringify({ - grabbableKey: { - grabbable: true - }, - hifiHomeKey: { - reset: true - } - }), - dimensions: block.dimensions, - modelURL: block.url, - shapeType: 'box', - velocity: { - x: 0, - y: -0.01, - z: 0, - }, - position: PLAYABLE_BLOCKS_POSITION - } - this.playableBlocks.push(Entities.addEntity(blockProps)); - } - }, - unload: function() { - this.cleanup(); - }, - clickReleaseOnEntity: function() { - print('BLOCKY click') - this.startNearTrigger(); + }), + dimensions: block.dimensions, + modelURL: block.url, + shapeType: 'box', + velocity: { + x: 0, + y: -0.01, + z: 0, + }, + position: PLAYABLE_BLOCKS_POSITION } - } + var newBlock = Entities.addEntity(blockProps); + print('BLOCKY made a playable block' + newBlock) + _this.playableBlocks.push(newBlock); + print('BLOCKY pushing it into playable blocks'); + }) - return new Blocky(); - }) \ No newline at end of file + print('BLOCKY after going through playable arrangement') + }, + + startNearTrigger: function() { + print('BLOCKY got a near trigger'); + this.advanceRound(); + }, + + advanceRound: function() { + print('BLOCKY advance round'); + this.busy = true; + this.cleanup(); + var arrangement = arrangements[Math.floor(Math.random() * arrangements.length)]; + this.createTargetBlocks(arrangement); + + if (this.debug === true) { + this.debugCreatePlayableBlocks(); + } else { + this.createPlayableBlocks(arrangement); + + } + this.busy = false; + }, + + findBlocks: function() { + var found = []; + var results = Entities.findEntities(MyAvatar.position, 10); + results.forEach(function(result) { + var properties = Entities.getEntityProperties(result); + print('got result props') + if (properties.name.indexOf('blocky_block') > -1) { + found.push(result); + } + }); + return found; + }, + + cleanup: function() { + print('BLOCKY cleanup'); + var blocks = this.findBlocks(); + print('BLOCKY cleanup2' + blocks.length) + blocks.forEach(function(block) { + Entities.deleteEntity(block); + }) + print('BLOCKY after find and delete') + this.targetBlocks.forEach(function(block) { + Entities.deleteEntity(block); + }); + this.playableBlocks.forEach(function(block) { + Entities.deleteEntity(block); + }); + this.targetBlocks = []; + this.playableBlocks = []; + }, + + debugCreatePlayableBlocks: function() { + print('BLOCKY debug create'); + var howMany = 10; + var i; + for (i = 0; i < howMany; i++) { + var block = blocks[Math.floor(Math.random() * blocks.length)]; + var blockProps = { + name: "home_model_blocky_block", + type: 'Model', + collisionSoundURL: "atp:/kineticObjects/blocks/ToyWoodBlock.L.wav", + dynamic: false, + collisionless: true, + userData: JSON.stringify({ + grabbableKey: { + grabbable: true + }, + hifiHomeKey: { + reset: true + } + }), + dimensions: block.dimensions, + modelURL: block.url, + shapeType: 'box', + velocity: { + x: 0, + y: -0.01, + z: 0, + }, + position: PLAYABLE_BLOCKS_POSITION + } + this.playableBlocks.push(Entities.addEntity(blockProps)); + } + }, + + unload: function() { + this.cleanup(); + Script.update.disconnect(_this.update); + }, + + clickReleaseOnEntity: function() { + print('BLOCKY click') + this.startNearTrigger(); + }, + + update: function() { + if (this.busy === true) { + return; + } + var BEAM_TRIGGER_THRESHOLD = 0.075; + + var BEAM_POSITION = { + x: 1098.5159, + y: 460.0490, + z: -66.3012 + }; + + var leftHandPosition = MyAvatar.getLeftPalmPosition(); + var rightHandPosition = MyAvatar.getRightPalmPosition(); + + var rightDistance = Vec3.distance(leftHandPosition, BEAM_POSITION) + var leftDistance = Vec3.distance(rightHandPosition, BEAM_POSITION) + + if (rightDistance < BEAM_TRIGGER_THRESHOLD || leftDistance < BEAM_TRIGGER_THRESHOLD) { + _this.startNearTrigger(); + } + } + } + + return new Blocky(); +}) \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/blocky/wrapper.js b/unpublishedScripts/DomainContent/Home/blocky/wrapper.js index 2b56b716ec..dfddbaff5d 100644 --- a/unpublishedScripts/DomainContent/Home/blocky/wrapper.js +++ b/unpublishedScripts/DomainContent/Home/blocky/wrapper.js @@ -11,18 +11,18 @@ var RESETTER_POSITION = { - x: 1098.27, - y: 460.43, - z: -66.15 + x: 1098.5159, + y: 460.0490, + z: -66.3012 }; BlockyGame = function(spawnPosition, spawnRotation) { - var scriptURL ="atp:/blocky/blocky.js"; + var scriptURL = "atp:/blocky/blocky.js"; var blockyProps = { type: 'Box', - name:'home_box_blocky_resetter', + name: 'home_box_blocky_resetter', color: { red: 0, green: 0, @@ -33,6 +33,7 @@ BlockyGame = function(spawnPosition, spawnRotation) { y: 0.25, z: 0.25 }, + rotation:Quat.fromPitchYawRollDegrees(-0.0029,32.9983,-0.0021), script: scriptURL, userData: JSON.stringify({ "grabbableKey": { diff --git a/unpublishedScripts/DomainContent/Home/reset.js b/unpublishedScripts/DomainContent/Home/reset.js index bdc97fcbc6..a15c0c4d87 100644 --- a/unpublishedScripts/DomainContent/Home/reset.js +++ b/unpublishedScripts/DomainContent/Home/reset.js @@ -330,7 +330,6 @@ y: 179.0293, z: 89.9698 }); - print('home before cuckooClock') var cuckooClock = new MyCuckooClock({ x: 1105.5237, @@ -341,11 +340,11 @@ y: -57.0089, z: -0.0013 }); - print('home after cuckooClock') + var blocky = new BlockyGame({ - x: 1098.27, - y: 460.43, - z: -66.15 + x: 1098.5159, + y: 460.0490, + z: -66.3012 }) print('HOME after creating scripted entities')