Пример #1
0
        private Level(BinaryReader reader) : this()
        {
            ID = reader.ReadInt32();
            var nameLength = reader.ReadInt32();

            Name      = Encoding.UTF8.GetString(reader.ReadBytes(nameLength));
            SPlusTime = reader.ReadUInt16();
            STime     = reader.ReadUInt16();
            ATime     = reader.ReadUInt16();
            BTime     = reader.ReadUInt16();
            CTime     = reader.ReadUInt16();
            CheckTime();
            var prismsCount = reader.ReadInt16();

            Size = new Size3D(reader);
            #region Boring verifying
            var temp = reader.ReadUInt16();
            if (Temp1 != temp)
            {
                Warning.WriteLine(string.Format(Localization.LevelInvalidArgument, temp, Temp1, "unknown_ushort_1"));
            }
            temp = reader.ReadUInt16();
            if (Temp2 != temp)
            {
                Warning.WriteLine(string.Format(Localization.LevelInvalidArgument, temp, Temp2, "unknown_ushort_2"));
            }
            ushort width = reader.ReadUInt16(), length = reader.ReadUInt16();
            var    legacyMinimapValid = true;
            if (LegacyMinimapSize.Width != width)
            {
                Warning.WriteLine(string.Format(Localization.LevelInvalidArgument, width, LegacyMinimapSize.Width,
                                                "unknown_ushort_3"));
                legacyMinimapValid = false;
            }
            if (LegacyMinimapSize.Length != length)
            {
                Warning.WriteLine(string.Format(Localization.LevelInvalidArgument, width, LegacyMinimapSize.Length,
                                                "unknown_ushort_4"));
                legacyMinimapValid = false;
            }
            if (!legacyMinimapValid)
            {
                Warning.WriteLine(Localization.LevelLegacyMinimapMalformed);
            }
            var tempByte = reader.ReadByte();
            if (tempByte != 10)
            {
                Warning.WriteLine(string.Format(Localization.LevelInvalidArgument, temp, 10, "unknown_byte_1"));
            }
            temp = reader.ReadUInt16();
            if (Size.Length - 1 != temp)
            {
                Warning.WriteLine(string.Format
                                      (Localization.LevelInvalidArgument, temp, Size.Length - 1, "unknown_ushort_5"));
            }
            temp = reader.ReadUInt16();
            if (0 != temp)
            {
                Warning.WriteLine(string.Format(Localization.LevelInvalidArgument, temp, 0, "unknown_ushort_6"));
            }
            #endregion
            if (legacyMinimapValid)
            {
                LegacyMinimap = new Flat(reader, LegacyMinimapSize);
            }
            else
            {
                LegacyMinimap = new Flat(LegacyMinimapSize);
                reader.ReadBytes((width * length + 7) / 8);
            }
            CollisionMap = new Cube(reader, Size);
            SpawnPoint   = new Point3D16(reader);
            Zoom         = reader.ReadInt16();
            if (Zoom < 0)
            {
                Value        = reader.ReadInt16();
                ValueIsAngle = reader.ReadBoolean();
            }
            ExitPoint = new Point3D16(reader);
            var count = reader.ReadUInt16();
            for (var i = 0; i < count; i++)
            {
                MovingPlatforms.Add(new MovingPlatform(MovingPlatforms, reader));
            }
            count = reader.ReadUInt16();
            for (var i = 0; i < count; i++)
            {
                Bumpers.Add(new Bumper(Bumpers, reader));
            }
            count = reader.ReadUInt16();
            for (var i = 0; i < count; i++)
            {
                FallingPlatforms.Add(new FallingPlatform(this, reader));
            }
            count = reader.ReadUInt16();
            for (var i = 0; i < count; i++)
            {
                Checkpoints.Add(new Checkpoint(reader));
            }
            count = reader.ReadUInt16();
            for (var i = 0; i < count; i++)
            {
                CameraTriggers.Add(new CameraTrigger(reader));
            }
            count = reader.ReadUInt16();
            for (var i = 0; i < count; i++)
            {
                Prisms.Add(new Prism(reader));
            }
            if (count != prismsCount)
            {
                Warning.WriteLine(string.Format
                                      (Localization.LevelInvalidArgument, prismsCount, count, "prisms_count"));
            }
            if ((count = reader.ReadUInt16()) > 0)
            {
                Warning.WriteLine(string.Format(Localization.DeprecatedElement, "Fan"));
            }
            for (var i = 0; i < count; i++)
            {
                Fans.Add(new Fan(reader));
            }
            Buttons = new Buttons(this, reader);
            count   = reader.ReadUInt16();
            for (var i = 0; i < count; i++)
            {
                OtherCubes.Add(new OtherCube(this, reader));
            }
            count = reader.ReadUInt16();
            for (var i = 0; i < count; i++)
            {
                Resizers.Add(new Resizer(this, reader));
            }
            if ((count = reader.ReadUInt16()) > 0)
            {
                Warning.WriteLine(string.Format(Localization.DeprecatedElement, "MiniBlock"));
            }
            for (var i = 0; i < count; i++)
            {
                MiniBlocks.Add(new MiniBlock(reader));
            }
            ModelTheme = Theme = reader.ReadByte();
            MusicJava  = reader.ReadByte();
            Music      = reader.ReadByte();
            foreach (var button in Buttons)
            {
                if (button.IsMoving)
                {
                    button.MovingPlatformID.Name.DoNothing();
                }
                foreach (var e in button.Events)
                {
                    Buttons.BlockEvents[e].ID.Name.DoNothing();
                }
            }
            foreach (var cube in OtherCubes)
            {
                cube.MovingBlockSync.Name.DoNothing();
                cube.DarkCubeMovingBlockSync?.Name.DoNothing();
            }
        }
