/*
 * Lever.h
 *
 *  Created on: 2009-07-11
 *      Author: wasyl
 */

#ifndef LEVER_H_
#define LEVER_H_

#include <allegro5/allegro.h>
#include <allegro5/acodec.h>
#include <allegro5/kcm_audio.h>
#include "../prep/misc/Vector2D.h"
#include "../prep/ent/Entity.h"
#include "../prep/res/Sheet.h"

class Lever : public Entity
{
protected:
	Sheet *mSprite;
	ALLEGRO_SAMPLE *mSndSwitch;

	int mControls;
	bool mOn;
	Entity *mToggler;

public:
	Lever(int controls, bool def);
	~Lever();

	int *indices()
	{
		static int ind[] = {ID("entt"), ID("rndr"), ID("dyna"), ID("posi"), ID("levr"), 0};
		return ind;
	}

	int order(int index)
	{
		if (index == ID("rndr"))
			return 35;
		else
			return (int)this;
	}

	void update(double dt);
	void render();

	Entity *clone() { return new Lever(mControls, mOn); };
	const char *code() { return "vr"; };
	std::string edString() { return SPrintF::format("lever(%d,%s)", mControls, mOn?"on":"off"); }

	void load(FILE *f);
	void save(FILE *f);
};

#endif /* LEVER_H_ */
