"use strict";
/* nominally chief; more of a figurehead.  Overflowing with optimism... or not. */
var GO_Teaset = function(){
	this.sprite = new Sprite(GO_Teaset.spriteSheet,"Teaset");
	this.sprite.collision_flags = 0;
	this.sprite.setBoundingBox(3,5,28,12);
	this.sprite.game_object = this; // no longer a generic GO

	this.anim_state = this.ANIM_STATES.materialize;
	this.frame_timer = this.anim_frames[this.anim_state].length;
	this.sprite.visible = false;

};
GO_Teaset.spriteImg = SDS_Load_Image("art/sheets/sprite/tea.png");
GO_Teaset.spriteSheet = new TileSheet(5, 4, 0, 3, GO_Teaset.spriteImg);

GO_Teaset.prototype = new GameObject(
	new Sprite(
		GO_Teaset.spriteSheet,
		"Teaset"
	),
	"Teaset"
	);

	GO_Teaset.prototype.interactions = 0;

	GO_Teaset.prototype.ANIM_STATES = {
		"materialize" : 0,
		"pour" : 1,
		"idle" : 2,
		"dematerialize" : 3
	};
	GO_Teaset.prototype.anim_frames = [
		[0,1,4,3], //"materialize" : 
		[3,2,2,2,2,3,3,4,5,6,6,7,7,7,7,6,6,5,4,3], //"pour" :
		[3,3,3,4,4,5,5,6,6,6,6,5,5,4,4,3], //"idle" :
		[3,4,1,0] //"dematerialize" : 
	];

	GO_Teaset.prototype.Show = function(){
		this.anim_state = this.ANIM_STATES.materialize;
		this.frame_timer = -1;
		this.sprite.visible = true;
	};

	// jic; tea will auto-serve after materialize
	GO_Teaset.prototype.Serve = function(){
		this.anim_state = this.ANIM_STATES.pour;
		this.frame_timer = -1;
	};

	GO_Teaset.prototype.Clear = function(){
		this.anim_state = this.ANIM_STATES.dematerialize;
		this.frame_timer = -1;
	};

	GO_Teaset.prototype.Update = function(){
		++this.frame_timer;
		this._heap.aniFrame = (this.frame_timer>>3);
		if (this._heap.aniFrame >= this.anim_frames[this.anim_state].length){
			switch (this.anim_state){
				case this.ANIM_STATES.materialize:
					//this._heap.aniFrame = this.anim_frames[this.anim_state].length-1;
					this.anim_state = this.ANIM_STATES.pour;
					this.frame_timer = 0;
					this._heap.aniFrame = 0;
				break;
				case this.ANIM_STATES.pour:
					this.anim_state = this.ANIM_STATES.idle;
					this.frame_timer = 0;
					this._heap.aniFrame = 0;
				break;
				case this.ANIM_STATES.idle:
					this._heap.aniFrame %= this.anim_frames[this.anim_state].length;
				break;
				case this.ANIM_STATES.dematerialize:
					this._heap.aniFrame = this.anim_frames[this.anim_state].length-1;
					this.sprite.visible = false;
				break;
			}
		}

		this.sprite.frame = this.anim_frames[this.anim_state][this._heap.aniFrame];

	};

