package projectzombie.model.player;

import gl_engine.texture.TextureRef3D;
import projectzombie.init.Resources;
import projectzombie.model.Model;

public class ModelPlayerBody extends Model
{
	protected TextureRef3D body_top, body_front, body_sides;
	protected TextureRef3D shirt_top, shirt_front, shirt_back, shirt_sides;
	protected int body_color = 0;
	protected int shirt_color = 0;
	protected int body_flags = 0;
	protected int shirt_flags = 0;
	
	public ModelPlayerBody()
	{
		body_top = Resources.ATLAS.get("/entity/player/body_top.png");
		body_front = Resources.ATLAS.get("/entity/player/body_front.png");
		body_sides = Resources.ATLAS.get("/entity/player/body_sides.png");
		
		shirt_top = Resources.ATLAS.get("/entity/player/shirt_top.png");
		shirt_front = Resources.ATLAS.get("/entity/player/shirt_front.png");
		shirt_back = Resources.ATLAS.get("/entity/player/shirt_back.png");
		shirt_sides = Resources.ATLAS.get("/entity/player/shirt_sides.png");
	}

	@Override
	public int[] getIndicies()
	{
		int[] indicies = new int[getIndexSize()];
		
		for(int i=0;i<indicies.length/6;i++) {
			indicies[i*6+0] = i*4+0;
			indicies[i*6+1] = i*4+1;
			indicies[i*6+2] = i*4+2;
			indicies[i*6+3] = i*4+2;
			indicies[i*6+4] = i*4+3;
			indicies[i*6+5] = i*4+0;
		}
		
		return indicies;
	}

	@Override
	public float[] getVerticies()
	{
		float b_f = body_flags;
		float s_f = shirt_flags;
		float b_c = body_color;
		float s_c = shirt_color;
		
		float x = 0.25f;
		float y = x * 2;
		float z = x * 1.1f;
		float m = y * 1.1f;
		
		int asi = 1;
		int asp = 1;
		
		return new float[]
		{
				 // Body
				-x, 0,  x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				 x, 0,  x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				 x, y,  x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				-x, y,  x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				
				-x, 0, -x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				 x, 0, -x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				 x, y, -x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				-x, y, -x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				
				 x, 0, -x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				 x, 0,  x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				 x, y,  x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				 x, y, -x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				
				-x, 0, -x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				-x, 0,  x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				-x, y,  x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				-x, y, -x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				
				-x, y, -x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				-x, y,  x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				 x, y,  x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				 x, y, -x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				
				-x, 0, -x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				-x, 0,  x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				 x, 0,  x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				 x, 0, -x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, b_c, b_f,
				 
				 // Shirt
				-z, 0,  z, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				 z, 0,  z, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				 z, m,  z, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				-z, m,  z, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,

				-z, 0, -z, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				 z, 0, -z, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				 z, m, -z, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				-z, m, -z, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,

				 z, 0, -z, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				 z, 0,  z, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				 z, m,  z, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				 z, m, -z, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,

				-z, 0, -z, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				-z, 0,  z, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				-z, m,  z, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				-z, m, -z, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,

				-z, m, -z, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				-z, m,  z, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				 z, m,  z, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
				 z, m, -z, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, s_c, s_f,
		};
	}

	@Override
	public TextureRef3D[] getTextures()
	{
		return new TextureRef3D[] {
				body_front, body_front, body_front, body_front,
				body_sides, body_sides, body_sides, body_sides,
				body_sides, body_sides, body_sides, body_sides,
				body_top, body_top, body_top, body_top,
				
				shirt_front, shirt_front, shirt_front, shirt_front,
				shirt_back, shirt_back, shirt_back, shirt_back,
				shirt_sides, shirt_sides, shirt_sides, shirt_sides,
				shirt_sides, shirt_sides, shirt_sides, shirt_sides,
				shirt_top, shirt_top, shirt_top, shirt_top,
		};
	}

	@Override
	public double getWidth() {
		return 1;
	}

	@Override
	public double getHeight() {
		return 1;
	}

	@Override
	public int getIndexSize() {
		return 66;
	}

	@Override
	public int getSize() {
		return 44;
	}
}
