Ejemplo n.º 1
0
        private static BinaryPacker.Element ReadElement(BinaryReader reader)
        {
            BinaryPacker.Element element = new BinaryPacker.Element();
            element.Name = BinaryPacker.stringLookup[(int)reader.ReadInt16()];
            byte num1 = reader.ReadByte();

            if (num1 > (byte)0)
            {
                element.Attributes = new Dictionary <string, object>();
            }
            for (int index = 0; index < (int)num1; ++index)
            {
                string key  = BinaryPacker.stringLookup[(int)reader.ReadInt16()];
                byte   num2 = reader.ReadByte();
                object obj  = (object)null;
                switch (num2)
                {
                case 0:
                    obj = (object)reader.ReadBoolean();
                    break;

                case 1:
                    obj = (object)Convert.ToInt32(reader.ReadByte());
                    break;

                case 2:
                    obj = (object)Convert.ToInt32(reader.ReadInt16());
                    break;

                case 3:
                    obj = (object)reader.ReadInt32();
                    break;

                case 4:
                    obj = (object)reader.ReadSingle();
                    break;

                case 5:
                    obj = (object)BinaryPacker.stringLookup[(int)reader.ReadInt16()];
                    break;

                case 6:
                    obj = (object)reader.ReadString();
                    break;

                case 7:
                    short num3 = reader.ReadInt16();
                    obj = (object)RunLengthEncoding.Decode(reader.ReadBytes((int)num3));
                    break;
                }
                element.Attributes.Add(key, obj);
            }
            short num4 = reader.ReadInt16();

            if (num4 > (short)0)
            {
                element.Children = new List <BinaryPacker.Element>();
            }
            for (int index = 0; index < (int)num4; ++index)
            {
                element.Children.Add(BinaryPacker.ReadElement(reader));
            }
            return(element);
        }
