<commit_before>AC = Artificial.Control
FM = FataMorgana
LOI = LandsOfIllusions

Bresenham = require('bresenham-zingl')

class LOI.Assets.SpriteEditor.Tools.Stroke extends LOI.Assets.SpriteEditor.Tools.Tool
  # cleanLine: boolean whether to maintain a clean line with consistent width
  # drawPreview: boolean whether to always draw preview of the pixels to be applied
  # fractionalPerfectLines: boolean whether to allow 3:2 and 5:2 lines
  constructor: ->
    super arguments...

    @drawLine = new ReactiveField false
    @drawStraight = new ReactiveField false

    @lastPixelCoordinates = new ReactiveField null
    @currentPixelCoordinates = new ReactiveField null
    @lastStrokeCoordinates = new ReactiveField null
    @secondToLastStrokeCoordinates = new ReactiveField null
    @lockedCoordinate = new ReactiveField null

    @perfectLineRatio = new ReactiveField null

    @paintHelper = @interface.getHelper LOI.Assets.SpriteEditor.Helpers.Paint
    @brushHelper = @interface.getHelper LOI.Assets.SpriteEditor.Helpers.Brush

    @pixels = new ReactiveField null

  onActivated: ->
    @processStroke()

    @_previewActive = false

    @_cursorChangesAutorun = @autorun (computation) =>
      # React to cursor changes.
      return unless @editor()?.cursor().cursorArea()
      Tracker.nonreactive => @processStroke()

    @_updatePreviewAutorun = @autorun (computation) =>
      # Show preview when we're drawing a line and mouse is on the canvas.
      preview = (@data.get('drawPreview') or @drawLine()) and @editor()?.mouse().pixelCoordinate()

      if preview
        # Update preview pixels.
        @editor().operationPreview().pixels @pixels()

      else if @_previewActive
        # Remove pixels, since we were the ones providing them.
        @editor().operationPreview().pixels []

      @_previewActive = preview

  createPixelsFromCoordinates: (coordinates) ->
    # Override to create full pixel data out of stroke coordinates.
    coordinates

  onDeactivated: ->
    @_cursorChangesAutorun.stop()
    @_updatePreviewAutorun.stop()
    @editor().operationPreview().pixels []

  infoText: ->
    return unless @drawLine()
    return unless ratio = @perfectLineRatio()<commit_msg>Editor closing fix.<commit_after>AC = Artificial.Control
FM = FataMorgana
LOI = LandsOfIllusions

Bresenham = require('bresenham-zingl')

class LOI.Assets.SpriteEditor.Tools.Stroke extends LOI.Assets.SpriteEditor.Tools.Tool
  # cleanLine: boolean whether to maintain a clean line with consistent width
  # drawPreview: boolean whether to always draw preview of the pixels to be applied
  # fractionalPerfectLines: boolean whether to allow 3:2 and 5:2 lines
  constructor: ->
    super arguments...

    @drawLine = new ReactiveField false
    @drawStraight = new ReactiveField false

    @lastPixelCoordinates = new ReactiveField null
    @currentPixelCoordinates = new ReactiveField null
    @lastStrokeCoordinates = new ReactiveField null
    @secondToLastStrokeCoordinates = new ReactiveField null
    @lockedCoordinate = new ReactiveField null

    @perfectLineRatio = new ReactiveField null

    @paintHelper = @interface.getHelper LOI.Assets.SpriteEditor.Helpers.Paint
    @brushHelper = @interface.getHelper LOI.Assets.SpriteEditor.Helpers.Brush

    @pixels = new ReactiveField null

  onActivated: ->
    @processStroke()

    @_previewActive = false

    @_cursorChangesAutorun = @autorun (computation) =>
      # React to cursor changes.
      return unless @editor()?.cursor().cursorArea()
      Tracker.nonreactive => @processStroke()

    @_updatePreviewAutorun = @autorun (computation) =>
      return unless editor = @editor()

      # Show preview when we're drawing a line and mouse is on the canvas.
      preview = (@data.get('drawPreview') or @drawLine()) and editor.mouse().pixelCoordinate()

      if preview
        # Update preview pixels.
        editor.operationPreview().pixels @pixels()

      else if @_previewActive
        # Remove pixels, since we were the ones providing them.
        editor.operationPreview().pixels []

      @_previewActive = preview

  createPixelsFromCoordinates: (coordinates) ->
    # Override to create full pixel data out of stroke coordinates.
    coordinates

  onDeactivated: ->
    @_cursorChangesAutorun.stop()
    @_updatePreviewAutorun.stop()
    @editor().operationPreview().pixels []

  infoText: ->
    return unless @drawLine()
    return unless ratio = @perfectLineRatio()
{'fraction_non_alphanumeric': 0.08782569631626236, 'fraction_numerical': 0.0017969451931716084, 'mean_word_length': 3.707188160676533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5012022', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1229, 'n_words': 355}