using ActionGame.GameResources.Models;
using ActionGame.RawResources.Models;
using System;
using System.Collections.Generic;


namespace GameMaker.Models
{
    public class Session
    {

        public Session()
        {
            this.Fonts = new List<RawResource>();
            this.Songs = new List<RawResource>();
            this.SoundEffects = new List<RawResource>();
            this.Textures = new List<RawResource>();
            this.TileSets = new List<TileSetDefinition>();
            this.CharacterSets = new List<CharacterSetDefinition>();
            this.Worlds = new List<WorldDefinition>();
            this.Enemies = new List<EnemyDefinition>();
            this.Items = new List<ItemDefinition>();
        }


        public String WorkingDirectory { get; set; }
        public IList<ItemDefinition> Items { get; set; }
        public IList<RawResource> Fonts { get; set; }
        public IList<RawResource> Songs { get; set; }
        public IList<RawResource> SoundEffects { get; set; }
        public IList<RawResource> Textures { get; set; }
        public IList<TileSetDefinition> TileSets { get; set; }
        public IList<CharacterSetDefinition> CharacterSets { get; set; }
        public IList<WorldDefinition> Worlds { get; set; }
        public PlayerDefinition Player { get; set; }
        public IList<EnemyDefinition> Enemies { get; set; }


        public IList<RawResource> GetListOfTexturesUsedByTileSets()
        {
            IList<RawResource> list = new List<RawResource>();

            foreach(RawResource texture in Textures)
            {
                Boolean used = false;

                foreach(TileSetDefinition tileSet in TileSets)
                {
                    if(tileSet.TextureKey == texture.Key) 
                    {
                        used = true;
                        break;
                    }
                }

                if (used) list.Add(texture);
            }

            return list;
        }


        public RawResource GetTexture(Int32 key)
        {
            foreach (RawResource texture in Textures)
            {
                if (texture.Key == key) return texture;
            }

            return null;
        }


        public TileSetDefinition GetTileSet(Int32 key)
        {
            foreach(TileSetDefinition def in TileSets)
            {
                if (def.Key == key) return def;
            }

            return null;
        }


        public Int32 GetMaxWorldKey()
        {
            Int32 key = -1;

            foreach(WorldDefinition world in this.Worlds)
            {
                if (key < world.Key) key = world.Key;
            }

            return key;
        }

    }
}