Ejemplo n.º 2
0
        public LevelData(BinaryPacker.Element data)
        {
            this.Bounds = new Rect();
            foreach (KeyValuePair <string, object> attribute in data.Attributes)
            {
                switch (attribute.Key)
                {
                case "alt_music":
                    this.AltMusic = (string)attribute.Value;
                    break;

                case "ambience":
                    this.Ambience = (string)attribute.Value;
                    break;

                case "ambienceProgress":
                    string s1 = attribute.Value.ToString();
                    if (string.IsNullOrEmpty(s1) || !int.TryParse(s1, out this.AmbienceProgress))
                    {
                        this.AmbienceProgress = -1;
                        break;
                    }
                    break;

                case "c":
                    this.EditorColorIndex = (int)attribute.Value;
                    break;

                case "cameraOffsetX":
                    this.CameraOffset.x = Convert.ToSingle(attribute.Value, (IFormatProvider)CultureInfo.InvariantCulture);
                    break;

                case "cameraOffsetY":
                    this.CameraOffset.y = Convert.ToSingle(attribute.Value, (IFormatProvider)CultureInfo.InvariantCulture);
                    break;

                case "dark":
                    this.Dark = (bool)attribute.Value;
                    break;

                case "delayAltMusicFade":
                    this.DelayAltMusic = (bool)attribute.Value;
                    break;

                case "disableDownTransition":
                    this.DisableDownTransition = (bool)attribute.Value;
                    break;

                case "enforceDashNumber":
                    this.EnforceDashNumber = (int)attribute.Value;
                    break;

                case "height":
                    this.Bounds.height = (int)attribute.Value;
                    if (this.Bounds.height == 184)
                    {
                        this.Bounds.height = 180;
                        break;
                    }
                    break;

                case "music":
                    this.Music = (string)attribute.Value;
                    break;

                case "musicLayer1":
                    this.MusicLayers[0] = (bool)attribute.Value ? 1f : 0.0f;
                    break;

                case "musicLayer2":
                    this.MusicLayers[1] = (bool)attribute.Value ? 1f : 0.0f;
                    break;

                case "musicLayer3":
                    this.MusicLayers[2] = (bool)attribute.Value ? 1f : 0.0f;
                    break;

                case "musicLayer4":
                    this.MusicLayers[3] = (bool)attribute.Value ? 1f : 0.0f;
                    break;

                case "musicProgress":
                    string s2 = attribute.Value.ToString();
                    if (string.IsNullOrEmpty(s2) || !int.TryParse(s2, out this.MusicProgress))
                    {
                        this.MusicProgress = -1;
                        break;
                    }
                    break;

                case "name":
                    this.Name = attribute.Value.ToString().Substring(4);
                    break;

                case "space":
                    this.Space = (bool)attribute.Value;
                    break;

                case "underwater":
                    this.Underwater = (bool)attribute.Value;
                    break;

                case "whisper":
                    this.MusicWhispers = (bool)attribute.Value;
                    break;

                case "width":
                    this.Bounds.width = (int)attribute.Value;
                    break;

                case "windPattern":
                    this.WindPattern = (WindController.Patterns)Enum.Parse(typeof(WindController.Patterns), (string)attribute.Value);
                    break;

                case "x":
                    this.Bounds.x = (int)attribute.Value;
                    break;

                case "y":
                    this.Bounds.y = (int)attribute.Value;
                    break;
                }
            }
            this.Spawns   = new List <Vector2>();
            this.Entities = new List <EntityData>();
            this.Triggers = new List <EntityData>();
            this.BgDecals = new List <DecalData>();
            this.FgDecals = new List <DecalData>();
            foreach (BinaryPacker.Element child1 in data.Children)
            {
                if (child1.Name == "entities")
                {
                    if (child1.Children != null)
                    {
                        foreach (BinaryPacker.Element child2 in child1.Children)
                        {
                            if (child2.Name == "player")
                            {
                                this.Spawns.Add(new Vector2((float)this.Bounds.x + Convert.ToSingle(child2.Attributes["x"], (IFormatProvider)CultureInfo.InvariantCulture), (float)this.Bounds.y + Convert.ToSingle(child2.Attributes["y"], (IFormatProvider)CultureInfo.InvariantCulture)));
                            }
                            else if (child2.Name == "strawberry" || child2.Name == "snowberry")
                            {
                                ++this.Strawberries;
                            }
                            else if (child2.Name == "shard")
                            {
                                this.HasGem = true;
                            }
                            else if (child2.Name == "blackGem")
                            {
                                this.HasHeartGem = true;
                            }
                            else if (child2.Name == "checkpoint")
                            {
                                this.HasCheckpoint = true;
                            }
                            if (!child2.Name.Equals("player"))
                            {
                                this.Entities.Add(this.CreateEntityData(child2));
                            }
                        }
                    }
                }
                else if (child1.Name == "triggers")
                {
                    if (child1.Children != null)
                    {
                        foreach (BinaryPacker.Element child2 in child1.Children)
                        {
                            this.Triggers.Add(this.CreateEntityData(child2));
                        }
                    }
                }
                else if (child1.Name == "bgdecals")
                {
                    if (child1.Children != null)
                    {
                        foreach (BinaryPacker.Element child2 in child1.Children)
                        {
                            this.BgDecals.Add(new DecalData()
                            {
                                Position = new Vector2(Convert.ToSingle(child2.Attributes["x"], (IFormatProvider)CultureInfo.InvariantCulture), Convert.ToSingle(child2.Attributes["y"], (IFormatProvider)CultureInfo.InvariantCulture)),
                                Scale    = new Vector2(Convert.ToSingle(child2.Attributes["scaleX"], (IFormatProvider)CultureInfo.InvariantCulture), Convert.ToSingle(child2.Attributes["scaleY"], (IFormatProvider)CultureInfo.InvariantCulture)),
                                Texture  = (string)child2.Attributes["texture"]
                            });
                        }
                    }
                }
                else if (child1.Name == "fgdecals")
                {
                    if (child1.Children != null)
                    {
                        foreach (BinaryPacker.Element child2 in child1.Children)
                        {
                            this.FgDecals.Add(new DecalData()
                            {
                                Position = new Vector2(Convert.ToSingle(child2.Attributes["x"], (IFormatProvider)CultureInfo.InvariantCulture), Convert.ToSingle(child2.Attributes["y"], (IFormatProvider)CultureInfo.InvariantCulture)),
                                Scale    = new Vector2(Convert.ToSingle(child2.Attributes["scaleX"], (IFormatProvider)CultureInfo.InvariantCulture), Convert.ToSingle(child2.Attributes["scaleY"], (IFormatProvider)CultureInfo.InvariantCulture)),
                                Texture  = (string)child2.Attributes["texture"]
                            });
                        }
                    }
                }
                else if (child1.Name == "solids")
                {
                    this.Solids = child1.Attr("innerText", "");
                }
                else if (child1.Name == "bg")
                {
                    this.Bg = child1.Attr("innerText", "");
                }
                else if (child1.Name == "fgtiles")
                {
                    this.FgTiles = child1.Attr("innerText", "");
                }
                else if (child1.Name == "bgtiles")
                {
                    this.BgTiles = child1.Attr("innerText", "");
                }
                else if (child1.Name == "objtiles")
                {
                    this.ObjTiles = child1.Attr("innerText", "");
                }
            }
            this.Dummy = this.Spawns.Count <= 0;
        }
