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

New script - "FindObjectsWithSprite.csx" #813

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions UndertaleModTool/CommunityScripts/FindObjectsInRooms.csx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ List<string> splitStringsList = new List<string>();
List<string> gameObjectsUsedList = new List<string>();
string InputtedText = "";
InputtedText = SimpleTextInput("Menu", "Enter name(s) of game object(s)", InputtedText, true);
string[] IndividualLineArray = InputtedText.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
string[] IndividualLineArray = InputtedText.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
int usage_count = 0;
int unique_objects_used = 0;
foreach (var OneLine in IndividualLineArray)
Expand Down Expand Up @@ -59,7 +59,7 @@ for (var k = 0; k < splitStringsList.Count; k++)
}
if (gameObjectsUsedList.Count < 1)
{
SimpleTextInput("No results for your query below", "No results for your query below", InputtedText, true);
SimpleTextOutput("No results for your query below", "No results for your query below", InputtedText, true);
return;
}
else
Expand Down
87 changes: 87 additions & 0 deletions UndertaleModTool/CommunityScripts/FindObjectsWithSprite.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System.Text;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using UndertaleModLib.Util;
using System.Text;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Linq;
using System.Text.RegularExpressions;

EnsureDataLoaded();

string[] spriteNames;
ConcurrentBag<string> resultList = new();

bool caseSensitive = ScriptQuestion("Case sensitive?");
bool regexCheck = ScriptQuestion("Regex search?");
string qText = regexCheck ? "Enter RegEx of sprite name(s)" : "Enter sprite name(s)";
string searchQuery = SimpleTextInput(qText, "Search box below", "", !regexCheck);

if (String.IsNullOrEmpty(searchQuery) || String.IsNullOrWhiteSpace(searchQuery))
{
ScriptError("Search query cannot be empty or null.");
return;
}

SetProgressBar(null, "Game objects", 0, Data.GameObjects.Count);
StartUpdater();

Regex searchRegex;
if (regexCheck)
{
if (caseSensitive)
searchRegex = new(searchQuery, RegexOptions.Compiled);
else
searchRegex = new(searchQuery, RegexOptions.Compiled | RegexOptions.IgnoreCase);

await Task.Run(() => Parallel.ForEach(Data.GameObjects, CheckObjectRegex));
}
else
{
spriteNames = searchQuery.Split('\n', StringSplitOptions.RemoveEmptyEntries); // Shift+Enter -> \v
VladiStep marked this conversation as resolved.
Show resolved Hide resolved

for (int i = 0; i < spriteNames.Length; i++)
spriteNames[i] = spriteNames[i].Trim();

await Task.Run(() => Parallel.ForEach(Data.GameObjects, CheckObject));
}

string label = "Objects with ";
if (spriteNames?.Length > 1)
label += "any of entered sprite";
else
label += "a sprite" + (regexCheck ? $" whose name matches \"{searchQuery}\" (RegEx)" : $" named \"{searchQuery}\"");

string[] objectNames = Data.GameObjects.Select(x => x.Name?.Content).ToArray(); // for "OrderBy()" acceleration

await StopUpdater();
SimpleTextOutput("Search results.", label, string.Join('\n', resultList.Distinct().OrderBy(x => Array.IndexOf(objectNames, x))), true);

EnableUI();


