<commit_before># Background
# ==========
# A gradient of bg and scroll factors based on coefficients.
# We're extending `FlxGroup` b/c there's nothing else. ArrayList would
# be better.

# Dependencies
# ------------
define [
  'phaser'
  'underscore'
  'app/helpers'
], (Phaser, _, Helpers) ->

  'use strict'

  class Background

    constructor: (@config, game) ->
      @height = @config.height

      @layers = []
      @topZIndex = 1

      # Main knobs.
      @parallaxFactor = 0.95
      @parallaxBuffer = 1.7
      @parallaxTolerance = -64

      # - full - Each image is a layer of the full original.
      # - clip - Images are only partial, and clip the transparent leftovers.
      @layoutMode = 'full' # TODO: Support 'clip'.

      @_initialize game

    _initialize: (game) ->
      @group = game.add.group()
      @width = @group.game.width

      @_initDebugging()

    _initDebugging: () ->
      @debugNamespace = 'background'

      @_initDebugMixin()

    # Public
    # ------

    addImages: (nameTemplate, topZIndex, bottomZIndex = 1) ->
      @topZIndex = topZIndex
      for zIndex in [bottomZIndex..topZIndex]
        name = nameTemplate { zIndex }
        image = @group.game.add.image 0, 0, name, @group
        @layers.push { image, zIndex }

    layout: ->
      # Offset group by its original (map) height while it's not resized from
      # the layer shifting below.
      # @group.y = -(@group.height - @group.game.height)

      # Set vertical scroll factor and offset.
      nearest = @_nearestLayer()
      farthest = @_farthestLayer()
      for layer in @layers
        {image, zIndex} = layer
        # Factor in z-index exponentially and constrain.
        factor = (zIndex / @layers.length) ** 2 * @parallaxFactor
        # Add buffer to further constrain.
        factor = (factor + @parallaxBuffer / 2) / @parallaxBuffer
        # Shift based on scroll factor for full bg visibility.
        unless zIndex is nearest.zIndex
          image.y -= @group.game.height * (1 - factor) - @parallaxTolerance
        # Set scroll factor.
        layer.scrollFactor = factor
        # Set shift.
        shift = if zIndex is farthest.zIndex then -farthest.image.y else 0
        image.y += shift

      # TODO: Remove the need for this magical-number hack.
      # nearest.sprite.y += 12
      # @group.height = shift + nearest.sprite.height / (@parallaxFactor ** 0.32)

      @debug 'layers', @layers

    # Helpers
    # -------<commit_msg>Turn off more legacy Background#layout logic for now.<commit_after># Background
# ==========
# A gradient of bg and scroll factors based on coefficients.
# We're extending `FlxGroup` b/c there's nothing else. ArrayList would
# be better.

# Dependencies
# ------------
define [
  'phaser'
  'underscore'
  'app/helpers'
], (Phaser, _, Helpers) ->

  'use strict'

  class Background

    constructor: (@config, game) ->
      @height = @config.height

      @layers = []
      @topZIndex = 1

      # Main knobs.
      @parallaxFactor = 0.95
      @parallaxBuffer = 1.7
      @parallaxTolerance = -64

      # - full - Each image is a layer of the full original.
      # - clip - Images are only partial, and clip the transparent leftovers.
      @layoutMode = 'full' # TODO: Support 'clip'.

      @_initialize game

    _initialize: (game) ->
      @group = game.add.group()
      @width = @group.game.width

      @_initDebugging()

    _initDebugging: () ->
      @debugNamespace = 'background'

      @_initDebugMixin()

    # Public
    # ------

    addImages: (nameTemplate, topZIndex, bottomZIndex = 1) ->
      @topZIndex = topZIndex
      for zIndex in [bottomZIndex..topZIndex]
        name = nameTemplate { zIndex }
        image = @group.game.add.image 0, 0, name, @group
        @layers.push { image, zIndex }

    layout: ->
      # Offset group by its original (map) height while it's not resized from
      # the layer shifting below.
      # @group.y = -(@group.height - @group.game.height)

      # Set vertical scroll factor and offset.
      nearest = @_nearestLayer()
      farthest = @_farthestLayer()
      for layer in @layers
        {image, zIndex} = layer
        # Factor in z-index exponentially and constrain.
        factor = (zIndex / @layers.length) ** 2 * @parallaxFactor
        # Add buffer to further constrain.
        factor = (factor + @parallaxBuffer / 2) / @parallaxBuffer
        # TODO: Shift based on scroll factor for full bg visibility.
        # unless zIndex is nearest.zIndex
          # image.y -= @group.game.height * (1 - factor) - @parallaxTolerance
        # Set scroll factor.
        layer.scrollFactor = factor
        # TODO: Set shift.
        shift = if zIndex is farthest.zIndex then -farthest.image.y else 0
        # image.y += shift

      # TODO: Remove the need for this magical-number hack.
      # nearest.sprite.y += 12
      # @group.height = shift + nearest.sprite.height / (@parallaxFactor ** 0.32)

      @debug 'layers', @layers

    # Helpers
    # -------
{'fraction_non_alphanumeric': 0.12155688622754492, 'fraction_numerical': 0.007984031936127744, 'mean_word_length': 2.1876590330788805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1165260', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1480, 'n_words': 459}