Ejemplo n.º 3
0
        private Backdrop ParseBackdrop(BinaryPacker.Element child, BinaryPacker.Element above)
        {
            Backdrop backdrop;

            if (child.Name.Equals("parallax", StringComparison.OrdinalIgnoreCase))
            {
                string id   = child.Attr("texture", "");
                string str1 = child.Attr("atlas", "game");
                //Parallax parallax = new Parallax(!(str1 == "game") || !GFX.Game.Has(id) ? (!(str1 == "gui") || !GFX.Gui.Has(id) ? GFX.Misc[id] : GFX.Gui[id]) : GFX.Game[id]);
                Parallax parallax = null;
                if (Gfx.Game.Has(id))
                {
                    parallax = new Parallax(Gfx.Game[id]);
                }
                else
                {
                    parallax = new Parallax(Gfx.Misc[id]);
                }
                backdrop = (Backdrop)parallax;
                string str2 = "";
                if (child.HasAttr("blendmode"))
                {
                    str2 = child.Attr("blendmode", "alphablend").ToLower();
                }
                else if (above != null && above.HasAttr("blendmode"))
                {
                    str2 = above.Attr("blendmode", "alphablend").ToLower();
                }
                if (str2.Equals("additive"))
                {
                    parallax.BlendState = BlendState.defaultValue;
                }
                parallax.DoFadeIn = bool.Parse(child.Attr("fadeIn", "false"));
            }
            else if (child.Name.Equals("snowfg", StringComparison.OrdinalIgnoreCase))
            {
                backdrop = (Backdrop) new Snow(true);
            }
            else if (child.Name.Equals("snowbg", StringComparison.OrdinalIgnoreCase))
            {
                backdrop = (Backdrop) new Snow(false);
            }
            //else if (child.Name.Equals("windsnow", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new WindSnowFG();
            //else if (child.Name.Equals("dreamstars", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new DreamStars();
            //else if (child.Name.Equals("stars", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new StarsBG();
            //else if (child.Name.Equals("mirrorfg", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new MirrorFG();
            //else if (child.Name.Equals("reflectionfg", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new ReflectionFG();
            //else if (child.Name.Equals("godrays", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new Godrays();
            //else if (child.Name.Equals("tentacles", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new Tentacles((Tentacles.Side)Enum.Parse(typeof(Tentacles.Side), child.Attr("side", "Right")), Calc.HexToColor(child.Attr("color", "")), child.AttrFloat("offset", 0.0f));
            //else if (child.Name.Equals("northernlights", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new NorthernLights();
            //else if (child.Name.Equals("bossStarField", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new FinalBossStarfield();
            //else if (child.Name.Equals("petals", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new Petals();
            //else if (child.Name.Equals("heatwave", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new HeatWave();
            //else if (child.Name.Equals("corestarsfg", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new CoreStarsFG();
            //else if (child.Name.Equals("starfield", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new Starfield(Calc.HexToColor(child.Attr("color", "")), child.AttrFloat("speed", 1f));
            //else if (child.Name.Equals("planets", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new Planets((int)child.AttrFloat("count", 32f), child.Attr("size", "small"));
            //else if (child.Name.Equals("rain", StringComparison.OrdinalIgnoreCase))
            //    backdrop = (Backdrop)new RainFG();
            //else if (child.Name.Equals("stardust", StringComparison.OrdinalIgnoreCase))
            //{
            //    backdrop = (Backdrop)new StardustFG();
            //}
            else
            {
                if (!child.Name.Equals("blackhole", StringComparison.OrdinalIgnoreCase))
                {
                    throw new Exception("Background type " + child.Name + " does not exist");
                }
                backdrop = (Backdrop) new BlackholeBG();
            }
            if (child.HasAttr("tag"))
            {
                backdrop.Tags.Add(child.Attr("tag", ""));
            }
            if (above != null && above.HasAttr("tag"))
            {
                backdrop.Tags.Add(above.Attr("tag", ""));
            }
            if (child.HasAttr("x"))
            {
                backdrop.Position.x = child.AttrFloat("x", 0.0f);
            }
            else if (above != null && above.HasAttr("x"))
            {
                backdrop.Position.x = above.AttrFloat("x", 0.0f);
            }
            if (child.HasAttr("y"))
            {
                backdrop.Position.y = child.AttrFloat("y", 0.0f);
            }
            else if (above != null && above.HasAttr("y"))
            {
                backdrop.Position.y = above.AttrFloat("y", 0.0f);
            }
            if (child.HasAttr("scrollx"))
            {
                backdrop.Scroll.x = child.AttrFloat("scrollx", 0.0f);
            }
            else if (above != null && above.HasAttr("scrollx"))
            {
                backdrop.Scroll.x = above.AttrFloat("scrollx", 0.0f);
            }
            if (child.HasAttr("scrolly"))
            {
                backdrop.Scroll.y = child.AttrFloat("scrolly", 0.0f);
            }
            else if (above != null && above.HasAttr("scrolly"))
            {
                backdrop.Scroll.y = above.AttrFloat("scrolly", 0.0f);
            }
            if (child.HasAttr("speedx"))
            {
                backdrop.Speed.x = child.AttrFloat("speedx", 0.0f);
            }
            else if (above != null && above.HasAttr("speedx"))
            {
                backdrop.Speed.x = above.AttrFloat("speedx", 0.0f);
            }
            if (child.HasAttr("speedy"))
            {
                backdrop.Speed.y = child.AttrFloat("speedy", 0.0f);
            }
            else if (above != null && above.HasAttr("speedy"))
            {
                backdrop.Speed.y = above.AttrFloat("speedy", 0.0f);
            }
            backdrop.Color = Color.white;
            if (child.HasAttr("color"))
            {
                backdrop.Color = Util.HexToColor(child.Attr("color", ""));
            }
            else if (above != null && above.HasAttr("color"))
            {
                backdrop.Color = Util.HexToColor(above.Attr("color", ""));
            }
            if (child.HasAttr("alpha"))
            {
                backdrop.Color *= child.AttrFloat("alpha", 0.0f);
            }
            else if (above != null && above.HasAttr("alpha"))
            {
                backdrop.Color *= above.AttrFloat("alpha", 0.0f);
            }
            if (child.HasAttr("flipx"))
            {
                backdrop.FlipX = child.AttrBool("flipx", false);
            }
            else if (above != null && above.HasAttr("flipx"))
            {
                backdrop.FlipX = above.AttrBool("flipx", false);
            }
            if (child.HasAttr("flipy"))
            {
                backdrop.FlipY = child.AttrBool("flipy", false);
            }
            else if (above != null && above.HasAttr("flipy"))
            {
                backdrop.FlipY = above.AttrBool("flipy", false);
            }
            if (child.HasAttr("loopx"))
            {
                backdrop.LoopX = child.AttrBool("loopx", false);
            }
            else if (above != null && above.HasAttr("loopx"))
            {
                backdrop.LoopX = above.AttrBool("loopx", false);
            }
            if (child.HasAttr("loopy"))
            {
                backdrop.LoopY = child.AttrBool("loopy", false);
            }
            else if (above != null && above.HasAttr("loopy"))
            {
                backdrop.LoopY = above.AttrBool("loopy", false);
            }
            if (child.HasAttr("wind"))
            {
                backdrop.WindMultiplier = child.AttrFloat("wind", 0.0f);
            }
            else if (above != null && above.HasAttr("wind"))
            {
                backdrop.WindMultiplier = above.AttrFloat("wind", 0.0f);
            }
            string list1 = (string)null;

            if (child.HasAttr("exclude"))
            {
                list1 = child.Attr("exclude", "");
            }
            else if (above != null && above.HasAttr("exclude"))
            {
                list1 = above.Attr("exclude", "");
            }
            if (list1 != null)
            {
                backdrop.ExcludeFrom = this.ParseLevelsList(list1);
            }
            string list2 = (string)null;

            if (child.HasAttr("only"))
            {
                list2 = child.Attr("only", "");
            }
            else if (above != null && above.HasAttr("only"))
            {
                list2 = above.Attr("only", "");
            }
            if (list2 != null)
            {
                backdrop.OnlyIn = this.ParseLevelsList(list2);
            }
            string str3 = (string)null;

            if (child.HasAttr("flag"))
            {
                str3 = child.Attr("flag", "");
            }
            else if (above != null && above.HasAttr("flag"))
            {
                str3 = above.Attr("flag", "");
            }
            if (str3 != null)
            {
                backdrop.OnlyIfFlag = str3;
            }
            string str4 = (string)null;

            if (child.HasAttr("notflag"))
            {
                str4 = child.Attr("notflag", "");
            }
            else if (above != null && above.HasAttr("notflag"))
            {
                str4 = above.Attr("notflag", "");
            }
            if (str4 != null)
            {
                backdrop.OnlyIfNotFlag = str4;
            }
            string str5 = (string)null;

            if (child.HasAttr("always"))
            {
                str5 = child.Attr("always", "");
            }
            else if (above != null && above.HasAttr("always"))
            {
                str5 = above.Attr("always", "");
            }
            if (str5 != null)
            {
                backdrop.AlsoIfFlag = str5;
            }
            bool?nullable = new bool?();

            if (child.HasAttr("dreaming"))
            {
                nullable = new bool?(child.AttrBool("dreaming", false));
            }
            else if (above != null && above.HasAttr("dreaming"))
            {
                nullable = new bool?(above.AttrBool("dreaming", false));
            }
            if (nullable.HasValue)
            {
                backdrop.Dreaming = nullable;
            }
            if (child.HasAttr("instantIn"))
            {
                backdrop.InstantIn = child.AttrBool("instantIn", false);
            }
            else if (above != null && above.HasAttr("instantIn"))
            {
                backdrop.InstantIn = above.AttrBool("instantIn", false);
            }
            if (child.HasAttr("instantOut"))
            {
                backdrop.InstantOut = child.AttrBool("instantOut", false);
            }
            else if (above != null && above.HasAttr("instantOut"))
            {
                backdrop.InstantOut = above.AttrBool("instantOut", false);
            }
            string str6 = (string)null;

            if (child.HasAttr("fadex"))
            {
                str6 = child.Attr("fadex", "");
            }
            else if (above != null && above.HasAttr("fadex"))
            {
                str6 = above.Attr("fadex", "");
            }
            if (str6 != null)
            {
                backdrop.FadeX = new Backdrop.Fader();
                string str1     = str6;
                char[] chArray1 = new char[1] {
                    ':'
                };
                foreach (string str2 in str1.Split(chArray1))
                {
                    char[] chArray2 = new char[1] {
                        ','
                    };
                    string[] strArray1 = str2.Split(chArray2);
                    if (strArray1.Length == 2)
                    {
                        string[] strArray2 = strArray1[0].Split('-');
                        string[] strArray3 = strArray1[1].Split('-');
                        float    fadeFrom  = float.Parse(strArray3[0], (IFormatProvider)CultureInfo.InvariantCulture);
                        float    fadeTo    = float.Parse(strArray3[1], (IFormatProvider)CultureInfo.InvariantCulture);
                        int      num1      = 1;
                        int      num2      = 1;
                        if (strArray2[0][0] == 'n')
                        {
                            num1         = -1;
                            strArray2[0] = strArray2[0].Substring(1);
                        }
                        if (strArray2[1][0] == 'n')
                        {
                            num2         = -1;
                            strArray2[1] = strArray2[1].Substring(1);
                        }
                        backdrop.FadeX.Add((float)(num1 * int.Parse(strArray2[0])), (float)(num2 * int.Parse(strArray2[1])), fadeFrom, fadeTo);
                    }
                }
            }
            string str7 = (string)null;

            if (child.HasAttr("fadey"))
            {
                str7 = child.Attr("fadey", "");
            }
            else if (above != null && above.HasAttr("fadey"))
            {
                str7 = above.Attr("fadey", "");
            }
            if (str7 != null)
            {
                backdrop.FadeY = new Backdrop.Fader();
                string str1     = str7;
                char[] chArray1 = new char[1] {
                    ':'
                };
                foreach (string str2 in str1.Split(chArray1))
                {
                    char[] chArray2 = new char[1] {
                        ','
                    };
                    string[] strArray1 = str2.Split(chArray2);
                    if (strArray1.Length == 2)
                    {
                        string[] strArray2 = strArray1[0].Split('-');
                        string[] strArray3 = strArray1[1].Split('-');
                        float    fadeFrom  = float.Parse(strArray3[0], (IFormatProvider)CultureInfo.InvariantCulture);
                        float    fadeTo    = float.Parse(strArray3[1], (IFormatProvider)CultureInfo.InvariantCulture);
                        int      num1      = 1;
                        int      num2      = 1;
                        if (strArray2[0][0] == 'n')
                        {
                            num1         = -1;
                            strArray2[0] = strArray2[0].Substring(1);
                        }
                        if (strArray2[1][0] == 'n')
                        {
                            num2         = -1;
                            strArray2[1] = strArray2[1].Substring(1);
                        }
                        backdrop.FadeY.Add((float)(num1 * int.Parse(strArray2[0])), (float)(num2 * int.Parse(strArray2[1])), fadeFrom, fadeTo);
                    }
                }
            }
            backdrop.OnRefresh();
            return(backdrop);
        }
