public static void Main(string[] args) { LispSerializer.SetupSerializers(typeof(Application).Assembly); Gtk.Application.Init(); Application app = new Application(args); #if !INSANEDEBUG try { #endif Gtk.Application.Run(); #if !INSANEDEBUG } catch (Exception e) { if (app.level != null) { string filename = System.IO.Path.GetTempPath() + "/supertux-editor-emergency." + ((app.level.isWorldmap)?"stwm":"stl"); LogManager.Log(LogLevel.Fatal, "Unexpected Exception... Emergency save to '" + filename + "'"); Console.Error.WriteLine(e.Message); app.serializer.Write(filename, app.level); } throw; } #endif Settings.Instance.Save(); }
public void CustomLispWrite(Writer Writer) { if (SortObjectTags) { var attributes = new List <Tuple <Type, SupertuxObjectAttribute> >(); foreach (Type type in GetType().Assembly.GetTypes()) { var attr = (SupertuxObjectAttribute)Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (attr != null) { attributes.Add(Tuple.Create(type, attr)); } } attributes.Sort((lhs, rhs) => lhs.Item2.Name.CompareTo(rhs.Item2.Name)); foreach (var attr in attributes) { LispSerializer serializer = new LispSerializer(attr.Item1); foreach (var obj in GetObjects(attr.Item1)) { serializer.Write(Writer, attr.Item2.Name, obj); } } } else { foreach (object obj in GetObjects()) { Type type = obj.GetType(); SupertuxObjectAttribute objectAttribute = (SupertuxObjectAttribute) Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (objectAttribute == null) { continue; } string name = objectAttribute.Name; LispSerializer serializer = new LispSerializer(type); serializer.Write(Writer, name, obj); } } }
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); } }
public void CustomLispWrite(Writer Writer) { Type[] types = this.GetType().Assembly.GetTypes(); Array.Sort(types, CompareTypeNames); foreach (Type type in types) { SupertuxObjectAttribute objectAttribute = (SupertuxObjectAttribute) Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (objectAttribute == null) { continue; } string name = objectAttribute.Name; LispSerializer serializer = new LispSerializer(type); foreach (object Object in GetObjects(type)) { serializer.Write(Writer, name, Object); } } }
public static void Main(string[] args) { // FIXME: 2018-10-12 // Temporary workaround to solve incompatibility of mono with ncurses6 // See: https://github.com/mono/mono/issues/6752 System.Environment.SetEnvironmentVariable("TERM", "xterm"); LispSerializer.SetupSerializers(typeof(Application).Assembly); Options opts = ParseArgs(args); if (opts.NoSort) { Sector.SortObjectTags = false; } if (opts.Help) { Console.WriteLine("Usage: supertux-editor.exe [--help|--resave|--no-sort] [FILENAME]..."); Console.WriteLine(); Console.WriteLine("A SuperTux level editor"); Console.WriteLine(); Console.WriteLine(" FILENAME A level or worldmap to load"); Console.WriteLine(" -h, --help Print this help"); Console.WriteLine(" --resave Load a level, save it and exit"); Console.WriteLine(" --no-sort Don't sort object tags"); } else if (opts.Resave) { var failedFiles = new List <string>(); foreach (var fileName in opts.FileNames) { try { ResaveLevel(fileName, fileName); } catch (Exception e) { LogManager.Log(LogLevel.Fatal, $"{fileName}: error while resaving the level:\n{e}"); failedFiles.Add(fileName); } } if (failedFiles.Count > 0) { Console.WriteLine("Files that failed to resave:"); foreach (var fileName in failedFiles) { Console.WriteLine($" {fileName}"); } } } else { Gtk.Application.Init(); Application app = new Application(opts); #if !INSANEDEBUG try { #endif Gtk.Application.Run(); #if !INSANEDEBUG } catch (Exception e) { if (app.level != null) { string filename = System.IO.Path.GetTempPath() + "/supertux-editor-emergency." + ((app.level.isWorldmap)?"stwm":"stl"); LogManager.Log(LogLevel.Fatal, "Unexpected Exception... Emergency save to '" + filename + "'"); Console.Error.WriteLine(e.Message); app.serializer.Write(filename, app.level); } throw; } #endif Settings.Instance.Save(); } }
/// <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; } } } } }