<commit_before>/*
Copyright 2013 <NAME>.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
define(["Inheritance","EventDispatcher","Subscription","./Constants","./ConsoleSubscriptionListener"],
    function(Inheritance,EventDispatcher,Subscription,Constants,ConsoleSubscriptionListener) {

  function generateId() {
    return "u-"+Math.round(Math.random()*1000);
  }
  
  var Player = function(nick,status,client) {
    this.initDispatcher();
    
    this.client = client;
    this.nick = nick;
    this.status = status;
    
    this.id = generateId(); 
    this.userSubscription = new Subscription("DISTINCT","user_"+this.id,["message","from"]); //USER_SUBSCRIPTION used only to signal presence
    this.userSubscription.setRequestedSnapshot("yes");
    this.userSubscription.addListener(this);
    this.client.subscribe(this.userSubscription);
    
    if (Constants.LOG_UPDATES_ON_CONSOLE) {
      this.userSubscription.addListener(new ConsoleSubscriptionListener("User"));
    }
    
    this.rooms = {};
    this.playing = false;
    
  };
  
  Player.prototype = {
    
      ready: function() {
        
        if (this.playing) {
          return;
        }
        this.playing = true;

        this.dispatchEvent("onIdConfirmed",[this.id]);
       
        //conf nick & status
        this.sendNick();
        this.sendStatus();
        
        //re-enter rooms
        for (var i in this.rooms) {
          this.enterRoomInternal(i);
        } 
      },
      
      reset: function() {
        /*if (!this.playing) {
          return;
        }*/
        this.playing = false;
      },
      
      retry: function() {
        this.id = generateId();
        this.client.unsubscribe(this.userSubscription);
        this.userSubscription.setItems(["user_"+this.id]);
        this.client.subscribe(this.userSubscription);
      },
      
      /**
       * @private
       */
      error: function(message) {
        this.dispatchEvent("onError",[message]);
      },
      
      /**
       * @private
       */
      sendRoomMessage: function(command,sequence,room) {
        if (!this.rooms[room]) {
          return;
        }
        this.sendMessage(command,sequence);
      },
      
      /**
       * @private
       */
      sendMessage: function(command,sequence) {
        if (!this.playing) {
          return;
        }
        this.client.sendMessage(command,sequence,0,this);
      },
      
      enterRoom: function(room) {
        if (this.rooms[room]){
          return;
        }
        
        this.enterRoomInternal(room);
        
        this.rooms[room] = true;
      },
      
      /**
       * @private
       */
      enterRoomInternal: function(room) {
        this.sendMessage("enter|"+room,"enterexit");
      },
      
      exitRoom: function(room) {
        this.sendRoomMessage("leave|"+room,"enterexit",room);
      },
      
      grab: function(room) {
        this.sendRoomMessage("grab|"+room,"3D",room);
      },
      
      release: function(room,sx,sy,sz) {
        this.sendRoomMessage("release|"+room+"|"+sx+"|"+sy+"|"+sz,"3D",room);
      },
      
      move: function(room,x,y,z) {
        this.sendRoomMessage("move|"+room+"|"+x+"|"+y+"|"+z,"3D",room);
      },
      
      changeNick: function(newNick) {
        if (this.nick == newNick) {
          return;<commit_msg>change sequence name<commit_after>/*
Copyright 2013 Weswit s.r.l.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
define(["Inheritance","EventDispatcher","Subscription","./Constants","./ConsoleSubscriptionListener"],
    function(Inheritance,EventDispatcher,Subscription,Constants,ConsoleSubscriptionListener) {

  function generateId() {
    return "u-"+Math.round(Math.random()*1000);
  }
  
  var Player = function(nick,status,client) {
    this.initDispatcher();
    
    this.client = client;
    this.nick = nick;
    this.status = status;
    
    this.id = generateId(); 
    this.userSubscription = new Subscription("DISTINCT","user_"+this.id,["message","from"]); //USER_SUBSCRIPTION used only to signal presence
    this.userSubscription.setRequestedSnapshot("yes");
    this.userSubscription.addListener(this);
    this.client.subscribe(this.userSubscription);
    
    if (Constants.LOG_UPDATES_ON_CONSOLE) {
      this.userSubscription.addListener(new ConsoleSubscriptionListener("User"));
    }
    
    this.rooms = {};
    this.playing = false;
    
  };
  
  Player.prototype = {
    
      ready: function() {
        
        if (this.playing) {
          return;
        }
        this.playing = true;

        this.dispatchEvent("onIdConfirmed",[this.id]);
       
        //conf nick & status
        this.sendNick();
        this.sendStatus();
        
        //re-enter rooms
        for (var i in this.rooms) {
          this.enterRoomInternal(i);
        } 
      },
      
      reset: function() {
        /*if (!this.playing) {
          return;
        }*/
        this.playing = false;
      },
      
      retry: function() {
        this.id = generateId();
        this.client.unsubscribe(this.userSubscription);
        this.userSubscription.setItems(["user_"+this.id]);
        this.client.subscribe(this.userSubscription);
      },
      
      /**
       * @private
       */
      error: function(message) {
        this.dispatchEvent("onError",[message]);
      },
      
      /**
       * @private
       */
      sendRoomMessage: function(command,sequence,room) {
        if (!this.rooms[room]) {
          return;
        }
        this.sendMessage(command,sequence);
      },
      
      /**
       * @private
       */
      sendMessage: function(command,sequence) {
        if (!this.playing) {
          return;
        }
        this.client.sendMessage(command,sequence,0,this);
      },
      
      enterRoom: function(room) {
        if (this.rooms[room]){
          return;
        }
        
        this.enterRoomInternal(room);
        
        this.rooms[room] = true;
      },
      
      /**
       * @private
       */
      enterRoomInternal: function(room) {
        this.sendMessage("enter|"+room,"enterexit"+room);
      },
      
      exitRoom: function(room) {
        this.sendRoomMessage("leave|"+room,"enterexit"+room,room);
      },
      
      grab: function(room) {
        this.sendRoomMessage("grab|"+room,"3D",room);
      },
      
      release: function(room,sx,sy,sz) {
        this.sendRoomMessage("release|"+room+"|"+sx+"|"+sy+"|"+sz,"3D",room);
      },
      
      move: function(room,x,y,z) {
        this.sendRoomMessage("move|"+room+"|"+x+"|"+y+"|"+z,"3D",room);
      },
      
      changeNick: function(newNick) {
        if (this.nick == newNick) {
          return;
{'fraction_non_alphanumeric': 0.13454309786130914, 'fraction_numerical': 0.004147764095917045, 'mean_word_length': 2.154538021259199, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6110427', 'n_tokens_mistral': 2269, 'n_tokens_neox': 2231, 'n_words': 408}