Skip to content

Commit

Permalink
Allow Minify With AcceptableRange
Browse files Browse the repository at this point in the history
  • Loading branch information
marcussacana committed Jul 13, 2023
1 parent c663732 commit 2b7aadd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
32 changes: 24 additions & 8 deletions StringReloads/Engine/Match/BasicMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ public bool HasValue(string String)
{

string Minified = String;
string UnmodifiedMinified = null;

if (!Engine.Settings.FastMode)
{
UnmodifiedMinified = Engine.Minify(String);
foreach (var Modifier in Engine.ReloadModifiers)
{
if (Modifier.CanRestore)
Expand All @@ -95,7 +97,10 @@ public bool HasValue(string String)
if (Engine.CurrentDatabase.HasKey(Minified))
return Engine.CurrentDatabase[Minified];

if (Engine.Settings.Hashset && !Engine.Hashset.Contains(String) && !Engine.Hashset.Contains(Minified))
if (UnmodifiedMinified != null && Engine.CurrentDatabase.HasKey(UnmodifiedMinified))
return Engine.CurrentDatabase[UnmodifiedMinified];

if (Engine.Settings.Hashset && !Engine.Hashset.Contains(String) && !Engine.Hashset.Contains(Minified) && !Engine.Hashset.Contains(UnmodifiedMinified))
return null;

for (int i = 0; i < Engine.Databases.Count; i++)
Expand All @@ -106,6 +111,13 @@ public bool HasValue(string String)
Log.Trace($"Database Changed to {Engine.Databases[i].Name} (ID: {i})");
return Engine.Databases[i][Minified];
}

if (UnmodifiedMinified != null && Engine.Databases[i].HasKey(UnmodifiedMinified))
{
Engine.CurrentDatabaseIndex = i;
Log.Trace($"Database Changed to {Engine.Databases[i].Name} (ID: {i})");
return Engine.Databases[i][UnmodifiedMinified];
}
}

if (Engine.Settings.Dump)
Expand All @@ -121,17 +133,12 @@ void DumpString(string String, string Minified)
if (Engine.Settings.Filter.DumpFilter && !String.IsDialogue(UseAcceptableRange: Engine.Settings.Filter.DumpAcceptableRange))
return;

if (DumpCache.Contains(Minified))
return;

DumpCache.Add(Minified);

if (DefaultLST == null)
{
string LSTPath = Path.Combine(Engine.Settings.WorkingDirectory, "Strings.lst");
if (File.Exists(LSTPath))
{
using (var Reader = new StreamReader(File.Open(LSTPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)))
using (var Reader = new StreamReader(File.Open(LSTPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)))
{
while (Reader.Peek() != -1)
{
Expand All @@ -141,9 +148,18 @@ void DumpString(string String, string Minified)
Reader.Close();
}
}
DefaultLST = new StreamWriter(File.Open(LSTPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite));

var FStream = File.Open(LSTPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
FStream.Seek(0, SeekOrigin.End);

DefaultLST = new StreamWriter(FStream);
}

if (DumpCache.Contains(Minified))
return;

DumpCache.Add(Minified);

String = String.Trim().Replace("\n", LSTParser.BreakLine).Replace("\r", LSTParser.ReturnLine);

DefaultLST.WriteLine(String);
Expand Down
1 change: 1 addition & 0 deletions StringReloads/SRL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ RemapAlt=false
UndoRemap=false

[Modifiers]
AcceptableRangeMinify=false
Escape=false
MonoWordWrap=false
Remaper=false
Expand Down
20 changes: 20 additions & 0 deletions StringReloads/StringModifier/Minify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ namespace StringReloads.StringModifier
{
class Minify : IStringModifier
{
public Minify() {
Config.Default.Modifiers.TryGetValue("acceptablerangeminify", out AcceptableRange);
}
public static Minify Default = new Minify();

bool AcceptableRange;
public string Name => "Minify";

public bool CanRestore => false;
Expand All @@ -26,6 +30,22 @@ public string Apply(string String, string Original)
if (char.IsWhiteSpace(Char))
break;

if (AcceptableRange)
{
bool Valid = false;
foreach (var Range in Config.Default.Filter.AcceptableRange)
{
if (Char >= Range.Begin && Char <= Range.End)
{
Valid = true;
break;
}
}

if (!Valid)
break;
}

Rst += char.ToLowerInvariant(Char);
break;
}
Expand Down

0 comments on commit 2b7aadd

Please sign in to comment.