/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


		#include "automation/automation_player.h"
		#include "motion/motion.h"
		#include "memory/memory.h"
		#include "log/log.h"

		using namespace GS::Automation;
		using namespace GS::NML;


//------------------------------------------------------------------------------
bool			Player::FromMetaTag(Tag &tag)
{
	if	(tag.name != "MotionPlayer")
		__ERR__(__LOG_E__ << "Could not parse motion player, incorrect root tag (" << tag.name << ").\n", false)

	NMLTagForeach(pt, tag)
	{
		if	(pt->name == "Motions")
		{
			NMLTagForeach(pm, *pt)
				if	(pm->name == "Motion")
				{
					if	(Motion *m = new Motion)
					{
						m->FromMetaTag(*pm);
						motions.Add(m);
					}
				}
				else	__LOG_W__ << "Unknown tag '" << pm->name << "' in <Motions>.\n";
		}
	#if	1
		else	if	(pt->name == "Flag")
			;
	#endif
		else	__LOG_W__ << "Unknown tag '" << pt->name << "' in <MotionPlayer>.\n";
	}
	return true;
}
Tag				*Player::AsMetaTag()
{
	Tag *root = new Tag("MotionPlayer");
	if	(!root)
		__ERR__(__LOG_E__ << "Could not create root tag to serialize.\n", NULL)

	// Dump all motions.
	if	(Tag *mtag = root->AddChild("Motions"))
		ListForeachPtr(Motion *, m, motions)
			mtag->AddChild(m->AsMetaTag());

	if	(!root->GetChildCount())
		_safe_delete(root);
	return root;
}
//------------------------------------------------------------------------------
