Page 1 of 2

YAML > XML

Posted: Sun Dec 06, 2009 8:59 pm
by K-Bal
Anyone who wants to use XML should consider a short look at YAML with libyaml-cpp. It's extremely easy to use (from my game):
rats.yaml wrote: -
name: "Small Rat"
model: "hueteotl"
texture: "rat.png"
scale: 2.0
maxhealth: 15.0
maxmana: 0.0
maxvelocity: 20.0
-
name: "Big Rat"
model: "hueteotl"
texture: "rat.png"
scale: 3.0
maxhealth: 25.0
maxmana: 0.0
maxvelocity: 20.0
Factory method:

Code: Select all

KMEntity* EntityFactory::CreateEnemy(const std::string& script, const std::string& type, const ggut::Vector2f& pos)
{
	//TODO: KMEnemy
	KMEntity* temp = new KMEntity();

	std::ifstream fin(script.c_str());
	YAML::Parser parser(fin);

	YAML::Node doc;
	parser.GetNextDocument(doc);

	try
	{
		for(std::size_t num = 0; num < doc.size(); ++num)
		{
			if(doc[num]["name"] == type)
			{
				temp->SetName(type);
				temp->SetMaxHealth(doc[num]["maxhealth"]);
				temp->SetHealth(doc[num]["maxhealth"]);
				temp->SetMaxMana(doc[num]["maxmana"]);
				temp->SetMana(doc[num]["maxmana"]);
				temp->SetModel(doc[num]["model"]);
				temp->SetPosition(pos);
				temp->SetScale(doc[num]["scale"]);
				temp->SetMaxVelocity(doc[num]["maxvelocity"]);
			}
		}
	}
	catch( ... )
	{
		std::cerr << "Failed to load Enemy from YAML file!" << std::endl;
	}

	return temp;
}
Use:

Code: Select all

myRat = myEntityFactory.CreateEnemy("entities/rats.yaml", "Small Rat", Vector2f(150, 150));
Just wanted to share this. I just discovered it one hour ago ;)

Re: YAML > XML

Posted: Sun Dec 06, 2009 10:14 pm
by XianForce
Wow... That looks pretty legit =D. I'll have to take a look at it =p.

Re: YAML > XML

Posted: Mon Dec 07, 2009 10:32 am
by M_D_K
That's pretty awesome, I'll be checking that out later.

Re: YAML > XML

Posted: Mon Dec 07, 2009 1:38 pm
by DaveB
Yeah I think I will diffidently use this, looks really clean and easy to use

Re: YAML > XML

Posted: Sun Feb 28, 2010 6:11 pm
by thejahooli
Do you know any tutorials or documentation on using it as there seems to be little on it.

Re: YAML > XML

Posted: Mon Mar 01, 2010 2:45 am
by K-Bal

Re: YAML > XML

Posted: Mon Mar 01, 2010 3:05 am
by LeonBlade
How would I use this for my maps ;)

Re: YAML > XML

Posted: Mon Mar 01, 2010 9:56 am
by pritam
This looks very nice and clean, unlike how bloated XML can get.

Re: YAML > XML

Posted: Mon Mar 01, 2010 1:03 pm
by mattheweston
I took a week long course on Adobe Flex and they were saying this is what will eventually replace XML due to various reasons.

Re: YAML > XML

Posted: Mon Mar 01, 2010 1:29 pm
by K-Bal
mattheweston wrote:I took a week long course on Adobe Flex and they were saying this is what will eventually replace XML due to various reasons.
It will replace XML if we (the developers) use it and spread the word ;)

Re: YAML > XML

Posted: Mon Mar 01, 2010 3:05 pm
by thejahooli
Sorry for being a noob, but could you please explain the set-up as I am not very experienced with command prompt, which is how they explain it.

Re: YAML > XML

Posted: Mon Mar 01, 2010 3:19 pm
by GroundUpEngine
Same here.. I epic fail at working with & setting up new libraries, I tryed to implement it before but gave up straight away lol. But I really want to use yaml properly! :)

Re: YAML > XML

Posted: Mon Mar 01, 2010 3:40 pm
by K-Bal
What exactly is your problem? What do you need the cmd prompt for?

Re: YAML > XML

Posted: Mon Mar 01, 2010 6:27 pm
by thejahooli
I realised after downloading it that it was just a usual library set-up. I was just a bit thrown off by the How To Build section of the website.

Re: YAML > XML

Posted: Mon Mar 01, 2010 8:47 pm
by LeonBlade
Hmm... I don't see how I could use this for a map structure, doesn't seem... efficient enough?
Should I just do tile by tile?