<commit_before>define([
  'missile_command/registry',
  'missile_command/persist',
  'missile_command/preview',
  'text!missile_command/missile_command.html'
], function(registry, persist, preview, html) {
  "use strict";

  engine.asyncCall("ubernet.getGameWithPlayer").done(function (data) {
    data = JSON.parse(data);
    persist.enableStorage(data.LobbyID, registry.registry)
  })

  var nuke_launcher = '/pa/units/land/nuke_launcher/nuke_launcher.json'
  //var nuke_launcher = '/pa/units/land/energy_plant/energy_plant.json'

  var checkCommand = function(command, selected) {
    if (command == 'attack' && selected) {
      registry.unready(selected)
      registry.nextReady()
    }
  }

  model.selection.subscribe(function(payload) {
    if (!payload) {
      registry.showSelected([])
      return
    }

    var si = payload.spec_ids
    if (Object.keys(si).length == 1) {
      if (si[nuke_launcher]) {
        if (si[nuke_launcher].length == 1) {
          registry.register(si[nuke_launcher][0])
        } else {
          registry.notice(si[nuke_launcher])
        }
      }
    }

    registry.showSelected(si[nuke_launcher])
  })

  var originalUnitCommand = api.Holodeck.prototype.unitCommand
  api.Holodeck.prototype.unitCommand = function(command, x, y, queue) {
    var selected = model.selection().spec_ids[nuke_launcher]
    return originalUnitCommand.apply(this, arguments).success(
      function() {checkCommand(command, selected)})
  }

  var originalTargetCommand = api.unit.targetCommand
  api.unit.targetCommand = function(command, target, queue) {
    var selected = model.selection().spec_ids[nuke_launcher]
    return originalTargetCommand.apply(this, arguments).success(
      function() {checkCommand(command, selected)})
  }


  var settings = alertsManager.makeEmptyFilterSettings();
  settings.selectedTypes[alertsManager.WATCH_TYPES.CREATED] = ['Nuke'];
  settings.selectedTypes[alertsManager.WATCH_TYPES.DESTROYED] = ['Nuke'];

  alertsManager.addFilteredListener(function(payload) {
    console.log(payload);
    payload.list.forEach(function(alert) {
      if (alert.watch_type == alertsManager.WATCH_TYPES.CREATED) {
        registry.created(alert.id, {location: alert.location, planet_id: alert.planet_id})
      } else if (alert.watch_type == alertsManager.WATCH_TYPES.DESTROYED) {
        registry.destroyed(alert.id)
      }
    })
  }, settings);
  //alertsManager.addListener(function(payload) {
    //console.log('all');
    //console.log(payload)
  //})

  var viewModel = {
    visible: ko.computed(function() {
      return registry.registry().length > 0
    }),
    registry: registry.registry,
    open: ko.observable(true),
    toggle: function() { this.open(!this.open()) },
    hidePreview: preview.hide,
    nextReady: registry.nextReady
  }

  return {
    ready: function() {
      createFloatingFrame('missile_command_frame', 210, 40, {'offset': 'leftCenter', 'left': 0});
      var $container = $('#missile_command_frame_content')
      $(html).appendTo($container)
      ko.applyBindings(viewModel, $container[0])
    },
    viewModel: viewModel
  }
})<commit_msg>engine.asyncCall not available at load time<commit_after>define([
  'missile_command/registry',
  'missile_command/persist',
  'missile_command/preview',
  'text!missile_command/missile_command.html'
], function(registry, persist, preview, html) {
  "use strict";

  var initiateStorage = function() {
    engine.asyncCall("ubernet.getGameWithPlayer").done(function (data) {
      data = JSON.parse(data);
      persist.enableStorage(data.LobbyID, registry.registry)
    })
  }

  var nuke_launcher = '/pa/units/land/nuke_launcher/nuke_launcher.json'
  //var nuke_launcher = '/pa/units/land/energy_plant/energy_plant.json'

  var checkCommand = function(command, selected) {
    if (command == 'attack' && selected) {
      registry.unready(selected)
      registry.nextReady()
    }
  }

  model.selection.subscribe(function(payload) {
    if (!payload) {
      registry.showSelected([])
      return
    }

    var si = payload.spec_ids
    if (Object.keys(si).length == 1) {
      if (si[nuke_launcher]) {
        if (si[nuke_launcher].length == 1) {
          registry.register(si[nuke_launcher][0])
        } else {
          registry.notice(si[nuke_launcher])
        }
      }
    }

    registry.showSelected(si[nuke_launcher])
  })

  var originalUnitCommand = api.Holodeck.prototype.unitCommand
  api.Holodeck.prototype.unitCommand = function(command, x, y, queue) {
    var selected = model.selection().spec_ids[nuke_launcher]
    return originalUnitCommand.apply(this, arguments).success(
      function() {checkCommand(command, selected)})
  }

  var originalTargetCommand = api.unit.targetCommand
  api.unit.targetCommand = function(command, target, queue) {
    var selected = model.selection().spec_ids[nuke_launcher]
    return originalTargetCommand.apply(this, arguments).success(
      function() {checkCommand(command, selected)})
  }


  var settings = alertsManager.makeEmptyFilterSettings();
  settings.selectedTypes[alertsManager.WATCH_TYPES.CREATED] = ['Nuke'];
  settings.selectedTypes[alertsManager.WATCH_TYPES.DESTROYED] = ['Nuke'];

  alertsManager.addFilteredListener(function(payload) {
    console.log(payload);
    payload.list.forEach(function(alert) {
      if (alert.watch_type == alertsManager.WATCH_TYPES.CREATED) {
        registry.created(alert.id, {location: alert.location, planet_id: alert.planet_id})
      } else if (alert.watch_type == alertsManager.WATCH_TYPES.DESTROYED) {
        registry.destroyed(alert.id)
      }
    })
  }, settings);
  //alertsManager.addListener(function(payload) {
    //console.log('all');
    //console.log(payload)
  //})

  var viewModel = {
    visible: ko.computed(function() {
      return registry.registry().length > 0
    }),
    registry: registry.registry,
    open: ko.observable(true),
    toggle: function() { this.open(!this.open()) },
    hidePreview: preview.hide,
    nextReady: registry.nextReady
  }

  return {
    ready: function() {
      createFloatingFrame('missile_command_frame', 210, 40, {'offset': 'leftCenter', 'left': 0});
      var $container = $('#missile_command_frame_content')
      $(html).appendTo($container)
      ko.applyBindings(viewModel, $container[0])

      // engine.asyncCall doens't exist at load time
      setTimeout(initiateStorage, 0)
    },
    viewModel: viewModel
  }
})
{'fraction_non_alphanumeric': 0.13666044776119404, 'fraction_numerical': 0.0035758706467661694, 'mean_word_length': 3.6819505094614264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2390488', 'n_tokens_mistral': 2101, 'n_tokens_neox': 2017, 'n_words': 314}