Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.IO;
using System.Linq;
using System.Text;
using Content.Shared.Administration;
using Content.Shared.Maps;
using Robust.Client.UserInterface;
using Robust.Shared.Console;
using Robust.Shared.Prototypes;

namespace Content.Client._DEN.DumpPrototypesCommand;

[AnyCommand]
public sealed class DumpPrototypesCommand : IConsoleCommand

Check failure on line 13 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

Type 'Content.Client._DEN.DumpPrototypesCommand.DumpPrototypesCommand' has

Check failure on line 13 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

Type 'Content.Client._DEN.DumpPrototypesCommand.DumpPrototypesCommand' has

Check failure on line 13 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Type 'Content.Client._DEN.DumpPrototypesCommand.DumpPrototypesCommand' has

Check failure on line 13 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Type 'Content.Client._DEN.DumpPrototypesCommand.DumpPrototypesCommand' has
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

Check failure on line 15 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

Field '_prototypeManager' is a

Check failure on line 15 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

Field '_prototypeManager' is a

Check failure on line 15 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Field '_prototypeManager' is a

Check failure on line 15 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Field '_prototypeManager' is a
[Dependency] private readonly IFileDialogManager _dialogManager = default!;

Check failure on line 16 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

Field '_dialogManager' is a

Check failure on line 16 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

Field '_dialogManager' is a

Check failure on line 16 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Field '_dialogManager' is a

Check failure on line 16 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Field '_dialogManager' is a
[Dependency] private readonly ILogManager _logManager = default!;

Check failure on line 17 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

Field '_logManager' is a

Check failure on line 17 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

Field '_logManager' is a

Check failure on line 17 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Field '_logManager' is a

Check failure on line 17 in Content.Client/_DEN/DumpPrototypes/DumpPrototypesCommand.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Field '_logManager' is a

public string Command => "dumpprototypes";
public string Description => Loc.GetString("Dumps all currently loaded entity and tile prototypes into a file.");
public string Help => ""; // doesn't need it, no arguments

public async void Execute(IConsoleShell shell, string argStr, string[] args)
{
var file = await _dialogManager.SaveFile(new FileDialogFilters(new FileDialogFilters.Group("txt"))); // Content.Client fails the type check when I try to use json

var sawmill = _logManager.GetSawmill(Command);

// while we wait for the dialog, we can do this in the background.

var entities = _prototypeManager.EnumeratePrototypes<EntityPrototype>();
var tiles = _prototypeManager.EnumeratePrototypes<ContentTileDefinition>();

var dump = new StringBuilder();

dump.AppendLine("=== Entities ===");

foreach (var entity in entities)
{
dump.AppendLine(entity.ID);
}

dump.AppendLine("=== Tiles ===");

foreach (var tile in tiles)
{
dump.AppendLine(tile.ID);
}

if (file == null)
{
sawmill.Error($"Error when dumping prototypes: Could not create file.");
return;
}

try
{
await using var writer = new StreamWriter(file.Value.fileStream);
writer.Write(dump.ToString());

}
catch (Exception exc)
{
sawmill.Error($"Error when dumping prototypes: {exc.Message}\n{exc.StackTrace}");
}
finally
{
await file.Value.fileStream.DisposeAsync();
}
}
}
Loading