<commit_before>using System;
using System.Collections.Generic;
using CocosSharp;
using Random = CocosSharp.CCRandom;

namespace tests
{
    public class ParticleTestScene : TestScene
    {
        #region eIDClick enum

        public enum eIDClick
        {
            IDC_NEXT = 100,
            IDC_BACK,
            IDC_RESTART,
            IDC_TOGGLE
        };

        #endregion

        internal static int TagLabelAtlas = 1;
        internal static int SceneIdx = -1;
        internal static int MAX_LAYER = 43;

        public static CCLayer CreateParticleLayer(int nIndex)
        {
            switch (nIndex)
            {
            case 0:
                return new ParticleReorder();
            case 1:
                return new ParticleBatchHybrid();
            case 2:
                return new ParticleBatchMultipleEmitters();
            case 3:
                return new DemoFlower();
            case 4:
                return new DemoGalaxy();
            case 5:
                return new DemoFirework();
            case 6:
                return new DemoSpiral();
            case 7:
                return new DemoSun();
            case 8:
                return new DemoMeteor();
            case 9:
                return new DemoFire();
            case 10:
                return new DemoSmoke();
            case 11:
                return new DemoExplosion();
            case 12:
                return new DemoSnow();
            case 13:
                return new DemoRain();
            case 14:
                return new DemoBigFlower();
            case 15:
                return new DemoRotFlower();
            case 16:
                return new DemoModernArt();
            case 17:
                return new DemoRing();
            case 18:
                return new ParallaxParticle();
            case 19:
                return new DemoParticleFromFile("BoilingFoam");
            case 20:
                return new DemoParticleFromFile("BurstPipe");
            case 21:
                return new DemoParticleFromFile("Comet");
            case 22:
                return new DemoParticleFromFile("debian");
            case 23:
                return new DemoParticleFromFile("ExplodingRing");
            case 24:
                return new DemoParticleFromFile("LavaFlow");
            case 25:
                return new DemoParticleFromFile("SpinningPeas");
            case 26:
                return new DemoParticleFromFile("SpookyPeas");
            case 27:
                return new DemoParticleFromFile("Upsidedown");
            case 28:
                return new DemoParticleFromFile("Flower");
            case 29:
                return new DemoParticleFromFile("Spiral");
            case 30:
                return new DemoParticleFromFile("Galaxy");
            case 31:
                return new DemoParticleFromFile("Phoenix");
            case 32:
                return new RadiusMode1();
            case 33:
                return new RadiusMode2();
            case 34:
                return new Issue704();
            case 35:
                return new Issue870();
            case 36:
                return new Issue1201();
                // v1.1 tests
            case 37:
                return new MultipleParticleSystems();
            case 38:
                return new MultipleParticleSystemsBatched();
            case 39:
                return new AddAndDeleteParticleSystems();
            case 40:
                return new ReorderParticleSystems();
            case 41:
                return new PremultipliedAlphaTest();
            case 42:
                return new PremultipliedAlphaTest2();
            }

            return null;
        }

        public static CCLayer NextParticleAction()
        {
            SceneIdx++;
            SceneIdx = SceneIdx % MAX_LAYER;

            CCLayer layer = CreateParticleLayer(SceneIdx);

            return layer;
        }

        public static CCLayer BackParticleAction()
        {
            SceneIdx--;
            int total = MAX_LAYER;
            if (SceneIdx < 0)
                SceneIdx += total;

            CCLayer layer = CreateParticleLayer(SceneIdx);

            return layer;
        }

        public static CCLayer RestartParticleAction()
        {
            CCLayer layer = CreateParticleLayer(SceneIdx);

            return layer;
        }

        protected override void NextTestCase()
        {
            NextParticleAction();
        }
        protected override void PreviousTestCase()
        {
            BackParticleAction();
        }
        protected override void RestTestCase()
        {
            RestartParticleAction();
        }

        public override void runThisTest()
        {
            AddChild(NextParticleAction());

            Director.ReplaceScene(this);
        }
    };

	public class ParticleDemo : TestNavigationLayer
    {
        const int labelTag = 9000;

        protected CCPoint MidWindowPoint;
        protected CCParticleSystem Emitter;
        protected CCSprite Background;

        CCLabelAtlas particleCounter;

        CCMenu particleMenu;
        CCMenuItemToggle toggleParticleMovMenuItem;

