From 280ea7b2c0f7423f5c06ffb089a6ccf45db800f9 Mon Sep 17 00:00:00 2001
From: Ryan Huffman <ryanhuffman@gmail.com>
Date: Thu, 2 Feb 2017 16:34:20 -0800
Subject: [PATCH] Move addition of localPosition to template data to
 shortbow.js

---
 .../marketplace/shortbow/enemyServerEntity.js  |  1 -
 .../marketplace/shortbow/shortbow.js           | 18 ++++++++++++++++++
 .../shortbow/shortbowGameManager.js            |  2 +-
 .../shortbow/shortbowServerEntity.js           |  4 +++-
 .../marketplace/shortbow/spawnShortbow.js      | 15 +++------------
 5 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/unpublishedScripts/marketplace/shortbow/enemyServerEntity.js b/unpublishedScripts/marketplace/shortbow/enemyServerEntity.js
index 322e440b27..fae15eb158 100644
--- a/unpublishedScripts/marketplace/shortbow/enemyServerEntity.js
+++ b/unpublishedScripts/marketplace/shortbow/enemyServerEntity.js
@@ -23,7 +23,6 @@
             }
             var self = this;
             this.heartbeatTimerID = Script.setInterval(function() {
-                print("Sending heartbeat", self.gameChannel);
                 Messages.sendMessage(self.gameChannel, JSON.stringify({
                     type: "enemy-heartbeat",
                     entityID: self.entityID,
diff --git a/unpublishedScripts/marketplace/shortbow/shortbow.js b/unpublishedScripts/marketplace/shortbow/shortbow.js
index 5534e31aae..1b9bb3858e 100644
--- a/unpublishedScripts/marketplace/shortbow/shortbow.js
+++ b/unpublishedScripts/marketplace/shortbow/shortbow.js
@@ -832,3 +832,21 @@ 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];
+    entitiesByID[entity.id] = entity;
+}
+for (var i = 0; i < entities.length; ++i) {
+    var entity = entities[i];
+    if (entity.parentID !== undefined) {
+        var parent = entitiesByID[entity.parentID];
+        if (parent !== undefined) {
+            entity.localPosition = Vec3.subtract(entity.position, parent.position);
+            delete entity.position;
+        }
+    }
+}
diff --git a/unpublishedScripts/marketplace/shortbow/shortbowGameManager.js b/unpublishedScripts/marketplace/shortbow/shortbowGameManager.js
index ab2269f737..81e8a0fc2b 100644
--- a/unpublishedScripts/marketplace/shortbow/shortbowGameManager.js
+++ b/unpublishedScripts/marketplace/shortbow/shortbowGameManager.js
@@ -198,7 +198,7 @@ ShortbowGameManager.prototype = {
         // Spawn bows
         for (var i = 0; i < this.bowPositions.length; ++i) {
             const bowPosition = Vec3.sum(this.rootPosition, this.bowPositions[i]);
-            Vec3.print("Creating bow: ", bowPosition);
+            Vec3.print("Creating bow: " + i, this.bowPositions[i]);
             this.bowIDs.push(Entities.addEntity({
                 position: bowPosition,
                 "collisionsWillMove": 1,
diff --git a/unpublishedScripts/marketplace/shortbow/shortbowServerEntity.js b/unpublishedScripts/marketplace/shortbow/shortbowServerEntity.js
index db1485399f..0b38a6e627 100644
--- a/unpublishedScripts/marketplace/shortbow/shortbowServerEntity.js
+++ b/unpublishedScripts/marketplace/shortbow/shortbowServerEntity.js
@@ -8,9 +8,11 @@
 
 (function() {
     Script.include('utils.js?' + Date.now());
-    Script.include('spawnShortbow.js?' + Date.now());
+    Script.include('shortbow.js?' + Date.now());
     Script.include('shortbowGameManager.js?' + Date.now());
 
+    TEMPLATES = SHORTBOW_ENTITIES.Entities;
+
     this.entityID = null;
     var gameManager = null;
     this.preload = function(entityID) {
diff --git a/unpublishedScripts/marketplace/shortbow/spawnShortbow.js b/unpublishedScripts/marketplace/shortbow/spawnShortbow.js
index 615f256eab..9ab42817ff 100644
--- a/unpublishedScripts/marketplace/shortbow/spawnShortbow.js
+++ b/unpublishedScripts/marketplace/shortbow/spawnShortbow.js
@@ -86,8 +86,6 @@ for (var i = 0; i < TEMPLATES.length; ++i) {
 
 var entityIDs = [];
 
-var rootPosition = null;
-var goalPosition = null;
 var scoreboardID = null;
 var buttonID = null;
 var waveDisplayID = null;
@@ -96,7 +94,7 @@ var highScoreDisplayID = null;
 var livesDisplayID = null;
 var platformID = null;
 function createLocalGame() {
-    rootPosition = utils.findSurfaceBelowPosition(MyAvatar.position);
+    var rootPosition = utils.findSurfaceBelowPosition(MyAvatar.position);
     rootPosition.y += 6.11;
 
     scoreboardID = spawnTemplate("SB.Scoreboard", {
@@ -110,7 +108,7 @@ function createLocalGame() {
         script: Script.resolvePath("startGameButtonClientEntity.js"),
         serverScripts: Script.resolvePath("startGameButtonServerEntity.js"),
         userData: JSON.stringify({
-            grabbableKey: { 
+            grabbableKey: {
                 wantsTrigger: true
             }
         }),
@@ -118,13 +116,6 @@ function createLocalGame() {
     entityIDs.push(buttonID);
 
 
-    // Generate goal that the enemies try to get to
-    goalPosition = Vec3.sum(rootPosition, { x: 0, y: -10, z: -20 });
-    const BASES_HEIGHT = 16;
-    const ROOF_HEIGHT = 0.2;
-
-    goalPosition.y += BASES_HEIGHT - ROOF_HEIGHT;
-
     waveDisplayID = spawnTemplate("SB.DisplayWave", {
         parentID: scoreboardID,
         userData: JSON.stringify({
@@ -200,7 +191,7 @@ function createLocalGame() {
 
 if (Script.isClientScript()) {
     createLocalGame();
-    //var gameManager = new ShortbowGameManager(rootPosition, goalPositionFront, bowPositions, spawnPositions, scoreboardID, buttonID, waveDisplayID, scoreDisplayID, livesDisplayID, highScoreDisplayID);
+    //var gameManager = new ShortbowGameManager(scoreboardID, bowPositions, spawnPositions);
 
     function cleanup() {
         for (var i = 0; i < entityIDs.length; ++i) {