<commit_before>using SpeedrunTimerMod.BeatTiming;
using UnityEngine;

namespace SpeedrunTimerMod
{
	class BeatTimerController : MonoBehaviour
	{
		public BeatTimer BeatTimer { get; set; }

		bool _firstLevelUpdate;
		bool _endSoundPlaying;
		bool _firstBeatAfterReset;

		void OnLevelWasLoaded(int level)
		{
			SubscribeGlobalBeatMaster();
			_firstLevelUpdate = true;
		}

		void Start()
		{
			SubscribeGlobalBeatMaster();
			_endSoundPlaying = TheEndSound.EndSoundPlaying() && Application.loadedLevelName == "Level_Menu";
		}

		void OnEnable()
		{
			if (Globals.beatMaster != null)
				SubscribeGlobalBeatMaster();
		}

		void OnDisable()
		{
			UnsubGlobalBeatMaster();
		}

		void UnsubGlobalBeatMaster()
		{
			Globals.beatMaster.onBeat -= OnGlobalBeat;
			Globals.beatMaster.onBeatReset -= OnGlobalBeatReset;
			Globals.beatMaster.globalBeatStarted -= OnGlobalBeatStarted;
		}

		void SubscribeGlobalBeatMaster()
		{
			UnsubGlobalBeatMaster();
			Globals.beatMaster.onBeat += OnGlobalBeat;
			Globals.beatMaster.onBeatReset += OnGlobalBeatReset;
			Globals.beatMaster.globalBeatStarted += OnGlobalBeatStarted;
		}

		void Update()
		{
			if (_firstLevelUpdate)
			{
				// this is when time starts counting down from the beat start offset
				_firstLevelUpdate = false;
				if (BeatTimer != null && BeatTimer.IsStarted)
				{
					BeatTimer.AddTime((int)BeatTimer.GetInterpolation());
					BeatTimer.ResetInterpolation();
				}
			}
		}

		void OnGlobalBeatStarted()
		{
			Debug.Log("GlobalBeatStarted: " + DebugBeatListener.DebugStr);
			if (BeatTimer == null || !BeatTimer.IsStarted)
				return;

			// we know the beat starts 1 second after level load
			// except when end sound is playing
			// see GlobalBeatMaster.startTime
			var beatStartTime = !_endSoundPlaying ? 1000 : 3000;

			BeatTimer.AddTime(beatStartTime);
			BeatTimer.ResetInterpolation();
			SpeedrunTimer.Instance.EndLoad(beatStartTime * -1);
		}

		void OnGlobalBeatReset()
		{
			_firstBeatAfterReset = true;
		}

		void OnGlobalBeat(int index)
		{
			if (!_firstBeatAfterReset)
				BeatTimer?.OnQuarterBeat();
			else
				_firstBeatAfterReset = false;
		}
	}
}
<commit_msg>add time in between beat resets<commit_after>using SpeedrunTimerMod.BeatTiming;
using UnityEngine;

namespace SpeedrunTimerMod
{
	class BeatTimerController : MonoBehaviour
	{
		public BeatTimer BeatTimer { get; set; }

		bool _firstLevelUpdate;
		bool _endSoundPlaying;
		bool _firstBeatAfterReset;

		void OnLevelWasLoaded(int level)
		{
			SubscribeGlobalBeatMaster();
			_firstLevelUpdate = true;
		}

		void Start()
		{
			SubscribeGlobalBeatMaster();
			_endSoundPlaying = TheEndSound.EndSoundPlaying() && Application.loadedLevelName == "Level_Menu";
		}

		void OnEnable()
		{
			if (Globals.beatMaster != null)
				SubscribeGlobalBeatMaster();
		}

		void OnDisable()
		{
			UnsubGlobalBeatMaster();
		}

		void UnsubGlobalBeatMaster()
		{
			Globals.beatMaster.onBeat -= OnGlobalBeat;
			Globals.beatMaster.onBeatReset -= OnGlobalBeatReset;
			Globals.beatMaster.globalBeatStarted -= OnGlobalBeatStarted;
		}

		void SubscribeGlobalBeatMaster()
		{
			UnsubGlobalBeatMaster();
			Globals.beatMaster.onBeat += OnGlobalBeat;
			Globals.beatMaster.onBeatReset += OnGlobalBeatReset;
			Globals.beatMaster.globalBeatStarted += OnGlobalBeatStarted;
		}

		void Update()
		{
			if (_firstLevelUpdate)
			{
				// this is when time starts counting down from the beat start offset
				_firstLevelUpdate = false;
				if (BeatTimer != null && BeatTimer.IsStarted)
				{
					var interpolation = BeatTimer.GetInterpolation();
					BeatTimer.AddTime((int)interpolation);
					BeatTimer.ResetInterpolation();

					Debug.Log($"First level update: added {interpolation}ms to timer \n"
						+ DebugBeatListener.DebugStr);
				}
			}
		}

		void OnGlobalBeatStarted()
		{
			if (BeatTimer == null || !BeatTimer.IsStarted)
				return;

			// we know the beat starts 1 second after level load
			// except when end sound is playing
			// see GlobalBeatMaster.startTime
			var beatStartTime = !_endSoundPlaying ? 1000 : 3000;

			BeatTimer.AddTime(beatStartTime);
			BeatTimer.ResetInterpolation();
			SpeedrunTimer.Instance.EndLoad(beatStartTime * -1);

			Debug.Log($"GlobalBeatStarted: added {beatStartTime}ms to timer\n"
				+ DebugBeatListener.DebugStr);
		}

		void OnGlobalBeatReset()
		{
			_firstBeatAfterReset = true;
		}

		void OnGlobalBeat(int index)
		{
			if (!_firstBeatAfterReset)
				BeatTimer?.OnQuarterBeat();
			else
			{
				_firstBeatAfterReset = false;
				var time = Mathf.RoundToInt((Time.time - DebugBeatListener.LastBeatTimestamp) * 1000);
				BeatTimer?.AddRealTime(time);
				Debug.Log($"First beat after reset: adding {time}ms to real time\n" + DebugBeatListener.DebugStr);
			}
		}
	}
}

{'fraction_non_alphanumeric': 0.09815436241610738, 'fraction_numerical': 0.0050335570469798654, 'mean_word_length': 3.8123107971745713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3309223', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1501, 'n_words': 301}