diff --git a/tutorial/fuse.js b/tutorial/fuse.js index d09dc11bd1..48efeb28e6 100644 --- a/tutorial/fuse.js +++ b/tutorial/fuse.js @@ -1,4 +1,38 @@ (function() { + var findEntity = function(properties, searchRadius, filterFn) { + var entities = findEntities(properties, searchRadius, filterFn); + return entities.length > 0 ? entities[0] : null; + } + + // Return all entities with properties `properties` within radius `searchRadius` + var findEntities = function(properties, searchRadius, filterFn) { + if (!filterFn) { + filterFn = function(properties, key, value) { + return value == properties[key]; + } + } + searchRadius = searchRadius ? searchRadius : 100000; + var entities = Entities.findEntities({ x: 0, y: 0, z: 0 }, searchRadius); + var matchedEntities = []; + var keys = Object.keys(properties); + for (var i = 0; i < entities.length; ++i) { + var match = true; + var candidateProperties = Entities.getEntityProperties(entities[i], keys); + for (var key in properties) { + if (!filterFn(properties, key, candidateProperties[key])) { + // This isn't a match, move to next entity + match = false; + break; + } + } + if (match) { + matchedEntities.push(entities[i]); + } + } + + return matchedEntities; + } + var fuseSound = SoundCache.getSound("https://hifi-content.s3.amazonaws.com/DomainContent/Tutorial/Sounds/fuse.wav"); function getChildProperties(entityID, propertyNames) { var childEntityIDs = Entities.getChildrenIDs(entityID); @@ -13,12 +47,18 @@ var Fuse = function() { }; Fuse.prototype = { - onLit: function() { + light: function() { print("LIT", this.entityID); + var anim = Entities.getEntityProperties(this.entityID, ['animation']).animation; + print("anim: ", anim.currentFrame, Object.keys(anim)); + + if (anim.currentFrame < 140) { + return; + } Entities.editEntity(this.entityID, { animation: { - currentFrame: 0, - //"lastFrame": 130, + currentFrame: 1, + lastFrame: 150, running: 1, url: "https://hifi-content.s3.amazonaws.com/ozan/dev/anim/fuse/fuse.fbx", loop: 0 @@ -47,7 +87,8 @@ var self = this; Script.setTimeout(function() { print("BLOW UP"); - Entities.callEntityMethod("{dd13fcd5-616f-4749-ab28-2e1e8bc512e9}", "onLit"); + var spinnerID = findEntity({ name: "tutorial/equip/spinner" }, 20); + Entities.callEntityMethod(spinnerID, "onLit"); injector.stop(); var childrenProps = getChildProperties(self.entityID, ['type']); diff --git a/tutorial/fuseCollider.js b/tutorial/fuseCollider.js new file mode 100644 index 0000000000..dd8195d9b0 --- /dev/null +++ b/tutorial/fuseCollider.js @@ -0,0 +1,60 @@ +(function() { + var findEntity = function(properties, searchRadius, filterFn) { + var entities = findEntities(properties, searchRadius, filterFn); + return entities.length > 0 ? entities[0] : null; + } + + // Return all entities with properties `properties` within radius `searchRadius` + var findEntities = function(properties, searchRadius, filterFn) { + if (!filterFn) { + filterFn = function(properties, key, value) { + return value == properties[key]; + } + } + searchRadius = searchRadius ? searchRadius : 100000; + var entities = Entities.findEntities({ x: 0, y: 0, z: 0 }, searchRadius); + var matchedEntities = []; + var keys = Object.keys(properties); + for (var i = 0; i < entities.length; ++i) { + var match = true; + var candidateProperties = Entities.getEntityProperties(entities[i], keys); + for (var key in properties) { + if (!filterFn(properties, key, candidateProperties[key])) { + // This isn't a match, move to next entity + match = false; + break; + } + } + if (match) { + matchedEntities.push(entities[i]); + } + } + + return matchedEntities; + } + + function getChildProperties(entityID, propertyNames) { + var childEntityIDs = Entities.getChildrenIDs(entityID); + var results = {} + for (var i = 0; i < childEntityIDs.length; ++i) { + var childEntityID = childEntityIDs[i]; + var properties = Entities.getEntityProperties(childEntityID, propertyNames); + results[childEntityID] = properties; + } + return results; + } + + var Fuse = function() { + }; + Fuse.prototype = { + onLit: function() { + print("LIT", this.entityID); + var fuseID = findEntity({ name: "tutorial/equip/fuse" }, 20); + Entities.callEntityMethod(fuseID, "light"); + }, + preload: function(entityID) { + this.entityID = entityID; + }, + }; + return new Fuse(); +});