#include <scene/3d/spatial.h>
#ifdef TOOLS_ENABLED
#include <scene/resources/packed_scene.h>
#include <scene/animation/animation_node_state_machine.h>
#endif

/* Starting point of animation */
class SmartObject: public Spatial {
	GDCLASS(SmartObject, Spatial)
	friend class SmartObjectManager;
protected:
	String anim_state;
	String anim_finish_state;
	bool enabled;
	bool teleport;
	float distance;
	SmartObject();
	int state;
	int npc_id;
	enum {STATE_INIT, STATE_SELECTED, STATE_CLOSE, STATE_ACTIVE, STATE_PROGRESS, STATE_FINISH};
	void _notification(int p_what);
	static void _bind_methods();
#if TOOLS_ENABLED
	Ref<PackedScene> character;
	void draw_debug();
	void clear_debug();
	bool run_in_editor;
	String dump_subnodes(Ref<AnimationNode> anode) const;
	template<class T>
	Ref<T> get_anode(Ref<AnimationRootNode> r) const
	{
		T *p = Object::cast_to<T>(r.ptr());
		return Ref<T>(p);
	}
	AnimationTree *find_animation_tree(Node *node) const;
	String get_animation_list() const;
#endif
public:
	void _get_property_list(List<PropertyInfo> *p_list) const;
	bool _get(const StringName &p_name, Variant &r_ret) const;
	bool _set(const StringName &p_name, const Variant &p_value);
	bool get_busy()
	{
		return state != STATE_INIT;
	}
};

class SmartObjectManager: public Node {
	GDCLASS(SmartObjectManager, Node)
protected:
	void _notification(int p_what);
	void update_state(SmartObject *sm);
public:
	static void play_animation(Node *cnode, const String &anim);
	void arrived(SmartObject *sm, Node *ch);
};

/* Manager of group animation */
class SmartObjectGroup: public Spatial {
	GDCLASS(SmartObjectGroup, Spatial)
};
