Example #1
0
 /// <summary>
 /// Создание новой дефолтной карты
 /// </summary>
 public static void NewMap()
 {
     M = null; //Хм, интересно, но если не сделать предварительную очистку, возникает перегрузка памяти, 2015 год, а гигабайт - максимум :-(
     M = new ushort[MaxLayers + 1, MaxWidth, MaxHeight];
     TileSize = 32;
     ScreenWidth = 640;
     ScreenHeight = 480;
     //CalculateTiles();
     Width = 20;
     Height = 15;
     Layers = MaxLayers;
     Main = 6;
     Editor.Layer = Main;
     Phantom = 0;
     Px = new Parallax[MaxLayers + 1];
     Px[0] = new Parallax();
     Px[1] = new Parallax(0);
     Px[2] = new Parallax(0.2f);
     Px[3] = new Parallax(0.4f);
     Px[4] = new Parallax(0.6f);
     Px[5] = new Parallax(0.8f);
     Px[6] = new Parallax(1);
     Px[7] = new Parallax(1);
     Px[8] = new Parallax(1.2f);
     Editor.Reset();
     Editor.Codes = false;
     AnimationClear();
     Animation.Enable = true;
     AutoRulesClear();
     AutoRule.Enable = true;
     RandomClear();
     RandomTile.Enable = true;
     StampesClear();
     Hystory.Clear();
     ToolBackground = 0;
     Saved = true;
 }
Example #2
0
        /// <summary>
        /// Открытие текущего файла
        /// </summary>
        public static void Load()
        {
            //Открываем
            try
            {
                NewMap();
                BinaryReader file = new BinaryReader(new FileStream(FileName, FileMode.Open));

                if (file.ReadString() != Application.ProductName) throw new Exception("Файл не поддерживается.");  //Читаем маркер о формате
                int count;
                TileSize = file.ReadInt16();
                ScreenWidth = file.ReadInt16();
                ScreenHeight = file.ReadInt16();
                Width = file.ReadInt16();
                Height = file.ReadInt16();
                Layers = file.ReadByte();
                Main = file.ReadByte();
                Editor.Layer = Main;
                Phantom = file.ReadByte();
                for (byte l = 0; l <= Layers; l++)
                {
                    if (file.ReadString() != "Layer" + l.ToString()) throw new Exception("Слой " + l.ToString() + " не обнаружен."); //Маркер слоя
                    bool OK = true;
                    do
                    {
                        int j = file.ReadUInt16();
                        if (j != 0xFFFF)
                        {
                            //Битность
                            byte bpt = file.ReadByte();
                            if (bpt == 1)
                            {
                                //Однобайтовая версия
                                byte p = 0;
                                for (int i = 0; i < Width; i++)
                                {
                                    byte n = file.ReadByte();
                                    if (n != 0xFF)
                                    {
                                        p = n;
                                        M[l, i, j] = p;
                                    }
                                    else
                                    {
                                        int c = file.ReadUInt16();
                                        i--;
                                        for (int s = 1; s < c; s++) M[l, i + s, j] = p;
                                        i += c - 1;
                                    }
                                }
                            }
                            else
                            {
                                //Двухбайтовая версия
                                ushort p = 0;
                                for (int i = 0; i < Width; i++)
                                {
                                    ushort n = file.ReadUInt16();
                                    if (n != 0xFFFF)
                                    {
                                        p = n;
                                        M[l, i, j] = p;
                                    }
                                    else
                                    {
                                        i--;
                                        int c = file.ReadUInt16();
                                        for (int s = 1; s < c; s++) M[l, i + s, j] = p;
                                        i += c - 1;
                                    }
                                }
                            }
                        }
                        else OK = false;
                    } while (OK);
                    Px[l] = new Parallax(file.ReadSingle(), file.ReadSingle());
                }
                //Текстуры
                if (file.ReadString() != "Textures") throw new Exception();
                FileBackground = file.ReadString();
                FileTexture = file.ReadString();
                FileFront = file.ReadString();
                FileKarkas = file.ReadString();
                //Правила анимации
                if (file.ReadString() != "Animation") throw new Exception(ErrorFileIntegrity); //Маркер параметров анимации
                count = file.ReadInt32();
                for (int i = 0; i < count; i++)
                    Animations.Add(new Animation(file.ReadUInt16(), file.ReadByte(), file.ReadByte(), (Animation.Types)file.ReadByte()));
                //Правила автозаполнения каркаса
                if (file.ReadString() != "AutoRules") throw new Exception(); //Маркер правил автозаполнения
                AutoRules.Clear();
                count = file.ReadInt32();
                for (int i = 0; i < count; i++) AutoRules.Add(new AutoRule(file.ReadUInt16(), file.ReadUInt16(), file.ReadUInt16()));
                //Параметры рандома
                if (file.ReadString() != "Random") throw new Exception();
                count = file.ReadInt32();
                for (int i = 0; i < count; i++) Randoms.Add(new RandomTile(file.ReadUInt16(), file.ReadUInt16(), file.ReadByte()));
                //Штампы
                if (file.ReadString() != "Stamps") throw new Exception();
                for (int s = 0; s < 10; s++)
                {
                    Stamps[s].Width = file.ReadByte();
                    Stamps[s].Height = file.ReadByte();
                    for (int i = 0; i < Stamps[s].Width; i++)
                        for (int j = 0; j < Stamps[s].Height; j++)
                            Stamps[s].M[i, j] = file.ReadUInt16();
                }
                if (file.ReadString() != "Options") throw new Exception();
                Editor.Codes = file.ReadBoolean();
                AutoRule.Enable = file.ReadBoolean();
                Animation.Enable = file.ReadBoolean();
                RandomTile.Enable = file.ReadBoolean();
                ToolBackground = file.ReadByte();
                file.Close();
                Saved = true;
            }
            catch (Exception e)
            {
                MessageBox.Show("Произошла ошибка при открытии файла.\n" + e.Message, Application.ProductName);
                NewMap();
                FileName = "";
            }
        }