Update ExportToProject.csx

This commit is contained in:
cubeww 2019-11-03 10:12:24 +08:00
parent 88bf8eac37
commit f5db9861ea

View file

@ -13,7 +13,6 @@ using UndertaleModLib.Decompiler;
int progress = 0; int progress = 0;
string projFolder = GetFolder(FilePath) + "Export_Project" + Path.DirectorySeparatorChar; string projFolder = GetFolder(FilePath) + "Export_Project" + Path.DirectorySeparatorChar;
var context = new DecompileContext(Data, true);
TextureWorker worker = new TextureWorker(); TextureWorker worker = new TextureWorker();
ThreadLocal<DecompileContext> DECOMPILE_CONTEXT = new ThreadLocal<DecompileContext>(() => new DecompileContext(Data, false)); ThreadLocal<DecompileContext> DECOMPILE_CONTEXT = new ThreadLocal<DecompileContext>(() => 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!"; 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 --------------- // --------------- 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 // Export sprites
UpdateProgressBar(null, "Exporting sprites...", progress++, resourceNum);
await ExportSprites(); await ExportSprites();
// Export backgrounds // Export backgrounds
UpdateProgressBar(null, "Exporting backgrounds...", progress++, resourceNum);
await ExportBackground(); await ExportBackground();
// Export objects // Export objects
UpdateProgressBar(null, "Exporting objects...", progress++, resourceNum);
await ExportGameObjects(); await ExportGameObjects();
// Export rooms // Export rooms
UpdateProgressBar(null, "Exporting rooms...", progress++, resourceNum);
await ExportRooms(); await ExportRooms();
// Export sounds // Export sounds
UpdateProgressBar(null, "Exporting sounds...", progress++, resourceNum);
await ExportSounds(); await ExportSounds();
// Export scripts // Export scripts
UpdateProgressBar(null, "Exporting scripts...", progress++, resourceNum);
await ExportScripts(); await ExportScripts();
// Export fonts // Export fonts
UpdateProgressBar(null, "Exporting fonts...", progress++, resourceNum);
await ExportFonts(); await ExportFonts();
// Export paths // Export paths
UpdateProgressBar(null, "Exporting paths...", progress++, resourceNum);
await ExportPaths(); await ExportPaths();
// Export timelines // Export timelines
UpdateProgressBar(null, "Exporting timelines...", progress++, resourceNum);
await ExportTimelines(); await ExportTimelines();
// Generate project file // Generate project file
UpdateProgressBar(null, "Generating project file...", progress++, resourceNum); GenerateProjectFile();
ExportProjectFile();
// --------------- Export completed --------------- // --------------- Export completed ---------------
worker.Cleanup(); worker.Cleanup();
@ -93,6 +90,8 @@ async Task ExportSprites()
} }
void ExportSprite(UndertaleSprite sprite) void ExportSprite(UndertaleSprite sprite)
{ {
UpdateProgressBar(null, $"Exporting sprite: {sprite.Name.Content}", progress++, resourceNum);
// Save the sprite GMX // Save the sprite GMX
var gmx = new XDocument( var gmx = new XDocument(
new XComment(gmxDeclaration), new XComment(gmxDeclaration),
@ -163,6 +162,8 @@ async Task ExportBackground()
} }
void ExportBackground(UndertaleBackground background) void ExportBackground(UndertaleBackground background)
{ {
UpdateProgressBar(null, $"Exporting background: {background.Name.Content}", progress++, resourceNum);
// Save the backgound GMX // Save the backgound GMX
var gmx = new XDocument( var gmx = new XDocument(
new XComment(gmxDeclaration), new XComment(gmxDeclaration),
@ -199,6 +200,8 @@ async Task ExportGameObjects()
} }
void ExportGameObject(UndertaleGameObject gameObject) void ExportGameObject(UndertaleGameObject gameObject)
{ {
UpdateProgressBar(null, $"Exporting object: {gameObject.Name.Content}", progress++, resourceNum);
// Save the object GMX // Save the object GMX
var gmx = new XDocument( var gmx = new XDocument(
new XComment(gmxDeclaration), new XComment(gmxDeclaration),
@ -286,6 +289,8 @@ async Task ExportRooms()
} }
void ExportRoom(UndertaleRoom room) void ExportRoom(UndertaleRoom room)
{ {
UpdateProgressBar(null, $"Exporting room: {room.Name.Content}", progress++, resourceNum);
// Save the room GMX // Save the room GMX
var gmx = new XDocument( var gmx = new XDocument(
new XComment(gmxDeclaration), new XComment(gmxDeclaration),
@ -299,7 +304,7 @@ void ExportRoom(UndertaleRoom room)
new XElement("speed", room.Speed.ToString()), new XElement("speed", room.Speed.ToString()),
new XElement("persistent", BoolToString(room.Persistent)), new XElement("persistent", BoolToString(room.Persistent)),
new XElement("colour", room.BackgroundColor.ToString()), 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("enableViews", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.EnableViews))),
new XElement("clearViewBackground", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ShowColor))), new XElement("clearViewBackground", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ShowColor))),
new XElement("clearDisplayBuffer", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ClearDisplayBuffer))) new XElement("clearDisplayBuffer", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ClearDisplayBuffer)))
@ -407,6 +412,8 @@ async Task ExportSounds()
} }
void ExportSound(UndertaleSound sound) void ExportSound(UndertaleSound sound)
{ {
UpdateProgressBar(null, $"Exporting sound: {sound.Name.Content}", progress++, resourceNum);
// Save the sound GMX // Save the sound GMX
var gmx = new XDocument( var gmx = new XDocument(
new XComment(gmxDeclaration), new XComment(gmxDeclaration),
@ -451,6 +458,8 @@ async Task ExportScripts()
} }
void ExportScript(UndertaleScript script) void ExportScript(UndertaleScript script)
{ {
UpdateProgressBar(null, $"Exporting script: {script.Name.Content}", progress++, resourceNum);
// Save GML files // Save GML files
File.WriteAllText(projFolder + "/scripts/" + script.Name.Content + ".gml", (script.Code != null ? Decompiler.Decompile(script.Code, DECOMPILE_CONTEXT.Value) : "")); 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) void ExportFont(UndertaleFont font)
{ {
UpdateProgressBar(null, $"Exporting font: {font.Name.Content}", progress++, resourceNum);
// Save the font GMX // Save the font GMX
var gmx = new XDocument( var gmx = new XDocument(
new XComment(gmxDeclaration), new XComment(gmxDeclaration),
@ -516,6 +527,8 @@ async Task ExportPaths()
} }
void ExportPath(UndertalePath path) void ExportPath(UndertalePath path)
{ {
UpdateProgressBar(null, $"Exporting path: {path.Name.Content}", progress++, resourceNum);
// Save the path GMX // Save the path GMX
var gmx = new XDocument( var gmx = new XDocument(
new XComment(gmxDeclaration), new XComment(gmxDeclaration),
@ -548,6 +561,8 @@ async Task ExportTimelines()
} }
void ExportTimeline(UndertaleTimeline timeline) void ExportTimeline(UndertaleTimeline timeline)
{ {
UpdateProgressBar(null, $"Exporting timeline: {timeline.Name.Content}", progress++, resourceNum);
// Save the timeline GMX // Save the timeline GMX
var gmx = new XDocument( var gmx = new XDocument(
new XComment(gmxDeclaration), new XComment(gmxDeclaration),
@ -591,8 +606,10 @@ void ExportTimeline(UndertaleTimeline timeline)
// --------------- Generate project file --------------- // --------------- Generate project file ---------------
void ExportProjectFile() void GenerateProjectFile()
{ {
UpdateProgressBar(null, $"Generating project file...", progress++, resourceNum);
var gmx = new XDocument( var gmx = new XDocument(
new XComment(gmxDeclaration), new XComment(gmxDeclaration),
new XElement("assets") new XElement("assets")