<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package src.io.controller;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Scanner;

import src.model.map.MapUser_Interface;
import src.model.map.constructs.Avatar;
import src.io.view.AvatarCreationView;
import src.io.view.Display;
import src.io.view.MapView;
import src.io.view.StatsView;
import src.io.view.Viewport;
/**
 * Uses keyboard input to control the avatar
 * @author JohnReedLOL
 */
public final class UserInput implements KeyListener, FocusListener
{

    /**
     * UserInput Constructor
     * @param avatar
     */
    public UserInput(MapUser_Interface mui, String uName) {
        Display.getDisplay().addKeyListener(this);
        Display.getDisplay().addFocusListener(this);
        MapUserAble_ = mui;
        userName_ = uName;
        setView(nullChar);
    	Display.getDisplay().setView(currentView_);
        Display.getDisplay().printView();
        
    }

    private MapUser_Interface MapUserAble_;
    private final String userName_;
    private Viewport currentView_ = new AvatarCreationView(); 
    private final char nullChar = (char)0;
    private void setView(char c){
    	boolean taken = false;
    	if(currentView_ instanceof AvatarCreationView){
    		if(c == 'Z' || c == 'C' || c == 'X' || c == 'V'){
    			currentView_ = new MapView(); 
    		}
    	}	
    	if(currentView_ instanceof MapView){
    		if(c == 'i'){currentView_ = new StatsView(userName_); taken = true;}
    	}
    	else if(currentView_ instanceof StatsView){
    		if(c == 'i'){currentView_ = new MapView(); taken = true;}
    	}
    	if(!taken){
    	currentView_.renderToDisplay(MapUserAble_.sendCommandToMap(userName_, c, Viewport.width_/2,Viewport.height_/2));
    	}
    	else{
    		currentView_.renderToDisplay(MapUserAble_.sendCommandToMap(userName_, nullChar, Viewport.width_/2,Viewport.height_/2));
    		//I need to get this info without sending a command, sending ' ' is a hack for now.
    	}
    }
    private void takeTurn(KeyEvent e) {

    	setView(e.getKeyChar());

    	//my_avatar_.getInput((char)input);
		//my_avatar_.getMapRelation().getSimpleAngle();//Example of simpleangle
		//my_avatar_.getMapRelation().getAngle();//Example of how to use getAngle
    	Display.getDisplay().setView(currentView_);
        Display.getDisplay().printView();
    	}
    	
    	

	@Override
	public void keyPressed(KeyEvent e) {
		//Nothing to do here
	}

	@Override
	public void keyReleased(KeyEvent e) {
		//We do nothing in this situation
		
	}

	@Override
	public void keyTyped(KeyEvent e) {
		takeTurn(e);
		
	}








	@Override
	public void focusGained(FocusEvent arg0) {
		// TODO Auto-generated method stub
		
	}



	@Override
	public void focusLost(FocusEvent arg0) {
		Display.getDisplay().requestFocus();//Required to work around a bug in swing
		//Otherwise, focus is never regained.
		
	}
    
}
<commit_msg>Revert "Revert "Used 'M' with sendCommand to avoid time passing""<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package src.io.controller;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Scanner;

import src.model.map.MapUser_Interface;
import src.model.map.constructs.Avatar;
import src.io.view.AvatarCreationView;
import src.io.view.Display;
import src.io.view.MapView;
import src.io.view.StatsView;
import src.io.view.Viewport;
/**
 * Uses keyboard input to control the avatar
 * @author JohnReedLOL
 */
public final class UserInput implements KeyListener, FocusListener
{

    /**
     * UserInput Constructor
     * @param avatar
     */
    public UserInput(MapUser_Interface mui, String uName) {
        Display.getDisplay().addKeyListener(this);
        Display.getDisplay().addFocusListener(this);
        MapUserAble_ = mui;
        userName_ = uName;
        setView(nullChar);
    	Display.getDisplay().setView(currentView_);
        Display.getDisplay().printView();
        
    }

    private MapUser_Interface MapUserAble_;
    private final String userName_;
    private Viewport currentView_ = new AvatarCreationView(); 
    private final char nullChar = (char)0;
    private void setView(char c){
    	boolean taken = false;
    	if(currentView_ instanceof AvatarCreationView){
    		if(c == 'Z' || c == 'C' || c == 'X' || c == 'V'){
    			currentView_ = new MapView(); 
    		}
    	}	
    	if(currentView_ instanceof MapView){
    		if(c == 'i'){currentView_ = new StatsView(userName_); taken = true;}
    	}
    	else if(currentView_ instanceof StatsView){
    		if(c == 'i'){currentView_ = new MapView(); taken = true;}
    	}
    	if(!taken){
    	currentView_.renderToDisplay(MapUserAble_.sendCommandToMap(userName_, c, Viewport.width_/2,Viewport.height_/2));
    	}
    	else{
    		currentView_.renderToDisplay(MapUserAble_.sendCommandToMap(userName_, 'M', Viewport.width_/2,Viewport.height_/2));
    		//I need to get this info without sending a command, sending ' ' is a hack for now.
    	}
    }
    private void takeTurn(KeyEvent e) {

    	setView(e.getKeyChar());

    	//my_avatar_.getInput((char)input);
		//my_avatar_.getMapRelation().getSimpleAngle();//Example of simpleangle
		//my_avatar_.getMapRelation().getAngle();//Example of how to use getAngle
    	Display.getDisplay().setView(currentView_);
        Display.getDisplay().printView();
    	}
    	
    	

	@Override
	public void keyPressed(KeyEvent e) {
		//Nothing to do here
	}

	@Override
	public void keyReleased(KeyEvent e) {
		//We do nothing in this situation
		
	}

	@Override
	public void keyTyped(KeyEvent e) {
		takeTurn(e);
		
	}








	@Override
	public void focusGained(FocusEvent arg0) {
		// TODO Auto-generated method stub
		
	}



	@Override
	public void focusLost(FocusEvent arg0) {
		Display.getDisplay().requestFocus();//Required to work around a bug in swing
		//Otherwise, focus is never regained.
		
	}
    
}

{'fraction_non_alphanumeric': 0.11294553309674434, 'fraction_numerical': 0.002160160469063416, 'mean_word_length': 3.309840425531915, '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': '1440600', 'n_tokens_mistral': 2134, 'n_tokens_neox': 2049, 'n_words': 493}