<commit_before>
using UnityEngine;
using System.Collections.Generic;
using System.Linq;

namespace ME {

	public class Tweener: MonoBehaviour {

		public interface ITransition {

			float interpolate(float start, float distance, float elapsedTime, float duration);

		}
	
		public interface ITween {

			bool isCompleted();
			void RaiseCancel();
			void RaiseComplete();
			object getTag();
			void update(float dt, bool debug);
			bool isDirty { get; set; }

		}
		
		public enum TimerType {
			Fixed,
			Game,
		}

		public class Tween<T>: ITween {

			public bool isDirty {
				get;
				set;
			}

			private static int INFINITE_LOOPS = -1;
			private T _obj;
			private float _duration;
			private float _start;
			
			private class Target {
				public float start;
				public float value;
				public float duration;
				public ITransition transition;
				public bool inverse = false;
			}
			
			private List<Target> _targets = new List<Target>();
			int _currentTarget = 0;
			private float _elapsed = 0.0f;
			private bool _completed = false;
			private object _tag;
			private int _loops = 1;
			private System.Action<T, float> _update = null;
			private System.Action<T> _complete = null;
			private System.Action<T> _cancel = null;
	
			public Tween(T obj, float duration, float start, float end) {
				_obj = obj;
				Target target = new Target();
				target.start = start;
				target.value = end;
				target.duration = duration;
				target.transition = Ease.Linear;
				
				_completed = false;
				
				_targets.Add(target);

				isDirty = false;
			}
			
			public void RaiseComplete() {
				
				if (_complete != null)
					_complete(_obj);
				
			}
			
			public void RaiseCancel() {
				
				if (_cancel != null)
					_cancel(_obj);
				
			}
	
			public bool isCompleted() {
				return _completed;
			}
	
			public object getTag() {
				return _tag;
			}
			
			public void update(float dt, bool debug = false) {
				_elapsed += dt;
				
				var target = _targets[_currentTarget];
				//if (debug == true) Debug.Log(_currentTarget + " " + _elapsed + " " + target.duration);
				
				if (_elapsed >= target.duration) {
					if ((_currentTarget + 1) == _targets.Count) {
						if (_update != null)
							_update(_obj, target.inverse ? target.start : target.value);
						
						if (_loops != INFINITE_LOOPS) {
							
							_completed = (--_loops == 0);
							
						}
						
						if (!_completed) {
							
							_elapsed = 0f;
							_currentTarget = 0;
							
						}
						
						if (_loops == INFINITE_LOOPS || _loops == 0) {
							
							RaiseComplete();
							
						}
						
						return;
					}
	
					_elapsed = _elapsed - target.duration;
					target = _targets[++_currentTarget];
				}
	
				if (_update != null) {
					float t = target.inverse ? target.duration - _elapsed : _elapsed;
					float v = target.transition.interpolate(target.start, target.value - target.start, t, target.duration);
					_update(_obj, v);
				}
	
				return;
			}
	
			public Tween<T> ease(ITransition value) {
				_targets[0].transition = value;
	
				return this;
			}
	
			public Tween<T> onUpdate(System.Action<T, float> func) {
				_update += func;
				return this;
			}
			
			public Tween<T> onComplete(System.Action<T> func) {
				_complete += func;
				return this;
			}

			public Tween<T> onComplete(System.Action func) {
				_complete += self => func();
				return this;
			}
			
			public Tween<T> onCancel(System.Action<T> func) {
				_cancel += func;
				return this;
			}
	
			public Tween<T> tag(object value) {
				_tag = value;
				return this;
			}
	
			public Tween<T> repeat() {
				_loops = INFINITE_LOOPS;
				return this;
			}
	
			public Tween<T> repeat(int loops) {
				
				_loops = loops;
				return this;
				
			}
	
			public Tween<T> addTarget(float duration, float end) {
				
				var target = new Target();
				target.start = _targets[_targets.Count - 1].value;
				target.value = end;
				target.duration = duration;
				target.transition = _targets[0].transition;
				_targets.Add(target);
				
				return this;
				
			}<commit_msg>version 0.9.6a - Tweener setValue added<commit_after>
using UnityEngine;
using System.Collections.Generic;
using System.Linq;

namespace ME {

	public class Tweener: MonoBehaviour {

		public interface ITransition {

