#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include "ZipLoader.h"

/*--------------------------------------------------------------------------*/

int main()
	{
	// Create the main window
	sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");
	
	// Loading images and fonts is straightforward
	
	// Load a sprite to display
	sf::Image Image;
	Zip::File File("Data/test.png");				// Load file from zip to memory
	if (!Image.LoadFromMemory(File,File.Size()))	// Load image from memory
		return EXIT_FAILURE;
	sf::Sprite Sprite(Image);
	
	// Create a graphical string to display
	sf::Font Arial;
	File.Load("Data/A Cut Above The Rest.ttf");		// Reuse file object to load font
	if (!Arial.LoadFromMemory(File,File.Size()))
		return EXIT_FAILURE;
	sf::String Text("Hello SFML", Arial, 50);
	
	// Loading music has a catch...
	
	// When you load music from memory, it means that music will be played
	// from that memory. Therefore data must exist while music is playing,
	// so Zip::File containing that data must not go out of scope.
	
	// Load a music to play
	sf::Music Music;
	File.Load("Data/32084__Quilt__Orchestral_5of5.ogg");
	if (!Music.OpenFromMemory(File,File.Size()))
		return EXIT_FAILURE;
	
	// Play the music
	Music.Play();
	
	// Start the game loop
	while (App.IsOpened())
		{
		// Process events
		sf::Event Event;
		while (App.GetEvent(Event))
			{
			// Close window : exit
			if (Event.Type == sf::Event::Closed)
				App.Close();
			if (Event.Key.Code==sf::Key::Escape)
				App.Close();
			}
		
		// Clear screen
		App.Clear();
		
		// Draw the sprite
		App.Draw(Sprite);
		
		// Draw the string
		App.Draw(Text);
		
		// Update the window
		App.Display();
		}
	
	// Stop music before audio data will be freed
	Music.Stop();
	
	return EXIT_SUCCESS;
	}
