Пример #1
0
 private void CheckTime()
 {
     if (SPlusTime >= STime || STime >= ATime || ATime >= BTime || BTime >= CTime)
     {
         Warning.WriteLine(Localization.LevelTimeThresholdsAscending);
     }
 }
Пример #2
0
        public Flat(string path, Size2D size) : this(size.Width, size.Length)
        {
            if (!File.Exists(path))
            {
                return;
            }
            Size2D fileSize;
            var    array = ImageConverter.Load(path, out fileSize);

            if (fileSize != size)
            {
                Warning.WriteLine(string.Format(Localization.ImageSizeIncorrect, path, size));
            }
            else
            {
                detailedInformation = array;
                var pos = 0;
                for (var y = 0; y < size.Length; y++)
                {
                    for (var x = 0; x < size.Width; x++, pos++)
                    {
                        var color = array[pos];
                        this[x, y] = color.R == 255;
                    }
                }
            }
        }
Пример #3
0
        public static XElement GetEanElement(EAN ean)
        {
            var result = new XElement("Animation");

            result.SetAttributeValueWithDefault("Unknown", ean.Header.Unknown1);
            result.SetAttributeValueWithDefault("Duration", ean.Header.Duration);
            if (ean.Header.Zero1 != 0)
            {
                Warning.WriteLine($"EANHeader.Zero1: {ean.Header.Zero1} => 0");
            }
            if (ean.Header.Zero2 != 0)
            {
                Warning.WriteLine($"EANHeader.Zero1: {ean.Header.Zero2} => 0");
            }
            result.SetAttributeValueWithDefault("NodeChild", ean.Header.NodeChild);
            result.SetAttributeValueWithDefault("NodeSibling", ean.Header.NodeSibling);
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockRotateX, "RotateX"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockRotateY, "RotateY"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockRotateZ, "RotateZ"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockScaleX, "ScaleX"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockScaleY, "ScaleY"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockScaleZ, "ScaleZ"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockTranslateX, "TranslateX"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockTranslateY, "TranslateY"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockTranslateZ, "TranslateZ"));
            return(result);
        }
Пример #4
0
 public Prism(XElement element)
 {
     element.GetAttributeValue(out Position, "Position");
     element.GetAttributeValueWithDefault(out Energy, "Energy", (byte)1);
     if (Energy != 1)
     {
         Warning.WriteLine(string.Format(Localization.DeprecatedAttribute, "Prism", "@Energy"));
     }
 }
Пример #5
0
 public Prism(BinaryReader reader)
 {
     Position = new Point3D16(reader);
     Energy   = reader.ReadByte();
     if (Energy != 1)
     {
         Warning.WriteLine(string.Format(Localization.DeprecatedAttribute, "Prism", "@Energy"));
     }
 }
Пример #6
0
 public CameraTrigger(XElement element)
 {
     element.GetAttributeValue(out Position, "Position");
     element.GetAttributeValueWithDefault(out Radius, "Radius");
     if (ValueIsAngle = element.AttributeCaseInsensitive("Angle") != null)
     {
         Value = element.GetAttributeValueWithDefault <short>("Angle", 22);
         if (element.AttributeCaseInsensitive("FieldOfView") != null)
         {
             Warning.WriteLine(string.Format(Localization.FieldOfViewIgnored, "CameraTrigger"));
         }
     }
     else if (!(Reset = element.AttributeCaseInsensitive("FieldOfView") == null))
     {
         Value = element.GetAttributeValueWithDefault <short>("FieldOfView", 22);
     }
     if ((Zoom = element.GetAttributeValueWithDefault("Zoom", (short)-1)) < 0)
     {
         Zoom = -1;
         element.GetAttributeValueWithDefault(out StartDelay, "StartDelay");
         element.GetAttributeValueWithDefault(out Duration, "Duration");
         element.GetAttributeValueWithDefault(out SingleUse, "SingleUse");
         if (Duration == 0)
         {
             Warning.WriteLine(Localization.CameraTriggerDisabled);
         }
         return;
     }
     if (!Reset)
     {
         Warning.WriteLine(string.Format(Localization.AdvancedCameraModeDisabled, "CameraTrigger",
                                         "@Reset, @Angle, @FieldOfView"));
     }
     if (element.AttributeCaseInsensitive("StartDelay") != null)
     {
         Warning.WriteLine(string.Format(
                               Localization.AdvancedCameraModeDisabled, "CameraTrigger", "@StartDelay"));
     }
     if (element.AttributeCaseInsensitive("Duration") != null)
     {
         Warning.WriteLine(string.Format(
                               Localization.AdvancedCameraModeDisabled, "CameraTrigger", "@Duration"));
     }
     if (element.AttributeCaseInsensitive("SingleUse") != null)
     {
         Warning.WriteLine(string.Format(
                               Localization.AdvancedCameraModeDisabled, "CameraTrigger", "@SingleUse"));
     }
 }
