<commit_before>part of couclient;

class Bool
{
	bool value = false;

	Bool([this.value]);

	bool operator ==(other)
	{
		if(other is bool)
			return this.value == other;
		if(other is Bool)
			return this.value == other.value;
		else
			return this == other;
	}
}

class InputManager {
  Bool rightKey = new Bool(), leftKey = new Bool(), upKey = new Bool(),
		downKey = new Bool(), jumpKey = new Bool(), actionKey = new Bool();
  Map<String, int> keys = {
    "LeftBindingPrimary": 65,
    "LeftBindingAlt": 37,
    "RightBindingPrimary": 68,
    "RightBindingAlt": 39,
    "UpBindingPrimary": 87,
    "UpBindingAlt": 38,
    "DownBindingPrimary": 83,
    "DownBindingAlt": 40,
    "JumpBindingPrimary": 32,
    "JumpBindingAlt": 32,
    "ActionBindingPrimary": 13,
    "ActionBindingAlt": 13
  };
  bool ignoreKeys = false,
      touched = false,
      clickUsed = false;
  StreamSubscription keyPressSub, keyDownSub, menuKeyListener;
  DateTime lastSelect = new DateTime.now();
  Map<String,Map<String,dynamic>> controlCounts = {};

	InputManager()
	{
		controlCounts = {'leftKey':{'signals':{},'keyBool':leftKey},
		                 'rightKey':{'signals':{},'keyBool':rightKey},
		                 'upKey':{'signals':{},'keyBool':upKey},
		                 'downKey':{'signals':{},'keyBool':downKey},
		                 'jumpKey':{'signals':{},'keyBool':jumpKey},
		                 'actionKey':{'signals':{},'keyBool':actionKey}
		                 };

		setupKeyBindings();

		document.onClick.listen((MouseEvent event) => clickOrTouch(event,null));
		document.onTouchStart.listen((TouchEvent event) => clickOrTouch(null,event));
    }

	activateControl(String control, bool active, String sourceName)
	{
		Map<String,Map> signalsList = controlCounts[control]['signals'];
		if(active && !signalsList.containsKey(sourceName+'-'+control))
			signalsList[sourceName+'-'+control] = {'sourceName':sourceName,'active':active};
		else if(!active)
			signalsList.remove(sourceName+'-'+control);

		if(signalsList.length <= 0)
			controlCounts[control]['keyBool'].value = false;
		else
			controlCounts[control]['keyBool'].value = true;
	}

	updateGamepad()
	{
		//get any gamepads
		List<Gamepad> gamepads = window.navigator.getGamepads();

		for(Gamepad gamepad in gamepads)
		{
			//the list of gamepads the browser returns can include nulls
			if(gamepad == null)
				continue;

			if(gamepad.axes[0] > .2 || gamepad.axes[2] > .2)
				activateControl('rightKey',true,'gamepad');
			else
				activateControl('rightKey',false,'gamepad');
	  		if(gamepad.axes[0] < -.2 || gamepad.axes[2] < -.2)
	  			activateControl('leftKey',true,'gamepad');<commit_msg>enable menu selections<commit_after>part of couclient;

class Bool
{
	bool value = false;

	Bool([this.value]);

	bool operator ==(other)
	{
		if(other is bool)
			return this.value == other;
		if(other is Bool)
			return this.value == other.value;
		else
			return this == other;
	}
}

class InputManager {
  Bool rightKey = new Bool(), leftKey = new Bool(), upKey = new Bool(),
		downKey = new Bool(), jumpKey = new Bool(), actionKey = new Bool();
  Map<String, int> keys = {
    "LeftBindingPrimary": 65,
    "LeftBindingAlt": 37,
    "RightBindingPrimary": 68,
    "RightBindingAlt": 39,
    "UpBindingPrimary": 87,
    "UpBindingAlt": 38,
    "DownBindingPrimary": 83,
    "DownBindingAlt": 40,
    "JumpBindingPrimary": 32,
    "JumpBindingAlt": 32,
    "ActionBindingPrimary": 13,
    "ActionBindingAlt": 13
  };
  bool ignoreKeys = false,
      touched = false,
      clickUsed = false;
  StreamSubscription keyPressSub, keyDownSub, menuKeyListener;
  DateTime lastSelect = new DateTime.now();
  Map<String,Map<String,dynamic>> controlCounts = {};

	InputManager()
	{
		controlCounts = {'leftKey':{'signals':{},'keyBool':leftKey},
		                 'rightKey':{'signals':{},'keyBool':rightKey},
		                 'upKey':{'signals':{},'keyBool':upKey},
		                 'downKey':{'signals':{},'keyBool':downKey},
		                 'jumpKey':{'signals':{},'keyBool':jumpKey},
		                 'actionKey':{'signals':{},'keyBool':actionKey}
		                 };

		setupKeyBindings();

		document.onClick.listen((MouseEvent event) => clickOrTouch(event,null));
		document.onTouchStart.listen((TouchEvent event) => clickOrTouch(null,event));
    }

	activateControl(String control, bool active, String sourceName)
	{
		Map<String,Map> signalsList = controlCounts[control]['signals'];
		if(active && !signalsList.containsKey(sourceName+'-'+control))
			signalsList[sourceName+'-'+control] = {'sourceName':sourceName,'active':active};
		else if(!active)
			signalsList.remove(sourceName+'-'+control);

		if(signalsList.length <= 0)
			controlCounts[control]['keyBool'].value = false;
		else
			controlCounts[control]['keyBool'].value = true;
	}

	updateGamepad()
	{
		//get any gamepads
		List<Gamepad> gamepads = window.navigator.getGamepads();

		for(Gamepad gamepad in gamepads)
		{
			//the list of gamepads the browser returns can include nulls
			if(gamepad == null)
				continue;

			//don't do anything in certain situations
			if (ignoreKeys || querySelector(".fill") != null) return;

			//interact with the menu
			Element clickMenu = querySelector("#RightClickMenu");
			if(clickMenu != null)
			{
				Element list = querySelector('#RCActionList');
				//only select a new option once every 300ms
				bool selectAgain = lastSelect.add(new Duration(milliseconds:300)).isBefore(new DateTime.now());
				if(controlCounts['upKey']['keyBool'] == true && selectAgain)
					selectUp(list,"RCItemSelected");
				if(controlCounts['downKey']['keyBool'] == true && selectAgain)
					selectDown(list,"RCItemSelected");
				if(controlCounts['leftKey']['keyBool'] == true ||
					controlCounts['rightKey']['keyBool'] == true ||
					controlCounts['jumpKey']['keyBool'] == true)
					stopMenu(clickMenu);
			}

			if(gamepad.axes[0] > .2 || gamepad.axes[2] > .2)
				activateControl('rightKey',true,'gamepad');
			else
				activateControl('rightKey',false,'gamepad');
	  		if(gamepad.axes[0] < -.2 || gamepad.axes[2] < -.2)
	  			activateControl('leftKey',true,'gamepad');
{'fraction_non_alphanumeric': 0.16044350236425892, 'fraction_numerical': 0.011739768465677482, 'mean_word_length': 3.8721207307386813, 'pattern_counts': {'":': 24, '<': 19, '<?xml version=': 0, '>': 21, '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': '1424478', 'n_tokens_mistral': 2218, 'n_tokens_neox': 1926, 'n_words': 386}