void CheckObject(UndertaleGameObject obj)
{
string sprName = obj.Sprite?.Name?.Content;

if (sprName is not null && spriteNames.Contains(sprName))
resultList.Add(obj.Name.Content);

IncProgressP();
}
void CheckObjectRegex(UndertaleGameObject obj)
{
string sprName = obj.Sprite?.Name?.Content;

if (sprName is not null && searchRegex.Match(sprName).Success)
resultList.Add(obj.Name.Content);

IncProgressP();
}
2 changes: 1 addition & 1 deletion UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ public string SimpleTextInput(string titleText, string labelText, string default
input.Dispose();

if (result == System.Windows.Forms.DialogResult.OK)
return input.ReturnString; //values preserved after close
return input.ReturnString.Replace('\v', '\n'); //values preserved after close; Shift+Enter -> '\v'
else
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModTool/Repackers/CopySound.csx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ List<string> GetSplitStringsList(string assetType)
List<string> splitStringsList = new List<string>();
string InputtedText = "";
InputtedText = SimpleTextInput("Menu", "Enter the name(s) of the " + assetType + "(s)", InputtedText, true);
string[] IndividualLineArray = InputtedText.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
string[] IndividualLineArray = InputtedText.Split('\n', StringSplitOptions.RemoveEmptyEntries);
foreach (var OneLine in IndividualLineArray)
{
splitStringsList.Add(OneLine.Trim());
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModTool/Repackers/CopySoundInternal.csx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ List<string> GetSplitStringsList(string assetType)
List<string> splitStringsList = new List<string>();
string InputtedText = "";
InputtedText = SimpleTextInput("Menu", "Enter the name(s) of the " + assetType + "(s)", InputtedText, true);
string[] IndividualLineArray = InputtedText.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
string[] IndividualLineArray = InputtedText.Split('\n', StringSplitOptions.RemoveEmptyEntries);
foreach (var OneLine in IndividualLineArray)
{
splitStringsList.Add(OneLine.Trim());
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModTool/Repackers/CopySpriteBgFont.csx
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ List<string> GetSplitStringsList(string assetType)
List<string> splitStringsList = new List<string>();
string InputtedText = "";
InputtedText = SimpleTextInput("Menu", "Enter the name(s) of the " + assetType + "(s)", InputtedText, true);
string[] IndividualLineArray = InputtedText.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
string[] IndividualLineArray = InputtedText.Split('\n', StringSplitOptions.RemoveEmptyEntries);
foreach (var OneLine in IndividualLineArray)
{
splitStringsList.Add(OneLine.Trim());
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModTool/Repackers/CopySpriteBgFontInternal.csx
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ List<string> GetSplitStringsList(string assetType)
List<string> splitStringsList = new List<string>();
string InputtedText = "";
InputtedText = SimpleTextInput("Menu", "Enter the name(s) of the " + assetType + "(s)", InputtedText, true);
string[] IndividualLineArray = InputtedText.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
string[] IndividualLineArray = InputtedText.Split('\n', StringSplitOptions.RemoveEmptyEntries);
foreach (var OneLine in IndividualLineArray)
{
splitStringsList.Add(OneLine.Trim());
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModTool/Repackers/GameObjectCopy.csx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ List<string> GetSplitStringsList(string assetType)
List<string> splitStringsList = new List<string>();
string InputtedText = "";
InputtedText = SimpleTextInput("Menu", "Enter the name(s) of the " + assetType + "(s)", InputtedText, true);
string[] IndividualLineArray = InputtedText.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
string[] IndividualLineArray = InputtedText.Split('\n', StringSplitOptions.RemoveEmptyEntries);
foreach (var OneLine in IndividualLineArray)
{
splitStringsList.Add(OneLine.Trim());
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModTool/Repackers/GameObjectCopyInternal.csx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ List<string> GetSplitStringsList(string assetType)
List<string> splitStringsList = new List<string>();
string InputtedText = "";
InputtedText = SimpleTextInput("Menu", "Enter the name(s) of the " + assetType + "(s)", InputtedText, true);
string[] IndividualLineArray = InputtedText.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
string[] IndividualLineArray = InputtedText.Split('\n', StringSplitOptions.RemoveEmptyEntries);
foreach (var OneLine in IndividualLineArray)
{
splitStringsList.Add(OneLine.Trim());
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModTool/TechnicalScripts/FindUnknownFunctions.csx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if (unknownFunctions.Count > 0)
resultsToDisplay += (unknownFunctions[i] + "\r\n");
}
resultsToDisplay = SimpleTextInput("Prune Menu", "Delete one or more lines to remove those entries", resultsToDisplay, true);
string[] IndividualLineArray = resultsToDisplay.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
string[] IndividualLineArray = resultsToDisplay.Split('\n', StringSplitOptions.RemoveEmptyEntries);
foreach (var OneLine in IndividualLineArray)
{
unknownFunctions2.Add(OneLine.Trim());
Expand Down
4 changes: 4 additions & 0 deletions UndertaleModTool/UndertaleModTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
<None Update="CommunityScripts\FindObjectsWithSprite.csx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
<None Update="CommunityScripts\SafeBlaster.csx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModTool/Unpackers/DumpSpecificCode.csx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ List<String> gameObjectCandidates = new List<String>();
List<String> splitStringsList = new List<String>();
string InputtedText = "";
InputtedText = SimpleTextInput("Menu", "Enter object, script, or code entry names", InputtedText, true);
string[] IndividualLineArray = InputtedText.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
string[] IndividualLineArray = InputtedText.Split('\n', StringSplitOptions.RemoveEmptyEntries);
foreach (var OneLine in IndividualLineArray)
{
splitStringsList.Add(OneLine.Trim());
Expand Down