public bool Load(string filename) { XDocument xDoc; string[] levelData = null; string[] compressData = null; SpriteData.Clear(); Pointers.Clear(); try { xDoc = XDocument.Load(filename); } catch { return false; } XElement level = xDoc.Element("level"); foreach (var a in level.Attributes()) { switch (a.Name.LocalName) { case "layout": LevelLayout = (LevelLayout)Enum.Parse(typeof(LevelLayout), a.Value, true); break; case "guid": Guid = a.Value.ToGuid(); break; case "type": Type = a.Value.ToInt(); break; case "clearvalue": ClearValue = a.Value.ToInt(); break; case "graphicsbank": GraphicsBank = a.Value.ToInt(); break; case "music": Music = a.Value.ToInt(); break; case "length": Length = a.Value.ToInt(); break; case "time": Time = a.Value.ToInt(); break; case "xstart": XStart = a.Value.ToInt(); break; case "ystart": YStart = a.Value.ToInt(); break; case "invincibleenemies": InvincibleEnemies = a.Value.ToBoolean(); break; case "vineblocked": VineBlocked = a.Value.ToBoolean(); break; case "paletteeffect": PaletteEffect = a.Value.ToInt(); break; case "palette": Palette = a.Value.ToInt(); break; case "scrolltype": ScrollType = a.Value.ToInt(); break; case "animationtype": AnimationType = a.Value.ToInt(); break; case "startaction": StartAction = a.Value.ToInt(); break; case "leveldata": levelData = a.Value.Split(','); break; case "compresseddata": compressData = a.Value.Split(','); break; case "challengeleveltype": ChallengeType = a.Value.ToInt(); break; case "specialleveltype": SpecialLevelType = a.Value.ToInt(); break; case "misc1": MiscByte1 = a.Value.ToInt(); break; case "misc2": MiscByte2 = a.Value.ToInt(); break; case "misc3": MiscByte3 = a.Value.ToInt(); break; case "tempprojeffects": ProjectileBlocksTemporary = a.Value.ToBoolean(); break; case "rhythm": RhythmPlatforms = a.Value.ToBoolean(); break; case "dpadtiles": DpadTiles = a.Value.ToBoolean(); break; } } int xPointer = 0, yPointer = 0; int[] tileCount = new int[256]; foreach (var c in levelData) { LevelData[xPointer, yPointer] = (byte)c.ToInt(); tileCount[c.ToInt()]++; xPointer++; if (xPointer >= Width) { xPointer = 0; yPointer++; if (yPointer > Height) break; } } int highestTileCount = -1; for (int i = 0; i < 256; i++) { if (tileCount[i] > highestTileCount) { highestTileCount = MostCommonTile = i; } } foreach (var x in level.Elements()) { switch (x.Name.LocalName) { case "spritedata": foreach (var spr in x.Elements("sprite")) { Sprite s = new Sprite(); s.LoadFromElement(spr); SpriteData.Add(s); } break; case "pointers": foreach (var ptr in x.Elements("pointer")) { LevelPointer p = new LevelPointer(); p.LoadFromElement(ptr); Pointers.Add(p); } break; case "settings": Settings.LoadFromElement(x); break; } } return true; }
public bool Load(string filename) { string[] compressData = null; string[] levelData = null; XDocument xDoc; try { xDoc = XDocument.Load(filename); } catch { return(false); } XElement world = xDoc.Element("world"); foreach (var a in world.Attributes()) { switch (a.Name.LocalName) { case "guid": Guid = a.Value.ToGuid(); break; case "graphicsbank": GraphicsBank = a.Value.ToInt(); break; case "music": Music = a.Value.ToInt(); break; case "length": Length = a.Value.ToInt(); break; case "palette": Palette = a.Value.ToInt(); break; case "compresseddata": compressData = a.Value.Split(','); break; case "worlddata": levelData = a.Value.Split(','); break; } } int xPointer = 0, yPointer = 0; foreach (var c in levelData) { LevelData[xPointer, yPointer] = (byte)c.ToInt(); xPointer++; if (xPointer >= Width) { xPointer = 0; yPointer++; if (yPointer > Height) { break; } } } SpriteData.Clear(); Pointers.Clear(); foreach (var x in world.Elements()) { switch (x.Name.LocalName) { case "spritedata": foreach (var spr in x.Elements("sprite")) { Sprite s = new Sprite(); s.LoadFromElement(spr); SpriteData.Add(s); } break; case "pointers": foreach (var ptr in x.Elements("pointer")) { WorldPointer p = new WorldPointer(); p.LoadFromElement(ptr); Pointers.Add(p); } break; case "settings": Settings.LoadFromElement(x); break; } } return(true); }
public bool Load(string filename) { string[] compressData = null; string[] levelData = null; XDocument xDoc; try { xDoc = XDocument.Load(filename); } catch { return false; } XElement world = xDoc.Element("world"); foreach (var a in world.Attributes()) { switch (a.Name.LocalName) { case "guid": Guid = a.Value.ToGuid(); break; case "graphicsbank": GraphicsBank = a.Value.ToInt(); break; case "music": Music = a.Value.ToInt(); break; case "length": Length = a.Value.ToInt(); break; case "palette": Palette = a.Value.ToInt(); break; case "compresseddata": compressData = a.Value.Split(','); break; case "worlddata": levelData = a.Value.Split(','); break; } } int xPointer = 0, yPointer = 0; foreach (var c in levelData) { LevelData[xPointer, yPointer] = (byte)c.ToInt(); xPointer++; if (xPointer >= Width) { xPointer = 0; yPointer++; if (yPointer > Height) break; } } SpriteData.Clear(); Pointers.Clear(); foreach (var x in world.Elements()) { switch (x.Name.LocalName) { case "spritedata": foreach (var spr in x.Elements("sprite")) { Sprite s = new Sprite(); s.LoadFromElement(spr); SpriteData.Add(s); } break; case "pointers": foreach (var ptr in x.Elements("pointer")) { WorldPointer p = new WorldPointer(); p.LoadFromElement(ptr); Pointers.Add(p); } break; case "settings": Settings.LoadFromElement(x); break; } } return true; }
public bool Load(string filename) { XDocument xDoc; string[] levelData = null; string[] compressData = null; SpriteData.Clear(); Pointers.Clear(); try { xDoc = XDocument.Load(filename); } catch { return(false); } XElement level = xDoc.Element("level"); foreach (var a in level.Attributes()) { switch (a.Name.LocalName) { case "layout": LevelLayout = (LevelLayout)Enum.Parse(typeof(LevelLayout), a.Value, true); break; case "guid": Guid = a.Value.ToGuid(); break; case "type": Type = a.Value.ToInt(); break; case "clearvalue": ClearValue = a.Value.ToInt(); break; case "graphicsbank": GraphicsBank = a.Value.ToInt(); break; case "music": Music = a.Value.ToInt(); break; case "length": Length = a.Value.ToInt(); break; case "time": Time = a.Value.ToInt(); break; case "xstart": XStart = a.Value.ToInt(); break; case "ystart": YStart = a.Value.ToInt(); break; case "invincibleenemies": InvincibleEnemies = a.Value.ToBoolean(); break; case "vineblocked": VineBlocked = a.Value.ToBoolean(); break; case "paletteeffect": PaletteEffect = a.Value.ToInt(); break; case "palette": Palette = a.Value.ToInt(); break; case "scrolltype": ScrollType = a.Value.ToInt(); break; case "animationtype": AnimationType = a.Value.ToInt(); break; case "startaction": StartAction = a.Value.ToInt(); break; case "leveldata": levelData = a.Value.Split(','); break; case "compresseddata": compressData = a.Value.Split(','); break; case "challengeleveltype": ChallengeType = a.Value.ToInt(); break; case "specialleveltype": SpecialLevelType = a.Value.ToInt(); break; case "misc1": MiscByte1 = a.Value.ToInt(); break; case "misc2": MiscByte2 = a.Value.ToInt(); break; case "misc3": MiscByte3 = a.Value.ToInt(); break; case "tempprojeffects": ProjectileBlocksTemporary = a.Value.ToBoolean(); break; case "rhythm": RhythmPlatforms = a.Value.ToBoolean(); break; case "dpadtiles": DpadTiles = a.Value.ToBoolean(); break; } } int xPointer = 0, yPointer = 0; int[] tileCount = new int[256]; foreach (var c in levelData) { LevelData[xPointer, yPointer] = (byte)c.ToInt(); tileCount[c.ToInt()]++; xPointer++; if (xPointer >= Width) { xPointer = 0; yPointer++; if (yPointer > Height) { break; } } } int highestTileCount = -1; for (int i = 0; i < 256; i++) { if (tileCount[i] > highestTileCount) { highestTileCount = MostCommonTile = i; } } foreach (var x in level.Elements()) { switch (x.Name.LocalName) { case "spritedata": foreach (var spr in x.Elements("sprite")) { Sprite s = new Sprite(); s.LoadFromElement(spr); SpriteData.Add(s); } break; case "pointers": foreach (var ptr in x.Elements("pointer")) { LevelPointer p = new LevelPointer(); p.LoadFromElement(ptr); Pointers.Add(p); } break; case "settings": Settings.LoadFromElement(x); break; } } return(true); }