private void Load(string fileName) { try { //undoSnapshots.Clear(); UndoManager.Clear(); Level newLevel = (Level)serializer.Read(fileName); if (newLevel.Version < 2) { ErrorDialog.ShowError("Couldn't load level: Old Level Format not supported", "Supertux-Editor does not support Supertux-0.1.x levels"); return; } CurrentLevel = newLevel; this.fileName = fileName; Settings.Instance.addToRecentDocuments(fileName); Settings.Instance.Save(); UpdateUndoButtons(); UpdateTitlebar(); UpdateRecentDocuments(); UndoManager.MarkAsSaved(); ToolButtonCamera.Sensitive = true; } catch (Exception e) { ErrorDialog.Exception("Error loading level", e); } }
public void CustomLispRead(Properties Props) { foreach (Type type in this.GetType().Assembly.GetTypes()) { SupertuxObjectAttribute objectAttribute = (SupertuxObjectAttribute)Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (objectAttribute == null) { continue; } LispSerializer serializer = new LispSerializer(type); foreach (List list in Props.GetList(objectAttribute.Name)) { IGameObject Object = (IGameObject)serializer.Read(list); GameObjects.Add(Object); } } }
public static void ResaveLevel(string inFileName, string outFileName) { Console.WriteLine($"Datadir: {Settings.Instance.SupertuxData}"); LispSerializer serializer = new LispSerializer(typeof(Level)); Console.WriteLine($"loading {inFileName}"); Level level = (Level)serializer.Read(inFileName); if (level.Version < 2) { throw new Exception("Couldn't load level: Old Level Format not supported\n" + "Supertux-Editor does not support Supertux-0.1.x levels"); } else { Console.WriteLine($"saving {outFileName}"); serializer.Write(outFileName, level); } }
/// <summary>Loads the tiles from <paramref name="Resourcepath"/>.</summary> /// <param name="Resourcepath">A path relative to the data folder of SuperTux.</param> public Tileset(string Resourcepath) { baseDir = ResourceManager.Instance.GetDirectoryName(Resourcepath); List TilesL = Util.Load(Resourcepath, "supertux-tiles"); Properties TilesP = new Properties(TilesL); // add blank tile with ID 0 Tile blank = new Tile(); blank.Id = 0; while (tiles.Count <= blank.Id) { tiles.Add(null); } tiles[blank.Id] = blank; foreach (List list in TilesP.GetList("tile")) { try { Tile tile = new Tile(); ParseTile(tile, list); while (tiles.Count <= tile.Id) { tiles.Add(null); } tiles[tile.Id] = tile; } catch (Exception e) { LogManager.Log(LogLevel.Error, "Couldn't parse a Tile: " + e.Message); Console.WriteLine(e.StackTrace); } } foreach (List list in TilesP.GetList("tiles")) { try { ParseTiles(list); } catch (Exception e) { LogManager.Log(LogLevel.Error, "Couldn't parse a tiles: " + e.Message); Console.WriteLine(e.StackTrace); } } // construct a tilegroup with all tiles Tilegroup allGroup = new Tilegroup(); allGroup.Name = "All"; foreach (Tile tile in tiles) { if (tile != null) { allGroup.Tiles.Add(tile.Id); } } tilegroups.Add(allGroup.Name, allGroup); LispSerializer serializer = new LispSerializer(typeof(Tilegroup)); foreach (List list in TilesP.GetList("tilegroup")) { try { Tilegroup group = (Tilegroup)serializer.Read(list); for (int i = 0; i < group.Tiles.Count;) { if (!IsValid(group.Tiles[i])) { LogManager.Log(LogLevel.DebugWarning, "Tilegroup " + group.Name + " contains invalid TileID " + group.Tiles[i]); group.Tiles.RemoveAt(i); continue; } ++i; } tilegroups.Add(group.Name, group); } catch (Exception e) { LogManager.Log(LogLevel.Error, "Couldn't parse tilegroup: " + e.Message); Console.WriteLine(e.StackTrace); } } }
public void CustomLispRead(Properties Props) { if (SortObjectTags) { foreach (Type type in this.GetType().Assembly.GetTypes()) { SupertuxObjectAttribute objectAttribute = (SupertuxObjectAttribute)Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (objectAttribute == null) { continue; } LispSerializer serializer = new LispSerializer(type); foreach (List list in Props.GetList(objectAttribute.Name)) { try { IGameObject Object = (IGameObject)serializer.Read(list); GameObjects.Add(Object); } catch (System.NullReferenceException) { if (type == typeof(MusicObject) || type == typeof(AmbientLightObject)) { // ignore errors here due to the given fields being // turned from properties to objects } else { Console.WriteLine("Unexpected error while parsing object: {0} {1}", type, list); throw; } } } } } else { // FIXME: this is all just a hack to make the // editor not reorder the elements on load, // could be done nicer. foreach (List list in Props.GetList()) { foreach (Type type in this.GetType().Assembly.GetTypes()) { SupertuxObjectAttribute objectAttribute = (SupertuxObjectAttribute)Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (objectAttribute == null) { continue; } if (objectAttribute.Name == (list[0] as Symbol).Name) { LispSerializer serializer = new LispSerializer(type); IGameObject Object = (IGameObject)serializer.Read(list); GameObjects.Add(Object); break; } } } } }