From f5db9861eada1c83e39d264d0301a12a233011bf Mon Sep 17 00:00:00 2001 From: cubeww <761397398@qq.com> Date: Sun, 3 Nov 2019 10:12:24 +0800 Subject: [PATCH] Update ExportToProject.csx --- ExportToProject.csx | 47 ++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/ExportToProject.csx b/ExportToProject.csx index 4893f90..cdcd433 100644 --- a/ExportToProject.csx +++ b/ExportToProject.csx @@ -13,7 +13,6 @@ using UndertaleModLib.Decompiler; int progress = 0; string projFolder = GetFolder(FilePath) + "Export_Project" + Path.DirectorySeparatorChar; -var context = new DecompileContext(Data, true); TextureWorker worker = new TextureWorker(); ThreadLocal DECOMPILE_CONTEXT = new ThreadLocal(() => new DecompileContext(Data, false)); string gmxDeclaration = "This Document is generated by GameMaker, if you edit it by hand then you do so at your own risk!"; @@ -28,47 +27,45 @@ Directory.CreateDirectory(projFolder); // --------------- Start exporting --------------- -var resourceNum = 10; +var resourceNum = Data.Sprites.Count + + Data.Backgrounds.Count + + Data.GameObjects.Count + + Data.Rooms.Count + + Data.Sounds.Count + + Data.Scripts.Count + + Data.Fonts.Count + + Data.Paths.Count + + Data.Timelines.Count; // Export sprites -UpdateProgressBar(null, "Exporting sprites...", progress++, resourceNum); await ExportSprites(); // Export backgrounds -UpdateProgressBar(null, "Exporting backgrounds...", progress++, resourceNum); await ExportBackground(); // Export objects -UpdateProgressBar(null, "Exporting objects...", progress++, resourceNum); await ExportGameObjects(); // Export rooms -UpdateProgressBar(null, "Exporting rooms...", progress++, resourceNum); await ExportRooms(); // Export sounds -UpdateProgressBar(null, "Exporting sounds...", progress++, resourceNum); await ExportSounds(); // Export scripts -UpdateProgressBar(null, "Exporting scripts...", progress++, resourceNum); await ExportScripts(); // Export fonts -UpdateProgressBar(null, "Exporting fonts...", progress++, resourceNum); await ExportFonts(); // Export paths -UpdateProgressBar(null, "Exporting paths...", progress++, resourceNum); await ExportPaths(); // Export timelines -UpdateProgressBar(null, "Exporting timelines...", progress++, resourceNum); await ExportTimelines(); // Generate project file -UpdateProgressBar(null, "Generating project file...", progress++, resourceNum); -ExportProjectFile(); +GenerateProjectFile(); // --------------- Export completed --------------- worker.Cleanup(); @@ -93,6 +90,8 @@ async Task ExportSprites() } void ExportSprite(UndertaleSprite sprite) { + UpdateProgressBar(null, $"Exporting sprite: {sprite.Name.Content}", progress++, resourceNum); + // Save the sprite GMX var gmx = new XDocument( new XComment(gmxDeclaration), @@ -163,6 +162,8 @@ async Task ExportBackground() } void ExportBackground(UndertaleBackground background) { + UpdateProgressBar(null, $"Exporting background: {background.Name.Content}", progress++, resourceNum); + // Save the backgound GMX var gmx = new XDocument( new XComment(gmxDeclaration), @@ -199,6 +200,8 @@ async Task ExportGameObjects() } void ExportGameObject(UndertaleGameObject gameObject) { + UpdateProgressBar(null, $"Exporting object: {gameObject.Name.Content}", progress++, resourceNum); + // Save the object GMX var gmx = new XDocument( new XComment(gmxDeclaration), @@ -286,6 +289,8 @@ async Task ExportRooms() } void ExportRoom(UndertaleRoom room) { + UpdateProgressBar(null, $"Exporting room: {room.Name.Content}", progress++, resourceNum); + // Save the room GMX var gmx = new XDocument( new XComment(gmxDeclaration), @@ -299,7 +304,7 @@ void ExportRoom(UndertaleRoom room) new XElement("speed", room.Speed.ToString()), new XElement("persistent", BoolToString(room.Persistent)), new XElement("colour", room.BackgroundColor.ToString()), - new XElement("code", room.CreationCodeId is null ? "" : Decompiler.Decompile(room.CreationCodeId, context)), + new XElement("code", room.CreationCodeId != null ? Decompiler.Decompile(room.CreationCodeId, DECOMPILE_CONTEXT.Value) : ""), new XElement("enableViews", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.EnableViews))), new XElement("clearViewBackground", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ShowColor))), new XElement("clearDisplayBuffer", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ClearDisplayBuffer))) @@ -407,6 +412,8 @@ async Task ExportSounds() } void ExportSound(UndertaleSound sound) { + UpdateProgressBar(null, $"Exporting sound: {sound.Name.Content}", progress++, resourceNum); + // Save the sound GMX var gmx = new XDocument( new XComment(gmxDeclaration), @@ -451,6 +458,8 @@ async Task ExportScripts() } void ExportScript(UndertaleScript script) { + UpdateProgressBar(null, $"Exporting script: {script.Name.Content}", progress++, resourceNum); + // Save GML files File.WriteAllText(projFolder + "/scripts/" + script.Name.Content + ".gml", (script.Code != null ? Decompiler.Decompile(script.Code, DECOMPILE_CONTEXT.Value) : "")); } @@ -463,6 +472,8 @@ async Task ExportFonts() } void ExportFont(UndertaleFont font) { + UpdateProgressBar(null, $"Exporting font: {font.Name.Content}", progress++, resourceNum); + // Save the font GMX var gmx = new XDocument( new XComment(gmxDeclaration), @@ -516,6 +527,8 @@ async Task ExportPaths() } void ExportPath(UndertalePath path) { + UpdateProgressBar(null, $"Exporting path: {path.Name.Content}", progress++, resourceNum); + // Save the path GMX var gmx = new XDocument( new XComment(gmxDeclaration), @@ -548,6 +561,8 @@ async Task ExportTimelines() } void ExportTimeline(UndertaleTimeline timeline) { + UpdateProgressBar(null, $"Exporting timeline: {timeline.Name.Content}", progress++, resourceNum); + // Save the timeline GMX var gmx = new XDocument( new XComment(gmxDeclaration), @@ -591,8 +606,10 @@ void ExportTimeline(UndertaleTimeline timeline) // --------------- Generate project file --------------- -void ExportProjectFile() +void GenerateProjectFile() { + UpdateProgressBar(null, $"Generating project file...", progress++, resourceNum); + var gmx = new XDocument( new XComment(gmxDeclaration), new XElement("assets")