From dd895dc04a9a3278140b1033295da83ed5217125 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 22 Feb 2017 16:49:22 -0800 Subject: [PATCH] Fix js linting issues in shortbow --- .../marketplace/shortbow/bow/spawnBow.js | 18 +++++-- .../marketplace/shortbow/shortbow.js | 15 +++--- .../marketplace/shortbow/spawnShortbow.js | 14 +++--- .../marketplace/shortbow/utils.js | 48 +++++++++---------- 4 files changed, 54 insertions(+), 41 deletions(-) diff --git a/unpublishedScripts/marketplace/shortbow/bow/spawnBow.js b/unpublishedScripts/marketplace/shortbow/bow/spawnBow.js index 23656b38a6..cb94b05556 100644 --- a/unpublishedScripts/marketplace/shortbow/bow/spawnBow.js +++ b/unpublishedScripts/marketplace/shortbow/bow/spawnBow.js @@ -1,5 +1,14 @@ +// +// Created by Ryan Huffman on 1/10/2017 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + var leftHandPosition = { - "x": 0,//-0.0881, + "x": 0, "y": 0.0559, "z": 0.0159 }; @@ -23,10 +32,10 @@ var userData = { ] } } -} +}; var id = Entities.addEntity({ - position: MyAvatar.position, + "position": MyAvatar.position, "collisionsWillMove": 1, "compoundShapeURL": Script.resolvePath("bow_collision_hull.obj"), "created": "2016-09-01T23:57:55Z", @@ -52,8 +61,7 @@ var id = Entities.addEntity({ "script": Script.resolvePath("bow.js"), "shapeType": "compound", "type": "Model", - //"userData": JSON.stringify(userData), "userData": "{\"grabbableKey\":{\"grabbable\":true},\"wearable\":{\"joints\":{\"RightHand\":[{\"x\":0.0813,\"y\":0.0452,\"z\":0.0095},{\"x\":-0.3946,\"y\":-0.6604,\"z\":0.4748,\"w\":-0.4275}],\"LeftHand\":[{\"x\":-0.0881,\"y\":0.0259,\"z\":0.0159},{\"x\":0.4427,\"y\":-0.6519,\"z\":0.4592,\"w\":0.4099}]}}}", - lifetime: 600 + "lifetime": 600 }); print("Created bow:", id); diff --git a/unpublishedScripts/marketplace/shortbow/shortbow.js b/unpublishedScripts/marketplace/shortbow/shortbow.js index 1b9bb3858e..8b54a53045 100644 --- a/unpublishedScripts/marketplace/shortbow/shortbow.js +++ b/unpublishedScripts/marketplace/shortbow/shortbow.js @@ -11,6 +11,8 @@ // // Because .json can't be Script.include'd directly, the contents are copied over // to here and exposed as a global variable. +// + SHORTBOW_ENTITIES = { "Entities": [ @@ -831,17 +833,18 @@ SHORTBOW_ENTITIES = } ], "Version": 65 -} +}; // Add LocalPosition to entity data if parent properties are available var entities = SHORTBOW_ENTITIES.Entities; -var entitiesByID = {} -for (var i = 0; i < entities.length; ++i) { - var entity = entities[i]; +var entitiesByID = {}; +var i, entity; +for (i = 0; i < entities.length; ++i) { + entity = entities[i]; entitiesByID[entity.id] = entity; } -for (var i = 0; i < entities.length; ++i) { - var entity = entities[i]; +for (i = 0; i < entities.length; ++i) { + entity = entities[i]; if (entity.parentID !== undefined) { var parent = entitiesByID[entity.parentID]; if (parent !== undefined) { diff --git a/unpublishedScripts/marketplace/shortbow/spawnShortbow.js b/unpublishedScripts/marketplace/shortbow/spawnShortbow.js index 3f155ecb48..df9d3a9b4d 100644 --- a/unpublishedScripts/marketplace/shortbow/spawnShortbow.js +++ b/unpublishedScripts/marketplace/shortbow/spawnShortbow.js @@ -5,6 +5,7 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +/* globals utils, SHORTBOW_ENTITIES, TEMPLATES:true */ Script.include('utils.js'); Script.include('shortbow.js'); @@ -19,10 +20,11 @@ TEMPLATES = SHORTBOW_ENTITIES.Entities; // @returns {object} The new object function mergeObjects(a, b) { var obj = {}; - for (var key in b) { + var key; + for (key in b) { obj[key] = b[key]; } - for (var key in a) { + for (key in a) { obj[key] = a[key]; } return obj; @@ -55,7 +57,7 @@ function spawnTemplate(templateName, overrides) { // @return {object} The matching template, or null if not found function getTemplate(name) { for (var i = 0; i < TEMPLATES.length; ++i) { - if (TEMPLATES[i].name == name) { + if (TEMPLATES[i].name === name) { return TEMPLATES[i]; } } @@ -68,7 +70,7 @@ for (var i = 0; i < TEMPLATES.length; ++i) { var template = TEMPLATES[i]; // Fixup model url - if (template.type == "Model") { + if (template.type === "Model") { var urlParts = template.modelURL.split("/"); var filename = urlParts[urlParts.length - 1]; var newURL = Script.resolvePath("models/" + filename); @@ -155,8 +157,8 @@ function createLocalGame() { serverScripts: Script.resolvePath('shortbowServerEntity.js') }); - bowPositions = []; - spawnPositions = []; + var bowPositions = []; + var spawnPositions = []; for (var i = 0; i < TEMPLATES.length; ++i) { var template = TEMPLATES[i]; if (template.name === "SB.BowSpawn") { diff --git a/unpublishedScripts/marketplace/shortbow/utils.js b/unpublishedScripts/marketplace/shortbow/utils.js index 80391bd120..6cd132c09c 100644 --- a/unpublishedScripts/marketplace/shortbow/utils.js +++ b/unpublishedScripts/marketplace/shortbow/utils.js @@ -7,45 +7,45 @@ // if (!Function.prototype.bind) { - Function.prototype.bind = function(oThis) { - if (typeof this !== 'function') { - // closest thing possible to the ECMAScript 5 - // internal IsCallable function - throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); - } + Function.prototype.bind = function(oThis) { + if (typeof this !== 'function') { + // closest thing possible to the ECMAScript 5 + // internal IsCallable function + throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); + } - var aArgs = Array.prototype.slice.call(arguments, 1), - fToBind = this, - fNOP = function() {}, - fBound = function() { - return fToBind.apply(this instanceof fNOP - ? this - : oThis, - aArgs.concat(Array.prototype.slice.call(arguments))); - }; + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + NOP = function() {}, + fBound = function() { + return fToBind.apply(this instanceof NOP + ? this + : oThis, + aArgs.concat(Array.prototype.slice.call(arguments))); + }; - if (this.prototype) { - // Function.prototype doesn't have a prototype property - fNOP.prototype = this.prototype; - } - fBound.prototype = new fNOP(); + if (this.prototype) { + // Function.prototype doesn't have a prototype property + NOP.prototype = this.prototype; + } + fBound.prototype = new NOP(); - return fBound; - }; + return fBound; + }; } utils = { parseJSON: function(json) { try { return JSON.parse(json); - } catch(e) { + } catch (e) { return undefined; } }, findSurfaceBelowPosition: function(pos) { var result = Entities.findRayIntersection({ origin: pos, - direction: { x: 0, y: -1, z: 0 } + direction: { x: 0.0, y: -1.0, z: 0.0 } }); if (result.intersects) { return result.intersection;