Example #1
0
        /// <summary>
        /// Loads a texture from a directory chosen
        /// </summary>
        /// <param name="directory">The directory of the zip file to load</param>
        public void LoadTexture(string directory)
        {
            string name = directory.Split('\\').Last();

            name            = name.Substring(0, name.Length - 4);
            _currentTexture = name;
            if (_blockPics != null)
            {
                for (int i = 0; i < _blockPics.Length; i++)
                {
                    _blockPics[i] = null;
                }
            }
            Console.WriteLine("Deleting old stuff...");
            while (Directory.Exists(TEXTURE_EXTRACT + name + "\\"))
            {
                if (Directory.Exists(TEXTURE_EXTRACT + name + "\\"))
                {
                    Directory.Delete(TEXTURE_EXTRACT + name + "\\", true);
                }
            }
            Console.WriteLine("Finished deleting");
            Console.WriteLine("Extraction started...");
            try
            {
                ZipFile.ExtractToDirectory(directory, TEXTURE_EXTRACT + name + "\\");
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Zip file not found");
                Console.WriteLine("Reverting to defualt...");
                LoadTexture();
                return;
            }
            Console.WriteLine("Extraction ended");
            var all = _data.All;

            _colorCodes = new int[all.Count];
            _colors     = new Color[all.Count];
            _blockPics  = new Canvas[all.Count];
            try
            {
                for (int i = 0; i < all.Count; i++)
                {
                    _blockPics[i]  = new Canvas(Image.FromFile(BlockPath + all[i].fileName));
                    _colors[i]     = Color.FromArgb(_colorCodes[i]);
                    _colorCodes[i] = _blockPics[i].AverageColor();
                }
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Couldn't find images; Either invalid or incomplete texture pack. Loading defualt...");
                LoadTexture();
            }
            TextureThreadEnd.Invoke(this, new EventArgs());
        }
Example #2
0
 private void _work_TextureEnd(object source, EventArgs e)
 {
     if (InvokeRequired)
     {
         TextureThreadEnd te = new TextureThreadEnd(UpdateTextureEnd);
         Invoke
             (te);
     }
     else
     {
         UpdateTextureEnd();
     }
 }