Ejemplo n.º 4
0
        private EntityData CreateEntityData(BinaryPacker.Element entity)
        {
            EntityData entityData = new EntityData();

            entityData.Name  = entity.Name;
            entityData.Level = this;
            if (entity.Attributes != null)
            {
                foreach (KeyValuePair <string, object> attribute in entity.Attributes)
                {
                    if (attribute.Key == "id")
                    {
                        entityData.ID = (int)attribute.Value;
                    }
                    else if (attribute.Key == "x")
                    {
                        entityData.Position.x = Convert.ToSingle(attribute.Value, (IFormatProvider)CultureInfo.InvariantCulture);
                    }
                    else if (attribute.Key == "y")
                    {
                        entityData.Position.y = Convert.ToSingle(attribute.Value, (IFormatProvider)CultureInfo.InvariantCulture);
                    }
                    else if (attribute.Key == "width")
                    {
                        entityData.Width = (int)attribute.Value;
                    }
                    else if (attribute.Key == "height")
                    {
                        entityData.Height = (int)attribute.Value;
                    }
                    else if (attribute.Key == "originX")
                    {
                        entityData.Origin.x = Convert.ToSingle(attribute.Value, (IFormatProvider)CultureInfo.InvariantCulture);
                    }
                    else if (attribute.Key == "originY")
                    {
                        entityData.Origin.y = Convert.ToSingle(attribute.Value, (IFormatProvider)CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        if (entityData.Values == null)
                        {
                            entityData.Values = new Dictionary <string, object>();
                        }
                        entityData.Values.Add(attribute.Key, attribute.Value);
                    }
                }
            }
            entityData.Nodes = new Vector2[entity.Children == null ? 0 : entity.Children.Count];
            for (int index = 0; index < entityData.Nodes.Length; ++index)
            {
                foreach (KeyValuePair <string, object> attribute in entity.Children[index].Attributes)
                {
                    if (attribute.Key == "x")
                    {
                        entityData.Nodes[index].x = Convert.ToSingle(attribute.Value, (IFormatProvider)CultureInfo.InvariantCulture);
                    }
                    else if (attribute.Key == "y")
                    {
                        entityData.Nodes[index].y = Convert.ToSingle(attribute.Value, (IFormatProvider)CultureInfo.InvariantCulture);
                    }
                }
            }
            return(entityData);
        }
Ejemplo n.º 5
0
        private void Load()
        {
            if (!File.Exists(this.Filepath))
            {
                return;
            }
            this.Strawberries = new List <EntityData>();
            BinaryPacker.Element element = BinaryPacker.FromBinary(this.Filepath);
            //string file = JsonConvert.SerializeObject(element);
            //File.WriteAllText("F:/test.json", file);
            if (!element.Package.Equals(this.ModeData.Path))
            {
                throw new Exception("Corrupted Level Data");
            }
            foreach (BinaryPacker.Element child1 in element.Children)
            {
                if (child1.Name == "levels")
                {
                    this.Levels = new List <LevelData>();
                    foreach (BinaryPacker.Element child2 in child1.Children)
                    {
                        LevelData levelData = new LevelData(child2);
                        this.DetectedStrawberries += levelData.Strawberries;
                        if (levelData.HasGem)
                        {
                            this.DetectedRemixNotes = true;
                        }
                        if (levelData.HasHeartGem)
                        {
                            this.DetectedHeartGem = true;
                        }
                        this.Levels.Add(levelData);
                    }
                }
                else if (child1.Name == "Filler")
                {
                    this.Filler = new List <Rectangle>();
                    if (child1.Children != null)
                    {
                        foreach (BinaryPacker.Element child2 in child1.Children)
                        {
                            this.Filler.Add(new Rectangle((int)child2.Attributes["x"], (int)child2.Attributes["y"], (int)child2.Attributes["w"], (int)child2.Attributes["h"]));
                        }
                    }
                }
                else if (child1.Name == "Style")
                {
                    if (child1.HasAttr("color"))
                    {
                        this.BackgroundColor = Util.HexToColor(child1.Attr("color", ""));
                    }
                    if (child1.Children != null)
                    {
                        foreach (BinaryPacker.Element child2 in child1.Children)
                        {
                            if (child2.Name == "Backgrounds")
                            {
                                this.Background = child2;
                            }
                            else if (child2.Name == "Foregrounds")
                            {
                                this.Foreground = child2;
                            }
                        }
                    }
                }
            }
            foreach (LevelData level in this.Levels)
            {
                foreach (EntityData entity in level.Entities)
                {
                    if (entity.Name == "strawberry")
                    {
                        this.Strawberries.Add(entity);
                    }
                    else if (entity.Name == "goldenBerry")
                    {
                        this.Goldenberries.Add(entity);
                    }
                }
            }
            int num1 = int.MaxValue;
            int num2 = int.MaxValue;
            int num3 = int.MinValue;
            int num4 = int.MinValue;

            foreach (LevelData level in this.Levels)
            {
                if (level.Bounds.xMin < num1)
                {
                    num1 = Mathf.RoundToInt(level.Bounds.xMin);
                }
                if (level.Bounds.top < num2)
                {
                    num2 = Mathf.RoundToInt(level.Bounds.top);
                }
                if (level.Bounds.xMax > num3)
                {
                    num3 = Mathf.RoundToInt(level.Bounds.xMax);
                }
                if (level.Bounds.bottom > num4)
                {
                    num4 = Mathf.RoundToInt(level.Bounds.bottom);
                }
            }
            foreach (Rectangle rectangle in this.Filler)
            {
                if (rectangle.Left < num1)
                {
                    num1 = rectangle.Left;
                }
                if (rectangle.Top < num2)
                {
                    num2 = rectangle.Top;
                }
                if (rectangle.Right > num3)
                {
                    num3 = rectangle.Right;
                }
                if (rectangle.Bottom > num4)
                {
                    num4 = rectangle.Bottom;
                }
            }
            int num5 = 64;

            this.Bounds = new Rectangle(num1 - num5, num2 - num5, num3 - num1 + num5 * 2, num4 - num2 + num5 * 2);
            this.ModeData.TotalStrawberries        = 0;
            this.ModeData.StartStrawberries        = 0;
            this.ModeData.StrawberriesByCheckpoint = new EntityData[10, 25];
            for (int index = 0; this.ModeData.Checkpoints != null && index < this.ModeData.Checkpoints.Length; ++index)
            {
                if (this.ModeData.Checkpoints[index] != null)
                {
                    this.ModeData.Checkpoints[index].Strawberries = 0;
                }
            }
            foreach (EntityData strawberry in this.Strawberries)
            {
                if (!strawberry.Bool("moon", false))
                {
                    int index1 = strawberry.Int("checkpointID", 0);
                    int index2 = strawberry.Int("order", 0);
                    if (this.ModeData.StrawberriesByCheckpoint[index1, index2] == null)
                    {
                        this.ModeData.StrawberriesByCheckpoint[index1, index2] = strawberry;
                    }
                    if (index1 == 0)
                    {
                        ++this.ModeData.StartStrawberries;
                    }
                    else if (this.ModeData.Checkpoints != null)
                    {
                        ++this.ModeData.Checkpoints[index1 - 1].Strawberries;
                    }
                    ++this.ModeData.TotalStrawberries;
                }
            }
        }