			float interpolate(float start, float distance, float elapsedTime, float duration);

		}
	
		public interface ITween {

			bool isCompleted();
			void RaiseCancel();
			void RaiseComplete();
			object getTag();
			void update(float dt, bool debug);
			bool isDirty { get; set; }

		}
		
		public enum TimerType {
			Fixed,
			Game,
		}

		public class Tween<T>: ITween {

			public bool isDirty {
				get;
				set;
			}

			private static int INFINITE_LOOPS = -1;
			private T _obj;
			private float _start;
			
			private class Target {
				public float start;
				public float value;
				public float duration;
				public ITransition transition;
				public bool inverse = false;
			}
			
			private List<Target> _targets = new List<Target>();
			int _currentTarget = 0;
			private float _elapsed = 0.0f;
			private bool _completed = false;
			private object _tag;
			private int _loops = 1;
			private System.Action<T, float> _update = null;
			private System.Action<T> _complete = null;
			private System.Action<T> _cancel = null;
	
			public Tween(T obj, float duration, float start, float end) {
				_obj = obj;
				Target target = new Target();
				target.start = start;
				target.value = end;
				target.duration = duration;
				target.transition = Ease.Linear;
				
				_completed = false;
				
				_targets.Add(target);

				isDirty = false;
			}
			
			public void RaiseComplete() {
				
				if (_complete != null)
					_complete(_obj);
				
			}
			
			public void RaiseCancel() {
				
				if (_cancel != null)
					_cancel(_obj);
				
			}
	
			public bool isCompleted() {
				return _completed;
			}
	
			public object getTag() {
				return _tag;
			}
			
			public void update(float dt, bool debug = false) {
				_elapsed += dt;
				
				var target = _targets[_currentTarget];
				//if (debug == true) Debug.Log(_currentTarget + " " + _elapsed + " " + target.duration);
				
				if (_elapsed >= target.duration) {
					if ((_currentTarget + 1) == _targets.Count) {
						if (_update != null)
							_update(_obj, target.inverse ? target.start : target.value);
						
						if (_loops != INFINITE_LOOPS) {
							
							_completed = (--_loops == 0);
							
						}
						
						if (!_completed) {
							
							_elapsed = 0f;
							_currentTarget = 0;
							
						}
						
						if (_loops == INFINITE_LOOPS || _loops == 0) {
							
							RaiseComplete();
							
						}
						
						return;
					}
	
					_elapsed = _elapsed - target.duration;
					target = _targets[++_currentTarget];
				}
	
				if (_update != null) {
					float t = target.inverse ? target.duration - _elapsed : _elapsed;
					float v = target.transition.interpolate(target.start, target.value - target.start, t, target.duration);
					_update(_obj, v);
				}
	
				return;
			}
	
			public Tween<T> ease(ITransition value) {

                _targets[_targets.Count - 1].transition = value;
	
				return this;

			}
	
			public Tween<T> onUpdate(System.Action<T, float> func) {
				_update += func;
				return this;
			}
			
			public Tween<T> onComplete(System.Action<T> func) {
				_complete += func;
				return this;
			}

			public Tween<T> onComplete(System.Action func) {
				_complete += self => func();
				return this;
			}
			
			public Tween<T> onCancel(System.Action<T> func) {
				_cancel += func;
				return this;
			}
	
			public Tween<T> tag(object value) {
				_tag = value;
				return this;
			}
	
			public Tween<T> repeat() {
				_loops = INFINITE_LOOPS;
				return this;
			}
	
			public Tween<T> repeat(int loops) {
				
				_loops = loops;
				return this;
				
			}

            public Tween<T> setValue(float value) {

                _elapsed = value * _targets[_targets.Count - 1].duration;

                return this;

            }
	
			public Tween<T> addTarget(float duration, float end) {
				
				var target = new Target();
				target.start = _targets[_targets.Count - 1].value;
				target.value = end;
				target.duration = duration;
				target.transition = _targets[0].transition;
				_targets.Add(target);
				
				return this;
				
			}
{'fraction_non_alphanumeric': 0.1070916905444126, 'fraction_numerical': 0.0035816618911174787, 'mean_word_length': 2.230620902429618, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 44, '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': '129062', 'n_tokens_mistral': 3771, 'n_tokens_neox': 2603, 'n_words': 696}