Пример #2
0
        private Level(string path) : this()
        {
            var element = XHelper.Load(path + ".xml").GetElement("Level");

            ID   = element.GetAttributeValue <int>("ID");
            Name = element.GetAttributeValueWithDefault("Name", string.Empty);
            var thresholds = element.GetAttributeValueWithDefault("TimeThresholds", "1,2,3,4,5").Split(',')
                             .Select(str => ushort.Parse(str.Trim())).ToArray();

            SPlusTime = thresholds[0];
            STime     = thresholds[1];
            ATime     = thresholds[2];
            BTime     = thresholds[3];
            CTime     = thresholds[4];
            CheckTime();
            Size          = element.GetAttributeValue <Size3D>("Size");
            LegacyMinimap = new Flat(path + ".png", LegacyMinimapSize);
            CollisionMap  = new Cube(path + ".{0}.png", Size);
            SpawnPoint    = element.GetAttributeValue <Point3D16>("SpawnPoint");
            ExitPoint     = element.GetAttributeValue <Point3D16>("ExitPoint");
            Theme         = element.GetAttributeValueWithDefault <byte>("Theme");
            ModelTheme    = element.GetAttributeValueWithDefault("ModelTheme", Theme);
            MusicJava     = element.GetAttributeValueWithDefault <byte>("MusicJava");
            Music         = element.GetAttributeValueWithDefault("Music", (byte)6);
            Zoom          = element.GetAttributeValueWithDefault("Zoom", (short)-1);
            var advanced = true;

            if (ValueIsAngle = element.AttributeCaseInsensitive("Angle") != null)
            {
                Value = element.GetAttributeValueWithDefault <short>("Angle", 22);
                if (element.AttributeCaseInsensitive("FieldOfView") != null)
                {
                    Warning.WriteLine(string.Format(Localization.FieldOfViewIgnored, "Level"));
                }
            }
            else if (element.AttributeCaseInsensitive("FieldOfView") != null)
            {
                Value = element.GetAttributeValueWithDefault <short>("FieldOfView", 22);
            }
            else if (Zoom < 0)
            {
                Value = 22;
            }
            else
            {
                advanced = false;
            }
            if (Zoom >= 0 && advanced)
            {
                Warning.WriteLine(string.Format(Localization.AdvancedCameraModeDisabled,
                                                "Level", "@Angle, @FieldOfView"));
            }
            Buttons = new Buttons(this);
            foreach (var e in element.Elements())
            {
                switch (e.Name.LocalName.ToLower())
                {
                case "movingplatform":
                    MovingPlatforms.Add(new MovingPlatform(MovingPlatforms, e));
                    break;

                case "bumper":
                    Bumpers.Add(new Bumper(Bumpers, e));
                    break;

                case "fallingplatform":
                    FallingPlatforms.Add(new FallingPlatform(this, e));
                    break;

                case "checkpoint":
                    Checkpoints.Add(new Checkpoint(e));
                    break;

                case "cameratrigger":
                    CameraTriggers.Add(new CameraTrigger(e));
                    break;

                case "prism":
                    Prisms.Add(new Prism(e));
                    break;

                case "fan":
                    Fans.Add(new Fan(e));
                    Warning.WriteLine(string.Format(Localization.DeprecatedElement, "Fan"));
                    break;

                case "button":
                case "buttonsequence":
                    // ReSharper disable once ObjectCreationAsStatement
                    new Button(Buttons, e);
                    break;

                case "othercube":
                case "darkcube":
                    OtherCubes.Add(new OtherCube(this, e));
                    break;

                case "resizergrow":
                case "resizershrink":
                    Resizers.Add(new Resizer(this, e));
                    break;

                case "miniblock":
                    MiniBlocks.Add(new MiniBlock(e));
                    Warning.WriteLine(string.Format(Localization.DeprecatedElement, "MiniBlock"));
                    break;

                default:
                    Warning.WriteLine(string.Format(Localization.UnrecognizedChildElement, e.Name, "Level"));
                    break;
                }
            }
        }