Пример #7
0
 public MovingPlatform(MovingPlatforms parent, BinaryReader reader) : this(parent)
 {
     AutoStart      = reader.ReadByte() != 0;
     LoopStartIndex = reader.ReadByte();
     Clones         = reader.ReadInt16();
     if (Clones != -1)
     {
         Warning.WriteLine(string.Format(Localization.DeprecatedAttribute, "MovingPlatform", "@Clones"));
     }
     FullBlock = reader.ReadBoolean();
     var count = reader.ReadByte();
     for (var i = 0; i < count; i++)
     {
         Waypoints.Add(new Waypoint(reader));
     }
 }
Пример #8
0
 public MovingPlatform(MovingPlatforms parent, XElement element) : this(parent)
 {
     id = element.GetAttributeValue("ID")?.Trim();
     var relatedTo = element.GetAttributeValue("RelatedTo");
     if (string.IsNullOrEmpty(relatedTo))
     {
         element.GetAttributeValueWithDefault(out AutoStart, "AutoStart", true);
         element.GetAttributeValueWithDefault(out LoopStartIndex, "LoopStartIndex", (byte)1);
         element.GetAttributeValueWithDefault(out Clones, "Clones", (short)-1);
         if (Clones != -1)
         {
             Warning.WriteLine(string.Format(Localization.DeprecatedAttribute, "MovingPlatform", "@Clones"));
         }
         element.GetAttributeValueWithDefault(out FullBlock, "FullBlock", true);
     }
     else
     {
         var relative = parent[relatedTo];
         element.GetAttributeValueWithDefault(out AutoStart, "AutoStart", relative.AutoStart);
         element.GetAttributeValueWithDefault(out LoopStartIndex, "LoopStartIndex", relative.LoopStartIndex);
         element.GetAttributeValueWithDefault(out Clones, "Clones", relative.Clones);
         if (Clones != -1)
         {
             Warning.WriteLine(string.Format(Localization.DeprecatedAttribute, "MovingPlatform", "@Clones"));
         }
         element.GetAttributeValueWithDefault(out FullBlock, "FullBlock", relative.FullBlock);
         var offset = element.GetAttributeValueWithDefault <Point3D16>("Offset");
         foreach (var waypoint in relative.Waypoints)
         {
             Waypoints.Add(new Waypoint
             {
                 Position   = waypoint.Position + offset,
                 PauseTime  = waypoint.PauseTime,
                 TravelTime = waypoint.TravelTime
             });
         }
     }
     foreach (var e in element.ElementsCaseInsensitive("Waypoint"))
     {
         Waypoints.Add(new Waypoint(e));
     }
 }
Пример #9
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();
            }
        }
Пример #10
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;
                }
            }
        }
Пример #11
0
        public OtherCube(Level parent, XElement element)
        {
            element.GetAttributeValue(out PositionTrigger, "PositionTrigger");
            var id   = element.GetAttributeValue("MovingBlockSync");
            var sync = id == null ? new IDReference <MovingPlatform>(parent.MovingPlatforms, -1)
                                  : new IDReference <MovingPlatform>(parent.MovingPlatforms, id);

            element.GetAttributeValueWithDefault(out DarkCubeRadius, "Radius");
            element.GetAttributeValue(out PositionCube, "PositionCube");
            foreach (var e in element.Elements())
            {
                try
                {
                    KeyEvents.Add(new KeyEvent(e));
                }
                catch
                {
                    if (!e.Name.LocalName.Equals("MovingPlatform", StringComparison.InvariantCultureIgnoreCase) &&
                        !e.Name.LocalName.Equals("Button", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Warning.WriteLine(string.Format(Localization.UnrecognizedChildElement, e.Name, element.Name));
                    }
                }
            }
            if (element.Name == "OtherCube")
            {
                MovingBlockSync = sync;
                var mode          = element.GetAttributeValueWithDefault("Mode", OtherCubeMode.AutoHide);
                var moveDirection = element.GetAttributeValueWithDefault("MoveDirection", GetDefaultDirection(mode));
                if (mode == OtherCubeMode.Hole)
                {
                    PositionTrigger -= moveDirection;
                }
                AddHelper(parent, mode, PositionTrigger, moveDirection, element);
                if (DarkCubeRadius.Equals(default(Point2D8)))
                {
                    return;
                }
                var radius = DarkCubeRadius;
                DarkCubeRadius = default(Point2D8);
                for (var x = -radius.X; x <= radius.X; x++)
                {
                    for (var y = -radius.Y; y <= radius.Y; y++)
                    {
                        if (x != 0 || y != 0)
                        {
                            var position = PositionTrigger + new Point3D16((short)x, (short)y, 0);
                            parent.OtherCubes.Add(new OtherCube
                            {
                                PositionTrigger = position,
                                MovingBlockSync = MovingBlockSync,
                                PositionCube    = PositionCube,
                                KeyEvents       = KeyEvents
                            });
                            AddHelper(parent, mode, position, moveDirection, element);
                        }
                    }
                }
            }
            else
            {
                MovingBlockSync         = new IDReference <MovingPlatform>(parent.MovingPlatforms, -2);
                DarkCubeMovingBlockSync = sync;
            }
        }