From c760c44531e1915671b17be1219301cfb0bcc045 Mon Sep 17 00:00:00 2001
From: Alexia Mandeville <alexia@HIGHFIDELITY.IO>
Date: Mon, 12 Mar 2018 13:17:23 -0700
Subject: [PATCH] Revert "Update repo script with marketplace script"

This reverts commit 5139f3f50328c0299801906ba435d5e1528c72f8.
---
 scripts/tutorials/entity_scripts/sit.js | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/scripts/tutorials/entity_scripts/sit.js b/scripts/tutorials/entity_scripts/sit.js
index 9de65d7037..70456ea493 100644
--- a/scripts/tutorials/entity_scripts/sit.js
+++ b/scripts/tutorials/entity_scripts/sit.js
@@ -12,9 +12,9 @@
     Script.include("/~/system/libraries/utils.js");
     if (!String.prototype.startsWith) {
         String.prototype.startsWith = function(searchString, position){
-          position = position || 0;
-          return this.substr(position, searchString.length) === searchString;
-      };
+            position = position || 0;
+            return this.substr(position, searchString.length) === searchString;
+        };
     }
 
     var SETTING_KEY = "com.highfidelity.avatar.isSitting";
@@ -122,10 +122,20 @@
 
     this.rolesToOverride = function() {
         return MyAvatar.getAnimationRoles().filter(function(role) {
-           return !(role.startsWith("right") || role.startsWith("left"));
+            return !(role.startsWith("right") || role.startsWith("left"));
         });
     }
 
+    // Handler for user changing the avatar model while sitting. There's currently an issue with changing avatar models while override role animations are applied,
+    // so to avoid that problem, re-apply the role overrides once the model has finished changing.
+    this.modelURLChangeFinished = function () {
+        print("Sitter's model has FINISHED changing. Reapply anim role overrides.");
+        var roles = this.rolesToOverride();
+        for (i in roles) {
+            MyAvatar.overrideRoleAnimation(roles[i], ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME);
+        }
+    }
+
     this.sitDown = function() {
         if (this.checkSeatForAvatar()) {
             print("Someone is already sitting in that chair.");
@@ -164,12 +174,14 @@
             return { headType: 0 };
         }, ["headType"]);
         Script.update.connect(this, this.update);
+        MyAvatar.onLoadComplete.connect(this, this.modelURLChangeFinished);
     }
 
     this.standUp = function() {
         print("Standing up (" + this.entityID + ")");
         MyAvatar.removeAnimationStateHandler(this.animStateHandlerID);
         Script.update.disconnect(this, this.update);
+        MyAvatar.onLoadComplete.disconnect(this, this.modelURLChangeFinished);
 
         if (MyAvatar.sessionUUID === this.getSeatUser()) {
             this.setSeatUser(null);
@@ -331,7 +343,7 @@
         }
         this.cleanupOverlay();
     }
-
+    
     this.clickDownOnEntity = function (id, event) {
         if (isInEditMode()) {
             return;
@@ -340,4 +352,4 @@
             this.sitDown();
         }
     }
-});
\ No newline at end of file
+});