        #region Constructors

        public ParticleDemo()
        {

            toggleParticleMovMenuItem = new CCMenuItemToggle(ToggleCallback,
                new CCMenuItemFont("Free Movement"),
                new CCMenuItemFont("Relative Movement"),
                new CCMenuItemFont("Grouped Movement"));

            particleMenu = new CCMenu(toggleParticleMovMenuItem);
            AddChild(particleMenu, 100);

            particleCounter = new CCLabelAtlas("0000", "Images/fps_Images", 16, 64, '.');
            AddChild(particleCounter, 100, ParticleTestScene.TagLabelAtlas);

            Background = new CCSprite(TestResource.s_back3);
            AddChild(Background, 5);

			// Add event listeners

			var listener = new CCEventListenerTouchAllAtOnce();
			listener.OnTouchesBegan = OnTouchesBegan;
			listener.OnTouchesMoved = OnTouchesMoved;
			listener.OnTouchesEnded = OnTouchesEnded;

			AddEventListener(listener);

            Color = new CCColor3B(127, 127, 127);
            Opacity = 255;
        }

        #endregion Constructors


        #region Setup content


		static CCMoveBy move = new CCMoveBy (4, new CCPoint(300, 0));
		static CCFiniteTimeAction move_back = move.Reverse();

        protected override void AddedToScene()
        {
            base.AddedToScene();

            var windowSize = VisibleBoundsWorldspace.Size;

			MidWindowPoint = windowSize.Center;

            // Laying out content based on window size

			particleMenu.Position = CCPoint.Zero;
            toggleParticleMovMenuItem.Position = new CCPoint(10, 100);
			toggleParticleMovMenuItem.AnchorPoint = CCPoint.AnchorLowerLeft;

            particleCounter.Position = new CCPoint(windowSize.Width - 70, 50);

			// Background could have been removed by overriding class
			if (Background != null)
			{
                Background.Position = windowSize.Center;//      new CCPoint(windowSize.Width / 2, windowSize.Height - 180);

				// Run background animation
				Background.RepeatForever(move, move_back);
			}


            Schedule(Step);

        }

        #endregion Setup content

        #region Titles

        public override string Title
		{
			get
			{
				return base.Title;
			}
		}

		public override string Subtitle
		{
			get
			{
				return base.Subtitle;
			}
		}

        #endregion Titles


        #region Callbacks

		public override void RestartCallback(object sender)
        {
            if (Emitter != null)
            {
                Emitter.ResetSystem();
            }
        }

		public override void NextCallback(object sender)
        {
            var s = new ParticleTestScene();
            s.AddChild(ParticleTestScene.NextParticleAction());

            Director.ReplaceScene(s);
        }

		public override void BackCallback(object sender)
        {
            var s = new ParticleTestScene();
            s.AddChild(ParticleTestScene.BackParticleAction());

            Director.ReplaceScene(s);
        }

        void ToggleCallback(object sender)
        {
            if (Emitter != null)
            {
                if (Emitter.PositionType == CCPositionType.Grouped)
                    Emitter.PositionType = CCPositionType.Free;
                else if (Emitter.PositionType == CCPositionType.Free)
                    Emitter.PositionType = CCPositionType.Relative;
                else if (Emitter.PositionType == CCPositionType.Relative)
                    Emitter.PositionType = CCPositionType.Grouped;
            }
        }

        #endregion Callbacks


        #region Event handling

        void OnTouchesBegan(List<CCTouch> touches, CCEvent touchEvent)
        {
            OnTouchesEnded(touches, touchEvent);
        }

        void OnTouchesMoved(List<CCTouch> touches, CCEvent touchEvent)
        {
            OnTouchesEnded(touches, touchEvent);
        }

