<commit_before>package haxepunk.graphics;

import flash.geom.Point;
import haxepunk.HXP;
import haxepunk.Graphic;

/**
 * A Graphic that can contain multiple Graphics of one or various types.
 * Useful for drawing sprites with multiple different parts, etc.
 */
class Graphiclist extends Graphic
{
	/**
	 * Constructor.
	 * @param	graphic		Graphic objects to add to the list.
	 */
	public function new(?graphic:Array<Graphic>)
	{
		_graphics = new Array<Graphic>();
		_temp = new Array<Graphic>();
		_camera = new Camera();

		super();

		if (graphic != null)
		{
			for (g in graphic) add(g);
		}
	}

	/** @private Updates the graphics in the list. */
	@:dox(hide)
	override public function update()
	{
		for (g in _graphics)
		{
			if (g.active) g.update();
		}
	}

	/**
	 * Returns the Graphic from the list.
	 * @param	i	The index of the array.
	 * @return	The graphic in n index.
	 */
	@:arrayAccess
	public function get(i:Int):Graphic
	{
		if ( i >= _graphics.length || i < 0 ) throw "Index out of bounds.";
		else return _graphics[i];
	}

	/** @private Renders the Graphics in the list. */
	override public function render(layer:Int, point:Point, camera:Camera)
	{
		for (g in _graphics)
		{
			if (g.visible)
			{
				if (g.relative)
				{
					_point.x = point.x + x;
					_point.y = point.y + y;
				}
				else _point.x = _point.y = 0;
				_camera.setTo(camera.x * scrollX, camera.y * scrollY);
				g.render(layer, _point, _camera);
			}
		}
	}

	/**
	 * Destroys the list of graphics
	 */
	override public function destroy()
	{
		for (g in _graphics)
		{
			g.destroy();
		}
	}

	/**
	 * Adds the Graphic to the list.
	 * @param	graphic		The Graphic to add.
	 * @return	The added Graphic.
	 */
	public function add(graphic:Graphic):Graphic
	{
		if (graphic == null) return graphic;

		_graphics[count++] = graphic;
		if (!active) active = graphic.active;
		return graphic;
	}

	/**
	 * Removes the Graphic from the list.
	 * @param	graphic		The Graphic to remove.
	 * @return	The removed Graphic.
	 */
	public function remove(graphic:Graphic):Graphic
	{
		if (HXP.indexOf(_graphics, graphic) < 0) return graphic;
		HXP.clear(_temp);

		for (g in _graphics)
		{
			if (g == graphic) count--;
			else _temp[_temp.length] = g;
		}
		var temp:Array<Graphic> = _graphics;
		_graphics = _temp;
		_temp = temp;
		updateCheck();
		return graphic;
	}

	/**
	 * Removes the Graphic from the position in the list.
	 * @param	index		Index to remove.
	 */
	public function removeAt(index:Int = 0)
	{
		if (_graphics.length == 0) return;
		index %= _graphics.length;
		remove(_graphics[index % _graphics.length]);
		updateCheck();
	}

	/**
	 * Removes all Graphics from the list.
	 */
	public function removeAll()
	{
		HXP.clear(_graphics);
		HXP.clear(_temp);
		count = 0;
		active = false;
	}

	/**
	 * All Graphics in this list.
	 */
	public var children(get, null):Array<Graphic>;
	function get_children():Array<Graphic> return _graphics;

	/**
	 * Amount of Graphics in this list.
	 */
	public var count(default, null):Int = 0;

	/**
	 * Check if the Graphiclist should update.
	 */
	function updateCheck()
	{
		active = false;
		for (g in _graphics)
		{
			if (g.active)
			{
				active = true;
				return;
			}
		}
	}

	// List information.
	var _graphics:Array<Graphic>;
	var _temp:Array<Graphic>;
	var _camera:Camera;
}
<commit_msg>Graphiclist alpha and color should propagate to children.<commit_after>package haxepunk.graphics;

import flash.geom.Point;
import haxepunk.HXP;
import haxepunk.Graphic;
import haxepunk.utils.Color;

/**
 * A Graphic that can contain multiple Graphics of one or various types.
 * Useful for drawing sprites with multiple different parts, etc.
 */
