<commit_before>package flixel.group; 

import flash.display.BitmapData;
import flash.display.BlendMode;
import flixel.FlxCamera;
import flixel.FlxSprite;
import flixel.graphics.frames.FlxFrame;
import flixel.graphics.frames.FlxFramesCollection;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.group.FlxGroup.FlxTypedGroupIterator;
import flixel.math.FlxMath;
import flixel.math.FlxPoint;
import flixel.math.FlxRect;
import flixel.system.FlxAssets.FlxGraphicAsset;
import flixel.util.FlxColor;
import flixel.util.FlxDestroyUtil;
import flixel.util.FlxSort;

typedef FlxSpriteGroup = FlxTypedSpriteGroup<FlxSprite>;

/**
 * `FlxSpriteGroup` is a special `FlxSprite` that can be treated like
 * a single sprite even if it's made up of several member sprites.
 * It shares the `FlxTypedGroup` API, but it doesn't inherit from it.
 */
class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
{
	/**
	 * The actual group which holds all sprites.
	 */
	public var group:FlxTypedGroup<T>;
	
	/**
	 * The link to a group's `members` array.
	 */
	public var members(get, null):Array<T>;
	
	/**
	 * The number of entries in the members array. For performance and safety you should check this
	 * variable instead of `members.length` unless you really know what you're doing!
	 */
	public var length(get, null):Int;
	
	/**
	 * Whether to attempt to preserve the ratio of alpha values of group members, or set them directly through
	 * the alpha property. Defaults to `false` (preservation).
	 * @since 4.5.0
	 */
	public var directAlpha:Bool = false;
	
	/**
	 * The maximum capacity of this group. Default is `0`, meaning no max capacity, and the group can just grow.
	 */
	public var maxSize(get, set):Int;
	
	/**
	 * Optimization to allow setting position of group without transforming children twice.
	 */
	var _skipTransformChildren:Bool = false;

	/**
	 * Array of all the `FlxSprite`s that exist in this group for
	 * optimization purposes / static typing on cpp targets.
	 */
	var _sprites:Array<FlxSprite>;
	
	/**
	 * @param   X         The initial X position of the group.
	 * @param   Y         The initial Y position of the group.
	 * @param   MaxSize   Maximum amount of members allowed.
	 */
	public function new(X:Float = 0, Y:Float = 0, MaxSize:Int = 0)
	{
		super(X, Y);
		group = new FlxTypedGroup<T>(MaxSize);
		_sprites = cast group.members;
	}
	
	/**
	 * This method is used for initialization of variables of complex types.
	 * Don't forget to call `super.initVars()` if you'll override this method,
	 * or you'll get `null` object error and app will crash.
	 */
	override function initVars():Void 
	{
		flixelType = SPRITEGROUP;
		
		offset = new FlxCallbackPoint(offsetCallback);
		origin = new FlxCallbackPoint(originCallback);
		scale = new FlxCallbackPoint(scaleCallback);
		scrollFactor = new FlxCallbackPoint(scrollFactorCallback);
		
		scale.set(1, 1);
		scrollFactor.set(1, 1);

		initMotionVars();
	}
	
	/**
	 * Handy function for "killing" game objects. Use `reset()` to revive them.
	 * Default behavior is to flag them as nonexistent AND dead.
	 * However, if you want the "corpse" to remain in the game, like to animate an effect or whatever,
	 * you should `override` this, setting only `alive` to `false`, and leaving `exists` `true`.
	 */
	override public function destroy():Void
	{
		// normally don't have to destroy FlxPoints, but these are FlxCallbackPoints!
		offset = FlxDestroyUtil.destroy(offset);
		origin = FlxDestroyUtil.destroy(origin);
		scale = FlxDestroyUtil.destroy(scale);
		scrollFactor = FlxDestroyUtil.destroy(scrollFactor);
		
		group = FlxDestroyUtil.destroy(group);
		_sprites = null;
		
		super.destroy();
	}
	
