Reworked RecrownedGTK tools.

This commit is contained in:
Harrison Deng 2020-05-18 16:44:25 -05:00
parent 635ed9fb7d
commit ef806b8174
27 changed files with 147 additions and 356 deletions

28
.vscode/launch.json vendored
View File

@ -1,28 +0,0 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/RecrownedAthenaeum.Tools/bin/Debug/netcoreapp2.1/RecrownedAthenaeum.Tools.dll",
"args": [],
"cwd": "${workspaceFolder}/RecrownedAthenaeum.Tools",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}

36
.vscode/tasks.json vendored
View File

@ -1,36 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/RecrownedAthenaeum.Tools/RecrownedAthenaeum.Tools.csproj"
],
"problemMatcher": "$tsc"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/RecrownedAthenaeum.Tools/RecrownedAthenaeum.Tools.csproj"
],
"problemMatcher": "$tsc"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/RecrownedAthenaeum.Tools/RecrownedAthenaeum.Tools.csproj"
],
"problemMatcher": "$tsc"
}
]
}

View File

@ -2,6 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net48</TargetFramework> <TargetFramework>net48</TargetFramework>
<DebugType>portable</DebugType>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>

View File

@ -1,27 +0,0 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/RecrownedGTK.Tools.Tests.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}

View File

@ -1,42 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/RecrownedGTK.Tools.Tests.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/RecrownedGTK.Tools.Tests.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/RecrownedGTK.Tools.Tests.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@ -44,15 +44,14 @@ namespace RecrownedGTK.Tools.Tests.CommandProcessor
this.commandArguments = engineCommandArguments; this.commandArguments = engineCommandArguments;
} }
public override void Run(IUserInput userInput, IUserOutput userOutput, params string[] arguments) public override bool Run(IUserInput userInput, IUserOutput userOutput, params string[] arguments)
{ {
if (arguments != null && arguments[0] != null) { if (arguments != null && arguments[0] != null) {
userOutput.Output(arguments[0] + " argument"); userOutput.Output(arguments[0] + " argument");
} else { } else {
userOutput.Output(userInput.GetInput() + " input"); userOutput.Output(userInput.GetInput() + " input");
} }
return true;
} }
} }

View File

@ -43,15 +43,14 @@ namespace RecrownedGTK.Tools.Tests.CommandProcessor {
this.commandArguments = engineCommandArguments; this.commandArguments = engineCommandArguments;
} }
public override void Run(IUserInput userInput, IUserOutput userOutput, params string[] arguments) public override bool Run(IUserInput userInput, IUserOutput userOutput, params string[] arguments)
{ {
if (arguments != null && arguments[0] != null) { if (arguments != null && arguments[0] != null) {
userOutput.Output(arguments[0] + " argument"); userOutput.Output(arguments[0] + " argument");
} else { } else {
userOutput.Output(userInput.GetInput() + " input"); userOutput.Output(userInput.GetInput() + " input");
} }
return true;
} }
} }

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net48</TargetFramework> <TargetFramework>net48</TargetFramework>
<DebugType>portable</DebugType>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>

View File

@ -5,23 +5,14 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": ".NET Core Launch (console)", "name": "Debug R.Tools",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/RecrownedGTK.Tools.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach", "request": "attach",
"processId": "${command:pickProcess}" "type": "mono",
"address": "localhost",
"port": 55555,
"preLaunchTask": "launch debug server",
"postDebugTask": "stop debug server"
} }
] ]
} }

View File

@ -1,42 +1,31 @@
{ {
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": [
{ {
"label": "build", "label": "build",
"type": "shell",
"command": "dotnet", "command": "dotnet",
"type": "process",
"args": [ "args": [
"build", "build"
"${workspaceFolder}/RecrownedGTK.Tools.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
], ],
"problemMatcher": "$msCompile" "problemMatcher": []
}, },
{ {
"label": "publish", "dependsOn": ["build"],
"command": "dotnet", "label": "launch debug server",
"type": "process", "type": "process",
"args": [ "command": "powershell",
"publish", "problemMatcher": [],
"${workspaceFolder}/RecrownedGTK.Tools.csproj", "args": ["-ExecutionPolicy", "Bypass", "-File", "./start_process.ps1"]
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}, },
{ {
"label": "watch", "label": "stop debug server",
"command": "dotnet",
"type": "process", "type": "process",
"args": [ "command": "powershell",
"watch", "problemMatcher": [],
"run", "args": ["-ExecutionPolicy", "Bypass", "-File", "./end_process.ps1"]
"${workspaceFolder}/RecrownedGTK.Tools.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
} }
] ]
} }

View File

