<commit_before>﻿using System;
using Duality;
using Duality.Input;

namespace MFEP.Duality.Plugins.InputPlugin
{
	public enum KeyType
	{
		KeyboardType = 0,
		MouseButtonType = 1
	}

	public struct KeyValue
	{
		private const int mouseButtonOffset = 1000;
		private readonly int storeField;

		public KeyValue (Key key)
		{
			storeField = (int)key;
		}

		public KeyValue (MouseButton mouseButton)
		{
			storeField = (int)mouseButton + mouseButtonOffset;
		}

		public KeyType KeyType => storeField < mouseButtonOffset ? KeyType.KeyboardType : KeyType.MouseButtonType;

		public override bool Equals (object obj)
		{
			if (obj is KeyValue)
				return storeField == ((KeyValue)obj).storeField;
			return false;
		}

		public override int GetHashCode ()
		{
			return storeField;
		}

		public Key Key
		{
			get
			{
				if (KeyType != KeyType.KeyboardType) throw new InvalidCastException ();
				return (Key)storeField;
			}
		}

		public MouseButton MouseButton
		{
			get
			{
				if (KeyType != KeyType.MouseButtonType) throw new InvalidCastException ();
				return (MouseButton)(storeField - mouseButtonOffset);
			}
		}

		public int Index
		{
			get
			{
				switch (KeyType) {
					case KeyType.KeyboardType:
						return storeField;
					case KeyType.MouseButtonType:
						return storeField - mouseButtonOffset;
					default:
						throw new ArgumentOutOfRangeException ();
				}
			}
		}

		internal bool IsHit
		{
			get
			{
				switch (KeyType) {
					case KeyType.KeyboardType:
						return DualityApp.Keyboard.KeyHit (Key);
					case KeyType.MouseButtonType:
						return DualityApp.Mouse.ButtonHit (MouseButton);
					default:
						throw new ArgumentOutOfRangeException ();
				}
			}
		}

		internal bool IsPressed
		{
			get
			{
				switch (KeyType) {
					case KeyType.KeyboardType:
						return DualityApp.Keyboard.KeyPressed (Key);
					case KeyType.MouseButtonType:
						return DualityApp.Mouse.ButtonPressed (MouseButton);
					default:
						throw new ArgumentOutOfRangeException ();
				}
			}
		}

		internal bool IsReleased
		{
			get
			{
				switch (KeyType) {
					case KeyType.KeyboardType:
						return DualityApp.Keyboard.KeyReleased (Key);
					case KeyType.MouseButtonType:
						return DualityApp.Mouse.ButtonReleased (MouseButton);<commit_msg>Use cast operators in KeyValue instead of properties<commit_after>﻿using System;
using Duality;
using Duality.Input;

namespace MFEP.Duality.Plugins.InputPlugin
{
	public enum KeyType
	{
		KeyboardType = 0,
		MouseButtonType = 1
	}

	public struct KeyValue
	{
		private const int mouseButtonOffset = 1000;
		private readonly int storeField;

		public KeyValue (Key key)
		{
			storeField = (int)key;
		}

		public KeyValue (MouseButton mouseButton)
		{
			storeField = (int)mouseButton + mouseButtonOffset;
		}

		public KeyType KeyType => storeField < mouseButtonOffset ? KeyType.KeyboardType : KeyType.MouseButtonType;

		public override bool Equals (object obj)
		{
			if (obj is KeyValue)
				return storeField == ((KeyValue)obj).storeField;
			return false;
		}

		public override int GetHashCode ()
		{
			return storeField;
		}

		public static explicit operator Key (KeyValue kv)
		{
			if (kv.KeyType != KeyType.KeyboardType) throw new InvalidCastException();
			return (Key)kv.storeField;
		}

		public static explicit operator MouseButton (KeyValue kv)
		{
			if (kv.KeyType != KeyType.MouseButtonType) throw new InvalidCastException();
			return (MouseButton)(kv.storeField - mouseButtonOffset);
		}

		public int Index
		{
			get
			{
				switch (KeyType) {
					case KeyType.KeyboardType:
						return storeField;
					case KeyType.MouseButtonType:
						return storeField - mouseButtonOffset;
					default:
						throw new ArgumentOutOfRangeException ();
				}
			}
		}

		internal bool IsHit
		{
			get
			{
				switch (KeyType) {
					case KeyType.KeyboardType:
						return DualityApp.Keyboard.KeyHit ((Key)this);
					case KeyType.MouseButtonType:
						return DualityApp.Mouse.ButtonHit ((MouseButton)this);
					default:
						throw new ArgumentOutOfRangeException ();
				}
			}
		}

		internal bool IsPressed
		{
			get
			{
				switch (KeyType) {
					case KeyType.KeyboardType:
						return DualityApp.Keyboard.KeyPressed ((Key)this);
					case KeyType.MouseButtonType:
						return DualityApp.Mouse.ButtonPressed ((MouseButton)this);
					default:
						throw new ArgumentOutOfRangeException ();
				}
			}
		}

		internal bool IsReleased
		{
			get
			{
				switch (KeyType) {
					case KeyType.KeyboardType:
						return DualityApp.Keyboard.KeyReleased ((Key)this);
					case KeyType.MouseButtonType:
						return DualityApp.Mouse.ButtonReleased ((MouseButton)this);
{'fraction_non_alphanumeric': 0.08420602692883095, 'fraction_numerical': 0.0025646505663603335, 'mean_word_length': 3.0625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1191637', 'n_tokens_mistral': 1880, 'n_tokens_neox': 1435, 'n_words': 348}