<commit_before>﻿using System.Diagnostics;
using Duality.Components;
using Duality.Components.Physics;
using Duality.Editor;
using Duality.Input;
using Duality.Plugins.Pathfindax.Components;
using Pathfindax.Nodes;
using Pathfindax.PathfindEngine;
using Pathfindax.Paths;
using Pathfindax.Utils;

namespace Duality.Plugins.Pathfindax.Examples.Components
{
	[EditorHintCategory(PathfindaxStrings.PathfindaxTest)]
	[RequiredComponent(typeof(RigidBody))]
	public class PotentialFieldFollowerComponent : Component, ICmpUpdatable, ICmpInitializable, IPathProvider
	{
		[EditorHintRange(0, float.MaxValue)]
		public float MovementSpeed { get; set; } = 1f;

		[EditorHintRange(1, byte.MaxValue)]
		public byte AgentSize { get; set; }

		public Camera Camera { get; set; }
		public DynamicPotentialFieldComponent DynamicPotentialFieldComponent { get; set; }
		public PotentialFieldPathfinderComponent PathfinderComponent { get; set; }
		public Vector2 CurrentPosition => new Vector2(GameObj.Transform.Pos.X, GameObj.Transform.Pos.Y);

		IPath IPathProvider.Path => _path;

		[DontSerialize]
		private IPath _path;

		[DontSerialize]
		private RigidBody _rigidBody;

		[DontSerialize]
		private PathfindaxCollisionCategory _collisionCategory;

		void ICmpInitializable.OnInit(InitContext context)
		{
			if (context == InitContext.Activate && DualityApp.ExecContext == DualityApp.ExecutionContext.Game)
			{
				DynamicPotentialFieldComponent.PotentialField.AddPotentialFunction(this,
					new QuadraticPotentialFunction(() => CurrentPosition, (float)AgentSize / 2 + 1.0f, 1.2f * AgentSize));
				_rigidBody = GameObj.GetComponent<RigidBody>();
				_collisionCategory = (PathfindaxCollisionCategory)_rigidBody.CollisionCategory;
				DualityApp.Mouse.ButtonDown += Mouse_ButtonDown;
			}
		}

		void ICmpInitializable.OnShutdown(ShutdownContext context)
		{
			DualityApp.Mouse.ButtonDown -= Mouse_ButtonDown;
			DynamicPotentialFieldComponent?.PotentialField?.RemovePotentialFunction(this);
		}

		void ICmpUpdatable.OnUpdate()
		{
			//if (_path != null)
			//{
			//	var heading = _path.GetHeading(GameObj.Transform.Pos);
			//	_rigidBody.ApplyWorldForce(heading * MovementSpeed);
			//}
		}

		private async void Mouse_ButtonDown(object sender, MouseButtonEventArgs e)
		{
			var targetPos = Camera.GetSpaceCoord(e.Position);
			var request = PathfinderComponent.Pathfinder.RequestPath(GameObj.Transform.Pos, targetPos, _collisionCategory, AgentSize);
			var completedPath = await request;
			switch (request.Status)
			{
				//case PathRequestStatus.Solved:
				//	_path = new AggregratedPotentialField(DynamicPotentialFieldComponent.PotentialField.GridTransformer, completedPath, DynamicPotentialFieldComponent.PotentialField);
				//	break;
				//case PathRequestStatus.NoPathFound:
				//	_path = new AggregratedPotentialField(DynamicPotentialFieldComponent.PotentialField.GridTransformer, DynamicPotentialFieldComponent.PotentialField);
				//	break;
				case PathRequestStatus.Solved:
					_path = completedPath;
					break;
				case PathRequestStatus.NoPathFound:
					_path = completedPath;
					break;
			}
		}
	}
}
<commit_msg>removed test code from potentialfield follower<commit_after>﻿using Duality.Components;
using Duality.Components.Physics;
using Duality.Editor;
using Duality.Input;
using Duality.Plugins.Pathfindax.Components;
using Pathfindax.Nodes;
using Pathfindax.PathfindEngine;
using Pathfindax.Paths;
using Pathfindax.Utils;

namespace Duality.Plugins.Pathfindax.Examples.Components
{
	[EditorHintCategory(PathfindaxStrings.PathfindaxTest)]
	[RequiredComponent(typeof(RigidBody))]
	public class PotentialFieldFollowerComponent : Component, ICmpUpdatable, ICmpInitializable, IPathProvider
	{
		[EditorHintRange(0, float.MaxValue)]
		public float MovementSpeed { get; set; } = 1f;

		[EditorHintRange(1, byte.MaxValue)]
		public byte AgentSize { get; set; }

		public Camera Camera { get; set; }
		public DynamicPotentialFieldComponent DynamicPotentialFieldComponent { get; set; }
		public PotentialFieldPathfinderComponent PathfinderComponent { get; set; }
		public Vector2 CurrentPosition => new Vector2(GameObj.Transform.Pos.X, GameObj.Transform.Pos.Y);

		IPath IPathProvider.Path => _path;

		[DontSerialize]
		private AggregratedPotentialField _path;

		[DontSerialize]
		private RigidBody _rigidBody;

		[DontSerialize]
		private PathfindaxCollisionCategory _collisionCategory;

		void ICmpInitializable.OnInit(InitContext context)
		{
			if (context == InitContext.Activate && DualityApp.ExecContext == DualityApp.ExecutionContext.Game)
			{
				DynamicPotentialFieldComponent.PotentialField.AddPotentialFunction(this,
					new QuadraticPotentialFunction(() => CurrentPosition, (float)AgentSize / 2 + 1.0f, 1.2f * AgentSize));
				_rigidBody = GameObj.GetComponent<RigidBody>();
				_collisionCategory = (PathfindaxCollisionCategory)_rigidBody.CollisionCategory;
				DualityApp.Mouse.ButtonDown += Mouse_ButtonDown;
			}
		}

		void ICmpInitializable.OnShutdown(ShutdownContext context)
		{
			DualityApp.Mouse.ButtonDown -= Mouse_ButtonDown;
			DynamicPotentialFieldComponent?.PotentialField?.RemovePotentialFunction(this);
		}

		void ICmpUpdatable.OnUpdate()
		{
			if (_path != null)
			{
				var heading = _path.GetHeading(GameObj.Transform.Pos);
				_rigidBody.ApplyWorldForce(heading * MovementSpeed);
			}
		}

		private async void Mouse_ButtonDown(object sender, MouseButtonEventArgs e)
		{
			var targetPos = Camera.GetSpaceCoord(e.Position);
			var request = PathfinderComponent.Pathfinder.RequestPath(GameObj.Transform.Pos, targetPos, _collisionCategory, AgentSize);
			var completedPath = await request;
			switch (request.Status)
			{
				case PathRequestStatus.Solved:
					_path = new AggregratedPotentialField(DynamicPotentialFieldComponent.PotentialField.GridTransformer, completedPath, DynamicPotentialFieldComponent.PotentialField);
					break;
				case PathRequestStatus.NoPathFound:
					_path = new AggregratedPotentialField(DynamicPotentialFieldComponent.PotentialField.GridTransformer, DynamicPotentialFieldComponent.PotentialField);
					break;
			}
		}
	}
}

{'fraction_non_alphanumeric': 0.08936170212765958, 'fraction_numerical': 0.0032733224222585926, 'mean_word_length': 5.385579937304075, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3441553', 'n_tokens_mistral': 2136, 'n_tokens_neox': 1819, 'n_words': 329}