<commit_before>angular.module('gamEvolve.game.boardTree', [
  'ui.bootstrap'
  'gamEvolve.game.board.editEmitterDialog'
  'gamEvolve.game.board.editChipPinsDialog'
  'gamEvolve.game.board.editSplitterDialog'
  'treeRepeat'
  'gamEvolve.game.boardLabel'
  'gamEvolve.model.chips'
  'gamEvolve.game.boardNodes'
  'gamEvolve.model.circuits'
])

.controller 'BoardTreeCtrl', ($scope, $modal, currentGame, gameHistory, gameTime, treeDrag, chips, boardNodes, circuits) ->
  $scope.currentGame = currentGame
  $scope.treeDrag = treeDrag
  $scope.chips = chips 
  $scope.boardNodes = boardNodes

  $scope.isPreviewedAsSource = (chip) ->
    return false unless chip
    return false if chips.isRoot(chip)
    isDraggedAsSource(chip) && !isDraggedOverItself()

  isDraggedAsSource = (chip) ->
    source = treeDrag.data?.node
    chip is source

  isDraggedOverItself = ->
    source = treeDrag.data?.node
    target = treeDrag.lastHovered
    source is target or isFirstChildOf(source, target)

  isFirstChildOf = (chip, suspectedParent) ->
    chip is suspectedParent?.children?[0]

  isDraggedAsTarget = (chip) ->
    target = treeDrag.lastHovered
    chip is target

  $scope.isPreviewedAsTarget = (chip) ->
    return false unless chip
    isDraggedAsTarget(chip) && !isDraggedOverItself()

  $scope.allowDrop = (source) ->
    return false if chips.isRoot(source)
    chipType = chips.getType source
    return chipType in chips.types

  $scope.edit = (chip) ->
    switch chips.getType(chip) # Type of dialog depends on type of chip
      when "switch"
        showDialog 'game/board/editBoardChipPinsDialog.tpl.html', 'EditBoardChipPinsDialogCtrl', chip, (model) ->
          _.extend(chip, model)
      when "processor"
        showDialog 'game/board/editBoardChipPinsDialog.tpl.html', 'EditBoardChipPinsDialogCtrl', chip, (model) ->
          _.extend(chip, model)
      when "emitter"
        showDialog 'game/board/editBoardEmitterDialog.tpl.html', 'EditBoardEmitterDialogCtrl', chip, (model) ->
          _.extend(chip, model)
      when "splitter"
        showDialog 'game/board/editBoardSplitterDialog.tpl.html', 'EditBoardSplitterDialogCtrl', chip, (model) ->
          _.extend(chip, model)
      when "circuit"
        showDialog 'game/board/editBoardChipPinsDialog.tpl.html', 'EditBoardChipPinsDialogCtrl', chip, (model) ->
          if chip.id isnt model.id
            # Rename circuit layer
            parentCircuit = currentGame.version.circuits[circuits.currentCircuitMeta.type] 
            circuitLayer = _.findWhere(parentCircuit.io.layers, { name: chip.id })
            if circuitLayer then circuitLayer.name = model.id

          _.extend(chip, model)

  $scope.mute = (node) ->
    node.muted = !node.muted
    currentGame.updateLocalVersion()

  $scope.switchCircuit = (circuitNode) -><commit_msg>fixed renaming circuits in board<commit_after>angular.module('gamEvolve.game.boardTree', [
  'ui.bootstrap'
  'gamEvolve.game.board.editEmitterDialog'
  'gamEvolve.game.board.editChipPinsDialog'
  'gamEvolve.game.board.editSplitterDialog'
  'treeRepeat'
  'gamEvolve.game.boardLabel'
  'gamEvolve.model.chips'
  'gamEvolve.game.boardNodes'
  'gamEvolve.model.circuits'
])

.controller 'BoardTreeCtrl', ($scope, $modal, currentGame, gameHistory, gameTime, treeDrag, chips, boardNodes, circuits) ->
  $scope.currentGame = currentGame
  $scope.treeDrag = treeDrag
  $scope.chips = chips 
  $scope.boardNodes = boardNodes

  $scope.isPreviewedAsSource = (chip) ->
    return false unless chip
    return false if chips.isRoot(chip)
    isDraggedAsSource(chip) && !isDraggedOverItself()

  isDraggedAsSource = (chip) ->
    source = treeDrag.data?.node
    chip is source

  isDraggedOverItself = ->
    source = treeDrag.data?.node
    target = treeDrag.lastHovered
    source is target or isFirstChildOf(source, target)

  isFirstChildOf = (chip, suspectedParent) ->
    chip is suspectedParent?.children?[0]

  isDraggedAsTarget = (chip) ->
    target = treeDrag.lastHovered
    chip is target

  $scope.isPreviewedAsTarget = (chip) ->
    return false unless chip
    isDraggedAsTarget(chip) && !isDraggedOverItself()

  $scope.allowDrop = (source) ->
    return false if chips.isRoot(source)
    chipType = chips.getType source
    return chipType in chips.types

  $scope.edit = (chip) ->
    switch chips.getType(chip) # Type of dialog depends on type of chip
      when "switch"
        showDialog 'game/board/editBoardChipPinsDialog.tpl.html', 'EditBoardChipPinsDialogCtrl', chip, (model) ->
          _.extend(chip, model)
      when "processor"
        showDialog 'game/board/editBoardChipPinsDialog.tpl.html', 'EditBoardChipPinsDialogCtrl', chip, (model) ->
          _.extend(chip, model)
      when "emitter"
        showDialog 'game/board/editBoardEmitterDialog.tpl.html', 'EditBoardEmitterDialogCtrl', chip, (model) ->
          _.extend(chip, model)
      when "splitter"
        showDialog 'game/board/editBoardSplitterDialog.tpl.html', 'EditBoardSplitterDialogCtrl', chip, (model) ->
          _.extend(chip, model)
      when "circuit"
        # Rename id -> comment and back again
        newChip = _.extend({}, chip, { comment: chip.id })
        showDialog 'game/board/editBoardChipPinsDialog.tpl.html', 'EditBoardChipPinsDialogCtrl', newChip, (model) ->
          newModel = _.extend({}, model, { id: model.comment })
          if chip.id isnt model.comment
            # Rename circuit layer
            parentCircuit = currentGame.version.circuits[circuits.currentCircuitMeta.type] 
            circuitLayer = _.findWhere(parentCircuit.io.layers, { name: chip.id })
            if circuitLayer then circuitLayer.name = newModel.id

          _.extend(chip, newModel)

  $scope.mute = (node) ->
    node.muted = !node.muted
    currentGame.updateLocalVersion()

  $scope.switchCircuit = (circuitNode) ->
{'fraction_non_alphanumeric': 0.115160848733744, 'fraction_numerical': 0.00034223134839151266, 'mean_word_length': 3.3947368421052633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 36, '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': '4812045', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1827, 'n_words': 370}