@ -18,17 +18,9 @@ namespace RecrownedGTK.Tools.CommandProcessor
{ {
while (running) while (running)
{ {
output.WrappedOutput("\nAwaiting command."); output.WriteLine("Awaiting command.");
string command = input.GetInput(); string command = input.GetInput();
try Process(input, output, command);
{
Process(input, output, command);
}
catch (ArgumentException ae)
{
output.WrappedOutput("Error: " + ae.Message);
}
} }
} }
@ -39,11 +31,13 @@ namespace RecrownedGTK.Tools.CommandProcessor
} }
string command = commandAndArguments; string command = commandAndArguments;
string[] arguments = null; string[] arguments = null;
if (!ContainsCommand(command)) {
userOutput.Write("Unable to find command. Type \"help\" for more information.");
return;
}
if (commandAndArguments.Contains(" ")) if (commandAndArguments.Contains(" "))
{ {
command = command.Remove(command.IndexOf(' ')); command = command.Remove(command.IndexOf(' '));
if (!ContainsCommand(command)) throw new ArgumentException("Command not found.");
string[] argumentsSplit = commandAndArguments.Substring(command.Length + 1).Split(' '); string[] argumentsSplit = commandAndArguments.Substring(command.Length + 1).Split(' ');
List<string> argumentsList = new List<string>(); List<string> argumentsList = new List<string>();
@ -59,7 +53,7 @@ namespace RecrownedGTK.Tools.CommandProcessor
i++; i++;
if (i >= argumentsSplit.Length) if (i >= argumentsSplit.Length)
{ {
throw new ArgumentException("Argument is missing terminating \'\"\'"); userOutput.Write("Argument is missing terminating \'\"\'");
} }
} while (!argumentsSplit[i].Contains("\"")); } while (!argumentsSplit[i].Contains("\""));
@ -74,8 +68,9 @@ namespace RecrownedGTK.Tools.CommandProcessor
} }
arguments = argumentsList.ToArray(); arguments = argumentsList.ToArray();
} }
if (!ContainsCommand(command)) throw new ArgumentException("Command not found. Type \"help\" for a list of commands."); if (!GetCommand(command).Run(userInput, userOutput, arguments)) {
GetCommand(command).Run(userInput, userOutput, arguments); userOutput.Write("Command {0} was not used correctly. Please refer to \"help\" for more information.");
}
} }
/// <summary> /// <summary>

View File

@ -4,14 +4,14 @@ namespace RecrownedGTK.Tools.CommandProcessor.Commands
{ {
public class ClearConsoleCommand : EngineCommand public class ClearConsoleCommand : EngineCommand
{ {
public ClearConsoleCommand() : base("clear") public ClearConsoleCommand() : base("Clears the console.", "clear")
{ {
help = "Clears the console.";
} }
public override void Run(IUserInput userInput, IUserOutput userOutput, string[] arguments = null) public override bool Run(IUserInput userInput, IUserOutput userOutput, string[] arguments = null)
{ {
userOutput.ClearOutput(); userOutput.ClearOutput();
return true;
} }
} }
} }

View File

@ -6,49 +6,49 @@ namespace RecrownedGTK.Tools.CommandProcessor.Commands
{ {
CommandEngine commandEngine; CommandEngine commandEngine;
public HelpCommand(CommandEngine commandEngine) : base("help") public HelpCommand(CommandEngine commandEngine) : base("help [command] [arg]", "help")
{ {
this.commandEngine = commandEngine; this.commandEngine = commandEngine;
help = "help [command] [arg]";
} }
public override void Run(IUserInput userInput, IUserOutput userOutput, string[] arguments) public override bool Run(IUserInput userInput, IUserOutput userOutput, string[] arguments)
{ {
if (arguments != null) if (arguments != null)
{ {
if (commandEngine.ContainsCommand(arguments[0])) if (commandEngine.ContainsCommand(arguments[0]))
{ {
if (arguments.Length < 2) userOutput.WrappedOutput(commandEngine.GetCommand(arguments[0]).Help(null)); if (arguments.Length < 2) userOutput.WriteLine(commandEngine.GetCommand(arguments[0]).Help(null));
for (int i = 1; i < arguments.Length; i++) for (int i = 1; i < arguments.Length; i++)
{ {
userOutput.WrappedOutput(commandEngine.GetCommand(arguments[0]).Help(arguments[i])); userOutput.WriteLine(commandEngine.GetCommand(arguments[0]).Help(arguments[i]));
} }
} }
else else
{ {
throw new ArgumentException(arguments[0] + " not a command. Type \"help\" for a list of commands."); return false;
} }
} }
else else
{ {
userOutput.WrappedOutput("Tools for RecrownedGTK library. Possible commands are as follows:\n"); userOutput.WriteLine("Tools for RecrownedGTK library. Possible commands are as follows:\n");
foreach (EngineCommand engineCommand in commandEngine.commands) foreach (EngineCommand engineCommand in commandEngine.commands)
{ {
for (int i = 0; i < engineCommand.InvokeStrings.Length; i++) for (int i = 0; i < engineCommand.InvokeStrings.Length; i++)
{ {
userOutput.WrappedOutput(engineCommand.InvokeStrings[i]); userOutput.Write(engineCommand.InvokeStrings[i]);
if (i + 1 < engineCommand.InvokeStrings.Length) if (i + 1 < engineCommand.InvokeStrings.Length)
{ {
userOutput.WrappedOutput(", "); userOutput.Write(", ");
} }
} }
userOutput.WrappedOutput(" : "); userOutput.Write(": ");
userOutput.WrappedOutput(engineCommand.Help().Replace("\n", "\n\t")); userOutput.Write(engineCommand.Help());
userOutput.WrappedOutput("\n"); userOutput.Write("\n");
userOutput.Output("--------"); userOutput.WriteLine("--------");
} }
} }
return true;
} }
} }
} }

