<commit_before>/**
 * @author <NAME>
 * @author <NAME>

 * Date Created: 11/11/14
 * Date Modified: 11/11/14
 */
package com.print_stack_trace.voogasalad.model.engine.physics;

import java.util.Collection;
import java.util.Map;

import com.print_stack_trace.voogasalad.model.SpriteCharacteristics;
import com.print_stack_trace.voogasalad.model.engine.authoring.GameAuthorEngine.SpriteType;

public class PhysicsEngine {
	private static final int MATRIX_SIZE = SpriteType.values().length;
	
	/**
	 * The decision Matrix is the basis for determining HOW to handle a given collision.
	 * 
	 *	 								SpriteType
	 *			 			|	A	|	B	|	C	|	D	|
	 *				 	A	|Explode|		|		|		|
	 *  SpriteType	 	B	|		|Allow	|Disp2	|		|
	 *					C	|		|Disp1	|		|		|
	 *					D	|		|		|		|		|
	 *
	 * Given two objects that have collided, we can lookup their types in the table
	 * and get back a CollisionResult describing how the collision should play out.
	 * For example, if a sprite of type A collides with another sprite of type A,
	 * we know we must apply an "explode" type collision to them both.
	 */
	private CollisionResult[][] decisionMatrix;
	
	private Map<CollisionResult , CollisionHandler> handlerMap;
	private SoloPhysicsHandler soloHandler;

	public enum CollisionResult {
		ObjectOneFullDisplacement,
		ObjectTwoFullDisplacement,
		ObjectBothFullDisplacement,
		ObjectBothNoDisplacement,
		NoAction,
		ObjectOneDisappear,
		ObjectTwoDisappear,
		ObjectBothDisappear,
		GameOverLose,
		GameOverWin
	};
	
	public PhysicsEngine() {
		decisionMatrix = new CollisionResult[MATRIX_SIZE][MATRIX_SIZE];
	}
	
	public void animateAll(Collection<SpriteCharacteristics> allObjects) {
		for(SpriteCharacteristics obj : allObjects) {
			soloHandler.applyPhysics(obj);
		}
		/*
			TODO: Detect Collisions
			If a collision is detected, call the private method collisionHandler(SpriteCharacteristics s1, SpriteCharacteristics s2)
			with the two colliding SpriteCharactoristicObjects. It would be best to put the collision detection logic in a new class
			(maybe even static since instance vars may not be needed);.
			
			Ideal Example
			if(CollisionDetector.isIntersecting(SpriteCharacteristics s1, SpriteCharacteristics s2)) {
				collisionHandler(SpriteCharacteristics s1, SpriteCharacteristics s2);
			}
		*/
	}
	
	/**
	 * Private method to assist in the proper collision handling lifecycle.
	 * Once it has been confirmed that two SpriteCharacteristics are colliding, 
	 * we must determine what collision should occur given the types of colliding
	 * objects and then apply the collision to the objects.
	 * the following events happen:<commit_msg>Removed collisionrestult enum from PhysicsEngine<commit_after>/**
 * @author <NAME>
 * @author <NAME>
 * Date Created: 11/11/14
 * Date Modified: 11/22/14
 */
package com.print_stack_trace.voogasalad.model.engine.physics;

import java.util.Collection;
import java.util.Map;

import com.print_stack_trace.voogasalad.model.SpriteCharacteristics;
import com.print_stack_trace.voogasalad.model.engine.authoring.GameAuthorEngine.SpriteType;
import com.print_stack_trace.voogasalad.model.engine.physics.CollisionFactory.CollisionResult;

public class PhysicsEngine {
	private static final int MATRIX_SIZE = SpriteType.values().length;
	
	/**
	 * The decision Matrix is the basis for determining HOW to handle a given collision.
	 * 
	 *	 								SpriteType
	 *			 			|	A	|	B	|	C	|	D	|
	 *				 	A	|Explode|		|		|		|
	 *  SpriteType	 	B	|		|Allow	|Disp2	|		|
	 *					C	|		|Disp1	|		|		|
	 *					D	|		|		|		|		|
	 *
	 * Given two objects that have collided, we can lookup their types in the table
	 * and get back a CollisionResult describing how the collision should play out.
	 * For example, if a sprite of type A collides with another sprite of type A,
	 * we know we must apply an "explode" type collision to them both.
	 */
	private CollisionResult[][] decisionMatrix;
	
	private Map<CollisionResult , CollisionHandler> handlerMap;
	private SoloPhysicsHandler soloHandler;
	
	public PhysicsEngine() {
		decisionMatrix = new CollisionResult[MATRIX_SIZE][MATRIX_SIZE];
	}
	
	public void animateAll(Collection<SpriteCharacteristics> allObjects) {
		for(SpriteCharacteristics obj : allObjects) {
			soloHandler.applyPhysics(obj);
		}
		/*
			TODO: Detect Collisions
			If a collision is detected, call the private method collisionHandler(SpriteCharacteristics s1, SpriteCharacteristics s2)
			with the two colliding SpriteCharactoristicObjects. It would be best to put the collision detection logic in a new class
			(maybe even static since instance vars may not be needed);.
			
			Ideal Example
			if(CollisionDetector.isIntersecting(SpriteCharacteristics s1, SpriteCharacteristics s2)) {
				collisionHandler(SpriteCharacteristics s1, SpriteCharacteristics s2);
			}
		*/
	}
	
	/**
	 * Private method to assist in the proper collision handling lifecycle.
	 * Once it has been confirmed that two SpriteCharacteristics are colliding, 
	 * we must determine what collision should occur given the types of colliding
	 * objects and then apply the collision to the objects.
	 * the following events happen:
{'fraction_non_alphanumeric': 0.07410296411856475, 'fraction_numerical': 0.0078003120124804995, 'mean_word_length': 3.974781765276431, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2146339', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1535, 'n_words': 486}