<commit_before>/*
Copyright 2014 <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.
*/

//all <script> js loaded
addPerc(20);

require(["js/Constants","js/Field","js/Game",
         "js/Dart","js/Player","js/Options","js/Controls",
         "js/lsClient","js/Simulator","js/ConsoleSubscriptionListener",
         "js/Scoreboard","js/RoomSubscription",
         "js/ChatBoard","js/ChatSubscription",
         "js/FloatingMenu","js/Status", "js/Utils"],
    function(Constants,Field,Game,
        Dart,Player,Options,Controls,
        lsClient,Simulator,ConsoleSubscriptionListener,
        Scoreboard,RoomSubscription,
        ChatBoard,ChatSubscription,
        FloatingMenu,Status,Utils) {
  
  //all required js loaded
  addPerc(18);
  var loading = new FloatingMenu($("#loading"),{
    startOpen: true,
    zIndex: Constants.FLOATING_Z_INDEX.MAX,
    openPosition: {right: 0, bottom: 0, left: 0, top: 0}
  });

  THREE.DefaultLoadingManager.onProgress = function ( item, loaded, total ) {
    var perc = (50/total)*loaded + 50;
    showPerc(perc);
    
    if (loaded == total) {
      THREE.DefaultLoadingManager.onProgress = null;
      setTimeout(function() {
        loading.close();
      },1000);
    }
  };
  
  
  var options = new Options();
  var userNick = options.getNick();
  
  //setup game
  var field = null;
  try {
    field = new Field($("#theWorld")[0],$(".hideWhileFlying"));
  } catch(e) {
    Status.changeStatus(Status.NOT_COMPATIBLE);
    return;
  }
  
  var game = new Game(field);
  var scoreboard = new Scoreboard(field,"scoreboardTemplate",["td"],$("#scoreboard"));
  var chat = new ChatBoard(field,"chatTemplate",["span"],$("#chat"),$("#chatPlaceHolder"));
  var player = new Player(userNick,lsClient,game);
  var controls = new Controls(player);
  
  //setup chat subscription
  var chatSubscription = new ChatSubscription(Constants.ROOM);
  if (Constants.LOG_UPDATES_ON_CONSOLE) {
    chatSubscription.addListener(new ConsoleSubscriptionListener("Chat Subscription "+Constants.ROOM));
  }
  chatSubscription.addListener(chat);
  lsClient.subscribe(chatSubscription);
  
  //setup room subscription
  var roomSubscription = new RoomSubscription(Constants.ROOM);
  if (Constants.LOG_UPDATES_ON_CONSOLE) {
    roomSubscription.addListener(new ConsoleSubscriptionListener("Room Subscription "+Constants.ROOM));
  }
  roomSubscription.addListener(game);
  roomSubscription.addListener(scoreboard);
  lsClient.subscribe(roomSubscription);
  
  //bind to UI
  
  var cmBottom = $("#communicateButton").css("bottom").replace("px","") - $("#communicateMenu").outerHeight()/4;
  var cmRight = $("#communicateButton").outerWidth() + 20;
  
  var communicateMenu = new FloatingMenu($("#communicateMenu"),{
    startOpen: true,
    closedPosition: {right: cmRight, bottom: cmBottom},
    openPosition: {right: cmRight, bottom: cmBottom} ,
    zIndex: Constants.FLOATING_Z_INDEX.MIDDLE,
    effect: FloatingMenu.WIDTH_EFFECT,
    button: $("#communicateButton")
  });
  
  var instructionsMenu = new FloatingMenu($("#instructionsMenu"),{
    startOpen: options.getInstructionsOpen(),
    closedPosition: $("#instructionsButton"),
    effect: FloatingMenu.WIDTH_HEIGHT_EFFECT,
    button: $("#instructionsButton")
  });
  
  var optionsMenu = new FloatingMenu($("#optionsMenu"),{
    closedPosition: $("#optionsButton"),
    effect: FloatingMenu.WIDTH_HEIGHT_EFFECT,
    button: $("#optionsButton")
  });
      
  var grey = new FloatingMenu($("#grey"),{
    startOpen: options.getInstructionsOpen(),
    openPosition: {right: 0, bottom: 0, left: 0, top: 0},
    zIndex: Constants.FLOATING_Z_INDEX.MIN,
    effect: FloatingMenu.OPACITY_EFFECT,
    openOpacity: 0.7
  });
  
  instructionsMenu.addListener({
    onOpen: function() {
      optionsMenu.close();
      options.setInstructionsOpen(true);
    },
    onClose: function() {
      options.setInstructionsOpen(false);
    }
  });
  
  optionsMenu.addListener({
    onOpen: function() {
      instructionsMenu.close();
    }
  });
  
  
  controls.disable("menu");
  var menusListener = {
      onOpen: function() {
        grey.open();
        controls.disable("menu");
      },<commit_msg>fix disable call for startup with closed instructions case<commit_after>/*
Copyright 2014 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.
*/

//all <script> js loaded
addPerc(20);

require(["js/Constants","js/Field","js/Game",
         "js/Dart","js/Player","js/Options","js/Controls",
         "js/lsClient","js/Simulator","js/ConsoleSubscriptionListener",
         "js/Scoreboard","js/RoomSubscription",
         "js/ChatBoard","js/ChatSubscription",
         "js/FloatingMenu","js/Status", "js/Utils"],
    function(Constants,Field,Game,
        Dart,Player,Options,Controls,
        lsClient,Simulator,ConsoleSubscriptionListener,
        Scoreboard,RoomSubscription,
        ChatBoard,ChatSubscription,
        FloatingMenu,Status,Utils) {
  
  //all required js loaded
  addPerc(18);
  var loading = new FloatingMenu($("#loading"),{
    startOpen: true,
    zIndex: Constants.FLOATING_Z_INDEX.MAX,
    openPosition: {right: 0, bottom: 0, left: 0, top: 0}
  });

  THREE.DefaultLoadingManager.onProgress = function ( item, loaded, total ) {
    var perc = (50/total)*loaded + 50;
    showPerc(perc);
    
    if (loaded == total) {
      THREE.DefaultLoadingManager.onProgress = null;
      setTimeout(function() {
        loading.close();
      },1000);
    }
  };
  
  
  var options = new Options();
  var userNick = options.getNick();
  
  //setup game
  var field = null;
  try {
    field = new Field($("#theWorld")[0],$(".hideWhileFlying"));
  } catch(e) {
    Status.changeStatus(Status.NOT_COMPATIBLE);
    return;
  }
  
  var game = new Game(field);
  var scoreboard = new Scoreboard(field,"scoreboardTemplate",["td"],$("#scoreboard"));
  var chat = new ChatBoard(field,"chatTemplate",["span"],$("#chat"),$("#chatPlaceHolder"));
  var player = new Player(userNick,lsClient,game);
  var controls = new Controls(player);
  
  //setup chat subscription
  var chatSubscription = new ChatSubscription(Constants.ROOM);
  if (Constants.LOG_UPDATES_ON_CONSOLE) {
    chatSubscription.addListener(new ConsoleSubscriptionListener("Chat Subscription "+Constants.ROOM));
  }
  chatSubscription.addListener(chat);
  lsClient.subscribe(chatSubscription);
  
  //setup room subscription
  var roomSubscription = new RoomSubscription(Constants.ROOM);
  if (Constants.LOG_UPDATES_ON_CONSOLE) {
    roomSubscription.addListener(new ConsoleSubscriptionListener("Room Subscription "+Constants.ROOM));
  }
  roomSubscription.addListener(game);
  roomSubscription.addListener(scoreboard);
  lsClient.subscribe(roomSubscription);
  
  //bind to UI
  
  var cmBottom = $("#communicateButton").css("bottom").replace("px","") - $("#communicateMenu").outerHeight()/4;
  var cmRight = $("#communicateButton").outerWidth() + 20;
  
  var communicateMenu = new FloatingMenu($("#communicateMenu"),{
    startOpen: true,
    closedPosition: {right: cmRight, bottom: cmBottom},
    openPosition: {right: cmRight, bottom: cmBottom} ,
    zIndex: Constants.FLOATING_Z_INDEX.MIDDLE,
    effect: FloatingMenu.WIDTH_EFFECT,
    button: $("#communicateButton")
  });
  
  var instructionsMenu = new FloatingMenu($("#instructionsMenu"),{
    startOpen: options.getInstructionsOpen(),
    closedPosition: $("#instructionsButton"),
    effect: FloatingMenu.WIDTH_HEIGHT_EFFECT,
    button: $("#instructionsButton")
  });
  
  var optionsMenu = new FloatingMenu($("#optionsMenu"),{
    closedPosition: $("#optionsButton"),
    effect: FloatingMenu.WIDTH_HEIGHT_EFFECT,
    button: $("#optionsButton")
  });
      
  var grey = new FloatingMenu($("#grey"),{
    startOpen: options.getInstructionsOpen(),
    openPosition: {right: 0, bottom: 0, left: 0, top: 0},
    zIndex: Constants.FLOATING_Z_INDEX.MIN,
    effect: FloatingMenu.OPACITY_EFFECT,
    openOpacity: 0.7
  });
  
  instructionsMenu.addListener({
    onOpen: function() {
      optionsMenu.close();
      options.setInstructionsOpen(true);
    },
    onClose: function() {
      options.setInstructionsOpen(false);
    }
  });
  
  optionsMenu.addListener({
    onOpen: function() {
      instructionsMenu.close();
    }
  });
  
  if (options.getInstructionsOpen()) {
    controls.disable("menu");
  }
  var menusListener = {
      onOpen: function() {
        grey.open();
        controls.disable("menu");
      },
{'fraction_non_alphanumeric': 0.13538689531068063, 'fraction_numerical': 0.007198052291732825, 'mean_word_length': 3.855087358684481, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '3982396', 'n_tokens_mistral': 2852, 'n_tokens_neox': 2839, 'n_words': 621}