	/**<commit_msg>FlxSpriteGroup: fix docs for destroy() (#2162)<commit_after>package flixel.group; 

import flash.display.BitmapData;
import flash.display.BlendMode;
import flixel.FlxCamera;
import flixel.FlxSprite;
import flixel.graphics.frames.FlxFrame;
import flixel.graphics.frames.FlxFramesCollection;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.group.FlxGroup.FlxTypedGroupIterator;
import flixel.math.FlxMath;
import flixel.math.FlxPoint;
import flixel.math.FlxRect;
import flixel.system.FlxAssets.FlxGraphicAsset;
import flixel.util.FlxColor;
import flixel.util.FlxDestroyUtil;
import flixel.util.FlxSort;

typedef FlxSpriteGroup = FlxTypedSpriteGroup<FlxSprite>;

/**
 * `FlxSpriteGroup` is a special `FlxSprite` that can be treated like
 * a single sprite even if it's made up of several member sprites.
 * It shares the `FlxTypedGroup` API, but it doesn't inherit from it.
 */
class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
{
	/**
	 * The actual group which holds all sprites.
	 */
	public var group:FlxTypedGroup<T>;
	
	/**
	 * The link to a group's `members` array.
	 */
	public var members(get, null):Array<T>;
	
	/**
	 * The number of entries in the members array. For performance and safety you should check this
	 * variable instead of `members.length` unless you really know what you're doing!
	 */
	public var length(get, null):Int;
	
	/**
	 * Whether to attempt to preserve the ratio of alpha values of group members, or set them directly through
	 * the alpha property. Defaults to `false` (preservation).
	 * @since 4.5.0
	 */
	public var directAlpha:Bool = false;
	
	/**
	 * The maximum capacity of this group. Default is `0`, meaning no max capacity, and the group can just grow.
	 */
	public var maxSize(get, set):Int;
	
	/**
	 * Optimization to allow setting position of group without transforming children twice.
	 */
	var _skipTransformChildren:Bool = false;

	/**
	 * Array of all the `FlxSprite`s that exist in this group for
	 * optimization purposes / static typing on cpp targets.
	 */
	var _sprites:Array<FlxSprite>;
	
	/**
	 * @param   X         The initial X position of the group.
	 * @param   Y         The initial Y position of the group.
	 * @param   MaxSize   Maximum amount of members allowed.
	 */
	public function new(X:Float = 0, Y:Float = 0, MaxSize:Int = 0)
	{
		super(X, Y);
		group = new FlxTypedGroup<T>(MaxSize);
		_sprites = cast group.members;
	}
	
	/**
	 * This method is used for initialization of variables of complex types.
	 * Don't forget to call `super.initVars()` if you'll override this method,
	 * or you'll get `null` object error and app will crash.
	 */
	override function initVars():Void 
	{
		flixelType = SPRITEGROUP;
		
		offset = new FlxCallbackPoint(offsetCallback);
		origin = new FlxCallbackPoint(originCallback);
		scale = new FlxCallbackPoint(scaleCallback);
		scrollFactor = new FlxCallbackPoint(scrollFactorCallback);
		
		scale.set(1, 1);
		scrollFactor.set(1, 1);

		initMotionVars();
	}
	
	/**
	 * **WARNING:** A destroyed `FlxBasic` can't be used anymore.
	 * It may even cause crashes if it is still part of a group or state.
	 * You may want to use `kill()` instead if you want to disable the object temporarily only and `revive()` it later.
	 * 
	 * This function is usually not called manually (Flixel calls it automatically during state switches for all `add()`ed objects).
	 * 
	 * Override this function to `null` out variables manually or call `destroy()` on class members if necessary.
	 * Don't forget to call `super.destroy()`!
	 */
	override public function destroy():Void
	{
		// normally don't have to destroy FlxPoints, but these are FlxCallbackPoints!
		offset = FlxDestroyUtil.destroy(offset);
		origin = FlxDestroyUtil.destroy(origin);
		scale = FlxDestroyUtil.destroy(scale);
		scrollFactor = FlxDestroyUtil.destroy(scrollFactor);
		
		group = FlxDestroyUtil.destroy(group);
		_sprites = null;
		
		super.destroy();
	}
	
	/**
{'fraction_non_alphanumeric': 0.09881889763779528, 'fraction_numerical': 0.0034120734908136482, 'mean_word_length': 3.9487012987012986, 'pattern_counts': {'":': 0, '<': 15, '<?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': '2337582', 'n_tokens_mistral': 2474, 'n_tokens_neox': 2276, 'n_words': 805}