        void OnTouchesEnded(List<CCTouch> touches, CCEvent touchEvent)
        {
            var touch = touches [0];
            var convertedLocation = touch.LocationOnScreen;
            convertedLocation = ScreenToWorldspace(convertedLocation);

            var pos = CCPoint.Zero;
            if (Background != null)
            {
                pos = Background.ConvertToWorldspace(pos);
            }

            if (Emitter != null)
            {<commit_msg>Modified to use CCTouch.Location and not CCTouch.LocationOnScreen<commit_after>using System;
using System.Collections.Generic;
using CocosSharp;
using Random = CocosSharp.CCRandom;

namespace tests
{
    public class ParticleTestScene : TestScene
    {
        #region eIDClick enum

        public enum eIDClick
        {
            IDC_NEXT = 100,
            IDC_BACK,
            IDC_RESTART,
            IDC_TOGGLE
        };

        #endregion

        internal static int TagLabelAtlas = 1;
        internal static int SceneIdx = -1;
        internal static int MAX_LAYER = 43;

        public static CCLayer CreateParticleLayer(int nIndex)
        {
            switch (nIndex)
            {
            case 0:
                return new ParticleReorder();
            case 1:
                return new ParticleBatchHybrid();
            case 2:
                return new ParticleBatchMultipleEmitters();
            case 3:
                return new DemoFlower();
            case 4:
                return new DemoGalaxy();
            case 5:
                return new DemoFirework();
            case 6:
                return new DemoSpiral();
            case 7:
                return new DemoSun();
            case 8:
                return new DemoMeteor();
            case 9:
                return new DemoFire();
            case 10:
                return new DemoSmoke();
            case 11:
                return new DemoExplosion();
            case 12:
                return new DemoSnow();
            case 13:
                return new DemoRain();
            case 14:
                return new DemoBigFlower();
            case 15:
                return new DemoRotFlower();
            case 16:
                return new DemoModernArt();
            case 17:
                return new DemoRing();
            case 18:
                return new ParallaxParticle();
            case 19:
                return new DemoParticleFromFile("BoilingFoam");
            case 20:
                return new DemoParticleFromFile("BurstPipe");
            case 21:
                return new DemoParticleFromFile("Comet");
            case 22:
                return new DemoParticleFromFile("debian");
            case 23:
                return new DemoParticleFromFile("ExplodingRing");
            case 24:
                return new DemoParticleFromFile("LavaFlow");
            case 25:
                return new DemoParticleFromFile("SpinningPeas");
            case 26:
                return new DemoParticleFromFile("SpookyPeas");
            case 27:
                return new DemoParticleFromFile("Upsidedown");
            case 28:
                return new DemoParticleFromFile("Flower");
            case 29:
                return new DemoParticleFromFile("Spiral");
            case 30:
                return new DemoParticleFromFile("Galaxy");
            case 31:
                return new DemoParticleFromFile("Phoenix");
            case 32:
                return new RadiusMode1();
            case 33:
                return new RadiusMode2();
            case 34:
                return new Issue704();
            case 35:
                return new Issue870();
            case 36:
                return new Issue1201();
                // v1.1 tests
            case 37:
                return new MultipleParticleSystems();
            case 38:
                return new MultipleParticleSystemsBatched();
            case 39:
                return new AddAndDeleteParticleSystems();
            case 40:
                return new ReorderParticleSystems();
            case 41:
                return new PremultipliedAlphaTest();
            case 42:
                return new PremultipliedAlphaTest2();
            }

            return null;
        }

        public static CCLayer NextParticleAction()
        {
            SceneIdx++;
            SceneIdx = SceneIdx % MAX_LAYER;

            CCLayer layer = CreateParticleLayer(SceneIdx);

            return layer;
        }

        public static CCLayer BackParticleAction()
        {
            SceneIdx--;
            int total = MAX_LAYER;
            if (SceneIdx < 0)
                SceneIdx += total;

            CCLayer layer = CreateParticleLayer(SceneIdx);

            return layer;
        }

        public static CCLayer RestartParticleAction()
        {
            CCLayer layer = CreateParticleLayer(SceneIdx);

            return layer;
        }

        protected override void NextTestCase()
        {
            NextParticleAction();
        }
        protected override void PreviousTestCase()
        {
            BackParticleAction();
        }
        protected override void RestTestCase()
        {
            RestartParticleAction();
        }

        public override void runThisTest()
        {
            AddChild(NextParticleAction());

            Director.ReplaceScene(this);
        }
    };

	public class ParticleDemo : TestNavigationLayer
    {
        const int labelTag = 9000;

        protected CCPoint MidWindowPoint;
        protected CCParticleSystem Emitter;
        protected CCSprite Background;

        CCLabelAtlas particleCounter;

        CCMenu particleMenu;
        CCMenuItemToggle toggleParticleMovMenuItem;

        #region Constructors

        public ParticleDemo()
        {

            toggleParticleMovMenuItem = new CCMenuItemToggle(ToggleCallback,
                new CCMenuItemFont("Free Movement"),
                new CCMenuItemFont("Relative Movement"),
                new CCMenuItemFont("Grouped Movement"));

            particleMenu = new CCMenu(toggleParticleMovMenuItem);
            AddChild(particleMenu, 100);

            particleCounter = new CCLabelAtlas("0000", "Images/fps_Images", 16, 64, '.');
            AddChild(particleCounter, 100, ParticleTestScene.TagLabelAtlas);

            Background = new CCSprite(TestResource.s_back3);
            AddChild(Background, 5);

			// Add event listeners

			var listener = new CCEventListenerTouchAllAtOnce();
			listener.OnTouchesBegan = OnTouchesBegan;
			listener.OnTouchesMoved = OnTouchesMoved;
			listener.OnTouchesEnded = OnTouchesEnded;

			AddEventListener(listener);

            Color = new CCColor3B(127, 127, 127);
            Opacity = 255;
        }

        #endregion Constructors


        #region Setup content


		static CCMoveBy move = new CCMoveBy (4, new CCPoint(300, 0));
		static CCFiniteTimeAction move_back = move.Reverse();

        protected override void AddedToScene()
        {
            base.AddedToScene();

            var windowSize = VisibleBoundsWorldspace.Size;

			MidWindowPoint = windowSize.Center;

            // Laying out content based on window size

			particleMenu.Position = CCPoint.Zero;
            toggleParticleMovMenuItem.Position = new CCPoint(10, 100);
			toggleParticleMovMenuItem.AnchorPoint = CCPoint.AnchorLowerLeft;

            particleCounter.Position = new CCPoint(windowSize.Width - 70, 50);

			// Background could have been removed by overriding class
			if (Background != null)
			{
                Background.Position = windowSize.Center;//      new CCPoint(windowSize.Width / 2, windowSize.Height - 180);

				// Run background animation
				Background.RepeatForever(move, move_back);
			}


            Schedule(Step);

        }

        #endregion Setup content

        #region Titles

        public override string Title
		{
			get
			{
				return base.Title;
			}
		}

		public override string Subtitle
		{
			get
			{
				return base.Subtitle;
			}
		}

        #endregion Titles


        #region Callbacks

		public override void RestartCallback(object sender)
        {
            if (Emitter != null)
            {
                Emitter.ResetSystem();
            }
        }

		public override void NextCallback(object sender)
        {
            var s = new ParticleTestScene();
            s.AddChild(ParticleTestScene.NextParticleAction());

            Director.ReplaceScene(s);
        }

		public override void BackCallback(object sender)
        {
            var s = new ParticleTestScene();
            s.AddChild(ParticleTestScene.BackParticleAction());

            Director.ReplaceScene(s);
        }

        void ToggleCallback(object sender)
        {
            if (Emitter != null)
            {
                if (Emitter.PositionType == CCPositionType.Grouped)
                    Emitter.PositionType = CCPositionType.Free;
                else if (Emitter.PositionType == CCPositionType.Free)
                    Emitter.PositionType = CCPositionType.Relative;
                else if (Emitter.PositionType == CCPositionType.Relative)
                    Emitter.PositionType = CCPositionType.Grouped;
            }
        }

        #endregion Callbacks


        #region Event handling

        void OnTouchesBegan(List<CCTouch> touches, CCEvent touchEvent)
        {
            OnTouchesEnded(touches, touchEvent);
        }

        void OnTouchesMoved(List<CCTouch> touches, CCEvent touchEvent)
        {
            OnTouchesEnded(touches, touchEvent);
        }

        void OnTouchesEnded(List<CCTouch> touches, CCEvent touchEvent)
        {
            var touch = touches [0];
            var convertedLocation = touch.Location;

            var pos = CCPoint.Zero;
            if (Background != null)
            {
                pos = Background.ConvertToWorldspace(pos);
            }

            if (Emitter != null)
            {
{'fraction_non_alphanumeric': 0.07028753993610223, 'fraction_numerical': 0.015817315246425392, 'mean_word_length': 1.5595174262734584, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '527064', 'n_tokens_mistral': 5397, 'n_tokens_neox': 4715, 'n_words': 1206}