Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleans up PR 860 #862

Merged
merged 1 commit into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
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
152 changes: 0 additions & 152 deletions UndertaleModCli/CommandOptions.cs

This file was deleted.

40 changes: 40 additions & 0 deletions UndertaleModCli/CommandOptions/DumpOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.IO;

namespace UndertaleModCli
{
/// <summary>
/// Cli options for the Dump command
/// </summary>
public class DumpOptions
{
/// <summary>
/// File path to the data file
/// </summary>
public FileInfo Datafile { get; set; }

/// <summary>
/// Directory path to where to dump all contents
/// </summary>
public DirectoryInfo? Output { get; set; }

/// <summary>
/// Determines if Cli should print out verbose logs
/// </summary>
public bool Verbose { get; set; } = false;

/// <summary>
/// Names of the code entries that should get dumped
/// </summary>
public string[] Code { get; set; }

/// <summary>
/// Determines if strings should get dumped.
/// </summary>
public bool Strings { get; set; }

/// <summary>
/// Determines if embedded textures should get dumped
/// </summary>
public bool Textures { get; set; }
}
}
20 changes: 20 additions & 0 deletions UndertaleModCli/CommandOptions/InfoOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.IO;

namespace UndertaleModCli
{
/// <summary>
/// Cli options for the Info command
/// </summary>
public class InfoOptions
{
/// <summary>
/// File path to the data file
/// </summary>
public FileInfo Datafile { get; set; }

/// <summary>
/// Determines if Cli should print out verbose logs
/// </summary>
public bool Verbose { get; set; } = false;
}
}
40 changes: 40 additions & 0 deletions UndertaleModCli/CommandOptions/LoadOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.IO;

namespace UndertaleModCli
{
/// <summary>
/// Cli options for the Load command
/// </summary>
public class LoadOptions
{
/// <summary>
/// File path to the data file
/// </summary>
public FileInfo Datafile { get; set; }

/// <summary>
/// File paths to the scripts that shall be run
/// </summary>
public FileInfo[] Scripts { get; set; }

/// <summary>
/// C# string that shall be executed
/// </summary>
public string? Line { get; set; }

/// <summary>
/// File path to where to save the modified data file
/// </summary>
public FileInfo? Output { get; set; }

/// <summary>
/// Determines if Cli should be run in interactive mode
/// </summary>
public bool Interactive { get; set; } = false;

/// <summary>
/// Determines if Cli should print out verbose logs
/// </summary>
public bool Verbose { get; set; } = false;
}
}
30 changes: 30 additions & 0 deletions UndertaleModCli/CommandOptions/NewOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.IO;

namespace UndertaleModCli
{
/// <summary>
/// Cli options for the New command
/// </summary>
public class NewOptions
{
/// <summary>
/// File path for new data file
/// </summary>
public FileInfo Output { get; set; } = new FileInfo("data.win");

/// <summary>
/// If the existing file path at <see cref="Output"/> should be overwritten
/// </summary>
public bool Overwrite { get; set; } = false;

/// <summary>
/// Whether to write the new data to Stdout
/// </summary>
public bool Stdout { get; set; }

/// <summary>
/// Determines if Cli should print out verbose logs
/// </summary>
public bool Verbose { get; set; } = false;
}
}
35 changes: 35 additions & 0 deletions UndertaleModCli/CommandOptions/ReplaceOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.IO;

namespace UndertaleModCli
{
/// <summary>
/// Cli options for the Replace command
/// </summary>
public class ReplaceOptions
{
/// <summary>
/// File path to the data file
/// </summary>
public FileInfo Datafile { get; set; }

/// <summary>
/// File path to where to save the modified data file
/// </summary>
public FileInfo? Output { get; set; }

/// <summary>
/// Determines if Cli should print out verbose logs
/// </summary>
public bool Verbose { get; set; } = false;

/// <summary>
/// Equal separated values of code entry and the file to replace the code entry with.
/// </summary>
public string[] Code { get; set; }

/// <summary>
/// Equal separated values of embedded texture and the file to replace the embedded texture with.
/// </summary>
public string[] Textures { get; set; }
}
}
13 changes: 7 additions & 6 deletions UndertaleModCli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private static int Dump(DumpOptions options)
}

// If user provided code to dump, dump code
if ((options.Code != null) && (options.Code.Length > 0) && (program.Data.Code.Count > 0))
if ((options.Code?.Length > 0) && (program.Data.Code.Count > 0))
{
// If user wanted to dump everything, do that, otherwise only dump what user provided
string[] codeArray;
Expand Down Expand Up @@ -381,7 +381,7 @@ private static int Replace(ReplaceOptions options)
}

// If user provided code to replace, replace them
if ((options.Code != null) && (options.Code.Length > 0) && (program.Data.Code.Count > 0))
if ((options.Code?.Length > 0) && (program.Data.Code.Count > 0))
{
// get the values and put them into a dictionary for ease of use
Dictionary<string, FileInfo> codeDict = new Dictionary<string, FileInfo>();
Expand Down Expand Up @@ -414,7 +414,7 @@ private static int Replace(ReplaceOptions options)
}

// If user provided texture to replace, replace them
if ((options.Textures != null) && (options.Textures.Length > 0))
if (options.Textures?.Length > 0)
{
// get the values and put them into a dictionary for ease of use
Dictionary<string, FileInfo> textureDict = new Dictionary<string, FileInfo>();
Expand Down Expand Up @@ -579,7 +579,8 @@ private void CliQuickInfo()
/// <param name="codeEntry">The code entry that should get dumped</param>
private void DumpCodeEntry(string codeEntry)
{
UndertaleCode? code = Data.Code.FirstOrDefault(c => c.Name.Content == codeEntry);
UndertaleCode code = Data.Code.ByName(codeEntry);


if (code == null)
{
Expand Down Expand Up @@ -643,7 +644,7 @@ private void DumpAllTextures()
/// <param name="fileToReplace">File path which should replace the code entry.</param>
private void ReplaceCodeEntryWithFile(string codeEntry, FileInfo fileToReplace)
{
UndertaleCode? code = Data.Code.FirstOrDefault(c => c.Name.Content == codeEntry);
UndertaleCode code = Data.Code.ByName(codeEntry);

if (code == null)
{
Expand All @@ -664,7 +665,7 @@ private void ReplaceCodeEntryWithFile(string codeEntry, FileInfo fileToReplace)
/// <param name="fileToReplace">File path which should replace the embedded texture.</param>
private void ReplaceTextureWithFile(string textureEntry, FileInfo fileToReplace)
{
UndertaleEmbeddedTexture? texture = Data.EmbeddedTextures.FirstOrDefault(t => t.Name.Content == textureEntry);
UndertaleEmbeddedTexture texture = Data.EmbeddedTextures.ByName(textureEntry);

if (texture == null)
{
Expand Down