View File

@ -4,15 +4,15 @@
{ {
CommandEngine commandEngine; CommandEngine commandEngine;
public StopCommand(CommandEngine commandEngine) : base("quit", "stop", "q", "exit") public StopCommand(CommandEngine commandEngine) : base("Exits the tool.", "quit", "stop", "q", "exit")
{ {
this.commandEngine = commandEngine; this.commandEngine = commandEngine;
help = "Exits the tool.";
} }
public override void Run(IUserInput userInput, IUserOutput userOutput, string[] arguments = null) public override bool Run(IUserInput userInput, IUserOutput userOutput, string[] arguments = null)
{ {
commandEngine.running = false; commandEngine.running = false;
return true;
} }
} }
} }

View File

@ -18,8 +18,8 @@ namespace RecrownedGTK.Tools.CommandProcessor
/// <summary> /// <summary>
/// Arguments that this command should accept and take into account. /// Arguments that this command should accept and take into account.
/// </summary> /// </summary>
protected EngineCommandArgument[] commandArguments; protected EngineCommandArgument[] arguments;
protected string help; protected readonly string help;
public EngineCommand(string help, params string[] invokeStrings) public EngineCommand(string help, params string[] invokeStrings)
{ {
@ -56,10 +56,13 @@ namespace RecrownedGTK.Tools.CommandProcessor
} }
/// <summary> /// <summary>
/// Runs the command. /// Runs the engine command.
/// </summary> /// </summary>
/// <param name="arguments">arguments to be used. Each string should be the argument input. May be null.</param> /// <param name="userInput">The user input object.</param>
public abstract void Run(IUserInput userInput = null, IUserOutput userOutput = null, params string[] arguments); /// <param name="userOutput">The user output object.</param>
/// <param name="arguments">The arguments.</param>
/// <returns>True if the command executed successfully, otherwise false to display a help message.</returns>
public abstract bool Run(IUserInput userInput, IUserOutput userOutput, params string[] arguments);
/// <summary> /// <summary>
/// Check if given argument is viable for command. /// Check if given argument is viable for command.
@ -78,11 +81,11 @@ namespace RecrownedGTK.Tools.CommandProcessor
/// <returns>null if not viable or the <see cref="EngineCommandArgumentOf(argument)"/> if viable.</returns> /// <returns>null if not viable or the <see cref="EngineCommandArgumentOf(argument)"/> if viable.</returns>
public EngineCommandArgument EngineCommandArgumentOf(string argument) public EngineCommandArgument EngineCommandArgumentOf(string argument)
{ {
for (int i = 0; i < commandArguments.Length; i++) for (int i = 0; i < arguments.Length; i++)
{ {
if (commandArguments[i].invokeString == argument) if (arguments[i].invokeString == argument)
{ {
return commandArguments[i]; return arguments[i];
} }
} }
return null; return null;
@ -147,7 +150,7 @@ namespace RecrownedGTK.Tools.CommandProcessor
/// <returns>The string for the help.</returns> /// <returns>The string for the help.</returns>
public string Help(string argument = null) public string Help(string argument = null)
{ {
if (argument != null && commandArguments != null) if (argument != null && arguments != null)
{ {
if (Validate(argument)) if (Validate(argument))
{ {
@ -165,25 +168,24 @@ namespace RecrownedGTK.Tools.CommandProcessor
{ {
StringBuilder helpBuilder = new StringBuilder(); StringBuilder helpBuilder = new StringBuilder();
helpBuilder.Append(help); helpBuilder.Append(help);
if (commandArguments != null) if (arguments != null)
{ {
helpBuilder.AppendLine(); helpBuilder.AppendLine();
helpBuilder.Append("Possible arguments: "); helpBuilder.Append("Possible arguments: ");
for (int i = 0; i < commandArguments.Length; i++) for (int i = 0; i < arguments.Length; i++)
{ {
helpBuilder.Append(commandArguments[i].invokeString); helpBuilder.Append(arguments[i].invokeString);
if (commandArguments[i].required) helpBuilder.Append('*'); if (arguments[i].required) helpBuilder.Append('*');
if (i == commandArguments.Length - 2) if (i == arguments.Length - 2)
{ {
helpBuilder.Append(", and "); helpBuilder.Append(", and ");
} }
else if (i < commandArguments.Length - 2) else if (i < arguments.Length - 2)
{ {
helpBuilder.Append(", "); helpBuilder.Append(", ");
} }
} }
helpBuilder.Append('.'); helpBuilder.Append(". (* are required arguments.)");
helpBuilder.AppendLine(" (* are required arguments.)");
} }
return helpBuilder.ToString(); return helpBuilder.ToString();
} }

View File

@ -1,8 +1,8 @@
namespace RecrownedGTK.Tools.CommandProcessor { namespace RecrownedGTK.Tools.CommandProcessor {
public interface IUserOutput public interface IUserOutput
{ {
void Output(string output); void WriteLine(string output);
void WrappedOutput(string output); void Write(string output);
void ClearOutput(); void ClearOutput();
} }
} }

View File

@ -17,12 +17,12 @@ namespace RecrownedGTK.Tools.ConsoleInterface
} }
private class ConsoleOutput : IUserOutput { private class ConsoleOutput : IUserOutput {
public void Output(string output) { public void WriteLine(string output) {
Console.WriteLine(output); Console.WriteLine(ConsoleUtilities.WrapMessageToConsoleWidth(output));
} }
public void WrappedOutput(string output) { public void Write(string output) {
ConsoleUtilities.WrapMessageToConsoleWidth(output); Console.Write(ConsoleUtilities.WrapMessageToConsoleWidth(output));
} }
public void ClearOutput() { public void ClearOutput() {

View File

@ -12,7 +12,7 @@ namespace RecrownedGTK.Tools.ConsoleInterface
int currentLineSize = 0; int currentLineSize = 0;
for (int i = 0; i < words.Length; i++) for (int i = 0; i < words.Length; i++)
{ {
if (currentLineSize + words[i].Length >= Console.BufferWidth - Console.CursorLeft -1) if (currentLineSize + words[i].Length > Console.BufferWidth - Console.CursorLeft)
{ {
currentLineSize = 0; currentLineSize = 0;
stringBuilder.AppendLine(); stringBuilder.AppendLine();
@ -32,7 +32,6 @@ namespace RecrownedGTK.Tools.ConsoleInterface
stringBuilder.Append(' '); stringBuilder.Append(' ');
} }
} }
stringBuilder.AppendLine();
return stringBuilder.ToString(); return stringBuilder.ToString();
} }
} }

View File

@ -9,32 +9,30 @@ namespace RecrownedGTK.Tools.NinePatchTools
public class NinePatchCommand : EngineCommand public class NinePatchCommand : EngineCommand
{ {
public NinePatchCommand() : base("9p", "ninepatch", "9patch") public NinePatchCommand() : base("Generates a 9 patch file for a given image.", "9p", "ninepatch", "9patch")
{ {
help = "Generates a 9 patch file for a given image."; arguments = new EngineCommandArgument[6];
commandArguments = new EngineCommandArgument[6]; arguments[0] = new EngineCommandArgument("-i", "defines the path to the texture to be used for the nine patch.", true);
arguments[1] = new EngineCommandArgument("-o", "defines path of output file.");
commandArguments[0] = new EngineCommandArgument("-i", "defines the path to the texture to be used for the nine patch.", true); arguments[2] = new EngineCommandArgument("-l", "left patch.", true);
commandArguments[1] = new EngineCommandArgument("-o", "defines path of output file."); arguments[3] = new EngineCommandArgument("-r", "right patch.", true);
commandArguments[2] = new EngineCommandArgument("-l", "left patch.", true); arguments[4] = new EngineCommandArgument("-t", "top patch.", true);
commandArguments[3] = new EngineCommandArgument("-r", "right patch.", true); arguments[5] = new EngineCommandArgument("-b", "bottom patch.", true);
commandArguments[4] = new EngineCommandArgument("-t", "top patch.", true);
commandArguments[5] = new EngineCommandArgument("-b", "bottom patch.", true);
} }
public override void Run(IUserInput userInput = null, IUserOutput userOutput = null, string[] arguments = null) public override bool Run(IUserInput userInput = null, IUserOutput userOutput = null, string[] arguments = null)
{ {
if (arguments == null) throw new ArgumentException("Missing arguments. Type \"help 9p\" for more information."); if (arguments == null) throw new ArgumentException("Missing arguments. Type \"help 9p\" for more information.");
int leftBound = 0, rightBound = 0, topBound = 0, bottomBound = 0; int leftBound = 0, rightBound = 0, topBound = 0, bottomBound = 0;
string imagePath, outPath; string imagePath, outPath;
if (IndexOfArgument("-i", arguments) + 1 >= arguments.Length) throw new ArgumentException("Missing -i path after argument."); if (IndexOfArgument("-i", arguments) + 1 >= arguments.Length) userOutput.WriteLine("Missing -i path after argument.");
imagePath = arguments[IndexOfArgument("-i", arguments) + 1]; imagePath = arguments[IndexOfArgument("-i", arguments) + 1];
if (!File.Exists(imagePath)) throw new ArgumentException("Input file does not exist at " + imagePath + "."); if (!File.Exists(imagePath)) userOutput.WriteLine("Input file does not exist at " + imagePath + ".");
if (HasArgument(commandArguments[1], arguments)) if (HasArgument(base.arguments[1], arguments))
{ {
if (IndexOfArgument("-o", arguments) + 1 >= arguments.Length) throw new ArgumentException("Missing -o path after argument."); if (IndexOfArgument("-o", arguments) + 1 >= arguments.Length) userOutput.WriteLine("Missing -o path after argument.");
outPath = arguments[IndexOfArgument("-o", arguments) + 1]; outPath = arguments[IndexOfArgument("-o", arguments) + 1];
} else } else
{ {
@ -51,8 +49,10 @@ namespace RecrownedGTK.Tools.NinePatchTools
File.Move(imagePath, modifiedPath); File.Move(imagePath, modifiedPath);
File.WriteAllText(outPath + ".9p", serialized); File.WriteAllText(outPath + ".9p", serialized);
userOutput.WrappedOutput("Done. Written to \"" + outPath + "\" with values: left = " + leftBound + " right = " + rightBound + " top = " + topBound + " bottom = " + bottomBound); userOutput.WriteLine("Done. Written to \"" + outPath + "\" with values: left = " + leftBound + " right = " + rightBound + " top = " + topBound + " bottom = " + bottomBound);
userOutput.WrappedOutput("Image renamed to: " + Path.GetFileName(modifiedPath)); userOutput.WriteLine("Image renamed to: " + Path.GetFileName(modifiedPath));
return true;
} }
} }
} }

View File

@ -7,6 +7,7 @@
<StartupObject /> <StartupObject />
<AssemblyName>RecrownedGTK.Tools</AssemblyName> <AssemblyName>RecrownedGTK.Tools</AssemblyName>
<RootNamespace>RecrownedGTK.Tools</RootNamespace> <RootNamespace>RecrownedGTK.Tools</RootNamespace>
<DebugType>portable</DebugType>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@ -53,7 +53,7 @@ namespace RecrownedGTK.Tools.TextureAtlas
SupportedExtensions extension; SupportedExtensions extension;
if (Enum.TryParse(Path.GetExtension(paths[pathID]).ToLower().Substring(1), out extension)) if (Enum.TryParse(Path.GetExtension(paths[pathID]).ToLower().Substring(1), out extension))
{ {
userOutput.WrappedOutput("Reading texture data for: " + paths[pathID]); userOutput.WriteLine("Reading texture data for: " + paths[pathID]);
ImageHandler image = new ImageHandler(paths[pathID]); ImageHandler image = new ImageHandler(paths[pathID]);
imageHandlers.Add(image); imageHandlers.Add(image);
minAreaRequired += image.Area; minAreaRequired += image.Area;
@ -65,7 +65,7 @@ namespace RecrownedGTK.Tools.TextureAtlas
else if (Path.GetExtension(paths[pathID]).ToLower() == ".9p") else if (Path.GetExtension(paths[pathID]).ToLower() == ".9p")
{ {
if (ninePatchDictionary == null) ninePatchDictionary = new Dictionary<string, NinePatchInfo>(); if (ninePatchDictionary == null) ninePatchDictionary = new Dictionary<string, NinePatchInfo>();
userOutput.WrappedOutput("Reading ninepatch data for: " + paths[pathID]); userOutput.WriteLine("Reading ninepatch data for: " + paths[pathID]);
string serialized = File.ReadAllText(paths[pathID]); string serialized = File.ReadAllText(paths[pathID]);
NinePatchInfo npData = JsonConvert.DeserializeObject<NinePatchInfo>(serialized); NinePatchInfo npData = JsonConvert.DeserializeObject<NinePatchInfo>(serialized);
ninePatchDictionary.Add(npData.name, npData); ninePatchDictionary.Add(npData.name, npData);

View File

@ -9,10 +9,9 @@ namespace RecrownedGTK.Tools.TextureAtlasTools
{ {
private const int DMP = 9; private const int DMP = 9;
private const int DSP = 6; private const int DSP = 6;
public TexturePackerCommand() : base("texturepacker") public TexturePackerCommand() : base("Packs a given directory composed of png and jpg files into an atlas. Can also add 9patch properties. Images with the associated \".9p\" files will automatically be defined in the resulting .tatlas file, but can be overwritten by use of the \"-9p\" argument.", "texturepacker")
{ {
help = "Packs a given directory composed of png and jpg files into an atlas. Can also add 9patch properties. Images with the associated \".9p\" files will automatically be defined in the resulting .tatlas file, but can be overwritten by use of the \"-9p\" argument."; arguments = new[] {
commandArguments = new[] {
new EngineCommandArgument("-interactive", "runs in interactive mode. Ninepatches must still be defined with arguments or previously defined with associated \".9p\" files. Other arguments will be ignored."), new EngineCommandArgument("-interactive", "runs in interactive mode. Ninepatches must still be defined with arguments or previously defined with associated \".9p\" files. Other arguments will be ignored."),
new EngineCommandArgument("-i", "for input directory containing the textures.", true), new EngineCommandArgument("-i", "for input directory containing the textures.", true),
new EngineCommandArgument("-o", "Path for output files. Points to non-existent file. Will create texture and definitions file with name.", true), new EngineCommandArgument("-o", "Path for output files. Points to non-existent file. Will create texture and definitions file with name.", true),
@ -23,7 +22,7 @@ namespace RecrownedGTK.Tools.TextureAtlasTools
}; };
} }
public override void Run(IUserInput userInput, IUserOutput userOutput, string[] arguments) public override bool Run(IUserInput userInput, IUserOutput userOutput, string[] arguments)
{ {
TexturePacker texturePacker = null; TexturePacker texturePacker = null;
@ -36,30 +35,30 @@ namespace RecrownedGTK.Tools.TextureAtlasTools
if (HasArgument("-interactive", arguments)) if (HasArgument("-interactive", arguments))
{ {
string input; string input;
userOutput.WrappedOutput("Texture packer interactive mode triggered. Type \"q\" at any time to exit."); userOutput.WriteLine("Texture packer interactive mode triggered. Type \"q\" at any time to exit.");
userOutput.WrappedOutput("Please enter path of folder containing the textures to be packed."); userOutput.WriteLine("Please enter path of folder containing the textures to be packed.");
input = userInput.GetInput(); input = userInput.GetInput();
if (input == "q") return; if (input == "q") return true;
path = input.Replace("\"", ""); path = input.Replace("\"", "");
userOutput.WrappedOutput("Please enter output path of file name."); userOutput.WriteLine("Please enter output path of file name.");
input = userInput.GetInput(); input = userInput.GetInput();
if (input == "q") return; if (input == "q") return true;
output = input.Replace("\"", ""); output = input.Replace("\"", "");
do do
{ {
userOutput.WrappedOutput("Please enter a valid starting power of two for the lengths of the resulting texture atlas. Leave blank for default of " + sp + "."); userOutput.WriteLine("Please enter a valid starting power of two for the lengths of the resulting texture atlas. Leave blank for default of " + sp + ".");
input = userInput.GetInput(); input = userInput.GetInput();
if (input == "q") return; if (input == "q") return true;
if (input.Length == 0) break; if (input.Length == 0) break;
} while (!int.TryParse(input, out sp)); } while (!int.TryParse(input, out sp));
do do
{ {
userOutput.WrappedOutput("Please enter a valid maximum power by two of the lengths of the resulting texture atlas. Leave blank for default of " + mp + "."); userOutput.WriteLine("Please enter a valid maximum power by two of the lengths of the resulting texture atlas. Leave blank for default of " + mp + ".");
input = userInput.GetInput(); input = userInput.GetInput();
if (input == "q") return; if (input == "q") return true;
if (input.Length == 0) break; if (input.Length == 0) break;
} while (!int.TryParse(input, out mp)); } while (!int.TryParse(input, out mp));
@ -67,7 +66,10 @@ namespace RecrownedGTK.Tools.TextureAtlasTools
else else
{ {
int indexOfInputArg = IndexOfArgument("-i", arguments); int indexOfInputArg = IndexOfArgument("-i", arguments);
if (indexOfInputArg + 1 >= arguments.Length) throw new ArgumentException("-i is not followed by input path."); if (indexOfInputArg + 1 >= arguments.Length) {
userOutput.WriteLine("-i is not followed by input path.");
return true;
}
path = arguments[1 + IndexOfArgument("-i", arguments)]; path = arguments[1 + IndexOfArgument("-i", arguments)];
if (HasArgument("-mp", arguments)) if (HasArgument("-mp", arguments))
{ {
@ -78,28 +80,33 @@ namespace RecrownedGTK.Tools.TextureAtlasTools
int.TryParse(arguments[IndexOfArgument("-sp", arguments) + 1], out sp); int.TryParse(arguments[IndexOfArgument("-sp", arguments) + 1], out sp);
} }
int indexOfOutputArg = IndexOfArgument("-o", arguments); int indexOfOutputArg = IndexOfArgument("-o", arguments);
if (indexOfOutputArg + 1 >= arguments.Length) throw new ArgumentException("-o is not followed by input path."); if (indexOfOutputArg + 1 >= arguments.Length) {
userOutput.WriteLine("-o is not followed by input path.");
}
output = arguments[IndexOfArgument("-o", arguments) + 1]; output = arguments[IndexOfArgument("-o", arguments) + 1];
if (HasArgument("-dau", arguments)) dau = true; if (HasArgument("-dau", arguments)) dau = true;
} }
texturePacker = new TexturePacker(userOutput, path, mp, sp); texturePacker = new TexturePacker(userOutput, path, mp, sp);
userOutput.WrappedOutput("Calculated minimum texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + " with a total of " + texturePacker.TexturesFound + " textures."); userOutput.WriteLine("Calculated minimum texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + " with a total of " + texturePacker.TexturesFound + " textures.");
try try
{ {
texturePacker.Build(!dau); texturePacker.Build(!dau);
} }
catch (InvalidOperationException e) catch (InvalidOperationException)
{ {
throw new ArgumentException(e.Message); return false;
} }
for (int i = 0; i < arguments.Length; i++) for (int i = 0; i < arguments.Length; i++)
{ {
if (arguments[i] == "-9p") if (arguments[i] == "-9p")
{ {
if (i + 1 >= arguments.Length) throw new ArgumentException("-9p is not followed by proper specifiers for a 9Patch (format: \"-9p textureName,a,b,c,d\" where a, b, c, and d are integers definining the border regions for the 9patch.)"); if (i + 1 >= arguments.Length) {
userOutput.WriteLine("-9p is not followed by proper specifiers for a 9Patch (format: \"-9p textureName,a,b,c,d\" where a, b, c, and d are integers definining the border regions for the 9patch.)");
return true;
}
string[] nPatchArgs = arguments[i + 1].Split(','); string[] nPatchArgs = arguments[i + 1].Split(',');
try try
{ {
@ -107,12 +114,14 @@ namespace RecrownedGTK.Tools.TextureAtlasTools
} }
catch (FormatException) catch (FormatException)
{ {
throw new ArgumentException("-9p argument parameters must be in the format \"-9p textureName,a,b,c,d\" where a, b, c, and d are integers definining the border regions for the 9patch."); userOutput.WriteLine("-9p argument parameters must be in the format \"-9p textureName,a,b,c,d\" where a, b, c, and d are integers definining the border regions for the 9patch.");
} }
} }
} }
texturePacker.Save(Path.GetDirectoryName(output), Path.GetFileName(output)); texturePacker.Save(Path.GetDirectoryName(output), Path.GetFileName(output));
userOutput.Output("Complete. Final texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + "."); userOutput.WriteLine("Complete. Final texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + ".");
return true;
} }
} }
} }

View File

@ -0,0 +1,8 @@
if (Test-Path ./pid.temp) {
$sID = Get-Item -Path ./pid.temp | Get-Content -Tail 1
if (Get-Process -Id $sID -ErrorAction SilentlyContinue) {
Stop-Process -Id $sID
}
Remove-Item "./pid.temp"
}

View File

@ -0,0 +1,6 @@
write-Output "Attempting to start Paper test server."
$SID = Start-Process "C:\Program Files\Mono\bin\mono" -ArgumentList "--debug", "--debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:55555", "bin/Debug/net48/RecrownedGTK.Tools.exe" -PassThru
$SID = $SID.Id
write-Output "Process started. PID is: $SID"
$SID | Out-File -FilePath "pid.temp"

View File

@ -1,76 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RecrownedGTK", "RecrownedGTK\RecrownedGTK.csproj", "{5B004034-614D-4A12-A614-7E884B4E4F9B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RecrownedGTK.Tools", "RecrownedGTK.Tools\RecrownedGTK.Tools.csproj", "{95B7A776-DA73-48E6-B431-02AFD304F24A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RecrownedGTK.Tests", "RecrownedGTK.Tests\RecrownedGTK.Tests.csproj", "{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RecrownedGTK.Tools.Tests", "RecrownedGTK.Tools.Tests\RecrownedGTK.Tools.Tests.csproj", "{00A6755D-A2E4-4B65-97CF-762851A9D651}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5B004034-614D-4A12-A614-7E884B4E4F9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B004034-614D-4A12-A614-7E884B4E4F9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B004034-614D-4A12-A614-7E884B4E4F9B}.Debug|x64.ActiveCfg = Debug|Any CPU
{5B004034-614D-4A12-A614-7E884B4E4F9B}.Debug|x64.Build.0 = Debug|Any CPU
{5B004034-614D-4A12-A614-7E884B4E4F9B}.Debug|x86.ActiveCfg = Debug|Any CPU
{5B004034-614D-4A12-A614-7E884B4E4F9B}.Debug|x86.Build.0 = Debug|Any CPU
{5B004034-614D-4A12-A614-7E884B4E4F9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B004034-614D-4A12-A614-7E884B4E4F9B}.Release|Any CPU.Build.0 = Release|Any CPU
{5B004034-614D-4A12-A614-7E884B4E4F9B}.Release|x64.ActiveCfg = Release|Any CPU
{5B004034-614D-4A12-A614-7E884B4E4F9B}.Release|x64.Build.0 = Release|Any CPU
{5B004034-614D-4A12-A614-7E884B4E4F9B}.Release|x86.ActiveCfg = Release|Any CPU
{5B004034-614D-4A12-A614-7E884B4E4F9B}.Release|x86.Build.0 = Release|Any CPU
{95B7A776-DA73-48E6-B431-02AFD304F24A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95B7A776-DA73-48E6-B431-02AFD304F24A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95B7A776-DA73-48E6-B431-02AFD304F24A}.Debug|x64.ActiveCfg = Debug|Any CPU
{95B7A776-DA73-48E6-B431-02AFD304F24A}.Debug|x64.Build.0 = Debug|Any CPU
{95B7A776-DA73-48E6-B431-02AFD304F24A}.Debug|x86.ActiveCfg = Debug|Any CPU
{95B7A776-DA73-48E6-B431-02AFD304F24A}.Debug|x86.Build.0 = Debug|Any CPU
{95B7A776-DA73-48E6-B431-02AFD304F24A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95B7A776-DA73-48E6-B431-02AFD304F24A}.Release|Any CPU.Build.0 = Release|Any CPU
{95B7A776-DA73-48E6-B431-02AFD304F24A}.Release|x64.ActiveCfg = Release|Any CPU
{95B7A776-DA73-48E6-B431-02AFD304F24A}.Release|x64.Build.0 = Release|Any CPU
{95B7A776-DA73-48E6-B431-02AFD304F24A}.Release|x86.ActiveCfg = Release|Any CPU
{95B7A776-DA73-48E6-B431-02AFD304F24A}.Release|x86.Build.0 = Release|Any CPU
{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Debug|x64.ActiveCfg = Debug|Any CPU
{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Debug|x64.Build.0 = Debug|Any CPU
{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Debug|x86.ActiveCfg = Debug|Any CPU
{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Debug|x86.Build.0 = Debug|Any CPU
{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Release|Any CPU.Build.0 = Release|Any CPU
{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Release|x64.ActiveCfg = Release|Any CPU
{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Release|x64.Build.0 = Release|Any CPU
{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Release|x86.ActiveCfg = Release|Any CPU
{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Release|x86.Build.0 = Release|Any CPU
{00A6755D-A2E4-4B65-97CF-762851A9D651}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00A6755D-A2E4-4B65-97CF-762851A9D651}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00A6755D-A2E4-4B65-97CF-762851A9D651}.Debug|x64.ActiveCfg = Debug|Any CPU
{00A6755D-A2E4-4B65-97CF-762851A9D651}.Debug|x64.Build.0 = Debug|Any CPU
{00A6755D-A2E4-4B65-97CF-762851A9D651}.Debug|x86.ActiveCfg = Debug|Any CPU
{00A6755D-A2E4-4B65-97CF-762851A9D651}.Debug|x86.Build.0 = Debug|Any CPU
{00A6755D-A2E4-4B65-97CF-762851A9D651}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00A6755D-A2E4-4B65-97CF-762851A9D651}.Release|Any CPU.Build.0 = Release|Any CPU
{00A6755D-A2E4-4B65-97CF-762851A9D651}.Release|x64.ActiveCfg = Release|Any CPU
{00A6755D-A2E4-4B65-97CF-762851A9D651}.Release|x64.Build.0 = Release|Any CPU
{00A6755D-A2E4-4B65-97CF-762851A9D651}.Release|x86.ActiveCfg = Release|Any CPU
{00A6755D-A2E4-4B65-97CF-762851A9D651}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net48</TargetFramework> <TargetFramework>net48</TargetFramework>
<DebugType>portable</DebugType>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="OpenTK" Version="3.1.0" /> <PackageReference Include="OpenTK" Version="3.1.0" />