Skip to content

Commit f5db986

Browse files
committed
Update ExportToProject.csx
1 parent 88bf8ea commit f5db986

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

ExportToProject.csx

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ using UndertaleModLib.Decompiler;
1313

1414
int progress = 0;
1515
string projFolder = GetFolder(FilePath) + "Export_Project" + Path.DirectorySeparatorChar;
16-
var context = new DecompileContext(Data, true);
1716
TextureWorker worker = new TextureWorker();
1817
ThreadLocal<DecompileContext> DECOMPILE_CONTEXT = new ThreadLocal<DecompileContext>(() => new DecompileContext(Data, false));
1918
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);
2827

2928
// --------------- Start exporting ---------------
3029

31-
var resourceNum = 10;
30+
var resourceNum = Data.Sprites.Count +
31+
Data.Backgrounds.Count +
32+
Data.GameObjects.Count +
33+
Data.Rooms.Count +
34+
Data.Sounds.Count +
35+
Data.Scripts.Count +
36+
Data.Fonts.Count +
37+
Data.Paths.Count +
38+
Data.Timelines.Count;
3239

3340
// Export sprites
34-
UpdateProgressBar(null, "Exporting sprites...", progress++, resourceNum);
3541
await ExportSprites();
3642

3743
// Export backgrounds
38-
UpdateProgressBar(null, "Exporting backgrounds...", progress++, resourceNum);
3944
await ExportBackground();
4045

4146
// Export objects
42-
UpdateProgressBar(null, "Exporting objects...", progress++, resourceNum);
4347
await ExportGameObjects();
4448

4549
// Export rooms
46-
UpdateProgressBar(null, "Exporting rooms...", progress++, resourceNum);
4750
await ExportRooms();
4851

4952
// Export sounds
50-
UpdateProgressBar(null, "Exporting sounds...", progress++, resourceNum);
5153
await ExportSounds();
5254

5355
// Export scripts
54-
UpdateProgressBar(null, "Exporting scripts...", progress++, resourceNum);
5556
await ExportScripts();
5657

5758
// Export fonts
58-
UpdateProgressBar(null, "Exporting fonts...", progress++, resourceNum);
5959
await ExportFonts();
6060

6161
// Export paths
62-
UpdateProgressBar(null, "Exporting paths...", progress++, resourceNum);
6362
await ExportPaths();
6463

6564
// Export timelines
66-
UpdateProgressBar(null, "Exporting timelines...", progress++, resourceNum);
6765
await ExportTimelines();
6866

6967
// Generate project file
70-
UpdateProgressBar(null, "Generating project file...", progress++, resourceNum);
71-
ExportProjectFile();
68+
GenerateProjectFile();
7269

7370
// --------------- Export completed ---------------
7471
worker.Cleanup();
@@ -93,6 +90,8 @@ async Task ExportSprites()
9390
}
9491
void ExportSprite(UndertaleSprite sprite)
9592
{
93+
UpdateProgressBar(null, $"Exporting sprite: {sprite.Name.Content}", progress++, resourceNum);
94+
9695
// Save the sprite GMX
9796
var gmx = new XDocument(
9897
new XComment(gmxDeclaration),
@@ -163,6 +162,8 @@ async Task ExportBackground()
163162
}
164163
void ExportBackground(UndertaleBackground background)
165164
{
165+
UpdateProgressBar(null, $"Exporting background: {background.Name.Content}", progress++, resourceNum);
166+
166167
// Save the backgound GMX
167168
var gmx = new XDocument(
168169
new XComment(gmxDeclaration),
@@ -199,6 +200,8 @@ async Task ExportGameObjects()
199200
}
200201
void ExportGameObject(UndertaleGameObject gameObject)
201202
{
203+
UpdateProgressBar(null, $"Exporting object: {gameObject.Name.Content}", progress++, resourceNum);
204+
202205
// Save the object GMX
203206
var gmx = new XDocument(
204207
new XComment(gmxDeclaration),
@@ -286,6 +289,8 @@ async Task ExportRooms()
286289
}
287290
void ExportRoom(UndertaleRoom room)
288291
{
292+
UpdateProgressBar(null, $"Exporting room: {room.Name.Content}", progress++, resourceNum);
293+
289294
// Save the room GMX
290295
var gmx = new XDocument(
291296
new XComment(gmxDeclaration),
@@ -299,7 +304,7 @@ void ExportRoom(UndertaleRoom room)
299304
new XElement("speed", room.Speed.ToString()),
300305
new XElement("persistent", BoolToString(room.Persistent)),
301306
new XElement("colour", room.BackgroundColor.ToString()),
302-
new XElement("code", room.CreationCodeId is null ? "" : Decompiler.Decompile(room.CreationCodeId, context)),
307+
new XElement("code", room.CreationCodeId != null ? Decompiler.Decompile(room.CreationCodeId, DECOMPILE_CONTEXT.Value) : ""),
303308
new XElement("enableViews", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.EnableViews))),
304309
new XElement("clearViewBackground", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ShowColor))),
305310
new XElement("clearDisplayBuffer", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ClearDisplayBuffer)))
@@ -407,6 +412,8 @@ async Task ExportSounds()
407412
}
408413
void ExportSound(UndertaleSound sound)
409414
{
415+
UpdateProgressBar(null, $"Exporting sound: {sound.Name.Content}", progress++, resourceNum);
416+
410417
// Save the sound GMX
411418
var gmx = new XDocument(
412419
new XComment(gmxDeclaration),
@@ -451,6 +458,8 @@ async Task ExportScripts()
451458
}
452459
void ExportScript(UndertaleScript script)
453460
{
461+
UpdateProgressBar(null, $"Exporting script: {script.Name.Content}", progress++, resourceNum);
462+
454463
// Save GML files
455464
File.WriteAllText(projFolder + "/scripts/" + script.Name.Content + ".gml", (script.Code != null ? Decompiler.Decompile(script.Code, DECOMPILE_CONTEXT.Value) : ""));
456465
}
@@ -463,6 +472,8 @@ async Task ExportFonts()
463472
}
464473
void ExportFont(UndertaleFont font)
465474
{
475+
UpdateProgressBar(null, $"Exporting font: {font.Name.Content}", progress++, resourceNum);
476+
466477
// Save the font GMX
467478
var gmx = new XDocument(
468479
new XComment(gmxDeclaration),
@@ -516,6 +527,8 @@ async Task ExportPaths()
516527
}
517528
void ExportPath(UndertalePath path)
518529
{
530+
UpdateProgressBar(null, $"Exporting path: {path.Name.Content}", progress++, resourceNum);
531+
519532
// Save the path GMX
520533
var gmx = new XDocument(
521534
new XComment(gmxDeclaration),
@@ -548,6 +561,8 @@ async Task ExportTimelines()
548561
}
549562
void ExportTimeline(UndertaleTimeline timeline)
550563
{
564+
UpdateProgressBar(null, $"Exporting timeline: {timeline.Name.Content}", progress++, resourceNum);
565+
551566
// Save the timeline GMX
552567
var gmx = new XDocument(
553568
new XComment(gmxDeclaration),
@@ -591,8 +606,10 @@ void ExportTimeline(UndertaleTimeline timeline)
591606

592607

593608
// --------------- Generate project file ---------------
594-
void ExportProjectFile()
609+
void GenerateProjectFile()
595610
{
611+
UpdateProgressBar(null, $"Generating project file...", progress++, resourceNum);
612+
596613
var gmx = new XDocument(
597614
new XComment(gmxDeclaration),
598615
new XElement("assets")

0 commit comments

Comments
 (0)