class Graphiclist extends Graphic
{
	override function set_alpha(v:Float):Float
	{
		for (graphic in _graphics)
		{
			graphic.alpha = v;
		}
		return super.set_alpha(v);
	}

	override function set_color(v:Color):Color
	{
		for (graphic in _graphics)
		{
			graphic.color = v;
		}
		return super.set_color(v);
	}

	/**
	 * Constructor.
	 * @param	graphic		Graphic objects to add to the list.
	 */
	public function new(?graphic:Array<Graphic>)
	{
		_graphics = new Array<Graphic>();
		_temp = new Array<Graphic>();
		_camera = new Camera();

		super();

		if (graphic != null)
		{
			for (g in graphic) add(g);
		}
	}

	/** @private Updates the graphics in the list. */
	@:dox(hide)
	override public function update()
	{
		for (g in _graphics)
		{
			if (g.active) g.update();
		}
	}

	/**
	 * Returns the Graphic from the list.
	 * @param	i	The index of the array.
	 * @return	The graphic in n index.
	 */
	@:arrayAccess
	public function get(i:Int):Graphic
	{
		if ( i >= _graphics.length || i < 0 ) throw "Index out of bounds.";
		else return _graphics[i];
	}

	/** @private Renders the Graphics in the list. */
	override public function render(layer:Int, point:Point, camera:Camera)
	{
		for (g in _graphics)
		{
			if (g.visible)
			{
				if (g.relative)
				{
					_point.x = point.x + x;
					_point.y = point.y + y;
				}
				else _point.x = _point.y = 0;
				_camera.setTo(camera.x * scrollX, camera.y * scrollY);
				g.render(layer, _point, _camera);
			}
		}
	}

	/**
	 * Destroys the list of graphics
	 */
	override public function destroy()
	{
		for (g in _graphics)
		{
			g.destroy();
		}
	}

	/**
	 * Adds the Graphic to the list.
	 * @param	graphic		The Graphic to add.
	 * @return	The added Graphic.
	 */
	public function add(graphic:Graphic):Graphic
	{
		if (graphic == null) return graphic;

		_graphics[count++] = graphic;
		if (!active) active = graphic.active;
		return graphic;
	}

	/**
	 * Removes the Graphic from the list.
	 * @param	graphic		The Graphic to remove.
	 * @return	The removed Graphic.
	 */
	public function remove(graphic:Graphic):Graphic
	{
		if (HXP.indexOf(_graphics, graphic) < 0) return graphic;
		HXP.clear(_temp);

		for (g in _graphics)
		{
			if (g == graphic) count--;
			else _temp[_temp.length] = g;
		}
		var temp:Array<Graphic> = _graphics;
		_graphics = _temp;
		_temp = temp;
		updateCheck();
		return graphic;
	}

	/**
	 * Removes the Graphic from the position in the list.
	 * @param	index		Index to remove.
	 */
	public function removeAt(index:Int = 0)
	{
		if (_graphics.length == 0) return;
		index %= _graphics.length;
		remove(_graphics[index % _graphics.length]);
		updateCheck();
	}

	/**
	 * Removes all Graphics from the list.
	 */
	public function removeAll()
	{
		HXP.clear(_graphics);
		HXP.clear(_temp);
		count = 0;
		active = false;
	}

	/**
	 * All Graphics in this list.
	 */
	public var children(get, null):Array<Graphic>;
	function get_children():Array<Graphic> return _graphics;

	/**
	 * Amount of Graphics in this list.
	 */
	public var count(default, null):Int = 0;

	/**
	 * Check if the Graphiclist should update.
	 */
	function updateCheck()
	{
		active = false;
		for (g in _graphics)
		{
			if (g.active)
			{
				active = true;
				return;
			}
		}
	}

	// List information.
	var _graphics:Array<Graphic>;
	var _temp:Array<Graphic>;
	var _camera:Camera;
}

{'fraction_non_alphanumeric': 0.13035434751672123, 'fraction_numerical': 0.001992315355059058, 'mean_word_length': 2.977362761743067, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, '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': '499940', 'n_tokens_mistral': 2796, 'n_tokens_neox': 2458, 'n_words': 717}