<commit_before>// GLOBAL VARIABLES ================================================
var ROWS = 7;
var COLUMNS = 7;
//==================================================================

//==================MODEL CLASS=====================================
function Model(){
	// Local Variables
	var grid = initGrid(ROWS, COLUMNS); // calls with global vars
	var hl_grid = initGrid(ROWS, COLUMNS);
	// Fields
	this.grid = grid;
	this.hl_grid = hl_grid; 

	// Public Methods  

	//--Static Methods

	//--Instance Methods               

	// Private Methods
	function initGrid(rows, columns) {
		var grid = [];
		for (var i = 0; i < rows; i++) {
			var row = [];
			for (var j = 0; j < columns; j++) {
				row.push("");
			}
			grid.push(row);
		}
		return grid;
	};


	//console.table(grid);  (TESTING)

} // end of class
//==================================================================

//==================CONTROLLER CLASS================================


function Controller(){
	// Static Variables
	var canvasID = document.getElementById('canvas');
	var nextButton = document.getElementById("nextbtn");
	var view = new View(canvasID);
	var model = new Model();
	var state = "letters";

	// Event Listeners
	canvasID.addEventListener("click",onGridClick,false);
	nextButton.addEventListener("click",onNextClick,false);

	

	// PUBLIC FUNCTIONS 

	// Static Functions
	function onGridClick(e) {
		var x = getClick(e).x;
		var y = getClick(e).y;
		if (state == "letters") {
			inputLetter(x, y);
		
		} else if (state == "highlight") {
			highlight(getLetter(x, y), x, y);
		
		} else {
			// model = new Model();
			// view = new View();
		}
		
	}

	function onNextClick() {

		if (state == "letters") {
			state = "highlight";
		
		} else if (state == "highlight") {
			if (hl_check()) {
				state = "result";
			}
			else {
				// invalid highlighting of cells
				window.alert("Fix your shit");
			}

		} else {
			// reset everything
			model = new Model();
			view = new View();
		}
	}


	
	function highlight(letter, x, y) {
		view.highlight(letter, x, y);
		if (model.hl_grid[y][x] == "H") {

			// deletes highlight in array
			model.hl_grid[y][x] == "";
			console.table(model.hl_grid);

			// deletes highlight but keeps letter
			// in the view
			view.addLetter(letter, x, y);
		
		} else {

			// create highlight in array and view
			model.hl_grid[y][x] = "H";
			console.table(model.hl_grid);
		}
	
	}
	
	function inputLetter(x, y) {

		// will be moved to its own function in due time.
		// quick and dirty check to see if they entered exactly 1 char
		var letter = prompt("Enter a letter.\nEnter nothing to delete a letter.");

		// creating a regular expression and setting it to
		// a var. This regex means from a-z and A-Z it is true
		var aLetters = /[A-Z]|[a-z]/;		

		if (letter != null) {  // cancel returns null<commit_msg>highlight and Back button<commit_after>// GLOBAL VARIABLES ================================================
var ROWS = 7;
var COLUMNS = 7;
//==================================================================

//==================MODEL CLASS=====================================
function Model(){
	// Local Variables
	var grid = initGrid(ROWS, COLUMNS); // calls with global vars
	var hl_grid = initGrid(ROWS, COLUMNS);
	// Fields
	this.grid = grid;
	this.hl_grid = hl_grid; 

	// Public Methods  

	//--Static Methods

	//--Instance Methods               

	// Private Methods
	function initGrid(rows, columns) {
		var grid = [];
		for (var i = 0; i < rows; i++) {
			var row = [];
			for (var j = 0; j < columns; j++) {
				row.push("");
			}
			grid.push(row);
		}
		return grid;
	};


	//console.table(grid);  (TESTING)

} // end of class
//==================================================================

//==================CONTROLLER CLASS================================


function Controller(){
	// Static Variables
	var canvasID = document.getElementById('canvas');
	var nextButton = document.getElementById("nextbtn");
	var backButton = document.getElementById("backbtn");
	var view = new View(canvasID);
	var model = new Model();
	var state = "letters";

	// Event Listeners
	canvasID.addEventListener("click",onGridClick,false);
	nextButton.addEventListener("click",onNextClick,false);
	backButton.addEventListener("click",onBackClick,false);
	

	// PUBLIC FUNCTIONS 

	// Static Functions
	function onGridClick(e) {
		var x = getClick(e).x;
		var y = getClick(e).y;
		if (state == "letters") {
			inputLetter(x, y);
		
		} else if (state == "highlight") {
			highlight(getLetter(x, y), x, y);
		
		} else {
			// model = new Model();
			// view = new View();
		}
		
	}

	// determines what state will be travelled to once
	// the Next button is pressed
	function onNextClick() {

		if (state == "letters") {
			state = "highlight";
		
		} else if (state == "highlight") {
			if (hl_check()) {
				state = "result";
			}
			else {
				// invalid highlighting of cells
				window.alert("Fix your shit");
			}

		} else {
			// reset everything
			model = new Model();
			view = new View();
		}
	}

	// determines what state will be travelled to once
	// the Back button is pressed
	function onBackClick(){
		if (state == "highlight"){
			state = "letters";
		}
		else if (state == "result"){
			state = "highlight";
		}

	}


	
	function highlight(letter, x, y) {
		if (model.hl_grid[y][x] == "H") {

			// deletes highlight in array
			model.hl_grid[y][x] = "";
			view.addLetter(letter, x, y);
			console.table(model.hl_grid);

			// deletes highlight but keeps letter
			// in the view
			
		
		} else {

			// create highlight in array and view
			view.highlight(letter, x, y);
			model.hl_grid[y][x] = "H";
			console.table(model.hl_grid);
		}
	
	}
	
	function inputLetter(x, y) {

		// will be moved to its own function in due time.
		// quick and dirty check to see if they entered exactly 1 char
		var letter = prompt("Enter a letter.\nEnter nothing to delete a letter.");

		// creating a regular expression and setting it to
		// a var. This regex means from a-z and A-Z it is true
		var aLetters = /[A-Z]|[a-z]/;		

		if (letter != null) {  // cancel returns null
{'fraction_non_alphanumeric': 0.2273615635179153, 'fraction_numerical': 0.0016286644951140066, 'mean_word_length': 3.0912724850099935, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2464397', 'n_tokens_mistral': 2233, 'n_tokens_neox': 1855, 'n_words': 569}